made better use of Ui::trayActivated() so it can not only display the
context menu, it will also show the app when double clicked. AudFile::getDuration() and AudFile::duration() can now calculate the length of the audio based on the rate at which QMediaPlayer calls AudFile::seek() and the amount of data it pulls at a time. it converts that time internally to a string, where it is then used to display on Ui::timeDisp. i've also modified the minimize to tray function as a feasure that can be turned on/off within Conf and added the needed check box to the config menu.
This commit is contained in:
parent
2fa5bc7bf3
commit
c3ec7e7085
19
gui/ui.cpp
19
gui/ui.cpp
|
@ -5,6 +5,7 @@ Ui::Ui(const QStringList &args, QWidget *parent) : QWidget(parent)
|
|||
QWidget *btnWid = new QWidget(this);
|
||||
QHBoxLayout *btnLayout = new QHBoxLayout(btnWid);
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
||||
QLabel *timeDisp = new QLabel("00:00:00", this);
|
||||
Icon *trayPausePlay = new Icon(Icon::PAUSE_PLAY, this);
|
||||
Icon *trayOpen = new Icon(Icon::OPEN, this);
|
||||
Icon *trayStop = new Icon(Icon::STOP, this);
|
||||
|
@ -38,7 +39,7 @@ Ui::Ui(const QStringList &args, QWidget *parent) : QWidget(parent)
|
|||
fileName->setText(tr("Ready"));
|
||||
fileName->setFont(fnt);
|
||||
slider->setOrientation(Qt::Horizontal);
|
||||
trayIcon->show();
|
||||
trayIcon->setVisible(conf->trayIcon());
|
||||
trayIcon->setContextMenu(trayMenu);
|
||||
conf->populateOptionsMenu(menu, this);
|
||||
player->setVolume(conf->getVolume());
|
||||
|
@ -56,6 +57,7 @@ Ui::Ui(const QStringList &args, QWidget *parent) : QWidget(parent)
|
|||
btnLayout->addWidget(settings);
|
||||
mainLayout->addWidget(fileName);
|
||||
mainLayout->addWidget(slider);
|
||||
mainLayout->addWidget(timeDisp, 0, Qt::AlignCenter);
|
||||
mainLayout->addWidget(btnWid, 0, Qt::AlignCenter);
|
||||
|
||||
connect(trayRestore, SIGNAL(restore()), this, SLOT(showNormal()));
|
||||
|
@ -75,11 +77,13 @@ Ui::Ui(const QStringList &args, QWidget *parent) : QWidget(parent)
|
|||
connect(player, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(error(QMediaPlayer::Error)));
|
||||
connect(player, SIGNAL(stateChanged(QMediaPlayer::State)), pausePlay, SLOT(stateChanged(QMediaPlayer::State)));
|
||||
connect(player, SIGNAL(stateChanged(QMediaPlayer::State)), trayPausePlay, SLOT(stateChanged(QMediaPlayer::State)));
|
||||
connect(ioDev, SIGNAL(duration(QString)), timeDisp, SLOT(setText(QString)));
|
||||
connect(ioDev, SIGNAL(posChanged(qint64)), this, SLOT(posChanged(qint64)));
|
||||
connect(ioDev, SIGNAL(endOfPlayback()), this, SLOT(nextFile()));
|
||||
connect(slider, SIGNAL(sliderPressed()), this, SLOT(sliderPressed()));
|
||||
connect(slider, SIGNAL(sliderReleased()), this, SLOT(sliderReleased()));
|
||||
connect(conf, SIGNAL(volume(int)), player, SLOT(setVolume(int)));
|
||||
connect(conf, SIGNAL(enableTrayIcon(bool)), trayIcon, SLOT(setVisible(bool)));
|
||||
|
||||
if (args.size() > 1)
|
||||
{
|
||||
|
@ -224,14 +228,21 @@ void Ui::fileDir(char direction)
|
|||
|
||||
void Ui::trayActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
Q_UNUSED(reason);
|
||||
|
||||
if (reason == QSystemTrayIcon::DoubleClick)
|
||||
{
|
||||
showNormal();
|
||||
raise();
|
||||
activateWindow();
|
||||
}
|
||||
else if (reason == QSystemTrayIcon::Trigger)
|
||||
{
|
||||
trayMenu->popup(trayIcon->geometry().center());
|
||||
}
|
||||
}
|
||||
|
||||
void Ui::changeEvent(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::WindowStateChange)
|
||||
if ((event->type() == QEvent::WindowStateChange) && conf->trayIcon())
|
||||
{
|
||||
if (windowState() & Qt::WindowMinimized)
|
||||
{
|
||||
|
|
|
@ -96,9 +96,13 @@ qint64 AudFile::getOffset()
|
|||
return offset;
|
||||
}
|
||||
|
||||
qint64 AudFile::getDuration()
|
||||
QString AudFile::getDuration()
|
||||
{
|
||||
return ((size() - offset) / buffRate) * 1000;
|
||||
QTime time(0, 0, 0, 0);
|
||||
|
||||
time = time.addMSecs((size() / buffRate) * 1000);
|
||||
|
||||
return time.toString("hh:mm:ss");
|
||||
}
|
||||
|
||||
void AudFile::delayFinished()
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
#include <QTime>
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
|
||||
class AudFile : public QFile
|
||||
{
|
||||
|
@ -29,7 +31,7 @@ public:
|
|||
bool openFile(const QString &path);
|
||||
bool seek(qint64 off);
|
||||
qint64 getOffset();
|
||||
qint64 getDuration();
|
||||
QString getDuration();
|
||||
|
||||
~AudFile();
|
||||
|
||||
|
@ -37,7 +39,7 @@ signals:
|
|||
|
||||
void posChanged(qint64 off);
|
||||
void endOfPlayback();
|
||||
void duration(qint64 msec);
|
||||
void duration(QString timeStr);
|
||||
};
|
||||
|
||||
#endif // AUD_FILE_H
|
||||
|
|
24
io/conf.cpp
24
io/conf.cpp
|
@ -23,7 +23,6 @@ QWidget *MenuItem::createWidget(QWidget *parent)
|
|||
layout->addWidget(new QLabel(str, parent));
|
||||
|
||||
return widget;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,12 +45,15 @@ Conf::Conf(QObject *parent) : QObject(parent)
|
|||
|
||||
QByteArray pathBa = idm.value(LAST_PATH);
|
||||
QByteArray nextBa = idm.value(NEXT_FILE);
|
||||
QByteArray trayBa = idm.value(TRAY_ICON);
|
||||
QByteArray volBa = idm.value(VOLUME);
|
||||
|
||||
if (!pathBa.isEmpty()) lastPath = pathBa;
|
||||
else lastPath = QDir::homePath();
|
||||
if (!nextBa.isEmpty()) nextFileState = (nextBa == "Y");
|
||||
else nextFileState = true;
|
||||
if (!trayBa.isEmpty()) showTrayIcon = (trayBa == "Y");
|
||||
else showTrayIcon = false;
|
||||
if (!volBa.isEmpty()) volumeValue = rdInt(volBa);
|
||||
else volumeValue = 50;
|
||||
}
|
||||
|
@ -67,6 +69,9 @@ void Conf::sync()
|
|||
if (nextFileState) idm.insert(NEXT_FILE, "Y");
|
||||
else idm.insert(NEXT_FILE, "N");
|
||||
|
||||
if (showTrayIcon) idm.insert(TRAY_ICON, "Y");
|
||||
else idm.insert(TRAY_ICON, "N");
|
||||
|
||||
QFile file(confPath(), this);
|
||||
|
||||
file.open(QFile::WriteOnly | QFile::Truncate);
|
||||
|
@ -79,6 +84,7 @@ void Conf::populateOptionsMenu(QMenu *menu, QWidget *parent)
|
|||
QHBoxLayout *volLayout = new QHBoxLayout(volWidget);
|
||||
QSlider *volSlider = new QSlider(parent);
|
||||
QCheckBox *nextBox = new QCheckBox(parent);
|
||||
QCheckBox *trayBox = new QCheckBox(parent);
|
||||
Icon *volUp = new Icon(Icon::VOL_UP, parent);
|
||||
Icon *volDown = new Icon(Icon::VOL_DOWN, parent);
|
||||
|
||||
|
@ -93,13 +99,17 @@ void Conf::populateOptionsMenu(QMenu *menu, QWidget *parent)
|
|||
volLayout->addWidget(volUp);
|
||||
nextBox->setText(tr("Auto play next file in directory"));
|
||||
nextBox->setChecked(nextFile());
|
||||
trayBox->setText(tr("Enable tray icon"));
|
||||
trayBox->setChecked(trayIcon());
|
||||
|
||||
connect(volSlider, SIGNAL(valueChanged(int)), this, SLOT(setVolume(int)));
|
||||
connect(volSlider, SIGNAL(valueChanged(int)), this, SIGNAL(volume(int)));
|
||||
connect(nextBox, SIGNAL(clicked(bool)), this, SLOT(setNextFile(bool)));
|
||||
connect(trayBox, SIGNAL(clicked(bool)), this, SLOT(setTrayIcon(bool)));
|
||||
|
||||
menu->addAction(new MenuItem("", volWidget, this));
|
||||
menu->addAction(new MenuItem("", nextBox, this));
|
||||
menu->addAction(new MenuItem("", trayBox, this));
|
||||
}
|
||||
|
||||
void Conf::setLastPath(const QString &path)
|
||||
|
@ -112,6 +122,13 @@ void Conf::setNextFile(bool state)
|
|||
nextFileState = state; sync();
|
||||
}
|
||||
|
||||
void Conf::setTrayIcon(bool state)
|
||||
{
|
||||
emit enableTrayIcon(state);
|
||||
|
||||
showTrayIcon = state; sync();
|
||||
}
|
||||
|
||||
void Conf::setVolume(int value)
|
||||
{
|
||||
emit volume(value);
|
||||
|
@ -134,6 +151,11 @@ bool Conf::nextFile()
|
|||
return nextFileState;
|
||||
}
|
||||
|
||||
bool Conf::trayIcon()
|
||||
{
|
||||
return showTrayIcon;
|
||||
}
|
||||
|
||||
int Conf::getVolume()
|
||||
{
|
||||
return volumeValue;
|
||||
|
|
|
@ -42,10 +42,12 @@ private:
|
|||
{
|
||||
LAST_PATH = 1,
|
||||
NEXT_FILE,
|
||||
VOLUME
|
||||
VOLUME,
|
||||
TRAY_ICON
|
||||
};
|
||||
|
||||
QString lastPath;
|
||||
bool showTrayIcon;
|
||||
bool nextFileState;
|
||||
int volumeValue;
|
||||
|
||||
|
@ -57,11 +59,13 @@ public slots:
|
|||
void setLastPath(const QString &path);
|
||||
void setNextFile(bool state);
|
||||
void setVolume(int value);
|
||||
void setTrayIcon(bool state);
|
||||
|
||||
public:
|
||||
|
||||
QString getLastPath();
|
||||
bool nextFile();
|
||||
bool trayIcon();
|
||||
void populateOptionsMenu(QMenu *menu, QWidget *parent);
|
||||
int getVolume();
|
||||
|
||||
|
@ -69,7 +73,8 @@ public:
|
|||
|
||||
signals:
|
||||
|
||||
void volume(int);
|
||||
void volume(int value);
|
||||
void enableTrayIcon(bool state);
|
||||
};
|
||||
|
||||
#endif // CONF_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user