From 3f6793b46227dbab37fa9dadf092239a0fa5103a Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Tue, 3 Jul 2018 18:42:39 +0200 Subject: [PATCH] - center default native window - close button destroys window by default unless Desktop.CLOSE_BUTTON_HIDES flag is set --- interface/resources/qml/InteractiveWindow.qml | 25 ++++++++---- libraries/ui/src/InteractiveWindow.cpp | 4 +- libraries/ui/src/InteractiveWindow.h | 39 +++---------------- 3 files changed, 26 insertions(+), 42 deletions(-) diff --git a/interface/resources/qml/InteractiveWindow.qml b/interface/resources/qml/InteractiveWindow.qml index d1e9284101..e7a5585912 100644 --- a/interface/resources/qml/InteractiveWindow.qml +++ b/interface/resources/qml/InteractiveWindow.qml @@ -28,6 +28,8 @@ Windows.Window { // Don't destroy on close... otherwise the JS/C++ will have a dangling pointer destroyOnCloseButton: false; + signal selfDestruct(); + property var flags: 0; property var source; @@ -67,8 +69,14 @@ Windows.Window { x = interactiveWindowPosition.x; y = interactiveWindowPosition.y; } else if (presentationMode === Desktop.PresentationMode.NATIVE && nativeWindow) { - nativeWindow.x = interactiveWindowPosition.x; - nativeWindow.y = interactiveWindowPosition.y; + if (interactiveWindowPosition.x === 0 && interactiveWindowPosition.y === 0) { + // default position for native window in center of main application window + nativeWindow.x = Math.floor(Window.x + (Window.innerWidth / 2) - (interactiveWindowSize.width / 2)); + nativeWindow.y = Math.floor(Window.y + (Window.innerHeight / 2) - (interactiveWindowSize.height / 2)); + } else { + nativeWindow.x = interactiveWindowPosition.x; + nativeWindow.y = interactiveWindowPosition.y; + } } } @@ -83,7 +91,6 @@ Windows.Window { } function setupPresentationMode() { - console.warn(presentationMode); if (presentationMode === Desktop.PresentationMode.VIRTUAL) { if (nativeWindow) { nativeWindow.setVisible(false); @@ -104,7 +111,6 @@ Windows.Window { } Component.onCompleted: { - x = interactiveWindowPosition.x; y = interactiveWindowPosition.y; width = interactiveWindowSize.width; @@ -161,6 +167,11 @@ Windows.Window { } }); + nativeWindow.closing.connect(function(closeEvent) { + closeEvent.accepted = false; + windowClosed(); + }); + // finally set the initial window mode: setupPresentationMode(); @@ -243,10 +254,10 @@ Windows.Window { onWindowClosed: { // set invisible on close, to make it not re-appear unintended after switching PresentationMode interactiveWindowVisible = false; - } - onWindowDestroyed: { - console.warn("destroyed"); + if ((flags & Desktop.CLOSE_BUTTON_HIDES) !== Desktop.CLOSE_BUTTON_HIDES) { + selfDestruct(); + } } Item { diff --git a/libraries/ui/src/InteractiveWindow.cpp b/libraries/ui/src/InteractiveWindow.cpp index ad74ff3720..5078fcb602 100644 --- a/libraries/ui/src/InteractiveWindow.cpp +++ b/libraries/ui/src/InteractiveWindow.cpp @@ -84,7 +84,8 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap connect(object, SIGNAL(interactiveWindowVisibleChanged()), this, SIGNAL(visibleChanged()), Qt::QueuedConnection); connect(object, SIGNAL(presentationModeChanged()), this, SIGNAL(presentationModeChanged()), Qt::QueuedConnection); connect(object, SIGNAL(titleChanged()), this, SIGNAL(titleChanged()), Qt::QueuedConnection); - + connect(object, SIGNAL(windowClosed()), this, SIGNAL(closed()), Qt::QueuedConnection); + connect(object, SIGNAL(selfDestruct()), this, SLOT(close()), Qt::QueuedConnection); QUrl sourceURL{ sourceUrl }; // If the passed URL doesn't correspond to a known scheme, assume it's a local file path @@ -182,7 +183,6 @@ bool InteractiveWindow::isVisible() const { return result; } - // The tool window itself has special logic based on whether any tabs are enabled if (_qmlWindow.isNull()) { return false; } diff --git a/libraries/ui/src/InteractiveWindow.h b/libraries/ui/src/InteractiveWindow.h index 541ff2e140..800b810796 100644 --- a/libraries/ui/src/InteractiveWindow.h +++ b/libraries/ui/src/InteractiveWindow.h @@ -47,46 +47,19 @@ using namespace InteractiveWindowEnums; * @hifi-interface * @hifi-client-en * - * @property {string} mode + * @property {string} title + * @property {Vec2} position + * @property {Vec2} size + * @property {boolean} visible + * @property {Desktop.PresentationMode} presentationMode + * */ class InteractiveWindow : public QObject { Q_OBJECT - /**jsdoc - * title of the window - * - * @name InteractiveWindow#title - * @type string - * @default "InteractiveWindow" - */ Q_PROPERTY(QString title READ getTitle WRITE setTitle) - - /**jsdoc - * window position on current desktop - * - * @name InteractiveWindow#position - * @type Vec2 - */ Q_PROPERTY(glm::vec2 position READ getPosition WRITE setPosition) - - /**jsdoc - * window size - * - * @name InteractiveWindow#size - * @type Vec2 - */ Q_PROPERTY(glm::vec2 size READ getSize WRITE setSize) - - /**jsdoc - * visibility of the window - * - * @name InteractiveWindow#visible - * @type boolean - * @default true - * @example - * // Toggle window visiblity; - * interactiveWindow.visible = !interactiveWindow.visible; - */ Q_PROPERTY(bool visible READ isVisible WRITE setVisible) Q_PROPERTY(int presentationMode READ getPresentationMode WRITE setPresentationMode)