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