| 1 | // Copyright (C) 2022 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 QQUICKLABSPLATFORMMENUITEMGROUP_P_H |
| 5 | #define QQUICKLABSPLATFORMMENUITEMGROUP_P_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 | #include <QtCore/qobject.h> |
| 19 | #include <QtCore/qlist.h> |
| 20 | #include <QtQml/qqml.h> |
| 21 | #include <QtCore/private/qglobal_p.h> |
| 22 | |
| 23 | QT_BEGIN_NAMESPACE |
| 24 | |
| 25 | class QQuickLabsPlatformMenuItem; |
| 26 | class QQuickLabsPlatformMenuItemGroupPrivate; |
| 27 | |
| 28 | class QQuickLabsPlatformMenuItemGroup : public QObject |
| 29 | { |
| 30 | Q_OBJECT |
| 31 | QML_NAMED_ELEMENT(MenuItemGroup) |
| 32 | Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL) |
| 33 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL) |
| 34 | Q_PROPERTY(bool exclusive READ isExclusive WRITE setExclusive NOTIFY exclusiveChanged FINAL) |
| 35 | Q_PROPERTY(QQuickLabsPlatformMenuItem *checkedItem READ checkedItem WRITE setCheckedItem NOTIFY checkedItemChanged FINAL) |
| 36 | Q_PROPERTY(QQmlListProperty<QQuickLabsPlatformMenuItem> items READ items NOTIFY itemsChanged FINAL) |
| 37 | |
| 38 | public: |
| 39 | explicit QQuickLabsPlatformMenuItemGroup(QObject *parent = nullptr); |
| 40 | ~QQuickLabsPlatformMenuItemGroup(); |
| 41 | |
| 42 | bool isEnabled() const; |
| 43 | void setEnabled(bool enabled); |
| 44 | |
| 45 | bool isVisible() const; |
| 46 | void setVisible(bool visible); |
| 47 | |
| 48 | bool isExclusive() const; |
| 49 | void setExclusive(bool exclusive); |
| 50 | |
| 51 | QQuickLabsPlatformMenuItem *checkedItem() const; |
| 52 | void setCheckedItem(QQuickLabsPlatformMenuItem *item); |
| 53 | |
| 54 | QQmlListProperty<QQuickLabsPlatformMenuItem> items(); |
| 55 | |
| 56 | Q_INVOKABLE void addItem(QQuickLabsPlatformMenuItem *item); |
| 57 | Q_INVOKABLE void removeItem(QQuickLabsPlatformMenuItem *item); |
| 58 | Q_INVOKABLE void clear(); |
| 59 | |
| 60 | Q_SIGNALS: |
| 61 | void triggered(QQuickLabsPlatformMenuItem *item); |
| 62 | void hovered(QQuickLabsPlatformMenuItem *item); |
| 63 | |
| 64 | void enabledChanged(); |
| 65 | void visibleChanged(); |
| 66 | void exclusiveChanged(); |
| 67 | void checkedItemChanged(); |
| 68 | void itemsChanged(); |
| 69 | |
| 70 | private: |
| 71 | QQuickLabsPlatformMenuItem *findCurrent() const; |
| 72 | void updateCurrent(); |
| 73 | void activateItem(); |
| 74 | void hoverItem(); |
| 75 | |
| 76 | static void items_append(QQmlListProperty<QQuickLabsPlatformMenuItem> *prop, QQuickLabsPlatformMenuItem *obj); |
| 77 | static qsizetype items_count(QQmlListProperty<QQuickLabsPlatformMenuItem> *prop); |
| 78 | static QQuickLabsPlatformMenuItem *items_at(QQmlListProperty<QQuickLabsPlatformMenuItem> *prop, qsizetype index); |
| 79 | static void items_clear(QQmlListProperty<QQuickLabsPlatformMenuItem> *prop); |
| 80 | |
| 81 | bool m_enabled; |
| 82 | bool m_visible; |
| 83 | bool m_exclusive; |
| 84 | QQuickLabsPlatformMenuItem *m_checkedItem; |
| 85 | QList<QQuickLabsPlatformMenuItem*> m_items; |
| 86 | }; |
| 87 | |
| 88 | QT_END_NAMESPACE |
| 89 | |
| 90 | #endif // QQUICKLABSPLATFORMMENUITEMGROUP_P_H |
| 91 |
