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
66QT_BEGIN_NAMESPACE
67Q_DECLARE_LOGGING_CATEGORY(qLcMenu)
68
69class QDBusPlatformMenu;
70
71class QDBusPlatformMenuItem : public QPlatformMenuItem
72{
73 Q_OBJECT
74
75public:
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#if QT_CONFIG(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
113private:
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#if QT_CONFIG(shortcut)
127 QKeySequence m_shortcut;
128#endif
129};
130
131class QDBusPlatformMenu : public QPlatformMenu
132{
133 Q_OBJECT
134
135public:
136 QDBusPlatformMenu();
137 ~QDBusPlatformMenu();
138 void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) override;
139 void removeMenuItem(QPlatformMenuItem *menuItem) override;
140 void syncSubMenu(const QDBusPlatformMenu *menu);
141 void syncMenuItem(QPlatformMenuItem *menuItem) override;
142 void syncSeparatorsCollapsible(bool enable) override { Q_UNUSED(enable); }
143
144 const QString text() const { return m_text; }
145 void setText(const QString &text) override;
146 QIcon icon() const { return m_icon; }
147 void setIcon(const QIcon &icon) override;
148 bool isEnabled() const override { return m_isEnabled; }
149 void setEnabled(bool enabled) override;
150 bool isVisible() const { return m_isVisible; }
151 void setVisible(bool visible) override;
152 void setMinimumWidth(int width) override { Q_UNUSED(width); }
153 void setFont(const QFont &font) override { Q_UNUSED(font); }
154 void setMenuType(MenuType type) override { Q_UNUSED(type); }
155 void setContainingMenuItem(QDBusPlatformMenuItem *item);
156
157 void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item) override;
158
159 void dismiss() override { } // Closes this and all its related menu popups
160
161 QPlatformMenuItem *menuItemAt(int position) const override;
162 QPlatformMenuItem *menuItemForTag(quintptr tag) const override;
163 const QList<QDBusPlatformMenuItem *> items() const;
164
165 QPlatformMenuItem *createMenuItem() const override;
166 QPlatformMenu *createSubMenu() const override;
167
168 uint revision() const { return m_revision; }
169
170 void emitUpdated();
171
172signals:
173 void updated(uint revision, int dbusId);
174 void propertiesUpdated(QDBusMenuItemList updatedProps, QDBusMenuItemKeysList removedProps);
175 void popupRequested(int id, uint timestamp);
176
177private:
178 QString m_text;
179 QIcon m_icon;
180 bool m_isEnabled;
181 bool m_isVisible;
182 uint m_revision;
183 QHash<quintptr, QDBusPlatformMenuItem *> m_itemsByTag;
184 QList<QDBusPlatformMenuItem *> m_items;
185 QDBusPlatformMenuItem *m_containingMenuItem;
186};
187
188QT_END_NAMESPACE
189
190#endif
191
192