diff options
author | Loïc Collignon <loic.collignon@iot.bzh> | 2018-07-05 14:30:25 +0200 |
---|---|---|
committer | Loïc Collignon <loic.collignon@iot.bzh> | 2018-07-10 19:21:41 +0200 |
commit | d009b2e3665ab49ce8885a7d1f59d67bdaf4cd7e (patch) | |
tree | 38337c044e2c50989ffc98cc7c5d2b9598f36eca /app/Mixer.qml | |
parent | 9b2c0778e6b83591cbad1d9c76cbcad2186512d9 (diff) |
WIP better handling for slider creation
The creation of sliders is now using a template instead of a string
computation.
Also fixed some indentation and trailing spaces issues.
Change-Id: Ieb1d9f953d61fa1bac46bf1ab6904e67d09a3fa9
Signed-off-by: Loïc Collignon <loic.collignon@iot.bzh>
Diffstat (limited to 'app/Mixer.qml')
-rw-r--r-- | app/Mixer.qml | 63 |
1 files changed, 24 insertions, 39 deletions
diff --git a/app/Mixer.qml b/app/Mixer.qml index 631eda5..725c2bb 100644 --- a/app/Mixer.qml +++ b/app/Mixer.qml @@ -25,67 +25,52 @@ import AGL.Demo.Controls 1.0 import Mixer 1.0 ApplicationWindow { + property Component volumeSlider + id: root Mixer { id: mixer Component.onCompleted: { - mixer.open(bindingAddress) + root.volumeSlider = Qt.createComponent("VolumeSlider.qml"); + if (root.VolumeSlider.status !== Component.Ready) { + console.log("Failed to load the VolumeSlider.qml component: " + root.volumeSlider.errorString()); + } + mixer.open(bindingAddress); } onRolesChanged: { // Remove existing sliders for(var i = sliders.children.length; i > 0 ; --i) { - console.log("destroying: " + i) - sliders.children[i-1].destroy() + console.log("destroying: " + i); + sliders.children[i-1].destroy(); } // Add slider for each role for(var j = 0; j < mixer.roles.length; ++j) { - addSlider(mixer.roles[j]) + addSlider(mixer.roles[j]); } } - function addSlider(name) { - Qt.createQmlObject(" -import QtQuick.Layouts 1.1 -import QtQuick.Controls 2.0 -RowLayout { - property int value - id: slider_" + name + " - Layout.minimumHeight: 75 - Label { - font.pixelSize: 24 - text: \"" + name+ "\" - Layout.minimumWidth: 150 + onVolumeChanged: { + for(var i = 0; i < sliders.children.length ; i++) { + console.log("Slider found: " + i); + //if (sliders[i].role === name) { + // sliders[i].value = value; + //} } - Label { - id: slider_" + name + "_textvalue - font.pixelSize: 24 - text: \"0 %\" - } - Slider { - id: slider_" + name + "_slider - Layout.fillWidth: true - from: 0 - to: 100 - stepSize: 1 - snapMode: Slider.SnapOnRelease - onValueChanged: { - slider_" + name + "_textvalue.text = value + \" %\" - mixer.setVolume(\"" + name + "\", value) - } - Component.objectName: { - mixer.getVolume(\"" + name + "\") - } - } - }", sliders, "volumeslider") + } + + function addSlider(name) { + var sld = root.volumeSlider.createObject(sliders); + sld.role = name; + mixer.getVolume(name); // Update volume } function deleteChilds(item) { for(var i = item.children.length; i > 0 ; i--) { - deleteChilds(item.children[i-1]) + deleteChilds(item.children[i-1]); } - item.destroy() + item.destroy(); } } |