Impelement settingChanged; clean up some emoteIndicatorVisible code

This commit is contained in:
Zach Fox 2019-08-15 17:00:27 -07:00
parent 98eff6ebb6
commit a053f9ed9e
4 changed files with 51 additions and 35 deletions

View file

@ -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;
}
}
}
}
}

View file

@ -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<QVariant>(deepCopy).set(value);
emit valueChanged(setting, value);
}

View file

@ -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

View file

@ -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
};