From 6df0edd06c5d951013e3ba0de5677ecd904a68df Mon Sep 17 00:00:00 2001 From: mashiros <490328928@qq.com> Date: Sat, 9 Apr 2022 15:47:56 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E6=97=A0=E6=8C=82=E4=BB=B6=E6=97=B6?= =?UTF-8?q?=E7=A6=81=E7=94=A8websocket=20-=20=E7=BB=9F=E4=B8=80=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=A1=B5=E9=9D=A2=E6=A0=B7=E5=BC=8F=20-=20=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=97=A0=E7=94=A8=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module.qml | 2 +- qml/Common.qml | 8 +- qml/Main.qml | 6 ++ qml/StylePreferences.qml | 227 +++++++++++++++++++++++------------------------ qml/WSocket.qml | 2 - qml/api/StyleAPI.qml | 6 +- 6 files changed, 124 insertions(+), 127 deletions(-) diff --git a/module.qml b/module.qml index a9eda1d..e0ca425 100644 --- a/module.qml +++ b/module.qml @@ -7,7 +7,7 @@ NVG.Module { initialize: function () { console.log("Initializing ADV-Plugin."); Common.execute("../bin/ADVServer.exe", "-reboot"); - Common.setWsocket(true); +// Common.setWsocket(true); return true; } diff --git a/qml/Common.qml b/qml/Common.qml index ac4ab43..9057ade 100644 --- a/qml/Common.qml +++ b/qml/Common.qml @@ -11,6 +11,8 @@ Item { readonly property var stylesURL: [] readonly property var stylesCFG: [] + property int widgetsNum: 0 + signal audioDataUpdated(var audioData) signal wsocketClosed() @@ -73,7 +75,7 @@ Item { } wsPort = cfg["server"]["port"]; }} - active: false + active: widgetsNum>0 } function setWsocket(status) { @@ -117,8 +119,6 @@ Item { stylesCFG.push(styleCFG); } -// console.log(JSON.stringify(Object.keys(resource), null, 2)); -// console.log(JSON.stringify(resource.files(), null, 2)); }); } @@ -127,7 +127,5 @@ Item { parse_resource(preset_list, true); const third_list = NVG.Resources.filter(/.*/, /top.mashiros.advp-style/); parse_resource(third_list, false); -// console.log(JSON.stringify(styles, null, 2)); -// console.log(JSON.stringify(stylesURL, null, 2)); } } diff --git a/qml/Main.qml b/qml/Main.qml index cfdbcdc..10858a7 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -56,5 +56,11 @@ T.Widget { Component.onCompleted: { styleDialog.active = true; + Common.widgetsNum++; + } + + Component.onDestruction: { + styleDialog.active = false; + Common.widgetsNum--; } } diff --git a/qml/StylePreferences.qml b/qml/StylePreferences.qml index cb8ab18..411cdb2 100644 --- a/qml/StylePreferences.qml +++ b/qml/StylePreferences.qml @@ -4,6 +4,7 @@ import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 import NERvGear 1.0 as NVG import NERvGear.Preferences 1.0 as P +import NERvGear.Controls 1.0 import "." @@ -27,142 +28,136 @@ NVG.Window { property var configuration property var old_style_cfg - ColumnLayout { - id: root + Page { + id: cfg_page anchors.fill: parent - anchors.margins: 16 - anchors.topMargin: 0 - - Row { - spacing: window.width - 120 - - ToolButton { - text: qsTr("Save") - onClicked: { - configuration = rootPreference.save(); - let index = configuration["index"]; - widget.settings[Common.stylesURL[index]] = configuration[Common.stylesURL[index]]; - delete configuration[Common.stylesURL[index]]; - widget.settings.styles = configuration; - widget.settings.current_style = Common.stylesURL[index]; - styleDialog.active = false; - } - } - ToolButton { - text: qsTr("Reset") - onClicked: { - styleLoader.load(); - let cfg = rootPreference.save(); - let index = cfg["index"]; - widget.settings[Common.stylesURL[index]] = cfg[Common.stylesURL[index]]; - widget.setStyleURL(""); - widget.setStyleURL(Qt.resolvedUrl(Common.stylesURL[widget.settings.styles["index"]])); - } - } - } - - Label { - Layout.alignment: Qt.AlignCenter + header: TitleBar { text: qsTr("Settings") - font.pixelSize: 24 - } - Flickable { - Layout.fillWidth: true - Layout.fillHeight: true + standardButtons: Dialog.Save | Dialog.Reset - clip: true - contentWidth: preferenceLayout.implicitWidth - contentHeight: preferenceLayout.implicitHeight - - ColumnLayout { - id: preferenceLayout - width: root.width + onAccepted: { + configuration = rootPreference.save(); + let index = configuration["index"]; + widget.settings[Common.stylesURL[index]] = configuration[Common.stylesURL[index]]; + delete configuration[Common.stylesURL[index]]; + widget.settings.styles = configuration; + widget.settings.current_style = Common.stylesURL[index]; + styleDialog.active = false; + } - P.PreferenceGroup { - id: rootPreference - Layout.fillWidth: true + onReset: { + styleLoader.load(); + let cfg = rootPreference.save(); + let index = cfg["index"]; + widget.settings[Common.stylesURL[index]] = cfg[Common.stylesURL[index]]; + widget.setStyleURL(""); + widget.setStyleURL(Qt.resolvedUrl(Common.stylesURL[widget.settings.styles["index"]])); + } + } - label: qsTr("Configuration") + ColumnLayout { + id: root + anchors.fill: parent + anchors.margins: 16 + anchors.topMargin: 0 + + Flickable { + Layout.fillWidth: true + Layout.fillHeight: true + + clip: true + contentWidth: preferenceLayout.implicitWidth + contentHeight: preferenceLayout.implicitHeight + + ColumnLayout { + id: preferenceLayout + width: root.width + + P.PreferenceGroup { + id: rootPreference + Layout.fillWidth: true + + label: qsTr("Configuration") + + onPreferenceEdited: { + let cfg = rootPreference.save(); + let index = cfg["index"]; + if (widget.settings.styles["index"] !== index) { + widget.setStyleURL(""); + widget.settings[Common.stylesURL[widget.settings.styles["index"]]] = old_style_cfg; + old_style_cfg = widget.settings[Common.stylesURL[index]]; + } - onPreferenceEdited: { - let cfg = rootPreference.save(); - // console.log(JSON.stringify(cfg, null, 2)); - let index = cfg["index"]; - if (widget.settings.styles["index"] !== index) { - widget.setStyleURL(""); - widget.settings[Common.stylesURL[widget.settings.styles["index"]]] = old_style_cfg; - old_style_cfg = widget.settings[Common.stylesURL[index]]; + widget.settings[Common.stylesURL[index]] = cfg[Common.stylesURL[index]]; + delete cfg[Common.stylesURL[index]]; + widget.settings.styles = cfg; + widget.setStyleURL(Qt.resolvedUrl(Common.stylesURL[index])); } - widget.settings[Common.stylesURL[index]] = cfg[Common.stylesURL[index]]; - delete cfg[Common.stylesURL[index]]; - widget.settings.styles = cfg; - widget.setStyleURL(Qt.resolvedUrl(Common.stylesURL[index])); - } - - P.SelectPreference { - id: styleList - name: "index" - label: qsTr("Styles") - icon.name: "solid:\uf1fc" - defaultValue: 0 - model: Common.styles - } + P.SelectPreference { + id: styleList + name: "index" + label: qsTr("Styles") + icon.name: "solid:\uf1fc" + defaultValue: 0 + model: Common.styles + } - P.Separator {} - - P.PreferenceLoader { - id: styleLoader - name: Common.stylesURL[styleList.value] - source: Qt.resolvedUrl(Common.stylesCFG[styleList.value]) - onLoaded: { - let cfg = save(); - if (!widget.settings[Common.stylesURL[styleList.value]]) { - widget.settings[Common.stylesURL[styleList.value]] = cfg; - } else if(widget.settings[Common.stylesURL[styleList.value]]["__version"] === cfg["__version"]) { - load(widget.settings[Common.stylesURL[styleList.value]]); - } else { - widget.settings[Common.stylesURL[styleList.value]] = cfg; + P.Separator {} + + P.PreferenceLoader { + id: styleLoader + name: Common.stylesURL[styleList.value] + source: Qt.resolvedUrl(Common.stylesCFG[styleList.value]) + onLoaded: { + let cfg = save(); + if (!widget.settings[Common.stylesURL[styleList.value]]) { + widget.settings[Common.stylesURL[styleList.value]] = cfg; + } else if(widget.settings[Common.stylesURL[styleList.value]]["__version"] === cfg["__version"]) { + load(widget.settings[Common.stylesURL[styleList.value]]); + } else { + widget.settings[Common.stylesURL[styleList.value]] = cfg; + } + window.minimumHeight = cfg["__cfg_height"]; } - window.minimumHeight = cfg["__cfg_height"]; - } - onContentItemChanged: { - if(contentItem) { - contentItem.label = Common.styles[styleList.value]; + onContentItemChanged: { + if(contentItem) { + contentItem.label = Common.styles[styleList.value]; + } } } - } - P.Separator {} - - Component.onCompleted: { - if(!widget.settings.styles) { - configuration = rootPreference.save(); - let index = configuration["index"]; - widget.settings[Common.stylesURL[index]] = configuration[Common.stylesURL[index]]; - old_style_cfg = configuration[Common.stylesURL[index]]; - delete configuration[Common.stylesURL[index]]; - widget.settings.current_style = Common.stylesURL[index]; - widget.settings.styles = configuration; - } + P.Separator {} + + Component.onCompleted: { + if(!widget.settings.styles) { + configuration = rootPreference.save(); + let index = configuration["index"]; + widget.settings[Common.stylesURL[index]] = configuration[Common.stylesURL[index]]; + old_style_cfg = configuration[Common.stylesURL[index]]; + delete configuration[Common.stylesURL[index]]; + widget.settings.current_style = Common.stylesURL[index]; + widget.settings.styles = configuration; + } - let index = Common.stylesURL.indexOf(widget.settings.current_style); - if (index === -1) { - index = 0; - widget.settings.current_style = Common.stylesURL[index]; - } + let index = Common.stylesURL.indexOf(widget.settings.current_style); + if (index === -1) { + index = 0; + widget.settings.current_style = Common.stylesURL[index]; + } - widget.settings.styles["index"] = index; - widget.setStyleURL(Qt.resolvedUrl(Common.stylesURL[widget.settings.styles["index"]])); + widget.settings.styles["index"] = index; + widget.setStyleURL(Qt.resolvedUrl(Common.stylesURL[widget.settings.styles["index"]])); - rootPreference.load(widget.settings.styles); - configuration = widget.settings.styles; - old_style_cfg = widget.settings[Common.stylesURL[index]]; + rootPreference.load(widget.settings.styles); + configuration = widget.settings.styles; + old_style_cfg = widget.settings[Common.stylesURL[index]]; - styleLoader.load(widget.settings[Common.stylesURL[index]]); + styleLoader.load(widget.settings[Common.stylesURL[index]]); + } } } } diff --git a/qml/WSocket.qml b/qml/WSocket.qml index dfe2cf2..03c410f 100644 --- a/qml/WSocket.qml +++ b/qml/WSocket.qml @@ -18,8 +18,6 @@ WebSocket { onBinaryMessageReceived: { let arrayBuffer = new Float32Array(message); -// Common.audioData = arrayBuffer.slice(); Common.audioDataUpdated(arrayBuffer.slice()); -// arrayBuffer = null; } } diff --git a/qml/api/StyleAPI.qml b/qml/api/StyleAPI.qml index b044f63..1d8adbb 100644 --- a/qml/api/StyleAPI.qml +++ b/qml/api/StyleAPI.qml @@ -3,9 +3,9 @@ import QtQuick 2.12 import ".." //显式导入单例Common.qml Canvas { - width: widget.width; - height: widget.height; - contextType: "2d"; + width: widget.width + height: widget.height + contextType: "2d" renderTarget: Canvas.FramebufferObject renderStrategy: Canvas.Cooperative