diff options
author | Arno <arno@disconnect.de> | 2017-04-09 04:10:32 +0200 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2017-04-09 04:10:32 +0200 |
commit | 5e69e8130c9f207e5f8e3222841e7771c56ccd24 (patch) | |
tree | 36823d71b03aea9eefac15fc9303518b6ae0b836 /playerwidget.cpp | |
parent | 8d0f7783a4db453ccb0ac5f05798f277f5c01f65 (diff) | |
download | BeetPlayer-5e69e8130c9f207e5f8e3222841e7771c56ccd24.tar.gz BeetPlayer-5e69e8130c9f207e5f8e3222841e7771c56ccd24.tar.bz2 BeetPlayer-5e69e8130c9f207e5f8e3222841e7771c56ccd24.zip |
Show volume as tray icon message
Use a QTimer to prevent the messages to pile up on every volume change.
Only show it when the timer isn't running. The timeout value of 500msecs
is totally arbitrary.
The mStarting thingy prevents showing the message twice while
constructing (setupGui and readSettings).
Diffstat (limited to 'playerwidget.cpp')
-rw-r--r-- | playerwidget.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/playerwidget.cpp b/playerwidget.cpp index 1e4a7c6..c476f93 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -20,6 +20,7 @@ #include <QMenu> #include <QMessageBox> #include <QInputDialog> +#include <QTimer> #include <QApplication> #include <algorithm> @@ -35,8 +36,10 @@ #include "helper.h" PlayerWidget::PlayerWidget(QWidget *parent) : QWidget(parent), mDurSecs(0), mPlayListLength(0){ + mStarting = true; setupGui(); createActions(); + mStarting = false; } PlayerWidget::~PlayerWidget(){ @@ -53,6 +56,9 @@ void PlayerWidget::setupGui(){ mTrayIcon = new QSystemTrayIcon(this); mTrayIcon->setIcon(QIcon(":/stop.png")); mTrayIcon->show(); + mVolumeTimer = new QTimer(this); + mVolumeTimer->setSingleShot(true); + connect(mVolumeTimer, &QTimer::timeout, this, &PlayerWidget::showVolume); //THE view mView = new BeetView; @@ -633,7 +639,7 @@ void PlayerWidget::doPlay(){ emit playModeChanged(tr("Playing")); emit setWinTitle(mCurWinTitle); mTrayIcon->setIcon(QIcon(":/play.png")); - mTrayIcon->setToolTip(mCurWinTitle); + mTrayIcon->setToolTip(mCurToolTip); return; } int playListCount = mPlayListModel->rowCount(); @@ -727,6 +733,12 @@ void PlayerWidget::volumeDown(){ adjustVolume(-2); } +void PlayerWidget::showVolume(){ + int volume = mVolumeSlider->value(); + QString msg = QString(tr("Volume: %1%")).arg(volume, 3, 10, QChar('0')); + mTrayIcon->showMessage(msg, QString(), QSystemTrayIcon::Information, 2000); +} + void PlayerWidget::adjustVolume(int by){ int curVol = mVolumeSlider->value(); int newVol = curVol + by; @@ -971,7 +983,7 @@ void PlayerWidget::playCurrent(const QModelIndex &index){ QString fullPath = index.data(FullPathRole).toString(); play(fullPath); mTrayIcon->setIcon(QIcon(":/play.png")); - mTrayIcon->setToolTip(mCurWinTitle); + mTrayIcon->setToolTip(mCurToolTip); } void PlayerWidget::play(const QString &fullPath){ @@ -1004,13 +1016,11 @@ void PlayerWidget::play(const QString &fullPath){ mCurrentTE->append(QString("%1 %2:%3").arg(tr("Length:"), -20).arg(minutes, 2, 10, QChar('0')).arg(seconds, 2, 10, QChar('0'))); QString msg = QString("File: %1").arg(fullPath); emit message(msg); - mCurWinTitle = QString(tr("%1 [%2 - %3 - %4]")).arg(qApp->applicationName()).arg(artist).arg(album).arg(title); + mCurWinTitle = QString(tr("%1 - [%2] - [%3] - [%4]")).arg(qApp->applicationName()).arg(artist).arg(album).arg(title); + mCurToolTip = QString(tr("%1: [%2] - [%3]")).arg(artist).arg(album).arg(title); + mTrayIcon->setToolTip(mCurToolTip); + mTrayIcon->showMessage(QString(tr("Now Playing:")), mCurToolTip, QSystemTrayIcon::Information, 5000); emit setWinTitle(mCurWinTitle); - QString toolStr; - toolStr.append("<html><body>"); - toolStr.append(QString("<p style=\"margin:7px;\"><span style=\"font-weight: bold; font-size: large;\">%1</span></p>").arg(artist)); - toolStr.append(QString("<p style=\"margin:7px;\"><span style=\"font-weight: normal; font-size: medium;\">%1</span></p>").arg(title)); - toolStr.append("</body></html>"); mPlayer->play(); mPlayA->setChecked(true); @@ -1020,7 +1030,11 @@ void PlayerWidget::play(const QString &fullPath){ void PlayerWidget::volumeChanged(int volume){ QString s = QString("%1 %").arg(volume, 3, 10, QChar('0')); mVolumePos->setText(s); - QString tool = QString(tr("Volume: %1")).arg(s); + if(!mStarting){ + if(!mVolumeTimer->isActive()){ + mVolumeTimer->start(500); + } + } } void PlayerWidget::mute(bool triggered){ @@ -1096,11 +1110,13 @@ void PlayerWidget::expandRecursive(const QModelIndex &idx){ } void PlayerWidget::readSettings(){ + mStarting = true; QSettings s; int vol = s.value("volume").toInt(); mVolumeSlider->setValue(vol); QString dir = s.value("folderdir", QDir::homePath()).toString(); mCurDir = dir; + mStarting = false; } void PlayerWidget::writeSettings(){ |