File indexing completed on 2024-11-24 05:00:55

0001 /*  This file is part of the KDE libraries
0002     SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 #ifndef KDEPLATFORMSYSTEMTRAYICON_H
0007 #define KDEPLATFORMSYSTEMTRAYICON_H
0008 
0009 #include <QVariant>
0010 #include <qpa/qplatformmenu.h>
0011 #include <qpa/qplatformsystemtrayicon.h>
0012 
0013 class KStatusNotifierItem;
0014 class SystemTrayMenuItem;
0015 class QAction;
0016 class QMenu;
0017 
0018 class SystemTrayMenu : public QPlatformMenu
0019 {
0020     Q_OBJECT
0021 public:
0022     SystemTrayMenu();
0023     ~SystemTrayMenu() override;
0024     void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) override;
0025     QPlatformMenuItem *menuItemAt(int position) const override;
0026     QPlatformMenuItem *menuItemForTag(quintptr tag) const override;
0027     void removeMenuItem(QPlatformMenuItem *menuItem) override;
0028     void setEnabled(bool enabled) override;
0029     void setIcon(const QIcon &icon) override;
0030     void setTag(quintptr tag) override;
0031     void setText(const QString &text) override;
0032     void setVisible(bool visible) override;
0033     void syncMenuItem(QPlatformMenuItem *menuItem) override;
0034     void syncSeparatorsCollapsible(bool enable) override;
0035     quintptr tag() const override;
0036     QPlatformMenuItem *createMenuItem() const override;
0037     QPlatformMenu *createSubMenu() const override;
0038 
0039     QMenu *menu();
0040 
0041 private:
0042     void createMenu();
0043 
0044     QString m_text;
0045     QIcon m_icon;
0046     QVariant m_enabled;
0047     QVariant m_visible;
0048     QVariant m_separatorsCollapsible;
0049     quintptr m_tag;
0050     QPointer<QMenu> m_menu;
0051     QList<SystemTrayMenuItem *> m_items;
0052 };
0053 
0054 class SystemTrayMenuItem : public QPlatformMenuItem
0055 {
0056     Q_OBJECT
0057 public:
0058     SystemTrayMenuItem();
0059     ~SystemTrayMenuItem() override;
0060     void setCheckable(bool checkable) override;
0061     void setChecked(bool isChecked) override;
0062     void setEnabled(bool enabled) override;
0063     void setFont(const QFont &font) override;
0064     void setIcon(const QIcon &icon) override;
0065     void setIsSeparator(bool isSeparator) override;
0066     void setMenu(QPlatformMenu *menu) override;
0067     void setRole(MenuRole role) override;
0068     void setShortcut(const QKeySequence &shortcut) override;
0069     void setTag(quintptr tag) override;
0070     void setText(const QString &text) override;
0071     void setVisible(bool isVisible) override;
0072     quintptr tag() const override;
0073     void setIconSize(int size) override;
0074     void setHasExclusiveGroup(bool hasExclusiveGroup) override;
0075 
0076     QAction *action() const;
0077 
0078 private:
0079     quintptr m_tag;
0080     QAction *m_action = nullptr;
0081 };
0082 
0083 class KDEPlatformSystemTrayIcon : public QPlatformSystemTrayIcon
0084 {
0085 public:
0086     KDEPlatformSystemTrayIcon();
0087     ~KDEPlatformSystemTrayIcon() override;
0088 
0089     void init() override;
0090     void cleanup() override;
0091     void updateIcon(const QIcon &icon) override;
0092     void updateToolTip(const QString &tooltip) override;
0093     void updateMenu(QPlatformMenu *menu) override;
0094     QRect geometry() const override;
0095     void showMessage(const QString &title, const QString &msg, const QIcon &icon, MessageIcon iconType, int secs) override;
0096 
0097     bool isSystemTrayAvailable() const override;
0098     bool supportsMessages() const override;
0099 
0100     QPlatformMenu *createMenu() const override;
0101 
0102 private:
0103     KStatusNotifierItem *m_sni = nullptr;
0104 };
0105 
0106 #endif