diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2015-06-09 00:54:24 +0200 |
---|---|---|
committer | Anne Jan Brouwer <brouwer@annejan.com> | 2015-06-09 00:54:24 +0200 |
commit | 783e6b4a6b19223bc54cd99f0101d4131aab7048 (patch) | |
tree | 64631057aeed852b33f94dc09f92c3c68953da81 /trayicon.cpp | |
parent | 64898b575f9e7c3b5d4d072fc369a66d2c2397ee (diff) |
trying old trayicon code
Diffstat (limited to 'trayicon.cpp')
-rw-r--r-- | trayicon.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/trayicon.cpp b/trayicon.cpp new file mode 100644 index 00000000..452560fa --- /dev/null +++ b/trayicon.cpp @@ -0,0 +1,84 @@ +#include "trayicon.h" + +trayIcon::trayIcon(QMainWindow *parent) +{ + parentwin = parent; + + createActions(); + createTrayIcon(); + + sysTrayIcon->setIcon(QIcon(":/artwork/logo.png")); + + sysTrayIcon->show(); + + QObject::connect(sysTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), + this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); + +} + +void trayIcon::setVisible(bool visible) +{ + if(visible == true) { + parentwin->show(); + } else { + parentwin->hide(); + } +} + +void trayIcon::createActions() +{ + minimizeAction = new QAction(tr("Mi&nimize"), this); + connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide())); + + maximizeAction = new QAction(tr("Ma&ximize"), this); + connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized())); + + restoreAction = new QAction(tr("&Restore"), this); + connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal())); + + quitAction = new QAction(tr("&Quit"), this); + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); +} + + +void trayIcon::createTrayIcon() +{ + trayIconMenu = new QMenu(this); + trayIconMenu->addAction(minimizeAction); + trayIconMenu->addAction(maximizeAction); + trayIconMenu->addAction(restoreAction); + trayIconMenu->addSeparator(); + trayIconMenu->addAction(quitAction); + + sysTrayIcon = new QSystemTrayIcon(this); + sysTrayIcon->setContextMenu(trayIconMenu); +} + +void trayIcon::showHideParent() +{ + if(parentwin->isVisible() == true) { + parentwin->hide(); + } else { + parentwin->show(); + } +} + +void trayIcon::iconActivated(QSystemTrayIcon::ActivationReason reason) +{ + switch (reason) { + case QSystemTrayIcon::Trigger: + case QSystemTrayIcon::DoubleClick: + showHideParent(); + break; + case QSystemTrayIcon::MiddleClick: + showMessage("test", "test msg", 1000); + break; + default: + ; + } +} + +void trayIcon::showMessage(QString title, QString msg, int time) +{ + sysTrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, time); +} |