1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #ifndef QDBUSPLATFORMMENU_H
41 #define QDBUSPLATFORMMENU_H
42
43 //
44 // W A R N I N G
45 // -------------
46 //
47 // This file is not part of the Qt API. It exists purely as an
48 // implementation detail. This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 //
54 // W A R N I N G
55 // -------------
56 //
57 // This file is part of the DBus menu support and is not meant to be used
58 // in applications. Usage of this API may make your code
59 // source and binary incompatible with future versions of Qt.
60 //
61
62 #include <qpa/qplatformmenu.h>
63 #include <QLoggingCategory>
64 #include "qdbusmenutypes_p.h"
65
66 QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(qLcMenu)67 Q_DECLARE_LOGGING_CATEGORY(qLcMenu)
68
69 class QDBusPlatformMenu;
70
71 class QDBusPlatformMenuItem : public QPlatformMenuItem
72 {
73 Q_OBJECT
74
75 public:
76 QDBusPlatformMenuItem();
77 ~QDBusPlatformMenuItem();
78
79 const QString text() const { return m_text; }
80 void setText(const QString &text) override;
81 QIcon icon() const { return m_icon; }
82 void setIcon(const QIcon &icon) override;
83 const QPlatformMenu *menu() const { return m_subMenu; }
84 void setMenu(QPlatformMenu *menu) override;
85 bool isEnabled() const { return m_isEnabled; }
86 void setEnabled(bool enabled) override;
87 bool isVisible() const { return m_isVisible; }
88 void setVisible(bool isVisible) override;
89 bool isSeparator() const { return m_isSeparator; }
90 void setIsSeparator(bool isSeparator) override;
91 void setFont(const QFont &font) override { Q_UNUSED(font); }
92 void setRole(MenuRole role) override;
93 bool isCheckable() const { return m_isCheckable; }
94 void setCheckable(bool checkable) override;
95 bool isChecked() const { return m_isChecked; }
96 void setChecked(bool isChecked) override;
97 bool hasExclusiveGroup() const { return m_hasExclusiveGroup; }
98 void setHasExclusiveGroup(bool hasExclusiveGroup) override;
99 #ifndef QT_NO_SHORTCUT
100 QKeySequence shortcut() const { return m_shortcut; }
101 void setShortcut(const QKeySequence& shortcut) override;
102 #endif
103 void setIconSize(int size) override { Q_UNUSED(size); }
104 void setNativeContents(WId item) override { Q_UNUSED(item); }
105
106 int dbusID() const { return m_dbusID; }
107
108 void trigger();
109
110 static QDBusPlatformMenuItem *byId(int id);
111 static QList<const QDBusPlatformMenuItem *> byIds(const QList<int> &ids);
112
113 private:
114 QString m_text;
115 QIcon m_icon;
116 QPlatformMenu *m_subMenu;
117 MenuRole m_role : 4;
118 bool m_isEnabled : 1;
119 bool m_isVisible : 1;
120 bool m_isSeparator : 1;
121 bool m_isCheckable : 1;
122 bool m_isChecked : 1;
123 bool m_hasExclusiveGroup : 1;
124 short /*unused*/ : 6;
125 short m_dbusID : 16;
126 QKeySequence m_shortcut;
127 };
128
129 class QDBusPlatformMenu : public QPlatformMenu
130 {
131 Q_OBJECT
132
133 public:
134 QDBusPlatformMenu();
135 ~QDBusPlatformMenu();
136 void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) override;
137 void removeMenuItem(QPlatformMenuItem *menuItem) override;
138 void syncSubMenu(const QDBusPlatformMenu *menu);
139 void syncMenuItem(QPlatformMenuItem *menuItem) override;
syncSeparatorsCollapsible(bool enable)140 void syncSeparatorsCollapsible(bool enable) override { Q_UNUSED(enable); }
141
text()142 const QString text() const { return m_text; }
143 void setText(const QString &text) override;
icon()144 QIcon icon() const { return m_icon; }
145 void setIcon(const QIcon &icon) override;
isEnabled()146 bool isEnabled() const override { return m_isEnabled; }
147 void setEnabled(bool enabled) override;
isVisible()148 bool isVisible() const { return m_isVisible; }
149 void setVisible(bool visible) override;
setMinimumWidth(int width)150 void setMinimumWidth(int width) override { Q_UNUSED(width); }
setFont(const QFont & font)151 void setFont(const QFont &font) override { Q_UNUSED(font); }
setMenuType(MenuType type)152 void setMenuType(MenuType type) override { Q_UNUSED(type); }
153 void setContainingMenuItem(QDBusPlatformMenuItem *item);
154
155 void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item) override;
156
dismiss()157 void dismiss() override { } // Closes this and all its related menu popups
158
159 QPlatformMenuItem *menuItemAt(int position) const override;
160 QPlatformMenuItem *menuItemForTag(quintptr tag) const override;
161 const QList<QDBusPlatformMenuItem *> items() const;
162
163 QPlatformMenuItem *createMenuItem() const override;
164 QPlatformMenu *createSubMenu() const override;
165
revision()166 uint revision() const { return m_revision; }
167
168 void emitUpdated();
169
170 signals:
171 void updated(uint revision, int dbusId);
172 void propertiesUpdated(QDBusMenuItemList updatedProps, QDBusMenuItemKeysList removedProps);
173 void popupRequested(int id, uint timestamp);
174
175 private:
176 QString m_text;
177 QIcon m_icon;
178 bool m_isEnabled;
179 bool m_isVisible;
180 uint m_revision;
181 QHash<quintptr, QDBusPlatformMenuItem *> m_itemsByTag;
182 QList<QDBusPlatformMenuItem *> m_items;
183 QDBusPlatformMenuItem *m_containingMenuItem;
184 };
185
186 QT_END_NAMESPACE
187
188 #endif
189
190