1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWidgets module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qsystemtrayicon_p.h"
41
42#include <QtGui/qpa/qplatformsystemtrayicon.h>
43#include <qpa/qplatformtheme.h>
44#include <private/qguiapplication_p.h>
45#include <private/qhighdpiscaling_p.h>
46
47#include <QApplication>
48#include <QStyle>
49
50#ifndef QT_NO_SYSTEMTRAYICON
51
52QT_BEGIN_NAMESPACE
53
54QSystemTrayIconPrivate::QSystemTrayIconPrivate()
55 : qpa_sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon())
56 , visible(false), trayWatcher(nullptr)
57{
58}
59
60QSystemTrayIconPrivate::~QSystemTrayIconPrivate()
61{
62 delete qpa_sys;
63}
64
65void QSystemTrayIconPrivate::install_sys()
66{
67 if (qpa_sys)
68 install_sys_qpa();
69}
70
71void QSystemTrayIconPrivate::remove_sys()
72{
73 if (qpa_sys)
74 remove_sys_qpa();
75}
76
77QRect QSystemTrayIconPrivate::geometry_sys() const
78{
79 if (!qpa_sys)
80 return QRect();
81 auto screen = QGuiApplication::primaryScreen();
82#if QT_CONFIG(menu)
83 if (menu)
84 screen = menu->screen();
85#endif
86 return QHighDpi::fromNativePixels(qpa_sys->geometry(), screen);
87}
88
89void QSystemTrayIconPrivate::updateIcon_sys()
90{
91 if (qpa_sys)
92 qpa_sys->updateIcon(icon);
93}
94
95void QSystemTrayIconPrivate::updateMenu_sys()
96{
97#if QT_CONFIG(menu)
98 if (qpa_sys && menu) {
99 addPlatformMenu(menu);
100 qpa_sys->updateMenu(menu->platformMenu());
101 }
102#endif
103}
104
105void QSystemTrayIconPrivate::updateToolTip_sys()
106{
107 if (qpa_sys)
108 qpa_sys->updateToolTip(toolTip);
109}
110
111bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys()
112{
113 QScopedPointer<QPlatformSystemTrayIcon> sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon());
114 if (sys)
115 return sys->isSystemTrayAvailable();
116 else
117 return false;
118}
119
120bool QSystemTrayIconPrivate::supportsMessages_sys()
121{
122 QScopedPointer<QPlatformSystemTrayIcon> sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon());
123 if (sys)
124 return sys->supportsMessages();
125 else
126 return false;
127}
128
129void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message,
130 const QIcon &icon, QSystemTrayIcon::MessageIcon msgIcon, int msecs)
131{
132 if (qpa_sys)
133 qpa_sys->showMessage(title, message, icon,
134 static_cast<QPlatformSystemTrayIcon::MessageIcon>(msgIcon), msecs);
135}
136
137QT_END_NAMESPACE
138
139#endif // QT_NO_SYSTEMTRAYICON
140