From d9dc8ebc41b9810a09555029348d2e407be0568c Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Thu, 13 Apr 2017 15:48:51 -0700 Subject: [PATCH] More improvements --- .../qml/hifi/tablet/TabletAddressDialog.qml | 162 ++++++------------ interface/src/Menu.cpp | 2 +- .../DialogsManagerScriptingInterface.cpp | 16 ++ .../DialogsManagerScriptingInterface.h | 3 + interface/src/ui/DialogsManager.cpp | 21 ++- interface/src/ui/DialogsManager.h | 1 + interface/src/ui/overlays/Web3DOverlay.cpp | 1 + 7 files changed, 95 insertions(+), 111 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/TabletAddressDialog.qml b/interface/resources/qml/hifi/tablet/TabletAddressDialog.qml index 356ff92664..b84e1ae9d4 100644 --- a/interface/resources/qml/hifi/tablet/TabletAddressDialog.qml +++ b/interface/resources/qml/hifi/tablet/TabletAddressDialog.qml @@ -21,7 +21,7 @@ import "../../styles-uit" as HifiStyles import "../../controls-uit" as HifiControls StackView { - id: root + id: root; HifiConstants { id: hifi } HifiStyles.HifiConstants { id: hifiStyleConstants } initialItem: addressBarDialog @@ -34,24 +34,16 @@ StackView { property string metaverseBase: addressBarDialog.metaverseServerUrl + "/api/v1/"; property var tablet: null; - property bool isDesktop: false; Component { id: tabletStoryCard; TabletStoryCard {} } Component.onCompleted: { - root.currentItem.focus = true; - root.currentItem.forceActiveFocus(); - addressLine.focus = true; - addressLine.forceActiveFocus(); fillDestinations(); updateLocationText(false); + fillDestinations(); + addressLine.focus = true; root.parentChanged.connect(center); center(); - isDesktop = (typeof desktop !== "undefined"); tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); - - if (desktop) { - root.title = "GOTO"; - } } Component.onDestruction: { root.parentChanged.disconnect(center); @@ -78,8 +70,6 @@ StackView { toggleOrGo(true, targetString); clearAddressLineTimer.start(); } - - property bool isCursorVisible: false // Override default cursor visibility. AddressBarDialog { @@ -102,16 +92,11 @@ StackView { onMetaverseServerUrlChanged: updateLocationTextTimer.start(); Rectangle { id: navBar - width: 480 - height: 70 + width: parent.width + height: 50; color: hifiStyleConstants.colors.white - anchors { - top: parent.top - right: parent.right - rightMargin: 0 - left: parent.left - leftMargin: 0 - } + anchors.top: parent.top; + anchors.left: parent.left; ToolbarButton { id: homeButton @@ -149,85 +134,77 @@ StackView { Rectangle { id: addressBar - width: 480 + width: parent.width height: 70 color: hifiStyleConstants.colors.white anchors { - top: navBar.bottom - right: parent.right - rightMargin: 16 - left: parent.left - leftMargin: 16 + top: navBar.bottom; + left: parent.left; } - property int inputAreaHeight: 70 - property int inputAreaStep: (height - inputAreaHeight) / 2 - HifiStyles.RalewayLight { id: notice; - font.pixelSize: hifi.fonts.pixelSize * 0.50; + font.pixelSize: hifi.fonts.pixelSize * 0.7; anchors { - top: parent.top - topMargin: parent.inputAreaStep + 12 - left: addressLine.left - right: addressLine.right + top: parent.top; + left: addressLineContainer.left; + right: addressLineContainer.right; } } + HifiStyles.FiraSansRegular { id: location; + anchors { + left: addressLineContainer.left; + leftMargin: 8; + verticalCenter: addressLineContainer.verticalCenter; + } font.pixelSize: addressLine.font.pixelSize; color: "gray"; clip: true; - anchors.fill: addressLine; visible: addressLine.text.length === 0 } TextInput { id: addressLine - focus: true + width: addressLineContainer.width - addressLineContainer.anchors.leftMargin - addressLineContainer.anchors.rightMargin; anchors { - bottom: parent.bottom - left: parent.left - right: parent.right - leftMargin: 16 - rightMargin: 16 - topMargin: parent.inputAreaStep + (2 * hifi.layout.spacing) - bottomMargin: parent.inputAreaStep + left: addressLineContainer.left; + leftMargin: 8; + verticalCenter: addressLineContainer.verticalCenter; } font.pixelSize: hifi.fonts.pixelSize * 0.75 - cursorVisible: false onTextChanged: { filterChoicesByText(); updateLocationText(text.length > 0); - if (!isCursorVisible && text.length > 0) { - isCursorVisible = true; - cursorVisible = true; - } } onAccepted: { addressBarDialog.keyboardEnabled = false; - } - onActiveFocusChanged: { - cursorVisible = isCursorVisible && focus; - } - MouseArea { - // If user clicks in address bar show cursor to indicate ability to enter address. - anchors.fill: parent - onClicked: { - isCursorVisible = true; - parent.cursorVisible = true; - parent.focus = true; - parent.forceActiveFocus(); - addressBarDialog.keyboardEnabled = HMD.active - tabletRoot.playButtonClickSound(); - } + toggleOrGo(); } } Rectangle { - anchors.fill: addressLine + id: addressLineContainer; + height: 40; + anchors { + top: notice.bottom; + topMargin: 2; + left: parent.left; + leftMargin: 16; + right: parent.right; + rightMargin: 16; + } color: hifiStyleConstants.colors.lightGray opacity: 0.1 + MouseArea { + anchors.fill: parent + onClicked: { + addressLine.focus = true; + addressBarDialog.keyboardEnabled = HMD.active; + tabletRoot.playButtonClickSound(); + } + } } } Rectangle { @@ -347,13 +324,12 @@ StackView { Timer { // Delay clearing address line so as to avoid flicker of "not connected" being displayed after entering an address. - id: clearAddressLineTimer - running: false - interval: 100 // ms - repeat: false + id: clearAddressLineTimer; + running: false; + interval: 100; // ms + repeat: false; onTriggered: { addressLine.text = ""; - isCursorVisible = false; } } @@ -545,46 +521,14 @@ StackView { } } - onVisibleChanged: { - updateLocationText(false); - if (visible) { - addressLine.forceActiveFocus(); - fillDestinations(); - } - } - function toggleOrGo(fromSuggestions, address) { if (address !== undefined && address !== "") { - addressBarDialog.loadAddress(address, fromSuggestions) - } - - if (addressLine.text !== "") { - addressBarDialog.loadAddress(addressLine.text, fromSuggestions) - } - - if (isDesktop) { - tablet.gotoHomeScreen(); - } else { - HMD.closeTablet(); - } - - tabletRoot.shown = false; - } - - Keys.onPressed: { - switch (event.key) { - case Qt.Key_Escape: - case Qt.Key_Back: - tabletRoot.shown = false - clearAddressLineTimer.start(); - event.accepted = true - break - case Qt.Key_Enter: - case Qt.Key_Return: - toggleOrGo() - clearAddressLineTimer.start(); - event.accepted = true - break + addressBarDialog.loadAddress(address, fromSuggestions); + clearAddressLineTimer.start(); + } else if (addressLine.text !== "") { + addressBarDialog.loadAddress(addressLine.text, fromSuggestions); + clearAddressLineTimer.start(); } + DialogsManager.hideAddressBar(); } } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 23d689e339..2451f42bca 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -254,7 +254,7 @@ Menu::Menu() { // Navigate > Show Address Bar addActionToQMenuAndActionHash(navigateMenu, MenuOption::AddressBar, Qt::CTRL | Qt::Key_L, - dialogsManager.data(), SLOT(toggleAddressBar())); + dialogsManager.data(), SLOT(showAddressBar())); // Navigate > Bookmark related menus -- Note: the Bookmark class adds its own submenus here. qApp->getBookmarks()->setupMenus(this, navigateMenu); diff --git a/interface/src/scripting/DialogsManagerScriptingInterface.cpp b/interface/src/scripting/DialogsManagerScriptingInterface.cpp index 1604c45593..f1c96b4309 100644 --- a/interface/src/scripting/DialogsManagerScriptingInterface.cpp +++ b/interface/src/scripting/DialogsManagerScriptingInterface.cpp @@ -22,11 +22,27 @@ DialogsManagerScriptingInterface::DialogsManagerScriptingInterface() { this, &DialogsManagerScriptingInterface::addressBarShown); } + +DialogsManagerScriptingInterface* DialogsManagerScriptingInterface::getInstance() { + static DialogsManagerScriptingInterface sharedInstance; + return &sharedInstance; +} + void DialogsManagerScriptingInterface::toggleAddressBar() { QMetaObject::invokeMethod(DependencyManager::get().data(), "toggleAddressBar", Qt::QueuedConnection); } +void DialogsManagerScriptingInterface::showAddressBar() { + QMetaObject::invokeMethod(DependencyManager::get().data(), + "showAddressBar", Qt::QueuedConnection); +} + +void DialogsManagerScriptingInterface::hideAddressBar() { + QMetaObject::invokeMethod(DependencyManager::get().data(), + "hideAddressBar", Qt::QueuedConnection); +} + void DialogsManagerScriptingInterface::showFeed() { QMetaObject::invokeMethod(DependencyManager::get().data(), "showFeed", Qt::QueuedConnection); diff --git a/interface/src/scripting/DialogsManagerScriptingInterface.h b/interface/src/scripting/DialogsManagerScriptingInterface.h index 86cd22af1c..aa231afb4a 100644 --- a/interface/src/scripting/DialogsManagerScriptingInterface.h +++ b/interface/src/scripting/DialogsManagerScriptingInterface.h @@ -18,10 +18,13 @@ class DialogsManagerScriptingInterface : public QObject { Q_OBJECT public: DialogsManagerScriptingInterface(); + static DialogsManagerScriptingInterface* getInstance(); Q_INVOKABLE void showFeed(); public slots: void toggleAddressBar(); + void showAddressBar(); + void hideAddressBar(); signals: void addressBarToggled(); diff --git a/interface/src/ui/DialogsManager.cpp b/interface/src/ui/DialogsManager.cpp index a95ac8d91f..c5932aae07 100644 --- a/interface/src/ui/DialogsManager.cpp +++ b/interface/src/ui/DialogsManager.cpp @@ -67,12 +67,14 @@ void DialogsManager::toggleAddressBar() { emit addressBarToggled(); } else { tablet->loadQMLSource(TABLET_ADDRESS_DIALOG); + qApp->setKeyboardFocusOverlay(hmd->getCurrentTabletScreenID()); _closeAddressBar = true; emit addressBarToggled(); } } else { tablet->loadQMLSource(TABLET_ADDRESS_DIALOG); hmd->openTablet(); + qApp->setKeyboardFocusOverlay(hmd->getCurrentTabletScreenID()); _closeAddressBar = true; emit addressBarToggled(); } @@ -84,11 +86,28 @@ void DialogsManager::showAddressBar() { auto hmd = DependencyManager::get(); auto tabletScriptingInterface = DependencyManager::get(); auto tablet = dynamic_cast(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system")); - tablet->loadQMLSource(TABLET_ADDRESS_DIALOG); + if (!tablet->isPathLoaded(TABLET_ADDRESS_DIALOG)) { + tablet->loadQMLSource(TABLET_ADDRESS_DIALOG); + } if (!hmd->getShouldShowTablet()) { hmd->openTablet(); } + qApp->setKeyboardFocusOverlay(hmd->getCurrentTabletScreenID()); + emit addressBarShown(true); +} + +void DialogsManager::hideAddressBar() { + auto hmd = DependencyManager::get(); + auto tabletScriptingInterface = DependencyManager::get(); + auto tablet = dynamic_cast(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system")); + + if (tablet->isPathLoaded(TABLET_ADDRESS_DIALOG)) { + tablet->gotoHomeScreen(); + hmd->closeTablet(); + } + qApp->setKeyboardFocusOverlay(UNKNOWN_OVERLAY_ID); + emit addressBarShown(false); } void DialogsManager::showFeed() { diff --git a/interface/src/ui/DialogsManager.h b/interface/src/ui/DialogsManager.h index 24b9078baf..76c4f083d2 100644 --- a/interface/src/ui/DialogsManager.h +++ b/interface/src/ui/DialogsManager.h @@ -43,6 +43,7 @@ public: public slots: void toggleAddressBar(); void showAddressBar(); + void hideAddressBar(); void showFeed(); void setDomainConnectionFailureVisibility(bool visible); void toggleLoginDialog(); diff --git a/interface/src/ui/overlays/Web3DOverlay.cpp b/interface/src/ui/overlays/Web3DOverlay.cpp index 502006c862..f80589e5a1 100644 --- a/interface/src/ui/overlays/Web3DOverlay.cpp +++ b/interface/src/ui/overlays/Web3DOverlay.cpp @@ -198,6 +198,7 @@ void Web3DOverlay::loadSourceURL() { _webSurface->getRootContext()->setContextProperty("AvatarInputs", AvatarInputs::getInstance()); _webSurface->getRootContext()->setContextProperty("GlobalServices", GlobalServicesScriptingInterface::getInstance()); _webSurface->getRootContext()->setContextProperty("AvatarList", DependencyManager::get().data()); + _webSurface->getRootContext()->setContextProperty("DialogsManager", DialogsManagerScriptingInterface::getInstance()); _webSurface->getRootContext()->setContextProperty("pathToFonts", "../../"); tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface->getRootItem(), _webSurface.data());