QtPass  1.2.1
Multi-platform GUI for pass, the standard unix password manager.
trayicon.cpp
Go to the documentation of this file.
1 #include "trayicon.h"
2 #include <QAction>
3 #include <QApplication>
4 #include <QMainWindow>
5 #include <QMenu>
6 
12 TrayIcon::TrayIcon(QMainWindow *parent) {
13  parentwin = parent;
14 
15  createActions();
16  createTrayIcon();
17 
18  sysTrayIcon->setIcon(
19  QIcon::fromTheme("qtpass-tray", QIcon(":/artwork/icon.png")));
20 
21  sysTrayIcon->show();
22 
23  QObject::connect(sysTrayIcon,
24  SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this,
25  SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
26 }
27 
32 void TrayIcon::setVisible(bool visible) {
33  if (visible == true)
34  parentwin->show();
35  else
36  parentwin->hide();
37 }
38 
42 void TrayIcon::createActions() {
43  showAction = new QAction(tr("&Show"), this);
44  connect(showAction, SIGNAL(triggered()), parentwin, SLOT(show()));
45  hideAction = new QAction(tr("&Hide"), this);
46  connect(hideAction, SIGNAL(triggered()), parentwin, SLOT(hide()));
47 
48  minimizeAction = new QAction(tr("Mi&nimize"), this);
49  connect(minimizeAction, SIGNAL(triggered()), parentwin,
50  SLOT(showMinimized()));
51  maximizeAction = new QAction(tr("Ma&ximize"), this);
52  connect(maximizeAction, SIGNAL(triggered()), parentwin,
53  SLOT(showMaximized()));
54  restoreAction = new QAction(tr("&Restore"), this);
55  connect(restoreAction, SIGNAL(triggered()), parentwin, SLOT(showNormal()));
56 
57  quitAction = new QAction(tr("&Quit"), this);
58  connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
59 }
60 
64 void TrayIcon::createTrayIcon() {
65  trayIconMenu = new QMenu(this);
66  trayIconMenu->addAction(showAction);
67  trayIconMenu->addAction(hideAction);
68  trayIconMenu->addAction(minimizeAction);
69  trayIconMenu->addAction(maximizeAction);
70  trayIconMenu->addAction(restoreAction);
71  trayIconMenu->addSeparator();
72  trayIconMenu->addAction(quitAction);
73 
74  sysTrayIcon = new QSystemTrayIcon(this);
75  sysTrayIcon->setContextMenu(trayIconMenu);
76 }
77 
82  if (parentwin->isVisible() == true)
83  parentwin->hide();
84  else
85  parentwin->show();
86 }
87 
92 void TrayIcon::iconActivated(QSystemTrayIcon::ActivationReason reason) {
93  switch (reason) {
94  case QSystemTrayIcon::Trigger:
95  case QSystemTrayIcon::DoubleClick:
97  break;
98  case QSystemTrayIcon::MiddleClick:
99  showMessage("test", "test msg", 1000);
100  break;
101  default: {};
102  }
103 }
104 
111 void TrayIcon::showMessage(QString title, QString msg, int time) {
112  sysTrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, time);
113 }
void setVisible(bool visible)
TrayIcon::setVisible show or hide the icon.
Definition: trayicon.cpp:32
TrayIcon(QMainWindow *parent)
TrayIcon::TrayIcon use a (system) tray icon with a nice QtPass logo on it (currently) only Quits...
Definition: trayicon.cpp:12
void showMessage(QString title, QString msg, int time)
TrayIcon::showMessage show a systray message for notification.
Definition: trayicon.cpp:111
void iconActivated(QSystemTrayIcon::ActivationReason reason)
TrayIcon::iconActivated you clicked on the trayicon.
Definition: trayicon.cpp:92
void showHideParent()
TrayIcon::showHideParent toggle app visibility.
Definition: trayicon.cpp:81