summaryrefslogtreecommitdiffstats
path: root/toolwindow.cpp
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2017-03-25 09:01:41 +0100
committerArno <arno@disconnect.de>2017-03-25 09:01:41 +0100
commitbe7f32353d736ff1dc1f74ae80e301ce72044dee (patch)
tree46e0bdc022605058031da77c2d9e1b6edd39411d /toolwindow.cpp
parenta55b7eb7a765f09f0e83e9d3ce5696f540b6bd9b (diff)
downloadBeetPlayer-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...
Diffstat (limited to 'toolwindow.cpp')
-rw-r--r--toolwindow.cpp45
1 files changed, 45 insertions, 0 deletions
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();
+}