QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
trayicon.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2015 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
8#ifndef SRC_TRAYICON_H_
9#define SRC_TRAYICON_H_
10
11#include <QObject>
12#include <QSystemTrayIcon>
13
14class QAction;
15class QMainWindow;
16class QMenu;
17
28class TrayIcon : public QObject {
29 Q_OBJECT
30
31public:
36 explicit TrayIcon(QMainWindow *parent);
37
42 auto getIsAllocated() -> bool;
43
49 void addToggle(QAction *action);
50
51signals:
52
53public slots:
57 void showHideParent();
58
63 void iconActivated(QSystemTrayIcon::ActivationReason reason);
64
65private:
71 void createActions();
72
78 void createTrayIcon();
79
81 QAction *showAction{nullptr};
83 QAction *hideAction{nullptr};
85 QAction *minimizeAction{nullptr};
87 QAction *maximizeAction{nullptr};
89 QAction *restoreAction{nullptr};
91 QAction *quitAction{nullptr};
96 QAction *quitSeparator{nullptr};
97
103 QSystemTrayIcon *sysTrayIcon{nullptr};
109 QMenu *trayIconMenu{nullptr};
111 QMainWindow *parentwin;
112
117 bool isAllocated{false};
118};
119
120#endif // SRC_TRAYICON_H_
QAction * hideAction
Hides the main window (QWidget::hide()).
Definition trayicon.h:83
void showHideParent()
Toggle the visibility of the associated main window.
Definition trayicon.cpp:84
void createActions()
Create the Show/Hide/Minimize/Maximize/Restore/Quit actions and wire each one to the matching QWidget...
Definition trayicon.cpp:40
void iconActivated(QSystemTrayIcon::ActivationReason reason)
Handle activation events from the system tray icon.
Definition trayicon.cpp:92
QAction * restoreAction
Restores the main window to its normal size.
Definition trayicon.h:89
void addToggle(QAction *action)
Put one of the window's toggles in the tray menu, above Quit.
Definition trayicon.cpp:76
TrayIcon(QMainWindow *parent)
Construct a TrayIcon associated with the given main window.
Definition trayicon.cpp:16
QSystemTrayIcon * sysTrayIcon
The icon in the notification area; owned by this object so it is destroyed, and the icon removed,...
Definition trayicon.h:103
QAction * maximizeAction
Maximises the main window.
Definition trayicon.h:87
QAction * quitSeparator
Separator directly above Quit; addToggle() inserts the window's toggles (each with its own separator)...
Definition trayicon.h:96
QMenu * trayIconMenu
Context menu of the tray icon; a child of the main window because QMenu needs a widget parent....
Definition trayicon.h:109
bool isAllocated
true once the actions, menu and icon exist; stays false when QSystemTrayIcon::isSystemTrayAvailable()...
Definition trayicon.h:117
void createTrayIcon()
Build the context menu from the actions and create the QSystemTrayIcon that pops it up....
Definition trayicon.cpp:60
QAction * minimizeAction
Minimises the main window.
Definition trayicon.h:85
QMainWindow * parentwin
The main window the actions and showHideParent() operate on.
Definition trayicon.h:111
QAction * showAction
Shows the main window (QWidget::show()).
Definition trayicon.h:81
auto getIsAllocated() -> bool
Check whether tray resources have been allocated and initialized.
Definition trayicon.cpp:38
QAction * quitAction
Quits the application.
Definition trayicon.h:91