MCPcopy Create free account
hub / github.com/YACReader/yacreader / TrayIconController

Method TrayIconController

YACReaderLibrary/trayicon_controller.cpp:15–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13using namespace YACReader;
14
15TrayIconController::TrayIconController(QSettings *settings, LibraryWindow *window)
16 : QObject(nullptr), settings(settings), window(window)
17{
18
19 // If a window icon was set in main() we reuse it for the tray too.
20 // This allows support for third party icon themes on Freedesktop(Linux/Unix)
21 // systems.
22 if (!QApplication::windowIcon().isNull()) {
23 trayIcon.setIcon(QApplication::windowIcon());
24 } else {
25#ifdef Q_OS_WIN
26 trayIcon.setIcon(QIcon(":/icon.ico"));
27#else
28#ifdef Q_OS_MACOS
29 auto icon = QIcon(":/macostrayicon.svg");
30 icon.setIsMask(true);
31 trayIcon.setIcon(icon);
32#else
33 trayIcon.setIcon(QIcon(":/images/iconLibrary.png"));
34#endif
35#endif
36 }
37
38 connect(&trayIcon, &QSystemTrayIcon::activated, this,
39 [=](QSystemTrayIcon::ActivationReason reason) {
40#ifdef Q_OS_LINUX
41 auto expectedReason = QSystemTrayIcon::Trigger;
42#else
43 auto expectedReason = QSystemTrayIcon::DoubleClick;
44#endif
45
46 if (reason == expectedReason) {
47 showWindow();
48 }
49 });
50
51 auto restoreAction = new QAction(tr("&Restore"), this);
52 connect(restoreAction, &QAction::triggered, this, &TrayIconController::showWindow);
53
54 trayIconMenu = new QMenu(this->window);
55 trayIconMenu->addAction(restoreAction);
56 trayIconMenu->addSeparator();
57 trayIconMenu->addAction(this->window->actions.quitAction);
58
59 trayIcon.setContextMenu(trayIconMenu);
60
61 updateIconVisibility();
62}
63
64void TrayIconController::updateIconVisibility()
65{

Callers

nothing calls this directly

Calls 3

QIconClass · 0.85
setIconMethod · 0.80
addActionMethod · 0.80

Tested by

no test coverage detected