From c3f9d43acaa753149d17bed90114a266158ff683 Mon Sep 17 00:00:00 2001 From: Henning Gruendl Date: Thu, 16 Nov 2023 18:34:39 +0100 Subject: [PATCH] QmlDesigner: Fix PopupDialog popup location * Restrict popup location to single screen given by global position * Reintroduce PopupDialog title bar drag * Fix global popup show on linux Change-Id: If1923151cb9d0ec4286f27aeae2baa292e017eb5 Reviewed-by: Qt CI Patch Build Bot Reviewed-by: Thomas Hartmann --- .../connectionseditor/ConnectionsDialog.qml | 2 +- .../imports/StudioControls/PopupDialog.qml | 45 ++++++++++++++----- .../qmldesignerbase/utils/windowmanager.cpp | 11 +++++ .../qmldesignerbase/utils/windowmanager.h | 1 + 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/share/qtcreator/qmldesigner/connectionseditor/ConnectionsDialog.qml b/share/qtcreator/qmldesigner/connectionseditor/ConnectionsDialog.qml index 85a847ba5e0..965f31d21ab 100644 --- a/share/qtcreator/qmldesigner/connectionseditor/ConnectionsDialog.qml +++ b/share/qtcreator/qmldesigner/connectionseditor/ConnectionsDialog.qml @@ -49,7 +49,7 @@ StudioControls.PopupDialog { root.close() } function onPopupShouldOpen() { - root.showGlobal() + Qt.callLater(root.showGlobal) } } } diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/PopupDialog.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/PopupDialog.qml index ae821804a5d..1f62ba81818 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/PopupDialog.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/PopupDialog.qml @@ -33,9 +33,8 @@ QtObject { signal closing(close: var) - function showGlobal() - { - var pos = WindowManager.globalCursorPosition(); + function showGlobal() { + var pos = WindowManager.globalCursorPosition() root.__itemGlobal = Qt.rect(pos.x, pos.y, 300, 20) root.chevronVisible = false root.layout() @@ -57,11 +56,8 @@ QtObject { } function layout() { - // Setup - var screen = Qt.rect(0, //Screen.virtualX, // TODO - 0, //Screen.virtualY, // TODO - Screen.desktopAvailableWidth, - Screen.desktopAvailableHeight) + let position = Qt.point(root.__itemGlobal.x, root.__itemGlobal.y) + var screen = WindowManager.getScreenGeometry(position) // Collect region information let edges = window.getRegions(screen, root.__itemGlobal) @@ -165,9 +161,18 @@ QtObject { var targetCenter = Qt.point(target.x + (target.width * 0.5), target.y + (target.height * 0.5)) + // Just as a reminder why calculating custom right and bottom: + // > Note that for historical reasons this function returns top() + height() - 1; + // > use y() + height() to retrieve the true y-coordinate. + let sourceRight = source.x + source.width + let sourceBottom = source.y + source.height + // TOP let topAnchor = Qt.point(targetCenter.x, target.y) - let topRegion = Qt.rect(source.x, source.y, source.width, Math.max(0, topAnchor.y)) + let topRegion = Qt.rect(source.x, + source.y, + source.width, + (topAnchor.y < source.top) ? 0 : Math.abs(topAnchor.y - source.top)) edges[Qt.TopEdge] = { anchor: topAnchor, @@ -180,7 +185,7 @@ QtObject { let rightAnchor = Qt.point(target.x + target.width, targetCenter.y) let rightRegion = Qt.rect(rightAnchor.x, source.y, - Math.max(0, source.width - rightAnchor.x), + (rightAnchor.x > sourceRight) ? 0 : Math.abs(sourceRight - rightAnchor.x), source.height) edges[Qt.RightEdge] = { @@ -195,7 +200,7 @@ QtObject { let bottomRegion = Qt.rect(source.x, bottomAnchor.y, source.width, - Math.max(0, source.height - bottomAnchor.y)) + (bottomAnchor.y > sourceBottom) ? 0 : Math.abs(sourceBottom - bottomAnchor.y)) edges[Qt.BottomEdge] = { anchor: bottomAnchor, @@ -206,7 +211,10 @@ QtObject { // LEFT let leftAnchor = Qt.point(target.x, targetCenter.y) - let leftRegion = Qt.rect(source.x, source.y, Math.max(0, leftAnchor.x), source.height) + let leftRegion = Qt.rect(source.x, + source.y, + (leftAnchor.x < source.left) ? 0 : Math.abs(leftAnchor.x - source.left), + source.height) edges[Qt.LeftEdge] = { anchor: leftAnchor, @@ -392,6 +400,19 @@ QtObject { width: parent.width height: StudioTheme.Values.titleBarHeight + DragHandler { + id: dragHandler + + target: null + grabPermissions: PointerHandler.CanTakeOverFromAnything + onActiveChanged: { + if (dragHandler.active) + window.startSystemMove() // QTBUG-102488 + + root.chevronVisible = false + } + } + Row { id: row anchors.fill: parent diff --git a/src/plugins/qmldesignerbase/utils/windowmanager.cpp b/src/plugins/qmldesignerbase/utils/windowmanager.cpp index c52d5d469a6..146535ceac1 100644 --- a/src/plugins/qmldesignerbase/utils/windowmanager.cpp +++ b/src/plugins/qmldesignerbase/utils/windowmanager.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include namespace QmlDesignerBase { @@ -43,4 +44,14 @@ QPoint WindowManager::globalCursorPosition() return QCursor::pos(); } +QRect WindowManager::getScreenGeometry(QPoint point) +{ + QScreen *screen = QGuiApplication::screenAt(point); + + if (!screen) + return {}; + + return screen->geometry(); +} + } // namespace QmlDesignerBase diff --git a/src/plugins/qmldesignerbase/utils/windowmanager.h b/src/plugins/qmldesignerbase/utils/windowmanager.h index 3d8e692c1aa..87a0b701463 100644 --- a/src/plugins/qmldesignerbase/utils/windowmanager.h +++ b/src/plugins/qmldesignerbase/utils/windowmanager.h @@ -25,6 +25,7 @@ public: static void registerDeclarativeType(); Q_INVOKABLE QPoint globalCursorPosition(); + Q_INVOKABLE QRect getScreenGeometry(QPoint point); signals: void focusWindowChanged(QWindow *window);