From 835b23832fc309df61bbb56988729bc6d7a8791b Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Sat, 25 Feb 2017 00:40:38 +0000 Subject: [PATCH] some modal clean up --- .../qml/dialogs/TabletFileDialog.qml | 14 +++++++---- .../qml/dialogs/TabletMessageBox.qml | 15 ++++++------ .../qml/dialogs/TabletQueryDialog.qml | 11 +++++---- .../resources/qml/hifi/tablet/TabletRoot.qml | 11 ++++++++- .../qml/windows/TabletModalFrame.qml | 3 +++ interface/src/Application.cpp | 20 ++++++++++++---- .../src/TabletScriptingInterface.cpp | 12 ++++++++++ .../src/TabletScriptingInterface.h | 10 ++++++++ scripts/system/libraries/WebTablet.js | 23 ++++++++++++++----- 9 files changed, 91 insertions(+), 28 deletions(-) diff --git a/interface/resources/qml/dialogs/TabletFileDialog.qml b/interface/resources/qml/dialogs/TabletFileDialog.qml index 1b0e6d694d..0aef9179e8 100644 --- a/interface/resources/qml/dialogs/TabletFileDialog.qml +++ b/interface/resources/qml/dialogs/TabletFileDialog.qml @@ -101,9 +101,13 @@ TabletModalWindow { TabletModalFrame { id: fileDialogItem - width: parent.width - height: parent.height - anchors.margins: 0 + width: parent.width - 6 + height: parent.height - 6 + + anchors { + horizontalCenter: root.horizontalCenter + verticalCenter: root.verticalCenter + } property bool keyboardEnabled: false property bool keyboardRaised: false @@ -123,6 +127,7 @@ TabletModalWindow { top: parent.top topMargin: (fileDialogItem.hasTitle ? (fileDialogItem.frameMarginTop + hifi.dimensions.modalDialogMargin.y) : hifi.dimension.modalDialogMargin.y) left: parent.left + leftMargin: hifi.dimensions.contentSpacing.x } spacing: hifi.dimensions.contentSpacing.x @@ -623,7 +628,8 @@ TabletModalWindow { anchors { left: parent.left right: selectionType.visible ? selectionType.left: parent.right - rightMargin: selectionType.visible ? hifi.dimensions.contentSpacing.x : 0 + rightMargin: hifi.dimensions.contentSpacing.x + leftMargin: hifi.dimensions.contentSpacing.x bottom: keyboard.top bottomMargin: hifi.dimensions.contentSpacing.y } diff --git a/interface/resources/qml/dialogs/TabletMessageBox.qml b/interface/resources/qml/dialogs/TabletMessageBox.qml index 2102874ffd..e9b5f45e7f 100644 --- a/interface/resources/qml/dialogs/TabletMessageBox.qml +++ b/interface/resources/qml/dialogs/TabletMessageBox.qml @@ -66,7 +66,8 @@ TabletModalWindow { id: messageBox clip: true anchors.verticalCenter: parent.verticalCenter - width: parent.width + anchors.horizontalCenter: parent.horizontalCenter + width: parent.width - 6 height: 300 QtObject { @@ -77,15 +78,11 @@ TabletModalWindow { readonly property int maxHeight: 720 function resize() { - console.log("[DR]-> setting the target height"); var targetWidth = Math.max(titleWidth, mainTextContainer.contentWidth) var targetHeight = mainTextContainer.height + 3 * hifi.dimensions.contentSpacing.y + (informativeTextContainer.text != "" ? informativeTextContainer.contentHeight + 3 * hifi.dimensions.contentSpacing.y : 0) + buttons.height + (details.implicitHeight + hifi.dimensions.contentSpacing.y) + messageBox.frameMarginTop - //messageBox.width = (targetWidth < d.minWidth) ? d.minWidth : ((targetWidth > d.maxWidth) ? d.maxWidth : targetWidth) - - console.log("[DR} -> about to set the height"); messageBox.height = (targetHeight < d.minHeight) ? d.minHeight: ((targetHeight > d.maxHeight) ? d.maxHeight : targetHeight) } } @@ -93,24 +90,28 @@ TabletModalWindow { RalewaySemiBold { id: mainTextContainer onTextChanged: d.resize(); - wrapMode: Text.WrapAnywhere + wrapMode: Text.WordWrap size: hifi.fontSizes.sectionName color: hifi.colors.baseGrayHighlight + width: parent.width - 6 anchors { top: parent.top horizontalCenter: parent.horizontalCenter margins: 0 topMargin: hifi.dimensions.contentSpacing.y + messageBox.frameMarginTop } + maximumLineCount: 30 + elide: Text.ElideLeft lineHeight: 2 lineHeightMode: Text.ProportionalHeight horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter } RalewaySemiBold { id: informativeTextContainer onTextChanged: d.resize(); - wrapMode: Text.WrapAnywhere + wrapMode: Text.WordWrap size: hifi.fontSizes.sectionName color: hifi.colors.baseGrayHighlight anchors { diff --git a/interface/resources/qml/dialogs/TabletQueryDialog.qml b/interface/resources/qml/dialogs/TabletQueryDialog.qml index a920971031..3ff3347ebc 100644 --- a/interface/resources/qml/dialogs/TabletQueryDialog.qml +++ b/interface/resources/qml/dialogs/TabletQueryDialog.qml @@ -63,9 +63,8 @@ TabletModalWindow { TabletModalFrame { id: modalWindowItem - width: parent.width + width: parent.width - 12 height: 240 - anchors.margins: 0 anchors { verticalCenter: parent.verticalCenter horizontalCenter: parent.horizontalCenter @@ -73,13 +72,13 @@ TabletModalWindow { QtObject { id: d - readonly property int minWidth: 480 - readonly property int maxWdith: 480 + readonly property int minWidth: 470 + readonly property int maxWidth: 470 readonly property int minHeight: 120 readonly property int maxHeight: 720 function resize() { - var targetWidth = Math.max(titleWidth, 480) + var targetWidth = Math.max(titleWidth, 470) var targetHeight = (items ? comboBox.controlHeight : textResult.controlHeight) + 5 * hifi.dimensions.contentSpacing.y + buttons.height modalWindowItem.width = (targetWidth < d.minWidth) ? d.minWidth : ((targetWidth > d.maxWdith) ? d.maxWidth : targetWidth); modalWindowItem.height = ((targetHeight < d.minHeight) ? d.minHeight : ((targetHeight > d.maxHeight) ? d.maxHeight : targetHeight)) + ((keyboardEnabled && keyboardRaised) ? (keyboard.raisedHeight + 2 * hifi.dimensions.contentSpacing.y) : 0) + modalWindowItem.frameMarginTop @@ -106,6 +105,7 @@ TabletModalWindow { left: parent.left; right: parent.right; bottom: parent.bottom + leftMargin: 5 } } @@ -118,6 +118,7 @@ TabletModalWindow { left: parent.left right: parent.right bottom: parent.bottom + rightMargin: 5 } model: items ? items : [] } diff --git a/interface/resources/qml/hifi/tablet/TabletRoot.qml b/interface/resources/qml/hifi/tablet/TabletRoot.qml index 348d8167b1..102094ae1a 100644 --- a/interface/resources/qml/hifi/tablet/TabletRoot.qml +++ b/interface/resources/qml/hifi/tablet/TabletRoot.qml @@ -10,6 +10,7 @@ Item { property var rootMenu; property var openModal: null; + property var openMessage: null; property string subMenu: "" signal showDesktop(); @@ -24,7 +25,7 @@ Item { } Component { id: messageBoxBuilder; TabletMessageBox { } } function messageBox(properties) { - openModal = messageBoxBuilder.createObject(tabletRoot, properties); + openMessage = messageBoxBuilder.createObject(tabletRoot, properties); return openModal; } @@ -42,6 +43,14 @@ Item { tabletRoot.subMenu = subMenu; } + function isDialogOpen() { + if (openMessage !== null || openModal !== null) { + return true; + } + + return false; + } + function loadSource(url) { loader.source = ""; // make sure we load the qml fresh each time. loader.source = url; diff --git a/interface/resources/qml/windows/TabletModalFrame.qml b/interface/resources/qml/windows/TabletModalFrame.qml index 6d357a091a..550eec8357 100644 --- a/interface/resources/qml/windows/TabletModalFrame.qml +++ b/interface/resources/qml/windows/TabletModalFrame.qml @@ -39,6 +39,8 @@ Rectangle { visible: frameContent.hasTitle anchors { + horizontalCenter: parent.horizontalCenter + verticalCenter: parent.verticalCenter fill: parent topMargin: frameMarginTop leftMargin: frameMarginLeft @@ -71,6 +73,7 @@ Rectangle { y: -hifi.dimensions.modalDialogTitleHeight anchors.rightMargin: -50 anchors.right: parent.right + //anchors.horizontalCenter: parent.horizontalCenter } } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d8b974def2..c0c5a1d748 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1617,9 +1617,13 @@ void Application::toggleTabletUI() const { return; } lastTabletUIToggle = now; - - auto HMD = DependencyManager::get(); - HMD->toggleShouldShowTablet(); + auto tabletScriptingInterface = DependencyManager::get(); + TabletProxy* tablet = dynamic_cast(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system")); + bool messageOpen = tablet->isMessageDialogOpen(); + if (!messageOpen) { + auto HMD = DependencyManager::get(); + HMD->toggleShouldShowTablet(); + } } void Application::checkChangeCursor() { @@ -5776,8 +5780,14 @@ void Application::toggleRunningScriptsWidget() const { static const QUrl url("hifi/dialogs/RunningScripts.qml"); DependencyManager::get()->show(url, "RunningScripts"); } else { - static const QUrl url("../../hifi/dialogs/TabletRunningScripts.qml"); - tablet->pushOntoStack(url); + QQuickItem* tabletRoot = tablet->getTabletRoot(); + if (!tabletRoot && !isHMDMode()) { + static const QUrl url("hifi/dialogs/RunningScripts.qml"); + DependencyManager::get()->show(url, "RunningScripts"); + } else { + static const QUrl url("../../hifi/dialogs/TabletRunningScripts.qml"); + tablet->pushOntoStack(url); + } } //DependencyManager::get()->show(url, "RunningScripts"); //if (_runningScriptsWidget->isVisible()) { diff --git a/libraries/script-engine/src/TabletScriptingInterface.cpp b/libraries/script-engine/src/TabletScriptingInterface.cpp index 04e170a8d7..3e0babd086 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.cpp +++ b/libraries/script-engine/src/TabletScriptingInterface.cpp @@ -250,6 +250,18 @@ static QString getUsername() { } } +bool TabletProxy::isMessageDialogOpen() { + if (_qmlTabletRoot) { + QVariant result; + QMetaObject::invokeMethod(_qmlTabletRoot, "isDialogOpen",Qt::DirectConnection, + Q_RETURN_ARG(QVariant, result)); + + return result.toBool(); + } + + return false; +} + void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscreenSurface) { std::lock_guard guard(_mutex); _qmlOffscreenSurface = qmlOffscreenSurface; diff --git a/libraries/script-engine/src/TabletScriptingInterface.h b/libraries/script-engine/src/TabletScriptingInterface.h index 8b9bec4013..f17d441023 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.h +++ b/libraries/script-engine/src/TabletScriptingInterface.h @@ -109,6 +109,12 @@ public: Q_INVOKABLE void pushOntoStack(const QVariant& path); Q_INVOKABLE void popFromStack(); + /** jsdoc + * Check if the tablet has a message dialog open + * @function TabletProxy#isMessageDialogOpen + */ + Q_INVOKABLE bool isMessageDialogOpen(); + /**jsdoc * Creates a new button, adds it to this and returns it. * @function TabletProxy#addButton @@ -152,6 +158,10 @@ public: */ Q_INVOKABLE void sendToQml(QVariant msg); + /**jsdoc + * Check if the tablet is on the homescreen + * @function TabletProxy#onHomeScreen() + */ Q_INVOKABLE bool onHomeScreen(); QQuickItem* getTabletRoot() const { return _qmlTabletRoot; } diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 367ef05aea..dbda42e407 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -169,10 +169,16 @@ WebTablet = function (url, width, dpi, hand, clientOnly) { var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var onHomeScreen = tablet.onHomeScreen(); if (onHomeScreen) { - HMD.closeTablet(); + var isMessageOpen = tablet.isMessageDialogOpen(); + if (isMessageOpen === false) { + HMD.closeTablet(); + } } else { - tablet.gotoHomeScreen(); - _this.setHomeButtonTexture(); + var isMessageOpen = tablet.isMessageDialogOpen(); + if (isMessageOpen === false) { + tablet.gotoHomeScreen(); + _this.setHomeButtonTexture(); + } } } }; @@ -432,11 +438,16 @@ WebTablet.prototype.mousePressEvent = function (event) { if (overlayPickResults.intersects && overlayPickResults.overlayID === HMD.homeButtonID) { var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var onHomeScreen = tablet.onHomeScreen(); + var isMessageOpen = tablet.isMessageDialogOpen(); if (onHomeScreen) { - HMD.closeTablet(); + if (isMessageOpen === false) { + HMD.closeTablet(); + } } else { - tablet.gotoHomeScreen(); - this.setHomeButtonTexture(); + if (isMessageOpen === false) { + tablet.gotoHomeScreen(); + this.setHomeButtonTexture(); + } } } else if (!HMD.active && (!overlayPickResults.intersects || !overlayPickResults.overlayID === this.webOverlayID)) { this.dragging = true;