aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/platform/widgets
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-06-21 15:43:06 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-06-22 19:51:33 +0000
commitaafe27dd091db7560758b727c3e28263d0a2edcd (patch)
tree982f7dae7f49d1ceb28220d3e2c91fc26c9c95d2 /src/imports/platform/widgets
parentab3f016fb34b5ec0d62b8d3bf9bb6349eeea320d (diff)
SystemTrayIcon: use widgets as a fallback
This makes system tray icons available on Windows and KDE. One more reason to keep the module experimental. In the long run, platforms should implement QPA system trays so that we can remove the undesired dependency. Change-Id: Ibc30f881525cd14091affc996104c65310c0a13e Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/imports/platform/widgets')
-rw-r--r--src/imports/platform/widgets/qwidgetplatformsystemtrayicon.cpp123
-rw-r--r--src/imports/platform/widgets/qwidgetplatformsystemtrayicon_p.h85
-rw-r--r--src/imports/platform/widgets/widgets.pri6
3 files changed, 212 insertions, 2 deletions
diff --git a/src/imports/platform/widgets/qwidgetplatformsystemtrayicon.cpp b/src/imports/platform/widgets/qwidgetplatformsystemtrayicon.cpp
new file mode 100644
index 00000000..b8aff340
--- /dev/null
+++ b/src/imports/platform/widgets/qwidgetplatformsystemtrayicon.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs Platform module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qwidgetplatformsystemtrayicon_p.h"
+#include "qwidgetplatformmenu_p.h"
+#include "qwidgetplatform_p.h"
+
+#include <QtWidgets/qsystemtrayicon.h>
+
+QT_BEGIN_NAMESPACE
+
+QWidgetPlatformSystemTrayIcon::QWidgetPlatformSystemTrayIcon(QObject *parent)
+{
+ setParent(parent);
+
+ static bool available = QWidgetPlatform::isAvailable("system tray");
+ if (available) {
+ m_systray.reset(new QSystemTrayIcon);
+ connect(m_systray.data(), &QSystemTrayIcon::messageClicked, this, &QPlatformSystemTrayIcon::messageClicked);
+ connect(m_systray.data(), &QSystemTrayIcon::activated, [this](QSystemTrayIcon::ActivationReason reason) {
+ emit activated(static_cast<ActivationReason>(reason));
+ });
+ }
+}
+
+QWidgetPlatformSystemTrayIcon::~QWidgetPlatformSystemTrayIcon()
+{
+}
+
+void QWidgetPlatformSystemTrayIcon::init()
+{
+ if (m_systray)
+ m_systray->show();
+}
+
+void QWidgetPlatformSystemTrayIcon::cleanup()
+{
+ if (m_systray)
+ m_systray->hide();
+}
+
+void QWidgetPlatformSystemTrayIcon::updateIcon(const QIcon &icon)
+{
+ if (m_systray)
+ m_systray->setIcon(icon);
+}
+
+void QWidgetPlatformSystemTrayIcon::updateToolTip(const QString &tooltip)
+{
+ if (m_systray)
+ m_systray->setToolTip(tooltip);
+}
+
+void QWidgetPlatformSystemTrayIcon::updateMenu(QPlatformMenu *menu)
+{
+ QWidgetPlatformMenu *widgetMenu = qobject_cast<QWidgetPlatformMenu *>(menu);
+ if (!widgetMenu || !m_systray)
+ return;
+
+ m_systray->setContextMenu(widgetMenu->menu());
+}
+
+QRect QWidgetPlatformSystemTrayIcon::geometry() const
+{
+ return m_systray ? m_systray->geometry() : QRect();
+}
+
+void QWidgetPlatformSystemTrayIcon::showMessage(const QString &title, const QString &msg, const QIcon &icon, MessageIcon iconType, int msecs)
+{
+ Q_UNUSED(icon);
+ if (m_systray)
+ m_systray->showMessage(title, msg, static_cast<QSystemTrayIcon::MessageIcon>(iconType), msecs);
+}
+
+bool QWidgetPlatformSystemTrayIcon::isSystemTrayAvailable() const
+{
+ return m_systray && QSystemTrayIcon::isSystemTrayAvailable();
+}
+
+bool QWidgetPlatformSystemTrayIcon::supportsMessages() const
+{
+ return m_systray && QSystemTrayIcon::supportsMessages();
+}
+
+QPlatformMenu *QWidgetPlatformSystemTrayIcon::createMenu() const
+{
+ return new QWidgetPlatformMenu;
+}
+
+QT_END_NAMESPACE
diff --git a/src/imports/platform/widgets/qwidgetplatformsystemtrayicon_p.h b/src/imports/platform/widgets/qwidgetplatformsystemtrayicon_p.h
new file mode 100644
index 00000000..905d8b82
--- /dev/null
+++ b/src/imports/platform/widgets/qwidgetplatformsystemtrayicon_p.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs Platform module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWIDGETPLATFORMSYSTEMTRAYICON_P_H
+#define QWIDGETPLATFORMSYSTEMTRAYICON_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtGui/qpa/qplatformsystemtrayicon.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSystemTrayIcon;
+
+class QWidgetPlatformSystemTrayIcon : public QPlatformSystemTrayIcon
+{
+ Q_OBJECT
+
+public:
+ explicit QWidgetPlatformSystemTrayIcon(QObject *parent = nullptr);
+ ~QWidgetPlatformSystemTrayIcon();
+
+ void init() override;
+ void cleanup() override;
+ void updateIcon(const QIcon &icon) override;
+ void updateToolTip(const QString &tooltip) override;
+ void updateMenu(QPlatformMenu *menu) override;
+ QRect geometry() const override;
+ void showMessage(const QString &title, const QString &msg,
+ const QIcon &icon, MessageIcon iconType, int msecs) override;
+
+ bool isSystemTrayAvailable() const override;
+ bool supportsMessages() const override;
+
+ QPlatformMenu *createMenu() const;
+
+private:
+ QScopedPointer<QSystemTrayIcon> m_systray;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWIDGETPLATFORMSYSTEMTRAYICON_P_H
diff --git a/src/imports/platform/widgets/widgets.pri b/src/imports/platform/widgets/widgets.pri
index 8759a655..a816d487 100644
--- a/src/imports/platform/widgets/widgets.pri
+++ b/src/imports/platform/widgets/widgets.pri
@@ -3,8 +3,10 @@ QT += widgets
HEADERS += \
$$PWD/qwidgetplatform_p.h \
$$PWD/qwidgetplatformmenu_p.h \
- $$PWD/qwidgetplatformmenuitem_p.h
+ $$PWD/qwidgetplatformmenuitem_p.h \
+ $$PWD/qwidgetplatformsystemtrayicon_p.h
SOURCES += \
$$PWD/qwidgetplatformmenu.cpp \
- $$PWD/qwidgetplatformmenuitem.cpp
+ $$PWD/qwidgetplatformmenuitem.cpp \
+ $$PWD/qwidgetplatformsystemtrayicon.cpp