Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquicklabsplatformsystemtrayicon.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
7
8#include <QtCore/qloggingcategory.h>
9#include <QtGui/qpa/qplatformtheme.h>
10#include <QtGui/private/qguiapplication_p.h>
11
13
15
20
133Q_LOGGING_CATEGORY(qtLabsPlatformTray, "qt.labs.platform.tray")
134
136 : QObject(parent),
137 m_complete(false),
138 m_visible(false),
139 m_menu(nullptr),
140 m_iconLoader(nullptr),
141 m_handle(nullptr)
142{
144 if (!m_handle)
146 qCDebug(qtLabsPlatformTray) << "SystemTrayIcon ->" << m_handle;
147
148 if (m_handle) {
151 }
152}
153
155{
156 if (m_menu)
157 m_menu->setSystemTrayIcon(nullptr);
158 cleanup();
159 delete m_iconLoader;
160 m_iconLoader = nullptr;
161 delete m_handle;
162 m_handle = nullptr;
163}
164
166{
167 return m_handle;
168}
169
177{
178 return m_handle && m_handle->isSystemTrayAvailable();
179}
180
190{
191 return m_handle && m_handle->supportsMessages();
192}
193
202{
203 return m_visible;
204}
205
207{
208 if (m_visible == visible)
209 return;
210
211 if (m_handle && m_complete) {
212 if (visible)
213 init();
214 else
215 cleanup();
216 }
217
218 m_visible = visible;
220}
221
228{
229 return m_tooltip;
230}
231
233{
234 if (m_tooltip == tooltip)
235 return;
236
237 if (m_handle && m_complete)
238 m_handle->updateToolTip(tooltip);
239
240 m_tooltip = tooltip;
242}
243
250{
251 return m_menu;
252}
253
255{
256 if (m_menu == menu)
257 return;
258
259 if (m_menu)
260 m_menu->setSystemTrayIcon(nullptr);
261 if (menu) {
262 menu->setSystemTrayIcon(this);
263 if (m_handle && m_complete && menu->create())
264 m_handle->updateMenu(menu->handle());
265 }
266
267 m_menu = menu;
269}
270
278{
279 return m_handle ? m_handle->geometry() : QRect();
280}
281
298{
299 if (!m_iconLoader)
300 return QQuickLabsPlatformIcon();
301
302 return m_iconLoader->icon();
303}
304
306{
307 if (iconLoader()->icon() == icon)
308 return;
309
311 emit iconChanged();
312}
313
320{
321 setVisible(true);
322}
323
330{
331 setVisible(false);
332}
333
347{
348 if (m_handle)
349 m_handle->showMessage(title, msg, QIcon(), icon, msecs);
350}
351
353{
354 if (!m_handle)
355 return;
356
357 m_handle->init();
358 if (m_menu && m_menu->create())
359 m_handle->updateMenu(m_menu->handle());
360 m_handle->updateToolTip(m_tooltip);
361 if (m_iconLoader)
362 m_iconLoader->setEnabled(true);
363}
364
366{
367 if (m_handle)
368 m_handle->cleanup();
369 if (m_iconLoader)
370 m_iconLoader->setEnabled(false);
371}
372
374{
375}
376
378{
379 m_complete = true;
380 if (m_visible)
381 init();
382}
383
385{
386 if (!m_iconLoader) {
388 static int slot = staticMetaObject.indexOfSlot("updateIcon()");
389 m_iconLoader = new QQuickLabsPlatformIconLoader(slot, that);
390 m_iconLoader->setEnabled(m_complete);
391 }
392 return m_iconLoader;
393}
394
395void QQuickLabsPlatformSystemTrayIcon::updateIcon()
396{
397 if (!m_handle || !m_iconLoader)
398 return;
399
400 const QRect oldGeometry = m_handle->geometry();
401
402 m_handle->updateIcon(m_iconLoader->toQIcon());
403
404 if (oldGeometry != m_handle->geometry())
405 emit geometryChanged();
406}
407
409
410#include "moc_qquicklabsplatformsystemtrayicon_p.cpp"
static QPlatformTheme * platformTheme()
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
\inmodule QtCore
Definition qobject.h:90
MessageIcon
This enum describes the icon that is shown when a balloon message is displayed.
virtual void cleanup()=0
This method is called to cleanup the platform dependent implementation.
virtual void updateIcon(const QIcon &icon)=0
This method is called when the icon did change.
virtual bool isSystemTrayAvailable() const =0
Returns true if the system tray is available on the platform.
void activated(QPlatformSystemTrayIcon::ActivationReason reason)
This signal is emitted when the user activates the system tray icon.
virtual void updateToolTip(const QString &tooltip)=0
This method is called when the tooltip text did change.
void messageClicked()
This signal is emitted when the message displayed using showMessage() was clicked by the user.
virtual void showMessage(const QString &title, const QString &msg, const QIcon &icon, MessageIcon iconType, int msecs)=0
Shows a balloon message for the entry with the given title, message msg and icon for the time specifi...
virtual QRect geometry() const =0
This method returns the geometry of the platform dependent system tray icon on the screen.
virtual bool supportsMessages() const =0
Returns true if the system tray supports messages on the platform.
virtual void updateMenu(QPlatformMenu *menu)=0
This method is called when the system tray menu did change.
virtual void init()=0
This method is called to initialize the platform dependent implementation.
virtual QPlatformSystemTrayIcon * createPlatformSystemTrayIcon() const
Factory function for QSystemTrayIcon.
void setIcon(const QQuickLabsPlatformIcon &icon)
QQuickLabsPlatformIcon icon() const
QPlatformMenu * handle() const
void hide()
\qmlmethod void Qt.labs.platform::SystemTrayIcon::hide()
bool isVisible() const
\qmlproperty bool Qt.labs.platform::SystemTrayIcon::visible
void showMessage(const QString &title, const QString &message, QPlatformSystemTrayIcon::MessageIcon iconType=QPlatformSystemTrayIcon::Information, int msecs=10000)
\qmlmethod void Qt.labs.platform::SystemTrayIcon::showMessage(string title, string message,...
void activated(QPlatformSystemTrayIcon::ActivationReason reason)
void classBegin() override
Invoked after class creation, but before any properties have been set.
QQuickLabsPlatformIconLoader * iconLoader() const
void show()
\qmlmethod void Qt.labs.platform::SystemTrayIcon::show()
bool isAvailable() const
\readonly \qmlproperty bool Qt.labs.platform::SystemTrayIcon::available
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void setIcon(const QQuickLabsPlatformIcon &icon)
\inmodule QtCore\reentrant
Definition qrect.h:30
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
Combined button and popup list for selecting options.
static QPlatformSystemTrayIcon * createSystemTrayIcon(QObject *parent=nullptr)
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
#define emit
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
QString title
[35]
QMenu menu
[5]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent