|
QtPass 2.0.0
Developer documentation
|
Handles the system tray icon and menu. More...
#include <trayicon.h>
Public Slots | |
| void | showHideParent () |
| Toggle the visibility of the associated main window. | |
| void | iconActivated (QSystemTrayIcon::ActivationReason reason) |
| Handle activation events from the system tray icon. | |
Public Member Functions | |
| TrayIcon (QMainWindow *parent) | |
| Construct a TrayIcon associated with the given main window. | |
| auto | getIsAllocated () -> bool |
| Check whether tray resources have been allocated and initialized. | |
| void | addToggle (QAction *action) |
| Put one of the window's toggles in the tray menu, above Quit. | |
Private Member Functions | |
| void | createActions () |
| Create the Show/Hide/Minimize/Maximize/Restore/Quit actions and wire each one to the matching QWidget slot of the main window (Quit goes to QApplication::quit()). | |
| void | createTrayIcon () |
| Build the context menu from the actions and create the QSystemTrayIcon that pops it up. Called only when a system tray is available. | |
Private Attributes | |
| QAction * | showAction {nullptr} |
| Shows the main window (QWidget::show()). | |
| QAction * | hideAction {nullptr} |
| Hides the main window (QWidget::hide()). | |
| QAction * | minimizeAction {nullptr} |
| Minimises the main window. | |
| QAction * | maximizeAction {nullptr} |
| Maximises the main window. | |
| QAction * | restoreAction {nullptr} |
| Restores the main window to its normal size. | |
| QAction * | quitAction {nullptr} |
| Quits the application. | |
| QAction * | quitSeparator {nullptr} |
| Separator directly above Quit; addToggle() inserts the window's toggles (each with its own separator) in front of it. | |
| QSystemTrayIcon * | sysTrayIcon {nullptr} |
| The icon in the notification area; owned by this object so it is destroyed, and the icon removed, when the main window goes away. Null when no system tray is available. | |
| QMenu * | trayIconMenu {nullptr} |
| Context menu of the tray icon; a child of the main window because QMenu needs a widget parent. Null when no system tray is available. | |
| QMainWindow * | parentwin |
| The main window the actions and showHideParent() operate on. | |
| bool | isAllocated {false} |
| true once the actions, menu and icon exist; stays false when QSystemTrayIcon::isSystemTrayAvailable() was false at construction. | |
Handles the system tray icon and menu.
A QObject parented to the main window: nothing here is a widget (the menu and the QSystemTrayIcon are children of this object), and the parent makes sure ~QSystemTrayIcon runs on quit, which is what removes the icon from the notification area on Windows.
Definition at line 28 of file trayicon.h.
|
explicit |
Construct a TrayIcon associated with the given main window.
| parent | Pointer to the QMainWindow this tray icon controls. |
Definition at line 16 of file trayicon.cpp.
| void TrayIcon::addToggle | ( | QAction * | action | ) |
Put one of the window's toggles in the tray menu, above Quit.
| action | The window's own action, so its checked state is the same in both places. Ignored when there is no tray. |
Definition at line 76 of file trayicon.cpp.
|
private |
Create the Show/Hide/Minimize/Maximize/Restore/Quit actions and wire each one to the matching QWidget slot of the main window (Quit goes to QApplication::quit()).
Definition at line 40 of file trayicon.cpp.
|
private |
Build the context menu from the actions and create the QSystemTrayIcon that pops it up. Called only when a system tray is available.
Definition at line 60 of file trayicon.cpp.
| auto TrayIcon::getIsAllocated | ( | ) | -> bool |
Check whether tray resources have been allocated and initialized.
Definition at line 38 of file trayicon.cpp.
|
slot |
Handle activation events from the system tray icon.
| reason | The activation reason provided by QSystemTrayIcon. |
Definition at line 92 of file trayicon.cpp.
|
slot |
Toggle the visibility of the associated main window.
Definition at line 84 of file trayicon.cpp.
|
private |
Hides the main window (QWidget::hide()).
Definition at line 83 of file trayicon.h.
|
private |
true once the actions, menu and icon exist; stays false when QSystemTrayIcon::isSystemTrayAvailable() was false at construction.
Definition at line 117 of file trayicon.h.
|
private |
Maximises the main window.
Definition at line 87 of file trayicon.h.
|
private |
Minimises the main window.
Definition at line 85 of file trayicon.h.
|
private |
The main window the actions and showHideParent() operate on.
Definition at line 111 of file trayicon.h.
|
private |
Quits the application.
Definition at line 91 of file trayicon.h.
|
private |
Separator directly above Quit; addToggle() inserts the window's toggles (each with its own separator) in front of it.
Definition at line 96 of file trayicon.h.
|
private |
Restores the main window to its normal size.
Definition at line 89 of file trayicon.h.
|
private |
Shows the main window (QWidget::show()).
Definition at line 81 of file trayicon.h.
|
private |
The icon in the notification area; owned by this object so it is destroyed, and the icon removed, when the main window goes away. Null when no system tray is available.
Definition at line 103 of file trayicon.h.
|
private |
Context menu of the tray icon; a child of the main window because QMenu needs a widget parent. Null when no system tray is available.
Definition at line 109 of file trayicon.h.