8b1ba069b5e4d9d18de21e6481c528bafe74c015
[apps/mixer.git] / app / Mixer.qml
1 /*
2  * Copyright 2016 Konsulko Group
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 // BUG: ValueChanged event is raised by sliders when you are moving the caret, should be raised only when you release it.
18 // TODO: Call mixer.setVolume(sliderName, Value) on value change
19 // TODO: Call mixer.getVolume(sliderName) on load
20
21 import QtQuick 2.6
22 import QtQuick.Layouts 1.1
23 import QtQuick.Controls 2.0
24 import AGL.Demo.Controls 1.0
25 import Mixer 1.0
26
27 ApplicationWindow {
28     id: root
29
30     Mixer {
31         id: mixer
32         Component.objectName: {
33             mixer.open(bindingAddress)
34         }
35         onRolesChanged: {
36             // Remove existing sliders
37             for(var i = sliders.children.length; i > 0 ; --i) {
38                 console.log("destroying: " + i)
39                 sliders.children[i-1].destroy()
40             }
41
42             // Add slider for each role
43             for(var j = 0; j < mixer.roles.length; ++j) {
44                 addSlider(mixer.roles[j])
45             }
46         }
47
48         function addSlider(name) {
49             Qt.createQmlObject("
50 import QtQuick.Layouts 1.1
51 import QtQuick.Controls 2.0
52 RowLayout {
53     property int value
54     id: slider_" + name + "
55             Layout.minimumHeight: 75
56             Label {
57                 font.pixelSize: 24
58                 text: \"" + name+ "\"
59                 Layout.minimumWidth: 150
60             }
61             Label {
62                 id: slider_" + name + "_textvalue
63                 font.pixelSize: 24
64                 text: \"0 %\"
65             }
66             Slider {
67                 id: slider_" + name + "_slider
68                 Layout.fillWidth: true
69                 from: 0
70                 to: 100
71                 stepSize: 1
72                 snapMode: Slider.SnapOnRelease
73                 onValueChanged: {
74                     slider_" + name + "_textvalue.text = value + \" %\"
75                     mixer.setVolume(\"" + name + "\", value)
76                 }
77                                 Component.objectName: {
78                     mixer.getVolume(\"" + name + "\")
79                 }
80             }
81         }", sliders, "volumeslider")
82         }
83
84         function deleteChilds(item) {
85             for(var i = item.children.length; i > 0 ; i--) {
86                 deleteChilds(item.children[i-1])
87             }
88             item.destroy()
89         }
90     }
91
92     Label {
93         id: title
94         font.pixelSize: 48
95         text: "Mixer"
96         anchors.horizontalCenter: parent.horizontalCenter
97     }
98
99     ColumnLayout {
100         id: sliders
101         anchors.margins: 80
102         anchors.top: title.bottom
103         anchors.left: parent.left
104         anchors.right: parent.right
105     }
106 }
107