qdbusplatformmenu.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/platformsupport/dbusmenu/qdbusplatformmenu.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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#include "qdbusplatformmenu_p.h"-
41-
42#include <QDebug>-
43#include <QWindow>-
44-
45QT_BEGIN_NAMESPACE-
46-
47Q_LOGGING_CATEGORY(qLcMenu, "qt.qpa.menu")-
48-
49static int nextDBusID = 1;-
50QHash<int, QDBusPlatformMenuItem *> menuItemsByID;-
51-
52QDBusPlatformMenuItem::QDBusPlatformMenuItem(quintptr tag)-
53 : m_tag(tag ? tag : reinterpret_cast<quintptr>(this)) // QMenu will overwrite this later-
54 , m_subMenu(Q_NULLPTR)-
55 , m_role(NoRole)-
56 , m_isEnabled(true)-
57 , m_isVisible(true)-
58 , m_isSeparator(false)-
59 , m_isCheckable(false)-
60 , m_isChecked(false)-
61 , m_dbusID(nextDBusID++)-
62 , m_hasExclusiveGroup(false)-
63{-
64 menuItemsByID.insert(m_dbusID, this);-
65}
never executed: end of block
0
66-
67QDBusPlatformMenuItem::~QDBusPlatformMenuItem()-
68{-
69 menuItemsByID.remove(m_dbusID);-
70 if (m_subMenu)-
71 static_cast<QDBusPlatformMenu *>(m_subMenu)->setContainingMenuItem(Q_NULLPTR);-
72}-
73-
74void QDBusPlatformMenuItem::setTag(quintptr tag)-
75{-
76 m_tag = tag;-
77}-
78-
79void QDBusPlatformMenuItem::setText(const QString &text)-
80{-
81 qCDebug(qLcMenu) << m_dbusID << text;-
82 m_text = text;-
83}-
84-
85void QDBusPlatformMenuItem::setIcon(const QIcon &icon)-
86{-
87 m_icon = icon;-
88}-
89-
90/*!-
91 Set a submenu under this menu item.-
92*/-
93void QDBusPlatformMenuItem::setMenu(QPlatformMenu *menu)-
94{-
95 if (m_subMenu)-
96 static_cast<QDBusPlatformMenu *>(m_subMenu)->setContainingMenuItem(Q_NULLPTR);-
97 m_subMenu = menu;-
98 if (menu)-
99 static_cast<QDBusPlatformMenu *>(menu)->setContainingMenuItem(this);-
100}-
101-
102void QDBusPlatformMenuItem::setEnabled(bool enabled)-
103{-
104 m_isEnabled = enabled;-
105}-
106-
107void QDBusPlatformMenuItem::setVisible(bool isVisible)-
108{-
109 m_isVisible = isVisible;-
110}-
111-
112void QDBusPlatformMenuItem::setIsSeparator(bool isSeparator)-
113{-
114 m_isSeparator = isSeparator;-
115}-
116-
117void QDBusPlatformMenuItem::setRole(QPlatformMenuItem::MenuRole role)-
118{-
119 m_role = role;-
120}-
121-
122void QDBusPlatformMenuItem::setCheckable(bool checkable)-
123{-
124 m_isCheckable = checkable;-
125}-
126-
127void QDBusPlatformMenuItem::setChecked(bool isChecked)-
128{-
129 m_isChecked = isChecked;-
130}-
131-
132void QDBusPlatformMenuItem::setHasExclusiveGroup(bool hasExclusiveGroup)-
133{-
134 m_hasExclusiveGroup = hasExclusiveGroup;-
135}
never executed: end of block
0
136-
137void QDBusPlatformMenuItem::setShortcut(const QKeySequence &shortcut)-
138{-
139 m_shortcut = shortcut;-
140}-
141-
142void QDBusPlatformMenuItem::trigger()-
143{-
144 emit activated();-
145}-
146-
147QDBusPlatformMenuItem *QDBusPlatformMenuItem::byId(int id)-
148{-
149 // We need to check contains because otherwise QHash would insert-
150 // a default-constructed nullptr value into menuItemsByID-
151 if (menuItemsByID.contains(id))-
152 return menuItemsByID[id];-
153 return Q_NULLPTR;-
154}-
155-
156QList<const QDBusPlatformMenuItem *> QDBusPlatformMenuItem::byIds(const QList<int> &ids)-
157{-
158 QList<const QDBusPlatformMenuItem *> ret;-
159 Q_FOREACH (int id, ids) {-
160 if (menuItemsByID.contains(id))-
161 ret << menuItemsByID[id];-
162 }-
163 return ret;-
164}-
165-
166-
167QDBusPlatformMenu::QDBusPlatformMenu(quintptr tag)-
168 : m_tag(tag ? tag : reinterpret_cast<quintptr>(this))-
169 , m_isEnabled(true)-
170 , m_isVisible(true)-
171 , m_isSeparator(false)-
172 , m_revision(1)-
173 , m_containingMenuItem(Q_NULLPTR)-
174{-
175}-
176-
177QDBusPlatformMenu::~QDBusPlatformMenu()-
178{-
179 if (m_containingMenuItem)-
180 m_containingMenuItem->setMenu(Q_NULLPTR);-
181}-
182-
183void QDBusPlatformMenu::insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before)-
184{-
185 QDBusPlatformMenuItem *item = static_cast<QDBusPlatformMenuItem *>(menuItem);-
186 QDBusPlatformMenuItem *beforeItem = static_cast<QDBusPlatformMenuItem *>(before);-
187 int idx = m_items.indexOf(beforeItem);-
188 qCDebug(qLcMenu) << item->dbusID() << item->text();-
189 if (idx < 0)-
190 m_items.append(item);-
191 else-
192 m_items.insert(idx, item);-
193 m_itemsByTag.insert(item->tag(), item);-
194 if (item->menu())-
195 syncSubMenu(static_cast<const QDBusPlatformMenu *>(item->menu()));-
196 emitUpdated();-
197}-
198-
199void QDBusPlatformMenu::removeMenuItem(QPlatformMenuItem *menuItem)-
200{-
201 QDBusPlatformMenuItem *item = static_cast<QDBusPlatformMenuItem *>(menuItem);-
202 m_items.removeAll(item);-
203 m_itemsByTag.remove(menuItem->tag());-
204 if (item->menu()) {-
205 // disconnect from the signals we connected to in syncSubMenu()-
206 const QDBusPlatformMenu *menu = static_cast<const QDBusPlatformMenu *>(item->menu());-
207 disconnect(menu, &QDBusPlatformMenu::propertiesUpdated,-
208 this, &QDBusPlatformMenu::propertiesUpdated);-
209 disconnect(menu, &QDBusPlatformMenu::updated,-
210 this, &QDBusPlatformMenu::updated);-
211 }-
212 emitUpdated();-
213}-
214-
215void QDBusPlatformMenu::syncSubMenu(const QDBusPlatformMenu *menu)-
216{-
217 // The adaptor is only connected to the propertiesUpdated signal of the top-level-
218 // menu, so the submenus should transfer their signals to their parents.-
219 connect(menu, &QDBusPlatformMenu::propertiesUpdated,-
220 this, &QDBusPlatformMenu::propertiesUpdated, Qt::UniqueConnection);-
221 connect(menu, &QDBusPlatformMenu::updated,-
222 this, &QDBusPlatformMenu::updated, Qt::UniqueConnection);-
223}-
224-
225void QDBusPlatformMenu::syncMenuItem(QPlatformMenuItem *menuItem)-
226{-
227 QDBusPlatformMenuItem *item = static_cast<QDBusPlatformMenuItem *>(menuItem);-
228 // if a submenu was added to this item, we need to connect to its signals-
229 if (item->menu())-
230 syncSubMenu(static_cast<const QDBusPlatformMenu *>(item->menu()));-
231 // TODO keep around copies of the QDBusMenuLayoutItems so they can be updated?-
232 // or eliminate them by putting dbus streaming operators in this class instead?-
233 // or somehow tell the dbusmenu client that something has changed, so it will ask for properties again-
234 QDBusMenuItemList updated;-
235 QDBusMenuItemKeysList removed;-
236 updated << QDBusMenuItem(item);-
237 qCDebug(qLcMenu) << updated;-
238 emit propertiesUpdated(updated, removed);-
239}-
240-
241void QDBusPlatformMenu::emitUpdated()-
242{-
243 if (m_containingMenuItem)-
244 emit updated(++m_revision, m_containingMenuItem->dbusID());-
245 else-
246 emit updated(++m_revision, 0);-
247}-
248-
249void QDBusPlatformMenu::setTag(quintptr tag)-
250{-
251 m_tag = tag;-
252}-
253-
254void QDBusPlatformMenu::setText(const QString &text)-
255{-
256 m_text = text;-
257}-
258-
259void QDBusPlatformMenu::setIcon(const QIcon &icon)-
260{-
261 m_icon = icon;-
262}-
263-
264void QDBusPlatformMenu::setEnabled(bool enabled)-
265{-
266 m_isEnabled = enabled;-
267}-
268-
269void QDBusPlatformMenu::setVisible(bool isVisible)-
270{-
271 m_isVisible = isVisible;-
272}-
273-
274void QDBusPlatformMenu::setContainingMenuItem(QDBusPlatformMenuItem *item)-
275{-
276 m_containingMenuItem = item;-
277}-
278-
279QPlatformMenuItem *QDBusPlatformMenu::menuItemAt(int position) const-
280{-
281 return m_items.value(position);-
282}-
283-
284QPlatformMenuItem *QDBusPlatformMenu::menuItemForTag(quintptr tag) const-
285{-
286 return m_itemsByTag[tag];-
287}-
288-
289const QList<QDBusPlatformMenuItem *> QDBusPlatformMenu::items() const-
290{-
291 return m_items;-
292}-
293-
294QPlatformMenuItem *QDBusPlatformMenu::createMenuItem() const-
295{-
296 QDBusPlatformMenuItem *ret = new QDBusPlatformMenuItem();-
297 return ret;-
298}-
299-
300QPlatformMenu *QDBusPlatformMenu::createSubMenu() const-
301{-
302 return new QDBusPlatformMenu;-
303}-
304-
305QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9