Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsystemtrayicon_qpa.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6
7#include <QtGui/qpa/qplatformsystemtrayicon.h>
8#include <qpa/qplatformtheme.h>
9#include <private/qguiapplication_p.h>
10#include <private/qhighdpiscaling_p.h>
11
12#include <QApplication>
13#include <QStyle>
14
15#ifndef QT_NO_SYSTEMTRAYICON
16
18
19QSystemTrayIconPrivate::QSystemTrayIconPrivate()
20 : qpa_sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon())
21 , visible(false), trayWatcher(nullptr)
22{
23}
24
29
31{
32 if (qpa_sys)
33 install_sys_qpa();
34}
35
37{
38 if (qpa_sys)
39 remove_sys_qpa();
40}
41
43{
44 if (!qpa_sys)
45 return QRect();
46 auto screen = QGuiApplication::primaryScreen();
47#if QT_CONFIG(menu)
48 if (menu)
49 screen = menu->screen();
50#endif
51 return QHighDpi::fromNativePixels(qpa_sys->geometry(), screen);
52}
53
55{
56 if (qpa_sys)
57 qpa_sys->updateIcon(icon);
58}
59
61{
62#if QT_CONFIG(menu)
63 if (qpa_sys) {
64 if (menu) {
65 addPlatformMenu(menu);
66 qpa_sys->updateMenu(menu->platformMenu());
67 } else {
68 qpa_sys->updateMenu(nullptr);
69 }
70 }
71#endif
72}
73
75{
76 if (qpa_sys)
77 qpa_sys->updateToolTip(toolTip);
78}
79
81{
82 QScopedPointer<QPlatformSystemTrayIcon> sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon());
83 if (sys)
84 return sys->isSystemTrayAvailable();
85 else
86 return false;
87}
88
90{
91 QScopedPointer<QPlatformSystemTrayIcon> sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon());
92 if (sys)
93 return sys->supportsMessages();
94 else
95 return false;
96}
97
98void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message,
99 const QIcon &icon, QSystemTrayIcon::MessageIcon msgIcon, int msecs)
100{
101 if (qpa_sys)
102 qpa_sys->showMessage(title, message, icon,
103 static_cast<QPlatformSystemTrayIcon::MessageIcon>(msgIcon), msecs);
104}
105
106QT_END_NAMESPACE
107
108#endif // QT_NO_SYSTEMTRAYICON
static bool isSystemTrayAvailable_sys()
QPlatformSystemTrayIcon * qpa_sys
void showMessage_sys(const QString &title, const QString &msg, const QIcon &icon, QSystemTrayIcon::MessageIcon msgIcon, int msecs)