From ff55644fe859a72da6e16e5b15d92f1e5da171b8 Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Thu, 30 Jun 2016 16:24:11 -0700 Subject: [PATCH] stateful hud toolbar buttons --- interface/resources/qml/AddressBarDialog.qml | 1 + .../DialogsManagerScriptingInterface.cpp | 2 ++ .../DialogsManagerScriptingInterface.h | 1 + interface/src/ui/AddressBarDialog.cpp | 4 ++++ interface/src/ui/AddressBarDialog.h | 1 + interface/src/ui/DialogsManager.h | 2 ++ scripts/system/examples.js | 18 +++++++++++------- scripts/system/goto.js | 16 +++++++++++----- scripts/system/hmd.js | 19 ++++++++++++------- scripts/system/mute.js | 19 ++++++++++++++----- 10 files changed, 59 insertions(+), 24 deletions(-) diff --git a/interface/resources/qml/AddressBarDialog.qml b/interface/resources/qml/AddressBarDialog.qml index a48804faba..dc060b70e1 100644 --- a/interface/resources/qml/AddressBarDialog.qml +++ b/interface/resources/qml/AddressBarDialog.qml @@ -30,6 +30,7 @@ Window { width: addressBarDialog.implicitWidth height: addressBarDialog.implicitHeight + onShownChanged: addressBarDialog.observeShownChanged(shown); Component.onCompleted: { root.parentChanged.connect(center); center(); diff --git a/interface/src/scripting/DialogsManagerScriptingInterface.cpp b/interface/src/scripting/DialogsManagerScriptingInterface.cpp index 80a8b4ac7c..cbca7ff4ff 100644 --- a/interface/src/scripting/DialogsManagerScriptingInterface.cpp +++ b/interface/src/scripting/DialogsManagerScriptingInterface.cpp @@ -18,6 +18,8 @@ DialogsManagerScriptingInterface::DialogsManagerScriptingInterface() { connect(DependencyManager::get().data(), &DialogsManager::addressBarToggled, this, &DialogsManagerScriptingInterface::addressBarToggled); + connect(DependencyManager::get().data(), &DialogsManager::addressBarShown, + this, &DialogsManagerScriptingInterface::addressBarShown); } void DialogsManagerScriptingInterface::toggleAddressBar() { diff --git a/interface/src/scripting/DialogsManagerScriptingInterface.h b/interface/src/scripting/DialogsManagerScriptingInterface.h index ef44e20d61..075b89f0e5 100644 --- a/interface/src/scripting/DialogsManagerScriptingInterface.h +++ b/interface/src/scripting/DialogsManagerScriptingInterface.h @@ -24,6 +24,7 @@ public slots: signals: void addressBarToggled(); + void addressBarShown(bool visible); }; #endif diff --git a/interface/src/ui/AddressBarDialog.cpp b/interface/src/ui/AddressBarDialog.cpp index ba0cf18d32..6fb437e312 100644 --- a/interface/src/ui/AddressBarDialog.cpp +++ b/interface/src/ui/AddressBarDialog.cpp @@ -16,6 +16,7 @@ #include "DependencyManager.h" #include "AddressManager.h" +#include "DialogsManager.h" HIFI_QML_DEF(AddressBarDialog) @@ -74,3 +75,6 @@ void AddressBarDialog::displayAddressNotFoundMessage() { OffscreenUi::critical("", "There is no address information for that user or place"); } +void AddressBarDialog::observeShownChanged(bool visible) { + DependencyManager::get()->emitAddressBarShown(visible); +} diff --git a/interface/src/ui/AddressBarDialog.h b/interface/src/ui/AddressBarDialog.h index b2751860cc..bbce52c67c 100644 --- a/interface/src/ui/AddressBarDialog.h +++ b/interface/src/ui/AddressBarDialog.h @@ -38,6 +38,7 @@ protected: Q_INVOKABLE void loadHome(); Q_INVOKABLE void loadBack(); Q_INVOKABLE void loadForward(); + Q_INVOKABLE void observeShownChanged(bool visible); bool _backEnabled; bool _forwardEnabled; diff --git a/interface/src/ui/DialogsManager.h b/interface/src/ui/DialogsManager.h index b8fa22ec83..c48c6df0e6 100644 --- a/interface/src/ui/DialogsManager.h +++ b/interface/src/ui/DialogsManager.h @@ -40,6 +40,7 @@ public: QPointer getHMDToolsDialog() const { return _hmdToolsDialog; } QPointer getLodToolsDialog() const { return _lodToolsDialog; } QPointer getOctreeStatsDialog() const { return _octreeStatsDialog; } + void emitAddressBarShown(bool visible) { emit addressBarShown(visible); } public slots: void toggleAddressBar(); @@ -60,6 +61,7 @@ public slots: signals: void addressBarToggled(); + void addressBarShown(bool visible); private slots: void hmdToolsClosed(); diff --git a/scripts/system/examples.js b/scripts/system/examples.js index a948f9e563..4d838bc8af 100644 --- a/scripts/system/examples.js +++ b/scripts/system/examples.js @@ -55,16 +55,20 @@ var toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system"); var browseExamplesButton = toolBar.addButton({ imageURL: toolIconUrl + "examples-01.svg", objectName: "examples", - yOffset: 50, - alpha: 0.9, + buttonState: 1, + alpha: 0.9 }); -var browseExamplesButtonDown = false; - -browseExamplesButton.clicked.connect(function(){ +function onExamplesWindowVisibilityChanged() { + browseExamplesButton.writeProperty('buttonState', examplesWindow.visible ? 0 : 1); +} +function onClick() { toggleExamples(); -}); +} +browseExamplesButton.clicked.connect(onClick); +examplesWindow.visibleChanged.connect(onExamplesWindowVisibilityChanged); Script.scriptEnding.connect(function () { - browseExamplesButton.clicked.disconnect(); + browseExamplesButton.clicked.disconnect(onClick); + examplesWindow.visibleChanged.disconnect(onExamplesWindowVisibilityChanged); }); diff --git a/scripts/system/goto.js b/scripts/system/goto.js index a2ade02a78..4650e72dad 100644 --- a/scripts/system/goto.js +++ b/scripts/system/goto.js @@ -16,14 +16,20 @@ var button = toolBar.addButton({ objectName: "goto", imageURL: Script.resolvePath("assets/images/tools/directory-01.svg"), visible: true, - yOffset: 50, + buttonState: 1, alpha: 0.9, }); - -button.clicked.connect(function(){ + +function onAddressBarShown(visible) { + button.writeProperty('buttonState', visible ? 0 : 1); +} +function onClicked(){ DialogsManager.toggleAddressBar(); -}); +} +button.clicked.connect(onClicked); +DialogsManager.addressBarShown.connect(onAddressBarShown); Script.scriptEnding.connect(function () { - button.clicked.disconnect(); + button.clicked.disconnect(onClicked); + DialogsManager.addressBarShown.disconnect(onAddressBarShown); }); diff --git a/scripts/system/hmd.js b/scripts/system/hmd.js index 2965c0d254..0d6a273975 100644 --- a/scripts/system/hmd.js +++ b/scripts/system/hmd.js @@ -20,23 +20,28 @@ var desktopMenuItemName = "Desktop"; var toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system"); var button; - +function onHmdChanged(isHmd) { + button.writeProperty('buttonState', isHmd ? 0 : 1); +} +function onClicked(){ + var isDesktop = Menu.isOptionChecked(desktopMenuItemName); + Menu.setIsOptionChecked(isDesktop ? headset : desktopMenuItemName, true); +} if (headset) { button = toolBar.addButton({ objectName: "hmdToggle", imageURL: Script.resolvePath("assets/images/tools/hmd-switch-01.svg"), visible: true, - yOffset: 50, alpha: 0.9, }); + onHmdChanged(HMD.active); - button.clicked.connect(function(){ - var isDesktop = Menu.isOptionChecked(desktopMenuItemName); - Menu.setIsOptionChecked(isDesktop ? headset : desktopMenuItemName, true); - }); + button.clicked.connect(onClicked); + HMD.displayModeChanged.connect(onHmdChanged); Script.scriptEnding.connect(function () { - button.clicked.disconnect(); + button.clicked.disconnect(onClicked); + HMD.displayModeChanged.disconnect(onHmdChanged); }); } diff --git a/scripts/system/mute.js b/scripts/system/mute.js index f66b6852ea..f91ecbafae 100644 --- a/scripts/system/mute.js +++ b/scripts/system/mute.js @@ -14,16 +14,25 @@ var toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system"); var button = toolBar.addButton({ objectName: "mute", - imageURL: Script.resolvePath("assets/images/tools/microphone.svg"), + imageURL: Script.resolvePath("assets/images/tools/mic-01.svg"), visible: true, alpha: 0.9, }); - -button.clicked.connect(function(){ + +function onMuteToggled() { + // We could just toggle state, but we're less likely to get out of wack if we read the AudioDevice. + // muted => "on" button state => buttonState 1 + button.writeProperty('buttonState', AudioDevice.getMuted() ? 1 : 0); +} +onMuteToggled(); +function onClicked(){ var menuItem = "Mute Microphone"; Menu.setIsOptionChecked(menuItem, !Menu.isOptionChecked(menuItem)); -}); +} +button.clicked.connect(onClicked); +AudioDevice.muteToggled.connect(onMuteToggled); Script.scriptEnding.connect(function () { - button.clicked.disconnect(); + button.clicked.disconnect(onClicked); + AudioDevice.muteToggled.disconnect(onMuteToggled); });