Improve output of multiple screen resolution
[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 import QtQuick 2.6
18 import QtQuick.Layouts 1.1
19 import QtQuick.Controls 2.0
20 import AGL.Demo.Controls 1.0
21 import Mixer 1.0
22
23 ApplicationWindow {
24     // ----- Signals
25
26     // ----- Properties
27     property Component volumeSlider
28
29     // ----- Setup
30     id: root
31     width: container.width * container.scale
32     height: container.height * container.scale
33
34     // ----- Childs
35     Mixer {
36         // ----- Signals
37         signal sliderVolumeChanged(string role, int value)
38
39         // ----- Properties
40
41         // ----- Setup
42         id: mixer
43
44         onSliderVolumeChanged: {
45             console.log("======role: " + role + ", volume: " + value);
46             mixer.setVolume(role, value);
47         }
48
49         Component.onCompleted: {
50             var vs = Qt.createComponent("VolumeSlider.qml");
51             if (vs.status !== Component.Ready) {
52                 console.log("Failed to load the VolumeSlider.qml component: " + vs.errorString());
53             }
54             root.volumeSlider = vs
55             mixer.open(bindingAddress);
56         }
57
58         onRolesChanged: {
59             // Remove existing sliders
60             for(var i = sliders.children.length; i > 0 ; --i) {
61                 console.log("destroying: " + i);
62                 sliders.children[i-1].destroy();
63             }
64
65             // Add slider for each role
66             for(var j = 0; j < mixer.roles.length; ++j) {
67                 addSlider(mixer.roles[j]);
68             }
69         }
70
71         onVolumeChanged: {
72             console.log("onVolumeChanged(\"" + name + "\", " + value + ")");
73             for(var i = 0; i < sliders.children.length ; i++) {
74                 var sld = sliders.children[i];
75                 console.log(i + " - Slider found:" + sld + "[\"" + sld.role + "\"] = " + sld.value);
76                 if (sld.role === name) {
77                     sld.value = value;
78                 }
79             }
80         }
81
82         // ----- Functions
83         function addSlider(name) {
84             var sld = root.volumeSlider.createObject(sliders)
85             sld.role = name
86             sld.onSliderValueChanged.connect(mixer.sliderVolumeChanged)
87             mixer.getVolume(name); // Update volume
88         }
89
90         function deleteChilds(item) {
91             for(var i = item.children.length; i > 0 ; i--) {
92                 deleteChilds(item.children[i-1]);
93             }
94             item.destroy();
95         }
96     }
97
98     Item {
99         id: container
100         anchors.centerIn: parent
101         width: 1080
102         height: 1487
103         scale: screenInfo.scale_factor()
104
105         Label {
106             id: title
107             font.pixelSize: 48
108             text: "Mixer"
109             anchors.horizontalCenter: parent.horizontalCenter
110         }
111
112         ColumnLayout {
113             id: sliders
114             anchors.margins: 80
115             anchors.top: title.bottom
116             anchors.left: parent.left
117             anchors.right: parent.right
118         }
119     }
120 }
121