[plasma/xdg-desktop-portal-kde] src: convert selectioneditor from a context property to a required one
David Redondo <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 1de8db7ee1e674d06b67f03a359cf9777beb8b8c by David Redondo.
Committed on 29/07/2026 at 10:06.
Pushed by davidre into branch 'master'.
convert selectioneditor from a context property to a required one
M +3 -0 src/CMakeLists.txt
M +14 -12 src/region-select/RegionSelectOverlay.qml
M +1 -1 src/region-select/SelectionEditor.cpp
M +2 -0 src/region-select/SelectionEditor.h
https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/commit/1de8db7ee1e674d06b67f03a359cf9777beb8b8c
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5a455b55..18c7d8cf 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -102,6 +102,9 @@ set(xdg_desktop_portal_kde_SRCS
wallpaper.cpp
)
+# Otherwise qml tooling cant find the include
+target_include_directories(xdg-desktop-portal-kde PRIVATE region-select)
+
ecm_qt_declare_logging_category(xdg_desktop_portal_kde_SRCS
IDENTIFIER "XdgDesktopPortalKdeBackground"
CATEGORY_NAME "xdp-kde-background"
diff --git a/src/region-select/RegionSelectOverlay.qml b/src/region-select/RegionSelectOverlay.qml
index f0b446c1..62f16690 100644
--- a/src/region-select/RegionSelectOverlay.qml
+++ b/src/region-select/RegionSelectOverlay.qml
@@ -3,6 +3,7 @@ import QtQuick.Layouts
import QtQuick.Controls as QQC2
import org.kde.kirigami as Kirigami
import org.kde.ki18n
+import org.kde.xdgdesktopportal
MouseArea {
// This needs to be a mousearea in orcer for the proper mouse events to be correctly filtered
@@ -18,22 +19,23 @@ MouseArea {
cursorShape: Qt.CrossCursor
readonly property point mousePosition: Qt.point(mouseX, mouseY)
+ required property SelectionEditor selectionEditor
onPressed: mouse => {
if (mouse.button & Qt.RightButton) {
- SelectionEditor.dragReset();
+ selectionEditor.dragReset();
}
if (mouse.button & Qt.LeftButton) {
- SelectionEditor.dragStart(Screen.name, mouse.x, mouse.y);
+ selectionEditor.dragStart(Screen.name, mouse.x, mouse.y);
}
}
onMousePositionChanged: {
- SelectionEditor.setMousePosition(Screen.name, mouseX, mouseY);
+ selectionEditor.setMousePosition(Screen.name, mouseX, mouseY);
}
onReleased: mouse => {
if (mouse.button & Qt.LeftButton) {
- SelectionEditor.dragRelease(Screen.name, mouse.x, mouse.y);
+ selectionEditor.dragRelease(Screen.name, mouse.x, mouse.y);
}
}
@@ -85,11 +87,11 @@ MouseArea {
color: "transparent"
border.color: palette.highlight
border.width: 1
- visible: SelectionEditor.rect.height > 0 && SelectionEditor.rect.width > 0
- x: SelectionEditor.rect.x - border.width - Screen.virtualX
- y: SelectionEditor.rect.y - border.width - Screen.virtualY
- width: SelectionEditor.rect.width + border.width * 2
- height: SelectionEditor.rect.height + border.width * 2
+ visible: root.selectionEditor.rect.height > 0 && root.selectionEditor.rect.width > 0
+ x: root.selectionEditor.rect.x - border.width - Screen.virtualX
+ y: root.selectionEditor.rect.y - border.width - Screen.virtualY
+ width: root.selectionEditor.rect.width + border.width * 2
+ height: root.selectionEditor.rect.height + border.width * 2
LayoutMirroring.enabled: false
LayoutMirroring.childrenInherit: true
@@ -121,7 +123,7 @@ MouseArea {
visible: selectionRectangle.visible && dragSizeBox.height < selectionRectangle.height && dragSizeBox.width < selectionRectangle.width
opacity: 1
contentItem: QQC2.Label {
- text: `${SelectionEditor.rect.width}x${SelectionEditor.rect.height}`
+ text: `${root.selectionEditor.rect.width}x${root.selectionEditor.rect.height}`
}
Behavior on opacity {
@@ -140,7 +142,7 @@ MouseArea {
bottom: parent.bottom
}
fontMetrics: fontMetrics
- visible: SelectionEditor.isDragging && selectionRectangle.y + selectionRectangle.height < dragBox.y
+ visible: root.selectionEditor.isDragging && selectionRectangle.y + selectionRectangle.height < dragBox.y
opacity: 1
contentItem: RowLayout {
ColumnLayout {
@@ -187,7 +189,7 @@ MouseArea {
verticalCenter: parent.verticalCenter
}
fontMetrics: fontMetrics
- visible: !SelectionEditor.isDragging
+ visible: !root.selectionEditor.isDragging
opacity: 1
contentItem: RowLayout {
diff --git a/src/region-select/SelectionEditor.cpp b/src/region-select/SelectionEditor.cpp
index 89464f47..c3185d06 100644
--- a/src/region-select/SelectionEditor.cpp
+++ b/src/region-select/SelectionEditor.cpp
@@ -87,7 +87,6 @@ SelectionEditor::SelectionEditor(QObject *parent)
, m_engine(new QQmlApplicationEngine(this))
{
KLocalization::setupLocalizedContext(m_engine);
- m_engine->rootContext()->setContextProperty(QStringLiteral("SelectionEditor"), QVariant::fromValue<QObject *>(this));
setObjectName(QStringLiteral("selectionEditor"));
@@ -116,6 +115,7 @@ void SelectionEditor::showViews()
view->create();
view->setScreen(screen);
+ view->setInitialProperties({{QStringLiteral("selectionEditor"), QVariant::fromValue(this)}});
view->loadFromModule("org.kde.xdgdesktopportal", "RegionSelectOverlay");
view->installEventFilter(this);
diff --git a/src/region-select/SelectionEditor.h b/src/region-select/SelectionEditor.h
index 70646cac..f5761458 100644
--- a/src/region-select/SelectionEditor.h
+++ b/src/region-select/SelectionEditor.h
@@ -14,6 +14,8 @@ class SelectionEditorPrivate;
class SelectionEditor : public QObject
{
Q_OBJECT
+ QML_ELEMENT
+ QML_UNCREATABLE("")
Q_PROPERTY(QRect rect READ rect NOTIFY rectChanged FINAL)
Q_PROPERTY(bool isDragging READ isDragging NOTIFY isDraggingChanged FINAL)