1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QDBUSPLATFORMMENU_H
5#define QDBUSPLATFORMMENU_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17//
18// W A R N I N G
19// -------------
20//
21// This file is part of the DBus menu support and is not meant to be used
22// in applications. Usage of this API may make your code
23// source and binary incompatible with future versions of Qt.
24//
25
26#include <qpa/qplatformmenu.h>
27#include <QLoggingCategory>
28#include "qdbusmenutypes_p.h"
29
30QT_BEGIN_NAMESPACE
31Q_DECLARE_LOGGING_CATEGORY(qLcMenu)
32
33class QDBusPlatformMenu;
34
35class QDBusPlatformMenuItem : public QPlatformMenuItem
36{
37 Q_OBJECT
38
39public:
40 QDBusPlatformMenuItem();
41 ~QDBusPlatformMenuItem();
42
43 const QString text() const { return m_text; }
44 void setText(const QString &text) override;
45 QIcon icon() const { return m_icon; }
46 void setIcon(const QIcon &icon) override;
47 const QPlatformMenu *menu() const { return m_subMenu; }
48 void setMenu(QPlatformMenu *menu) override;
49 bool isEnabled() const { return m_isEnabled; }
50 void setEnabled(bool enabled) override;
51 bool isVisible() const { return m_isVisible; }
52 void setVisible(bool isVisible) override;
53 bool isSeparator() const { return m_isSeparator; }
54 void setIsSeparator(bool isSeparator) override;
55 void setFont(const QFont &font) override { Q_UNUSED(font); }
56 void setRole(MenuRole role) override;
57 bool isCheckable() const { return m_isCheckable; }
58 void setCheckable(bool checkable) override;
59 bool isChecked() const { return m_isChecked; }
60 void setChecked(bool isChecked) override;
61 bool hasExclusiveGroup() const { return m_hasExclusiveGroup; }
62 void setHasExclusiveGroup(bool hasExclusiveGroup) override;
63#if QT_CONFIG(shortcut)
64 QKeySequence shortcut() const { return m_shortcut; }
65 void setShortcut(const QKeySequence& shortcut) override;
66#endif
67 void setIconSize(int size) override { Q_UNUSED(size); }
68 void setNativeContents(WId item) override { Q_UNUSED(item); }
69
70 int dbusID() const { return m_dbusID; }
71
72 void trigger();
73
74 static QDBusPlatformMenuItem *byId(int id);
75 static QList<const QDBusPlatformMenuItem *> byIds(const QList<int> &ids);
76
77private:
78 QString m_text;
79 QIcon m_icon;
80 QPlatformMenu *m_subMenu;
81 MenuRole m_role : 4;
82 bool m_isEnabled : 1;
83 bool m_isVisible : 1;
84 bool m_isSeparator : 1;
85 bool m_isCheckable : 1;
86 bool m_isChecked : 1;
87 bool m_hasExclusiveGroup : 1;
88 short /*unused*/ : 6;
89 short m_dbusID : 16;
90#if QT_CONFIG(shortcut)
91 QKeySequence m_shortcut;
92#endif
93};
94
95class QDBusPlatformMenu : public QPlatformMenu
96{
97 Q_OBJECT
98
99public:
100 QDBusPlatformMenu();
101 ~QDBusPlatformMenu();
102 void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) override;
103 void removeMenuItem(QPlatformMenuItem *menuItem) override;
104 void syncSubMenu(const QDBusPlatformMenu *menu);
105 void syncMenuItem(QPlatformMenuItem *menuItem) override;
106 void syncSeparatorsCollapsible(bool enable) override { Q_UNUSED(enable); }
107
108 const QString text() const { return m_text; }
109 void setText(const QString &text) override;
110 QIcon icon() const { return m_icon; }
111 void setIcon(const QIcon &icon) override;
112 bool isEnabled() const override { return m_isEnabled; }
113 void setEnabled(bool enabled) override;
114 bool isVisible() const { return m_isVisible; }
115 void setVisible(bool visible) override;
116 void setMinimumWidth(int width) override { Q_UNUSED(width); }
117 void setFont(const QFont &font) override { Q_UNUSED(font); }
118 void setMenuType(MenuType type) override { Q_UNUSED(type); }
119 void setContainingMenuItem(QDBusPlatformMenuItem *item);
120
121 void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item) override;
122
123 void dismiss() override { } // Closes this and all its related menu popups
124
125 QPlatformMenuItem *menuItemAt(int position) const override;
126 QPlatformMenuItem *menuItemForTag(quintptr tag) const override;
127 const QList<QDBusPlatformMenuItem *> items() const;
128
129 QPlatformMenuItem *createMenuItem() const override;
130 QPlatformMenu *createSubMenu() const override;
131
132 uint revision() const { return m_revision; }
133
134 void emitUpdated();
135
136signals:
137 void updated(uint revision, int dbusId);
138 void propertiesUpdated(QDBusMenuItemList updatedProps, QDBusMenuItemKeysList removedProps);
139 void popupRequested(int id, uint timestamp);
140
141private:
142 QString m_text;
143 QIcon m_icon;
144 bool m_isEnabled;
145 bool m_isVisible;
146 uint m_revision;
147 QHash<quintptr, QDBusPlatformMenuItem *> m_itemsByTag;
148 QList<QDBusPlatformMenuItem *> m_items;
149 QDBusPlatformMenuItem *m_containingMenuItem;
150};
151
152QT_END_NAMESPACE
153
154#endif
155
156

source code of qtbase/src/gui/platform/unix/dbusmenu/qdbusplatformmenu_p.h