From a053f9ed9efca3191a1762835c6d47c35b56c00b Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Thu, 15 Aug 2019 17:00:27 -0700 Subject: [PATCH] Impelement settingChanged; clean up some emoteIndicatorVisible code --- .../settingsApp/general/General.qml | 18 ++++-- .../scripting/SettingsScriptingInterface.cpp | 4 ++ .../scripting/SettingsScriptingInterface.h | 3 + .../simplifiedEmote/simplifiedEmote.js | 61 ++++++++++--------- 4 files changed, 51 insertions(+), 35 deletions(-) diff --git a/interface/resources/qml/hifi/simplifiedUI/settingsApp/general/General.qml b/interface/resources/qml/hifi/simplifiedUI/settingsApp/general/General.qml index 025aa82c6d..9be0336ed8 100644 --- a/interface/resources/qml/hifi/simplifiedUI/settingsApp/general/General.qml +++ b/interface/resources/qml/hifi/simplifiedUI/settingsApp/general/General.qml @@ -18,7 +18,6 @@ import PerformanceEnums 1.0 Flickable { property string avatarNametagMode: Settings.getValue("simplifiedNametag/avatarNametagMode", "on") - property bool emoteIndicatorVisible: true; id: root contentWidth: parent.width contentHeight: generalColumnLayout.height @@ -137,11 +136,20 @@ Flickable { Layout.preferredHeight: 18 Layout.preferredWidth: parent.width labelTextOn: "Show Emote UI" - checked: root.emoteIndicatorVisible + checked: Settings.getValue("simplifiedUI/emoteIndicatorVisible", true) onClicked: { - root.emoteIndicatorVisible = !root.emoteIndicatorVisible; - sendEmoteVisible({method: 'handleEmoteIndicatorVisible', emoteIndicatorVisible: root.emoteIndicatorVisible, source: "SettingsApp.qml"}); - console.log("emoteSwitch clicked. Emote UI is ", root.emoteIndicatorVisible); + var currentSetting = Settings.getValue("simplifiedUI/emoteIndicatorVisible", true); + Settings.setValue("simplifiedUI/emoteIndicatorVisible", !currentSetting); + } + + Connections { + target: Settings + + onValueChanged: { + if (setting === "simplifiedUI/emoteIndicatorVisible") { + emoteSwitch.checked = value; + } + } } } } diff --git a/interface/src/scripting/SettingsScriptingInterface.cpp b/interface/src/scripting/SettingsScriptingInterface.cpp index afafe1a350..c47d8e1da1 100644 --- a/interface/src/scripting/SettingsScriptingInterface.cpp +++ b/interface/src/scripting/SettingsScriptingInterface.cpp @@ -35,8 +35,12 @@ QVariant SettingsScriptingInterface::getValue(const QString& setting, const QVar } void SettingsScriptingInterface::setValue(const QString& setting, const QVariant& value) { + if (getValue(setting) == value) { + return; + } // Make a deep-copy of the string. // Dangling pointers can occur with QStrings that are implicitly shared from a QScriptEngine. QString deepCopy = QString::fromUtf16(setting.utf16()); Setting::Handle(deepCopy).set(value); + emit valueChanged(setting, value); } diff --git a/interface/src/scripting/SettingsScriptingInterface.h b/interface/src/scripting/SettingsScriptingInterface.h index 25a8b627cb..ff00299fd0 100644 --- a/interface/src/scripting/SettingsScriptingInterface.h +++ b/interface/src/scripting/SettingsScriptingInterface.h @@ -64,6 +64,9 @@ public slots: * print("Value: " + (typeof value) + " " + JSON.stringify(value)); // object {"x":0,"y":10,"z":0} */ void setValue(const QString& setting, const QVariant& value); + +signals: + void valueChanged(const QString& setting, const QVariant& value); }; #endif // hifi_SettingsScriptingInterface_h diff --git a/scripts/simplifiedUI/simplifiedEmote/simplifiedEmote.js b/scripts/simplifiedUI/simplifiedEmote/simplifiedEmote.js index 07275775e7..b887a2d5b2 100644 --- a/scripts/simplifiedUI/simplifiedEmote/simplifiedEmote.js +++ b/scripts/simplifiedUI/simplifiedEmote/simplifiedEmote.js @@ -230,14 +230,6 @@ function onGeometryChanged(rect) { } -function onEmoteAppBarClosed() { - if (emoteAppBarWindow) { - emoteAppBarWindow.fromQml.disconnect(onMessageFromEmoteAppBar); - } - emoteAppBarWindow = false; -} - - var POSITIVE_KEY = "z"; var NEGATIVE_KEY = "c"; var RAISE_HAND_KEY = "v"; @@ -304,8 +296,11 @@ var EMOTE_APP_BAR_WINDOW_FLAGS = 0x00000001 | // Qt::Window 0x40000000 | // Qt::NoDropShadowWindowHint 0x00200000; // Qt::WindowDoesNotAcceptFocus var emoteAppBarWindow = false; -var emoteIndicatorVisible = true; function showEmoteAppBar() { + if (emoteAppBarWindow) { + return; + } + emoteAppBarWindow = Desktop.createWindow(EMOTE_APP_BAR_QML_PATH, { title: EMOTE_APP_BAR_WINDOW_TITLE, presentationMode: EMOTE_APP_BAR_PRESENTATION_MODE, @@ -321,21 +316,40 @@ function showEmoteAppBar() { }); emoteAppBarWindow.fromQml.connect(onMessageFromEmoteAppBar); - emoteAppBarWindow.closed.connect(onEmoteAppBarClosed); +} + + +function handleEmoteIndicatorVisibleChanged(newValue) { + console.log("ZRF 2" + emoteAppBarWindow); + if (newValue && !emoteAppBarWindow) { + showEmoteAppBar(); + } else if (emoteAppBarWindow) { + if (emoteAppBarWindow) { + emoteAppBarWindow.fromQml.disconnect(onMessageFromEmoteAppBar); + } + emoteAppBarWindow.close(); + emoteAppBarWindow = false; + } +} + + +function onSettingsValueChanged(settingName, newValue) { + if (settingName === "simplifiedUI/emoteIndicatorVisible") { + handleEmoteIndicatorVisibleChanged(newValue); + } } var EmojiAPI = Script.require("./emojiApp/simplifiedEmoji.js?" + Date.now()); var emojiAPI = new EmojiAPI(); -var geometryChangedSignalConnected = false; var keyPressSignalsConnected = false; function init() { Window.geometryChanged.connect(onGeometryChanged); - geometryChangedSignalConnected = true; + Settings.valueChanged.connect(onSettingsValueChanged); emojiAPI.startup(); getSounds(); - showEmoteAppBar(); + handleEmoteIndicatorVisibleChanged(Settings.getValue("simplifiedUI/emoteIndicatorVisible", true)); Controller.keyPressEvent.connect(keyPressHandler); Controller.keyReleaseEvent.connect(keyReleaseHandler); @@ -347,7 +361,9 @@ function init() { function shutdown() { if (emoteAppBarWindow) { + emoteAppBarWindow.fromQml.disconnect(onMessageFromEmoteAppBar); emoteAppBarWindow.close(); + emoteAppBarWindow = false; } if (emojiAppWindow) { @@ -357,10 +373,8 @@ function shutdown() { emojiAPI.unload(); maybeClearClapSoundInterval(); - if (geometryChangedSignalConnected) { - Window.geometryChanged.disconnect(onGeometryChanged); - geometryChangedSignalConnected = false; - } + Window.geometryChanged.disconnect(onGeometryChanged); + Settings.valueChanged.disconnect(onSettingsValueChanged); if (keyPressSignalsConnected) { Controller.keyPressEvent.disconnect(keyPressHandler); @@ -515,18 +529,6 @@ function unload() { shutdown(); } -function handleEmoteIndicatorVisible(emoteIndicatorVisible) { - if (!emoteAppBarWindow) { - return; - } - - if (emoteIndicatorVisible) { - showEmoteAppBar(); - } else { - emoteAppBarWindow.close(); - } -} - var _this; function EmoteBar() { _this = this; @@ -535,7 +537,6 @@ function EmoteBar() { EmoteBar.prototype = { startup: startup, - handleEmoteIndicatorVisible: handleEmoteIndicatorVisible, unload: unload };