make floating icon translucent and frame less
This commit is contained in:
28
src/icon.cpp
28
src/icon.cpp
@ -1,25 +1,26 @@
|
|||||||
|
#include <QPainter>
|
||||||
|
|
||||||
#include "icon.h"
|
#include "icon.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
FloatingIcon::FloatingIcon( const QPixmap &icon, QMenu *popup, QWidget *parent, const char *name)
|
FloatingIcon::FloatingIcon( const QString &icon, QMenu *popup, QWidget *parent, const char *name)
|
||||||
: QDialog( parent ) {
|
: QDialog( parent ), icon(icon) {
|
||||||
this->setObjectName(name);
|
this->setObjectName(name);
|
||||||
|
setAttribute(Qt::WA_QuitOnClose);
|
||||||
|
setAttribute(Qt::WA_TranslucentBackground);
|
||||||
|
setWindowFlags(Qt::FramelessWindowHint);
|
||||||
setWindowTitle(QJOYPAD_NAME);
|
setWindowTitle(QJOYPAD_NAME);
|
||||||
QPalette palette;
|
|
||||||
palette.setBrush(backgroundRole(), QBrush(icon));
|
|
||||||
setPalette(palette);
|
|
||||||
//setPaletteBackgroundPixmap(icon);
|
|
||||||
pop = popup;
|
pop = popup;
|
||||||
|
|
||||||
setFixedSize(64,64);
|
setFixedSize(64,64);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloatingIcon::mousePressEvent( QMouseEvent* e ) {
|
void FloatingIcon::mousePressEvent( QMouseEvent* event ) {
|
||||||
//if it was the right mouse button,
|
//if it was the right mouse button,
|
||||||
if (e->button() == Qt::RightButton) {
|
if (event->button() == Qt::RightButton) {
|
||||||
//bring up the popup menu.
|
//bring up the popup menu.
|
||||||
pop->popup( e->globalPos() );
|
pop->popup( event->globalPos() );
|
||||||
e->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//otherwise, treat it as a regular click.
|
//otherwise, treat it as a regular click.
|
||||||
@ -27,7 +28,8 @@ void FloatingIcon::mousePressEvent( QMouseEvent* e ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloatingIcon::closeEvent( QCloseEvent* e ) {
|
void FloatingIcon::paintEvent( QPaintEvent* event ) {
|
||||||
emit closed();
|
Q_UNUSED(event);
|
||||||
e->accept();
|
QPainter painter(this);
|
||||||
|
painter.drawPixmap(0, 0, icon);
|
||||||
}
|
}
|
||||||
|
11
src/icon.h
11
src/icon.h
@ -12,14 +12,15 @@
|
|||||||
class FloatingIcon : public QDialog {
|
class FloatingIcon : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
FloatingIcon( const QPixmap &icon, QMenu *popup = 0, QWidget *parent = 0, const char *name = 0);
|
FloatingIcon( const QString &icon, QMenu *popup = 0, QWidget *parent = 0, const char *name = 0);
|
||||||
signals:
|
signals:
|
||||||
void closed();
|
|
||||||
void clicked();
|
void clicked();
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent( QMouseEvent* e );
|
void paintEvent(QPaintEvent* event);
|
||||||
void closeEvent( QCloseEvent* e );
|
void mousePressEvent(QMouseEvent* event);
|
||||||
|
private:
|
||||||
QMenu* pop;
|
QMenu* pop;
|
||||||
|
QPixmap icon;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,9 +29,10 @@ LayoutManager::LayoutManager( bool useTrayIcon, const QString &devdir, const QSt
|
|||||||
}
|
}
|
||||||
//or make a floating icon
|
//or make a floating icon
|
||||||
else {
|
else {
|
||||||
FloatingIcon* icon = new FloatingIcon(QPixmap(QJOYPAD_ICON64),&trayMenu,0,"tray");
|
FloatingIcon* icon = new FloatingIcon(QJOYPAD_ICON64,&trayMenu,0,"tray");
|
||||||
connect(icon, SIGNAL( clicked()), this, SLOT( iconClick()));
|
connect(icon, SIGNAL(clicked()), this, SLOT(iconClick()));
|
||||||
connect(icon, SIGNAL( closed()), qApp, SLOT( quit()));
|
connect(icon, SIGNAL(rejected()), qApp, SLOT(quit()));
|
||||||
|
connect(icon, SIGNAL(accepted()), qApp, SLOT(quit()));
|
||||||
icon->show();
|
icon->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user