From d65538a11b2a4050bbd98cab5309834c762924c3 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Fri, 18 Oct 2019 12:41:19 -0700 Subject: [PATCH 1/2] DEV-2471: Fix an issue with InteractiveWindow anchors that caused windows without anchors to move when the Interface window geometry changes --- interface/src/scripting/DesktopScriptingInterface.cpp | 2 ++ interface/src/ui/InteractiveWindow.cpp | 7 +++++-- interface/src/ui/InteractiveWindow.h | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/interface/src/scripting/DesktopScriptingInterface.cpp b/interface/src/scripting/DesktopScriptingInterface.cpp index 32b5eb768d..ae4af48cd6 100644 --- a/interface/src/scripting/DesktopScriptingInterface.cpp +++ b/interface/src/scripting/DesktopScriptingInterface.cpp @@ -55,12 +55,14 @@ static const QVariantMap DOCK_AREA { /**jsdoc * The possible "relative position anchors" of an InteractiveWindow. Used when defining the `relativePosition` property of an `InteractiveWindow`. * @typedef {object} InteractiveWindow.RelativePositionAnchors + * @property {InteractiveWindow.RelativePositionAnchor} NO_ANCHOR - Specifies that the position of the `InteractiveWindow` will not be relative to any part of the Interface window. * @property {InteractiveWindow.RelativePositionAnchor} TOP_LEFT - Specifies that the `relativePosition` of the `InteractiveWindow` will be offset from the top left of the Interface window. * @property {InteractiveWindow.RelativePositionAnchor} TOP_RIGHT - Specifies that the `relativePosition` of the `InteractiveWindow` will be offset from the top right of the Interface window. * @property {InteractiveWindow.RelativePositionAnchor} BOTTOM_RIGHT - Specifies that the `relativePosition` of the `InteractiveWindow` will be offset from the bottom right of the Interface window. * @property {InteractiveWindow.RelativePositionAnchor} BOTTOM_LEFT - Specifies that the `relativePosition` of the `InteractiveWindow` will be offset from the bottom left of the Interface window. */ static const QVariantMap RELATIVE_POSITION_ANCHOR { + { "NO_ANCHOR", RelativePositionAnchor::NO_ANCHOR }, { "TOP_LEFT", RelativePositionAnchor::TOP_LEFT }, { "TOP_RIGHT", RelativePositionAnchor::TOP_RIGHT }, { "BOTTOM_RIGHT", RelativePositionAnchor::BOTTOM_RIGHT }, diff --git a/interface/src/ui/InteractiveWindow.cpp b/interface/src/ui/InteractiveWindow.cpp index b7140b4009..8391923cbb 100644 --- a/interface/src/ui/InteractiveWindow.cpp +++ b/interface/src/ui/InteractiveWindow.cpp @@ -116,9 +116,10 @@ void InteractiveWindow::forwardKeyReleaseEvent(int key, int modifiers) { } void InteractiveWindow::onMainWindowGeometryChanged(QRect geometry) { + // This handler is only connected `if (_isFullScreenWindow || _relativePositionAnchor != RelativePositionAnchor::NONE)`. if (_isFullScreenWindow) { repositionAndResizeFullScreenWindow(); - } else { + } else if (_relativePositionAnchor != RelativePositionAnchor::NO_ANCHOR) { setPositionUsingRelativePositionAndAnchor(geometry); } } @@ -326,7 +327,9 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap connect(object, SIGNAL(presentationModeChanged()), this, SLOT(parentNativeWindowToMainWindow()), Qt::QueuedConnection); #endif - connect(qApp->getWindow(), &MainWindow::windowGeometryChanged, this, &InteractiveWindow::onMainWindowGeometryChanged, Qt::QueuedConnection); + if (_isFullScreenWindow || _relativePositionAnchor != RelativePositionAnchor::NO_ANCHOR) { + connect(qApp->getWindow(), &MainWindow::windowGeometryChanged, this, &InteractiveWindow::onMainWindowGeometryChanged, Qt::QueuedConnection); + } QUrl sourceURL{ sourceUrl }; // If the passed URL doesn't correspond to a known scheme, assume it's a local file path diff --git a/interface/src/ui/InteractiveWindow.h b/interface/src/ui/InteractiveWindow.h index d25c3d7ec2..fb10aac444 100644 --- a/interface/src/ui/InteractiveWindow.h +++ b/interface/src/ui/InteractiveWindow.h @@ -91,6 +91,7 @@ namespace InteractiveWindowEnums { Q_ENUM_NS(DockArea); enum RelativePositionAnchor { + NO_ANCHOR, TOP_LEFT, TOP_RIGHT, BOTTOM_RIGHT, @@ -147,7 +148,7 @@ private: Q_INVOKABLE glm::vec2 getPosition() const; Q_INVOKABLE void setPosition(const glm::vec2& position); - RelativePositionAnchor _relativePositionAnchor{ RelativePositionAnchor::TOP_LEFT }; + RelativePositionAnchor _relativePositionAnchor{ RelativePositionAnchor::NO_ANCHOR }; Q_INVOKABLE RelativePositionAnchor getRelativePositionAnchor() const; Q_INVOKABLE void setRelativePositionAnchor(const RelativePositionAnchor& position); From 4c48d80da7343be6542cd5375598c632115244f1 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Fri, 18 Oct 2019 13:34:42 -0700 Subject: [PATCH 2/2] Fix warning on MacOS and Ubuntu --- interface/src/ui/InteractiveWindow.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interface/src/ui/InteractiveWindow.cpp b/interface/src/ui/InteractiveWindow.cpp index 8391923cbb..6cc26e2409 100644 --- a/interface/src/ui/InteractiveWindow.cpp +++ b/interface/src/ui/InteractiveWindow.cpp @@ -497,6 +497,9 @@ void InteractiveWindow::setPositionUsingRelativePositionAndAnchor(const QRect& m newPosition.x = mainWindowGeometry.x() + relativePosition.x; newPosition.y = mainWindowGeometry.y() + mainWindowGeometry.height() - relativePosition.y; break; + case RelativePositionAnchor::NO_ANCHOR: + // No-op. + break; } // Make sure we include the dimensions of the docked widget!