| 1 | // Copyright (C) 2017 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QWAYLANDQUICKEXTENSION_H |
| 5 | #define QWAYLANDQUICKEXTENSION_H |
| 6 | |
| 7 | #if 0 |
| 8 | #pragma qt_class(QWaylandQuickExtension) |
| 9 | #endif |
| 10 | |
| 11 | #include <QtWaylandCompositor/QWaylandCompositorExtension> |
| 12 | #include <QtQml/QQmlParserStatus> |
| 13 | #include <QtQml/QQmlListProperty> |
| 14 | |
| 15 | QT_REQUIRE_CONFIG(wayland_compositor_quick); |
| 16 | |
| 17 | QT_BEGIN_NAMESPACE |
| 18 | |
| 19 | #define Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(className) \ |
| 20 | class Q_WAYLANDCOMPOSITOR_EXPORT className##QuickExtension : public className, public QQmlParserStatus \ |
| 21 | { \ |
| 22 | /* qmake ignore Q_OBJECT */ \ |
| 23 | Q_OBJECT \ |
| 24 | Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false) \ |
| 25 | Q_CLASSINFO("DefaultProperty", "data") \ |
| 26 | Q_INTERFACES(QQmlParserStatus) \ |
| 27 | public: \ |
| 28 | QQmlListProperty<QObject> data() \ |
| 29 | { \ |
| 30 | return QQmlListProperty<QObject>(this, &m_objects); \ |
| 31 | } \ |
| 32 | void classBegin() override {} \ |
| 33 | void componentComplete() override { if (!isInitialized()) initialize(); } \ |
| 34 | private: \ |
| 35 | QList<QObject *> m_objects; \ |
| 36 | }; |
| 37 | |
| 38 | #define Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CONTAINER_CLASS(className) \ |
| 39 | class Q_WAYLANDCOMPOSITOR_EXPORT className##QuickExtensionContainer : public className \ |
| 40 | { \ |
| 41 | /* qmake ignore Q_OBJECT */ \ |
| 42 | Q_OBJECT \ |
| 43 | Q_PROPERTY(QQmlListProperty<QWaylandCompositorExtension> extensions READ extensions) \ |
| 44 | Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false) \ |
| 45 | Q_CLASSINFO("DefaultProperty", "data") \ |
| 46 | public: \ |
| 47 | QQmlListProperty<QObject> data() \ |
| 48 | { \ |
| 49 | return QQmlListProperty<QObject>(this, &m_objects); \ |
| 50 | } \ |
| 51 | QQmlListProperty<QWaylandCompositorExtension> extensions() \ |
| 52 | { \ |
| 53 | return QQmlListProperty<QWaylandCompositorExtension>(this, this, \ |
| 54 | &className##QuickExtensionContainer::append_extension, \ |
| 55 | &className##QuickExtensionContainer::countFunction, \ |
| 56 | &className##QuickExtensionContainer::atFunction, \ |
| 57 | &className##QuickExtensionContainer::clearFunction); \ |
| 58 | } \ |
| 59 | static int countFunction(QQmlListProperty<QWaylandCompositorExtension> *list) \ |
| 60 | { \ |
| 61 | return static_cast<className##QuickExtensionContainer *>(list->data)->extension_vector.size(); \ |
| 62 | } \ |
| 63 | static QWaylandCompositorExtension *atFunction(QQmlListProperty<QWaylandCompositorExtension> *list, int index) \ |
| 64 | { \ |
| 65 | return static_cast<className##QuickExtensionContainer *>(list->data)->extension_vector.at(index); \ |
| 66 | } \ |
| 67 | static void append_extension(QQmlListProperty<QWaylandCompositorExtension> *list, QWaylandCompositorExtension *extension) \ |
| 68 | { \ |
| 69 | className##QuickExtensionContainer *quickExtObj = static_cast<className##QuickExtensionContainer *>(list->data); \ |
| 70 | extension->setExtensionContainer(quickExtObj); \ |
| 71 | } \ |
| 72 | static void clearFunction(QQmlListProperty<QWaylandCompositorExtension> *list) \ |
| 73 | { \ |
| 74 | static_cast<className##QuickExtensionContainer *>(list->data)->extension_vector.clear(); \ |
| 75 | } \ |
| 76 | private: \ |
| 77 | QList<QObject *> m_objects; \ |
| 78 | }; |
| 79 | |
| 80 | #define Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_NAMED_CLASS(className, QmlType) \ |
| 81 | Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_NAMED_ELEMENT(className, QmlType, 1, 0) |
| 82 | |
| 83 | #define Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_NAMED_ELEMENT(...) \ |
| 84 | QT_OVERLOADED_MACRO(Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_NAMED_ELEMENT, __VA_ARGS__) |
| 85 | |
| 86 | #define Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_NAMED_ELEMENT_4(className, QmlType, versionMajor, \ |
| 87 | versionMinor) \ |
| 88 | class Q_WAYLANDCOMPOSITOR_EXPORT className##QuickExtension : public className, \ |
| 89 | public QQmlParserStatus \ |
| 90 | { \ |
| 91 | /* qmake ignore Q_OBJECT */ \ |
| 92 | Q_OBJECT \ |
| 93 | Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false) \ |
| 94 | Q_CLASSINFO("DefaultProperty", "data") \ |
| 95 | Q_INTERFACES(QQmlParserStatus) \ |
| 96 | QML_NAMED_ELEMENT(QmlType) \ |
| 97 | QML_ADDED_IN_VERSION(versionMajor, versionMinor) \ |
| 98 | public: \ |
| 99 | QQmlListProperty<QObject> data() \ |
| 100 | { \ |
| 101 | return QQmlListProperty<QObject>(this, &m_objects); \ |
| 102 | } \ |
| 103 | void classBegin() override { } \ |
| 104 | void componentComplete() override \ |
| 105 | { \ |
| 106 | if (!isInitialized()) \ |
| 107 | initialize(); \ |
| 108 | } \ |
| 109 | \ |
| 110 | private: \ |
| 111 | QList<QObject *> m_objects; \ |
| 112 | }; |
| 113 | |
| 114 | #define Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_NAMED_ELEMENT_2(className, QmlType) \ |
| 115 | class Q_WAYLANDCOMPOSITOR_EXPORT className##QuickExtension : public className, \ |
| 116 | public QQmlParserStatus \ |
| 117 | { \ |
| 118 | /* qmake ignore Q_OBJECT */ \ |
| 119 | Q_OBJECT \ |
| 120 | Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false) \ |
| 121 | Q_CLASSINFO("DefaultProperty", "data") \ |
| 122 | Q_INTERFACES(QQmlParserStatus) \ |
| 123 | QML_NAMED_ELEMENT(QmlType) \ |
| 124 | public: \ |
| 125 | QQmlListProperty<QObject> data() \ |
| 126 | { \ |
| 127 | return QQmlListProperty<QObject>(this, &m_objects); \ |
| 128 | } \ |
| 129 | void classBegin() override { } \ |
| 130 | void componentComplete() override \ |
| 131 | { \ |
| 132 | if (!isInitialized()) \ |
| 133 | initialize(); \ |
| 134 | } \ |
| 135 | \ |
| 136 | private: \ |
| 137 | QList<QObject *> m_objects; \ |
| 138 | }; |
| 139 | |
| 140 | QT_END_NAMESPACE |
| 141 | |
| 142 | #endif /*QWAYLANDQUICKEXTENSION_H*/ |
| 143 | |