From 44e011e2c617342f9dffd6fc69f6f79d999f7575 Mon Sep 17 00:00:00 2001 From: Aleix Pol Gonzalez Date: Tue, 5 Mar 2024 14:51:50 +0100 Subject: [PATCH] declarative: Add a QML extension object for accessing the margins property Otherwise we get the following error message: Property "margins" with type "QMargins", which is not a value type Signed-off-by: Victoria Fischer --- src/declarative/layershellqtplugin.cpp | 26 ++++++++++++++++++++++++++ tests/quicktest.qml | 1 + 2 files changed, 27 insertions(+) diff --git a/src/declarative/layershellqtplugin.cpp b/src/declarative/layershellqtplugin.cpp index 2410382..fc4ae00 100644 --- a/src/declarative/layershellqtplugin.cpp +++ b/src/declarative/layershellqtplugin.cpp @@ -10,6 +10,31 @@ QML_DECLARE_TYPEINFO(LayerShellQt::Window, QML_HAS_ATTACHED_PROPERTIES) +class ExtQMargins +{ + QMargins m_margins; + Q_GADGET + Q_PROPERTY(int left READ left WRITE setLeft FINAL) + Q_PROPERTY(int right READ right WRITE setRight FINAL) + Q_PROPERTY(int top READ top WRITE setTop FINAL) + Q_PROPERTY(int bottom READ bottom WRITE setBottom FINAL) + QML_FOREIGN(QMargins) + QML_EXTENDED(ExtQMargins) +public: + ExtQMargins(const QMargins &margins); + int left() const { return m_margins.left(); } + void setLeft(int left) { m_margins.setLeft(left); } + + int right() const { return m_margins.right(); } + void setRight(int right) { m_margins.setRight(right); } + + int top() const { return m_margins.top(); } + void setTop(int top) { m_margins.setTop(top); } + + int bottom() const { return m_margins.bottom(); } + void setBottom(int bottom) { m_margins.setBottom(bottom); } +}; + class Plugin : public QQmlExtensionPlugin { Q_PLUGIN_METADATA(IID "org.kde.layershellqt") @@ -19,6 +44,7 @@ public: { Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.layershell")); qmlRegisterType(uri, 1, 0, "Window"); + qmlRegisterExtendedUncreatableType(uri, 1, 0, "ExtQMargins", QStringLiteral("Only created from C++")); } }; diff --git a/tests/quicktest.qml b/tests/quicktest.qml index 83f99bd..a3e6d88 100644 --- a/tests/quicktest.qml +++ b/tests/quicktest.qml @@ -39,6 +39,7 @@ Item LayerShell.Window.anchors: LayerShell.Window.AnchorLeft LayerShell.Window.layer: LayerShell.Window.LayerTop LayerShell.Window.exclusionZone: width + LayerShell.Window.margins.left: 100 width: 100 height: 100