QtPass  1.2.0-pre
Multi-platform GUI for pass, the standard unix password manager.
trayicon.cpp
Go to the documentation of this file.
1 #include "trayicon.h"
2 
8 TrayIcon::TrayIcon(QMainWindow *parent) {
9  parentwin = parent;
10 
11  createActions();
12  createTrayIcon();
13 
14  sysTrayIcon->setIcon(QIcon(":/artwork/icon.png"));
15 
16  sysTrayIcon->show();
17 
18  QObject::connect(sysTrayIcon,
19  SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this,
20  SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
21 }
22 
27 void TrayIcon::setVisible(bool visible) {
28  if (visible == true)
29  parentwin->show();
30  else
31  parentwin->hide();
32 }
33 
37 void TrayIcon::createActions() {
38  showAction = new QAction(tr("&Show"), this);
39  connect(showAction, SIGNAL(triggered()), parentwin, SLOT(show()));
40  hideAction = new QAction(tr("&Hide"), this);
41  connect(hideAction, SIGNAL(triggered()), parentwin, SLOT(hide()));
42 
43  minimizeAction = new QAction(tr("Mi&nimize"), this);
44  connect(minimizeAction, SIGNAL(triggered()), parentwin,
45  SLOT(showMinimized()));
46  maximizeAction = new QAction(tr("Ma&ximize"), this);
47  connect(maximizeAction, SIGNAL(triggered()), parentwin,
48  SLOT(showMaximized()));
49  restoreAction = new QAction(tr("&Restore"), this);
50  connect(restoreAction, SIGNAL(triggered()), parentwin, SLOT(showNormal()));
51 
52  quitAction = new QAction(tr("&Quit"), this);
53  connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
54 }
55 
59 void TrayIcon::createTrayIcon() {
60  trayIconMenu = new QMenu(this);
61  trayIconMenu->addAction(showAction);
62  trayIconMenu->addAction(hideAction);
63  trayIconMenu->addAction(minimizeAction);
64  trayIconMenu->addAction(maximizeAction);
65  trayIconMenu->addAction(restoreAction);
66  trayIconMenu->addSeparator();
67  trayIconMenu->addAction(quitAction);
68 
69  sysTrayIcon = new QSystemTrayIcon(this);
70  sysTrayIcon->setContextMenu(trayIconMenu);
71 }
72 
77  if (parentwin->isVisible() == true)
78  parentwin->hide();
79  else
80  parentwin->show();
81 }
82 
87 void TrayIcon::iconActivated(QSystemTrayIcon::ActivationReason reason) {
88  switch (reason) {
89  case QSystemTrayIcon::Trigger:
90  case QSystemTrayIcon::DoubleClick:
92  break;
93  case QSystemTrayIcon::MiddleClick:
94  showMessage("test", "test msg", 1000);
95  break;
96  default: {};
97  }
98 }
99 
106 void TrayIcon::showMessage(QString title, QString msg, int time) {
107  sysTrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, time);
108 }
void setVisible(bool visible)
TrayIcon::setVisible show or hide the icon.
Definition: trayicon.cpp:27
TrayIcon(QMainWindow *parent)
TrayIcon::TrayIcon use a (system) tray icon with a nice QtPass logo on it (currently) only Quits...
Definition: trayicon.cpp:8
void showMessage(QString title, QString msg, int time)
TrayIcon::showMessage show a systray message for notification.
Definition: trayicon.cpp:106
void iconActivated(QSystemTrayIcon::ActivationReason reason)
TrayIcon::iconActivated you clicked on the trayicon.
Definition: trayicon.cpp:87
void showHideParent()
TrayIcon::showHideParent toggle app visibility.
Definition: trayicon.cpp:76