- center default native window

- close button destroys window by default unless Desktop.CLOSE_BUTTON_HIDES flag is set
This commit is contained in:
Thijs Wenker 2018-07-03 18:42:39 +02:00
parent d886bc2d9c
commit 3f6793b462
3 changed files with 26 additions and 42 deletions

View file

@ -28,6 +28,8 @@ Windows.Window {
// Don't destroy on close... otherwise the JS/C++ will have a dangling pointer // Don't destroy on close... otherwise the JS/C++ will have a dangling pointer
destroyOnCloseButton: false; destroyOnCloseButton: false;
signal selfDestruct();
property var flags: 0; property var flags: 0;
property var source; property var source;
@ -67,8 +69,14 @@ Windows.Window {
x = interactiveWindowPosition.x; x = interactiveWindowPosition.x;
y = interactiveWindowPosition.y; y = interactiveWindowPosition.y;
} else if (presentationMode === Desktop.PresentationMode.NATIVE && nativeWindow) { } else if (presentationMode === Desktop.PresentationMode.NATIVE && nativeWindow) {
nativeWindow.x = interactiveWindowPosition.x; if (interactiveWindowPosition.x === 0 && interactiveWindowPosition.y === 0) {
nativeWindow.y = interactiveWindowPosition.y; // 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() { function setupPresentationMode() {
console.warn(presentationMode);
if (presentationMode === Desktop.PresentationMode.VIRTUAL) { if (presentationMode === Desktop.PresentationMode.VIRTUAL) {
if (nativeWindow) { if (nativeWindow) {
nativeWindow.setVisible(false); nativeWindow.setVisible(false);
@ -104,7 +111,6 @@ Windows.Window {
} }
Component.onCompleted: { Component.onCompleted: {
x = interactiveWindowPosition.x; x = interactiveWindowPosition.x;
y = interactiveWindowPosition.y; y = interactiveWindowPosition.y;
width = interactiveWindowSize.width; width = interactiveWindowSize.width;
@ -161,6 +167,11 @@ Windows.Window {
} }
}); });
nativeWindow.closing.connect(function(closeEvent) {
closeEvent.accepted = false;
windowClosed();
});
// finally set the initial window mode: // finally set the initial window mode:
setupPresentationMode(); setupPresentationMode();
@ -243,10 +254,10 @@ Windows.Window {
onWindowClosed: { onWindowClosed: {
// set invisible on close, to make it not re-appear unintended after switching PresentationMode // set invisible on close, to make it not re-appear unintended after switching PresentationMode
interactiveWindowVisible = false; interactiveWindowVisible = false;
}
onWindowDestroyed: { if ((flags & Desktop.CLOSE_BUTTON_HIDES) !== Desktop.CLOSE_BUTTON_HIDES) {
console.warn("destroyed"); selfDestruct();
}
} }
Item { Item {

View file

@ -84,7 +84,8 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap
connect(object, SIGNAL(interactiveWindowVisibleChanged()), this, SIGNAL(visibleChanged()), Qt::QueuedConnection); connect(object, SIGNAL(interactiveWindowVisibleChanged()), this, SIGNAL(visibleChanged()), Qt::QueuedConnection);
connect(object, SIGNAL(presentationModeChanged()), this, SIGNAL(presentationModeChanged()), Qt::QueuedConnection); connect(object, SIGNAL(presentationModeChanged()), this, SIGNAL(presentationModeChanged()), Qt::QueuedConnection);
connect(object, SIGNAL(titleChanged()), this, SIGNAL(titleChanged()), 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 }; QUrl sourceURL{ sourceUrl };
// If the passed URL doesn't correspond to a known scheme, assume it's a local file path // 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; return result;
} }
// The tool window itself has special logic based on whether any tabs are enabled
if (_qmlWindow.isNull()) { if (_qmlWindow.isNull()) {
return false; return false;
} }

View file

@ -47,46 +47,19 @@ using namespace InteractiveWindowEnums;
* @hifi-interface * @hifi-interface
* @hifi-client-en * @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 { class InteractiveWindow : public QObject {
Q_OBJECT Q_OBJECT
/**jsdoc
* title of the window
*
* @name InteractiveWindow#title
* @type string
* @default "InteractiveWindow"
*/
Q_PROPERTY(QString title READ getTitle WRITE setTitle) 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) 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) 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(bool visible READ isVisible WRITE setVisible)
Q_PROPERTY(int presentationMode READ getPresentationMode WRITE setPresentationMode) Q_PROPERTY(int presentationMode READ getPresentationMode WRITE setPresentationMode)