Fix indent using tab instead of spaces
[apps/mixer.git] / app / Mixer.qml
index 725c2bb..73587a5 100644 (file)
  * limitations under the License.
  */
 
-// BUG: ValueChanged event is raised by sliders when you are moving the caret, should be raised only when you release it.
-// TODO: Call mixer.setVolume(sliderName, Value) on value change
-// TODO: Call mixer.getVolume(sliderName) on load
-
 import QtQuick 2.6
 import QtQuick.Layouts 1.1
 import QtQuick.Controls 2.0
@@ -25,19 +21,40 @@ import AGL.Demo.Controls 1.0
 import Mixer 1.0
 
 ApplicationWindow {
+    // ----- Signals
+
+    // ----- Properties
     property Component volumeSlider
 
+    // ----- Setup
     id: root
+    width: container.width * container.scale
+    height: container.height * container.scale
 
+    // ----- Childs
     Mixer {
+        // ----- Signals
+        signal sliderVolumeChanged(string role, int value)
+
+        // ----- Properties
+
+        // ----- Setup
         id: mixer
+
+        onSliderVolumeChanged: {
+            console.log("======role: " + role + ", volume: " + value);
+            mixer.setVolume(role, value);
+        }
+
         Component.onCompleted: {
-            root.volumeSlider = Qt.createComponent("VolumeSlider.qml");
-            if (root.VolumeSlider.status !== Component.Ready) {
-                console.log("Failed to load the VolumeSlider.qml component: " + root.volumeSlider.errorString());
+            var vs = Qt.createComponent("VolumeSlider.qml");
+            if (vs.status !== Component.Ready) {
+                console.log("Failed to load the VolumeSlider.qml component: " + vs.errorString());
             }
+            root.volumeSlider = vs
             mixer.open(bindingAddress);
         }
+
         onRolesChanged: {
             // Remove existing sliders
             for(var i = sliders.children.length; i > 0 ; --i) {
@@ -52,17 +69,21 @@ ApplicationWindow {
         }
 
         onVolumeChanged: {
+            console.log("onVolumeChanged(\"" + name + "\", " + value + ")");
             for(var i = 0; i < sliders.children.length ; i++) {
-                console.log("Slider found: " + i);
-                //if (sliders[i].role === name) {
-                //    sliders[i].value = value;
-                //}
+                var sld = sliders.children[i];
+                console.log(i + " - Slider found:" + sld + "[\"" + sld.role + "\"] = " + sld.value);
+                if (sld.role === name) {
+                    sld.value = value;
+                }
             }
         }
 
+        // ----- Functions
         function addSlider(name) {
-            var sld = root.volumeSlider.createObject(sliders);
-            sld.role = name;
+            var sld = root.volumeSlider.createObject(sliders)
+            sld.role = name
+            sld.onSliderValueChanged.connect(mixer.sliderVolumeChanged)
             mixer.getVolume(name); // Update volume
         }
 
@@ -74,19 +95,27 @@ ApplicationWindow {
         }
     }
 
-    Label {
-        id: title
-        font.pixelSize: 48
-        text: "Mixer"
-        anchors.horizontalCenter: parent.horizontalCenter
-    }
+    Item {
+        id: container
+        anchors.centerIn: parent
+        width: 1080
+        height: 1487
+        scale: screenInfo.scale_factor()
 
-    ColumnLayout {
-        id: sliders
-        anchors.margins: 80
-        anchors.top: title.bottom
-        anchors.left: parent.left
-        anchors.right: parent.right
+        Label {
+            id: title
+            font.pixelSize: 48
+            text: "Mixer"
+            anchors.horizontalCenter: parent.horizontalCenter
+        }
+
+        ColumnLayout {
+            id: sliders
+            anchors.margins: 80
+            anchors.top: title.bottom
+            anchors.left: parent.left
+            anchors.right: parent.right
+        }
     }
 }