diff options
author | Arno <arno@disconnect.de> | 2017-03-25 09:01:41 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2017-03-25 09:01:41 +0100 |
commit | be7f32353d736ff1dc1f74ae80e301ce72044dee (patch) | |
tree | 46e0bdc022605058031da77c2d9e1b6edd39411d | |
parent | a55b7eb7a765f09f0e83e9d3ce5696f540b6bd9b (diff) | |
download | BeetPlayer-be7f32353d736ff1dc1f74ae80e301ce72044dee.tar.gz BeetPlayer-be7f32353d736ff1dc1f74ae80e301ce72044dee.tar.bz2 BeetPlayer-be7f32353d736ff1dc1f74ae80e301ce72044dee.zip |
Show Popup-Window on various occasions
When we play a new song, get paused, continue and change volume.
The hardest part was to display the QWidget on the current desktop.
Turns out KWindowSystem and Qt::ToolWindow don't work together well...
I should post that on my blog, I guess...
-rw-r--r-- | BeetPlayer.pro | 8 | ||||
-rw-r--r-- | playerwidget.cpp | 27 | ||||
-rw-r--r-- | playerwidget.h | 3 | ||||
-rw-r--r-- | toolwindow.cpp | 45 | ||||
-rw-r--r-- | toolwindow.h | 24 |
5 files changed, 104 insertions, 3 deletions
diff --git a/BeetPlayer.pro b/BeetPlayer.pro index bc8e1d3..15d495e 100644 --- a/BeetPlayer.pro +++ b/BeetPlayer.pro @@ -5,7 +5,7 @@ #------------------------------------------------- QT += core gui multimedia sql -QT += KGlobalAccel +QT += KGlobalAccel KWindowSystem greaterThan(QT_MAJOR_VERSION, 4): QT += widgets @@ -32,7 +32,8 @@ SOURCES += main.cpp\ playerwidget.cpp \ beetview.cpp \ indexerdialog.cpp \ - helper.cpp + helper.cpp \ + toolwindow.cpp HEADERS += beetplayer.h \ configurationdialog.h \ @@ -41,7 +42,8 @@ HEADERS += beetplayer.h \ playerwidget.h \ beetview.h \ indexerdialog.h \ - helper.h + helper.h \ + toolwindow.h LIBS += -ltag diff --git a/playerwidget.cpp b/playerwidget.cpp index f026bfe..035db06 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -31,6 +31,7 @@ #include "playerwidget.h" #include "beetview.h" #include "indexerdialog.h" +#include "toolwindow.h" #include "globals.h" #include "helper.h" @@ -54,6 +55,9 @@ void PlayerWidget::setupGui(){ mTrayIcon->setIcon(QIcon(":/stop.png")); mTrayIcon->show(); + //tool window + mToolWin = new ToolWindow; + //THE view mView = new BeetView; mView->setAlternatingRowColors(true); @@ -628,6 +632,8 @@ void PlayerWidget::doPlay(){ emit setWinTitle(mCurWinTitle); mTrayIcon->setIcon(QIcon(":/play.png")); mTrayIcon->setToolTip(mCurWinTitle); + mToolWin->toHTML(tr("[Continue...]")); + mToolWin->showMe(); return; } int playListCount = mPlayListModel->rowCount(); @@ -652,6 +658,8 @@ void PlayerWidget::doStop(){ emit setWinTitle(winTitle); mTrayIcon->setIcon(QIcon(":/stop.png")); mTrayIcon->setToolTip(tr("[Stopped]")); + mToolWin->toHTML("[Stopped]"); + mToolWin->showMe(); } void PlayerWidget::doPause(){ @@ -662,6 +670,8 @@ void PlayerWidget::doPause(){ emit setWinTitle(winTitle); mTrayIcon->setIcon(QIcon(":/pause.png")); mTrayIcon->setToolTip(tr("[Paused]")); + mToolWin->toHTML("[Paused]"); + mToolWin->showMe(); } void PlayerWidget::doPlayOrPause(){ @@ -1000,6 +1010,14 @@ void PlayerWidget::play(const QString &fullPath){ emit message(msg); mCurWinTitle = QString(tr("%1 [%2 - %3 - %4]")).arg(qApp->applicationName()).arg(artist).arg(album).arg(title); 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>"); + mToolWin->setText(toolStr); + mToolWin->showMe(); + mPlayer->play(); mPlayA->setChecked(true); emit playModeChanged(tr("Playing")); @@ -1008,10 +1026,19 @@ 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); + mToolWin->toHTML(tool); + mToolWin->showMe(); } void PlayerWidget::mute(bool triggered){ mPlayer->setMuted(triggered); + if(triggered){ + mToolWin->toHTML(tr("[Muted]")); + }else{ + mToolWin->toHTML(tr("[Unmuted]")); + } + mToolWin->showMe(); } void PlayerWidget::next(){ diff --git a/playerwidget.h b/playerwidget.h index 04e023a..606abc0 100644 --- a/playerwidget.h +++ b/playerwidget.h @@ -16,6 +16,8 @@ class QToolBar; class QAction; class BeetPlayerProxy; class BeetView; +class ToolWindow; +class QSystemTrayIcon; class PlayerWidget : public QWidget { Q_OBJECT @@ -117,6 +119,7 @@ class PlayerWidget : public QWidget { QString mCurDir; QString mCurWinTitle; QSystemTrayIcon *mTrayIcon; + ToolWindow *mToolWin; }; #endif // PLAYERWIDGET_H diff --git a/toolwindow.cpp b/toolwindow.cpp new file mode 100644 index 0000000..f32c15e --- /dev/null +++ b/toolwindow.cpp @@ -0,0 +1,45 @@ +#include <QLabel> +#include <QTimer> +#include <QHBoxLayout> +#include <QDesktopWidget> +#include <QApplication> +#include <kwindowsystem.h> + +#include "toolwindow.h" + +ToolWindow::ToolWindow(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f){ + setWindowOpacity(0.9); + mLabel = new QLabel; + mLabel->setFrameStyle(QFrame::Panel | QFrame::Plain); + mLabel->setFont(QFont("courier", 16, QFont::Bold)); + mLabel->setAlignment(Qt::AlignCenter); + QHBoxLayout *mainLayout = new QHBoxLayout; + mainLayout->addWidget(mLabel); + mHideTimer = new QTimer(this); + connect(mHideTimer, &QTimer::timeout, this, &QWidget::hide); + setLayout(mainLayout); + KWindowSystem::setOnAllDesktops(winId(), true); +} + +void ToolWindow::setText(const QString &text){ + mLabel->setText(text); +} + +void ToolWindow::toHTML(const QString &text){ + QString html; + html.append(QString("<p style=\"margin:7px;\"><span style=\"font-weight: bold; font-size: large;\">%1</span></p>").arg(text)); + mLabel->setText(html); +} + +void ToolWindow::showMe(){ + QDesktopWidget *dw = QApplication::desktop(); + QRect screenRect = dw->screenGeometry(QCursor::pos()); + QPoint screenCenter = screenRect.center(); + QPoint where(screenCenter.x() - width() / 2, 150); + move(where); + KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop()); + mHideTimer->stop(); + mHideTimer->start(5000); + show(); + raise(); +} diff --git a/toolwindow.h b/toolwindow.h new file mode 100644 index 0000000..7f8e621 --- /dev/null +++ b/toolwindow.h @@ -0,0 +1,24 @@ +#ifndef TOOLWINDOW_H +#define TOOLWINDOW_H + +#include <QWidget> + +class QLabel; +class QTimer; + +class ToolWindow : public QWidget { + Q_OBJECT + public: + explicit ToolWindow(QWidget *parent = 0, Qt::WindowFlags f = Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus); + + public slots: + void setText(const QString &text); + void toHTML(const QString &text); + void showMe(); + + private: + QLabel *mLabel; + QTimer *mHideTimer; +}; + +#endif // TOOLWINDOW_H |