312 lines
8.6 KiB
Diff
312 lines
8.6 KiB
Diff
|
--- a/src/widgets/util/qsystemtrayicon.cpp
|
||
|
+++ b/src/widgets/util/qsystemtrayicon.cpp
|
||
|
@@ -672,6 +672,74 @@
|
||
|
QWidget::timerEvent(e);
|
||
|
}
|
||
|
|
||
|
+//////////////////////////////////////////////////////////////////////
|
||
|
+void QSystemTrayIconPrivate::install_sys_qpa()
|
||
|
+{
|
||
|
+ qpa_sys->init();
|
||
|
+ QObject::connect(qpa_sys, SIGNAL(activated(QPlatformSystemTrayIcon::ActivationReason)),
|
||
|
+ q_func(), SLOT(_q_emitActivated(QPlatformSystemTrayIcon::ActivationReason)));
|
||
|
+ QObject::connect(qpa_sys, &QPlatformSystemTrayIcon::messageClicked,
|
||
|
+ q_func(), &QSystemTrayIcon::messageClicked);
|
||
|
+ updateMenu_sys();
|
||
|
+ updateIcon_sys();
|
||
|
+ updateToolTip_sys();
|
||
|
+}
|
||
|
+
|
||
|
+void QSystemTrayIconPrivate::remove_sys_qpa()
|
||
|
+{
|
||
|
+ qpa_sys->cleanup();
|
||
|
+}
|
||
|
+
|
||
|
+QRect QSystemTrayIconPrivate::geometry_sys_qpa() const
|
||
|
+{
|
||
|
+ return qpa_sys->geometry();
|
||
|
+}
|
||
|
+
|
||
|
+void QSystemTrayIconPrivate::updateIcon_sys_qpa()
|
||
|
+{
|
||
|
+ qpa_sys->updateIcon(icon);
|
||
|
+}
|
||
|
+
|
||
|
+void QSystemTrayIconPrivate::updateMenu_sys_qpa()
|
||
|
+{
|
||
|
+ if (menu) {
|
||
|
+ if (!menu->platformMenu()) {
|
||
|
+ QPlatformMenu *platformMenu = qpa_sys->createMenu();
|
||
|
+ if (platformMenu)
|
||
|
+ menu->setPlatformMenu(platformMenu);
|
||
|
+ }
|
||
|
+ qpa_sys->updateMenu(menu->platformMenu());
|
||
|
+ }
|
||
|
+}
|
||
|
+
|
||
|
+void QSystemTrayIconPrivate::updateToolTip_sys_qpa()
|
||
|
+{
|
||
|
+ qpa_sys->updateToolTip(toolTip);
|
||
|
+}
|
||
|
+
|
||
|
+void QSystemTrayIconPrivate::showMessage_sys_qpa(const QString &message,
|
||
|
+ const QString &title,
|
||
|
+ QSystemTrayIcon::MessageIcon icon,
|
||
|
+ int msecs)
|
||
|
+{
|
||
|
+ QIcon notificationIcon;
|
||
|
+ switch (icon) {
|
||
|
+ case QSystemTrayIcon::Information:
|
||
|
+ notificationIcon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation);
|
||
|
+ break;
|
||
|
+ case QSystemTrayIcon::Warning:
|
||
|
+ notificationIcon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning);
|
||
|
+ break;
|
||
|
+ case QSystemTrayIcon::Critical:
|
||
|
+ notificationIcon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical);
|
||
|
+ break;
|
||
|
+ default:
|
||
|
+ break;
|
||
|
+ }
|
||
|
+ qpa_sys->showMessage(message, title, notificationIcon,
|
||
|
+ static_cast<QPlatformSystemTrayIcon::MessageIcon>(icon), msecs);
|
||
|
+}
|
||
|
+
|
||
|
QT_END_NAMESPACE
|
||
|
|
||
|
#endif // QT_NO_SYSTEMTRAYICON
|
||
|
--- a/src/widgets/util/qsystemtrayicon_p.h
|
||
|
+++ b/src/widgets/util/qsystemtrayicon_p.h
|
||
|
@@ -98,6 +98,15 @@
|
||
|
QSystemTrayIconSys *sys;
|
||
|
QPlatformSystemTrayIcon *qpa_sys;
|
||
|
bool visible;
|
||
|
+
|
||
|
+private:
|
||
|
+ void install_sys_qpa();
|
||
|
+ void remove_sys_qpa();
|
||
|
+ void updateIcon_sys_qpa();
|
||
|
+ void updateToolTip_sys_qpa();
|
||
|
+ void updateMenu_sys_qpa();
|
||
|
+ QRect geometry_sys_qpa() const;
|
||
|
+ void showMessage_sys_qpa(const QString &msg, const QString &title, QSystemTrayIcon::MessageIcon icon, int secs);
|
||
|
};
|
||
|
|
||
|
class QBalloonTip : public QWidget
|
||
|
--- a/src/widgets/util/qsystemtrayicon_qpa.cpp
|
||
|
+++ b/src/widgets/util/qsystemtrayicon_qpa.cpp
|
||
|
@@ -65,28 +65,20 @@
|
||
|
|
||
|
void QSystemTrayIconPrivate::install_sys()
|
||
|
{
|
||
|
- if (qpa_sys) {
|
||
|
- qpa_sys->init();
|
||
|
- QObject::connect(qpa_sys, SIGNAL(activated(QPlatformSystemTrayIcon::ActivationReason)),
|
||
|
- q_func(), SLOT(_q_emitActivated(QPlatformSystemTrayIcon::ActivationReason)));
|
||
|
- QObject::connect(qpa_sys, SIGNAL(messageClicked()),
|
||
|
- q_func(), SIGNAL(messageClicked()));
|
||
|
- updateMenu_sys();
|
||
|
- updateIcon_sys();
|
||
|
- updateToolTip_sys();
|
||
|
- }
|
||
|
+ if (qpa_sys)
|
||
|
+ install_sys_qpa();
|
||
|
}
|
||
|
|
||
|
void QSystemTrayIconPrivate::remove_sys()
|
||
|
{
|
||
|
if (qpa_sys)
|
||
|
- qpa_sys->cleanup();
|
||
|
+ remove_sys_qpa();
|
||
|
}
|
||
|
|
||
|
QRect QSystemTrayIconPrivate::geometry_sys() const
|
||
|
{
|
||
|
if (qpa_sys)
|
||
|
- return qpa_sys->geometry();
|
||
|
+ return geometry_sys_qpa();
|
||
|
else
|
||
|
return QRect();
|
||
|
}
|
||
|
|
||
|
|
||
|
@@ -94,25 +86,19 @@
|
||
|
void QSystemTrayIconPrivate::updateIcon_sys()
|
||
|
{
|
||
|
if (qpa_sys)
|
||
|
- qpa_sys->updateIcon(icon);
|
||
|
+ updateIcon_sys_qpa();
|
||
|
}
|
||
|
|
||
|
void QSystemTrayIconPrivate::updateMenu_sys()
|
||
|
{
|
||
|
- if (qpa_sys && menu) {
|
||
|
- if (!menu->platformMenu()) {
|
||
|
- QPlatformMenu *platformMenu = qpa_sys->createMenu();
|
||
|
- if (platformMenu)
|
||
|
- menu->setPlatformMenu(platformMenu);
|
||
|
- }
|
||
|
- qpa_sys->updateMenu(menu->platformMenu());
|
||
|
- }
|
||
|
+ if (qpa_sys)
|
||
|
+ updateMenu_sys_qpa();
|
||
|
}
|
||
|
|
||
|
void QSystemTrayIconPrivate::updateToolTip_sys()
|
||
|
{
|
||
|
if (qpa_sys)
|
||
|
- qpa_sys->updateToolTip(toolTip);
|
||
|
+ updateToolTip_sys_qpa();
|
||
|
}
|
||
|
|
||
|
bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys()
|
||
|
@@ -138,25 +124,8 @@
|
||
|
QSystemTrayIcon::MessageIcon icon,
|
||
|
int msecs)
|
||
|
{
|
||
|
- if (!qpa_sys)
|
||
|
- return;
|
||
|
-
|
||
|
- QIcon notificationIcon;
|
||
|
- switch (icon) {
|
||
|
- case QSystemTrayIcon::Information:
|
||
|
- notificationIcon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation);
|
||
|
- break;
|
||
|
- case QSystemTrayIcon::Warning:
|
||
|
- notificationIcon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning);
|
||
|
- break;
|
||
|
- case QSystemTrayIcon::Critical:
|
||
|
- notificationIcon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical);
|
||
|
- break;
|
||
|
- default:
|
||
|
- break;
|
||
|
- }
|
||
|
- qpa_sys->showMessage(message, title, notificationIcon,
|
||
|
- static_cast<QPlatformSystemTrayIcon::MessageIcon>(icon), msecs);
|
||
|
+ if (qpa_sys)
|
||
|
+ showMessage_sys_qpa(message, title, icon, msecs);
|
||
|
}
|
||
|
|
||
|
QT_END_NAMESPACE
|
||
|
--- a/src/widgets/util/qsystemtrayicon_x11.cpp
|
||
|
+++ b/src/widgets/util/qsystemtrayicon_x11.cpp
|
||
|
@@ -55,6 +55,9 @@
|
||
|
#include <qscreen.h>
|
||
|
#include <qbackingstore.h>
|
||
|
#include <qpa/qplatformnativeinterface.h>
|
||
|
+#include <qpa/qplatformsystemtrayicon.h>
|
||
|
+#include <qpa/qplatformtheme.h>
|
||
|
+#include <private/qguiapplication_p.h>
|
||
|
#include <qdebug.h>
|
||
|
|
||
|
#ifndef QT_NO_SYSTEMTRAYICON
|
||
|
|
||
|
|
||
|
@@ -209,16 +212,22 @@
|
||
|
|
||
|
QSystemTrayIconPrivate::QSystemTrayIconPrivate()
|
||
|
: sys(0),
|
||
|
+ qpa_sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon()),
|
||
|
visible(false)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
QSystemTrayIconPrivate::~QSystemTrayIconPrivate()
|
||
|
{
|
||
|
+ delete qpa_sys;
|
||
|
}
|
||
|
|
||
|
void QSystemTrayIconPrivate::install_sys()
|
||
|
{
|
||
|
+ if (qpa_sys) {
|
||
|
+ install_sys_qpa();
|
||
|
+ return;
|
||
|
+ }
|
||
|
Q_Q(QSystemTrayIcon);
|
||
|
if (!sys && locateSystemTray()) {
|
||
|
sys = new QSystemTrayIconSys(q);
|
||
|
@@ -229,6 +238,8 @@
|
||
|
|
||
|
QRect QSystemTrayIconPrivate::geometry_sys() const
|
||
|
{
|
||
|
+ if (qpa_sys)
|
||
|
+ return geometry_sys_qpa();
|
||
|
if (!sys)
|
||
|
return QRect();
|
||
|
return sys->globalGeometry();
|
||
|
@@ -236,6 +247,10 @@
|
||
|
|
||
|
void QSystemTrayIconPrivate::remove_sys()
|
||
|
{
|
||
|
+ if (qpa_sys) {
|
||
|
+ remove_sys_qpa();
|
||
|
+ return;
|
||
|
+ }
|
||
|
if (!sys)
|
||
|
return;
|
||
|
QBalloonTip::hideBalloon();
|
||
|
|
||
|
|
||
|
@@ -246,17 +261,26 @@
|
||
|
|
||
|
void QSystemTrayIconPrivate::updateIcon_sys()
|
||
|
{
|
||
|
+ if (qpa_sys) {
|
||
|
+ updateIcon_sys_qpa();
|
||
|
+ return;
|
||
|
+ }
|
||
|
if (sys)
|
||
|
sys->updateIcon();
|
||
|
}
|
||
|
|
||
|
void QSystemTrayIconPrivate::updateMenu_sys()
|
||
|
{
|
||
|
-
|
||
|
+ if (qpa_sys)
|
||
|
+ updateMenu_sys_qpa();
|
||
|
}
|
||
|
|
||
|
void QSystemTrayIconPrivate::updateToolTip_sys()
|
||
|
{
|
||
|
+ if (qpa_sys) {
|
||
|
+ updateToolTip_sys_qpa();
|
||
|
+ return;
|
||
|
+ }
|
||
|
if (!sys)
|
||
|
return;
|
||
|
#ifndef QT_NO_TOOLTIP
|
||
|
@@ -266,6 +290,11 @@
|
||
|
|
||
|
bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys()
|
||
|
{
|
||
|
+ QScopedPointer<QPlatformSystemTrayIcon> sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon());
|
||
|
+ if (sys)
|
||
|
+ return sys->isSystemTrayAvailable();
|
||
|
+
|
||
|
+ // no QPlatformSystemTrayIcon so fall back to default xcb platform behavior
|
||
|
const QString platform = QGuiApplication::platformName();
|
||
|
if (platform.compare(QStringLiteral("xcb"), Qt::CaseInsensitive) == 0)
|
||
|
return locateSystemTray();
|
||
|
|
||
|
@@ -274,12 +303,21 @@
|
||
|
|
||
|
bool QSystemTrayIconPrivate::supportsMessages_sys()
|
||
|
{
|
||
|
+ QScopedPointer<QPlatformSystemTrayIcon> sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon());
|
||
|
+ if (sys)
|
||
|
+ return sys->supportsMessages();
|
||
|
+
|
||
|
+ // no QPlatformSystemTrayIcon so fall back to default xcb platform behavior
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void QSystemTrayIconPrivate::showMessage_sys(const QString &message, const QString &title,
|
||
|
QSystemTrayIcon::MessageIcon icon, int msecs)
|
||
|
{
|
||
|
+ if (qpa_sys) {
|
||
|
+ showMessage_sys_qpa(message, title, icon, msecs);
|
||
|
+ return;
|
||
|
+ }
|
||
|
if (!sys)
|
||
|
return;
|
||
|
const QPoint g = sys->globalGeometry().topLeft();
|