1 | // Copyright (C) 2017 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 | |
4 | #include "qwidgetplatformsystemtrayicon_p.h" |
5 | #include "qwidgetplatformmenu_p.h" |
6 | |
7 | #include <QtWidgets/qsystemtrayicon.h> |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | QWidgetPlatformSystemTrayIcon::QWidgetPlatformSystemTrayIcon(QObject *parent) |
12 | : m_systray(new QSystemTrayIcon) |
13 | { |
14 | setParent(parent); |
15 | |
16 | connect(sender: m_systray.data(), signal: &QSystemTrayIcon::messageClicked, context: this, slot: &QPlatformSystemTrayIcon::messageClicked); |
17 | connect(sender: m_systray.data(), signal: &QSystemTrayIcon::activated, slot: [this](QSystemTrayIcon::ActivationReason reason) { |
18 | emit activated(reason: static_cast<ActivationReason>(reason)); |
19 | }); |
20 | } |
21 | |
22 | QWidgetPlatformSystemTrayIcon::~QWidgetPlatformSystemTrayIcon() |
23 | { |
24 | } |
25 | |
26 | void QWidgetPlatformSystemTrayIcon::init() |
27 | { |
28 | m_systray->show(); |
29 | } |
30 | |
31 | void QWidgetPlatformSystemTrayIcon::cleanup() |
32 | { |
33 | m_systray->hide(); |
34 | } |
35 | |
36 | void QWidgetPlatformSystemTrayIcon::updateIcon(const QIcon &icon) |
37 | { |
38 | m_systray->setIcon(icon); |
39 | } |
40 | |
41 | void QWidgetPlatformSystemTrayIcon::updateToolTip(const QString &tooltip) |
42 | { |
43 | m_systray->setToolTip(tooltip); |
44 | } |
45 | |
46 | void QWidgetPlatformSystemTrayIcon::(QPlatformMenu *) |
47 | { |
48 | #if QT_CONFIG(menu) |
49 | QWidgetPlatformMenu * = qobject_cast<QWidgetPlatformMenu *>(object: menu); |
50 | if (!widgetMenu) |
51 | return; |
52 | |
53 | m_systray->setContextMenu(widgetMenu->menu()); |
54 | #else |
55 | Q_UNUSED(menu); |
56 | #endif |
57 | } |
58 | |
59 | QRect QWidgetPlatformSystemTrayIcon::geometry() const |
60 | { |
61 | return m_systray->geometry(); |
62 | } |
63 | |
64 | void QWidgetPlatformSystemTrayIcon::showMessage(const QString &title, const QString &msg, const QIcon &icon, MessageIcon iconType, int msecs) |
65 | { |
66 | Q_UNUSED(icon); |
67 | m_systray->showMessage(title, msg, icon: static_cast<QSystemTrayIcon::MessageIcon>(iconType), msecs); |
68 | } |
69 | |
70 | bool QWidgetPlatformSystemTrayIcon::isSystemTrayAvailable() const |
71 | { |
72 | return QSystemTrayIcon::isSystemTrayAvailable(); |
73 | } |
74 | |
75 | bool QWidgetPlatformSystemTrayIcon::supportsMessages() const |
76 | { |
77 | return QSystemTrayIcon::supportsMessages(); |
78 | } |
79 | |
80 | QPlatformMenu *QWidgetPlatformSystemTrayIcon::() const |
81 | { |
82 | #if QT_CONFIG(menu) |
83 | return new QWidgetPlatformMenu; |
84 | #else |
85 | return nullptr; |
86 | #endif |
87 | } |
88 | |
89 | QT_END_NAMESPACE |
90 | |
91 | #include "moc_qwidgetplatformsystemtrayicon_p.cpp" |
92 | |