From 0b08d3e6b3e714c49cc3aec38a3abc0221d47128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Panzenb=C3=B6ck?= Date: Mon, 17 Feb 2014 23:13:12 +0100 Subject: [PATCH] make floating icon translucent and frame less --- src/icon.cpp | 28 +++++++++++++++------------- src/icon.h | 11 ++++++----- src/layout.cpp | 7 ++++--- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/icon.cpp b/src/icon.cpp index 224f83a..8685036 100644 --- a/src/icon.cpp +++ b/src/icon.cpp @@ -1,25 +1,26 @@ +#include + #include "icon.h" #include "config.h" -FloatingIcon::FloatingIcon( const QPixmap &icon, QMenu *popup, QWidget *parent, const char *name) - : QDialog( parent ) { +FloatingIcon::FloatingIcon( const QString &icon, QMenu *popup, QWidget *parent, const char *name) + : QDialog( parent ), icon(icon) { this->setObjectName(name); + setAttribute(Qt::WA_QuitOnClose); + setAttribute(Qt::WA_TranslucentBackground); + setWindowFlags(Qt::FramelessWindowHint); setWindowTitle(QJOYPAD_NAME); - QPalette palette; - palette.setBrush(backgroundRole(), QBrush(icon)); - setPalette(palette); - //setPaletteBackgroundPixmap(icon); pop = popup; setFixedSize(64,64); } -void FloatingIcon::mousePressEvent( QMouseEvent* e ) { +void FloatingIcon::mousePressEvent( QMouseEvent* event ) { //if it was the right mouse button, - if (e->button() == Qt::RightButton) { + if (event->button() == Qt::RightButton) { //bring up the popup menu. - pop->popup( e->globalPos() ); - e->accept(); + pop->popup( event->globalPos() ); + event->accept(); } else { //otherwise, treat it as a regular click. @@ -27,7 +28,8 @@ void FloatingIcon::mousePressEvent( QMouseEvent* e ) { } } -void FloatingIcon::closeEvent( QCloseEvent* e ) { - emit closed(); - e->accept(); +void FloatingIcon::paintEvent( QPaintEvent* event ) { + Q_UNUSED(event); + QPainter painter(this); + painter.drawPixmap(0, 0, icon); } diff --git a/src/icon.h b/src/icon.h index feb7d91..e009564 100644 --- a/src/icon.h +++ b/src/icon.h @@ -12,14 +12,15 @@ class FloatingIcon : public QDialog { Q_OBJECT public: - FloatingIcon( const QPixmap &icon, QMenu *popup = 0, QWidget *parent = 0, const char *name = 0); - signals: - void closed(); + FloatingIcon( const QString &icon, QMenu *popup = 0, QWidget *parent = 0, const char *name = 0); + signals: void clicked(); protected: - void mousePressEvent( QMouseEvent* e ); - void closeEvent( QCloseEvent* e ); + void paintEvent(QPaintEvent* event); + void mousePressEvent(QMouseEvent* event); + private: QMenu* pop; + QPixmap icon; }; #endif diff --git a/src/layout.cpp b/src/layout.cpp index 6ee135b..ad46d77 100644 --- a/src/layout.cpp +++ b/src/layout.cpp @@ -29,9 +29,10 @@ LayoutManager::LayoutManager( bool useTrayIcon, const QString &devdir, const QSt } //or make a floating icon else { - FloatingIcon* icon = new FloatingIcon(QPixmap(QJOYPAD_ICON64),&trayMenu,0,"tray"); - connect(icon, SIGNAL( clicked()), this, SLOT( iconClick())); - connect(icon, SIGNAL( closed()), qApp, SLOT( quit())); + FloatingIcon* icon = new FloatingIcon(QJOYPAD_ICON64,&trayMenu,0,"tray"); + connect(icon, SIGNAL(clicked()), this, SLOT(iconClick())); + connect(icon, SIGNAL(rejected()), qApp, SLOT(quit())); + connect(icon, SIGNAL(accepted()), qApp, SLOT(quit())); icon->show(); }