on bb09f86 help sign in
unity8/tests/qmltests/Stage/ApplicationCheckBox.qml
189 lines 5.9 kB history raw
1/*
2 * Copyright (C) 2015-2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.4
18import QtQuick.Layouts 1.1
19import Ubuntu.Components 1.3
20import Unity.Application 0.1
22Column {
23 id: root
24 property string appId
25 property bool checked: false
27 function createSurface() {
28 if (d.application) {
29 d.application.createSurface();
30 }
31 }
33 enabled: appId !== "unity8-dash"
35 onCheckedChanged: {
36 if (d.bindGuard) { return; }
37 d.bindGuard = true;
39 if (checked) {
40 ApplicationManager.startApplication(root.appId);
41 } else {
42 ApplicationManager.stopApplication(root.appId);
43 }
44 d.bindGuard = false;
45 }
47 // Application checkbox row
48 RowLayout {
50 QtObject {
51 id: d
52 property bool bindGuard: false
53 property var application: null
54 Component.onCompleted: {
55 application = ApplicationManager.findApplication(root.appId);
56 }
57 }
59 Connections {
60 target: ApplicationManager
61 onCountChanged: {
62 d.application = ApplicationManager.findApplication(root.appId);
63 }
64 }
66 Layout.fillWidth: true
67 CheckBox {
68 id: checkbox
69 checked: false
70 activeFocusOnPress: false
72 onTriggered: {
73 if (d.bindGuard) { return; }
74 d.bindGuard = true;
76 if (checked) {
77 ApplicationManager.startApplication(root.appId);
78 } else {
79 ApplicationManager.stopApplication(root.appId);
80 }
81 d.bindGuard = false;
82 }
83 onCheckedChanged: {
84 if (d.bindGuard) { return; }
85 d.bindGuard = true;
87 root.checked = checked;
89 d.bindGuard = false;
90 }
91 Binding {
92 target: checkbox
93 property: "checked"
94 value: d.application != null
95 }
96 }
97 Label {
98 id: appIdLabel
99 text: root.appId
100 anchors.verticalCenter: parent.verticalCenter
101 }
102 Rectangle {
103 color: {
104 if (d.application) {
105 if (d.application.state === ApplicationInfoInterface.Starting) {
106 return "yellow";
107 } else if (d.application.state === ApplicationInfoInterface.Running) {
108 return "green";
109 } else if (d.application.state === ApplicationInfoInterface.Suspended) {
110 return "blue";
111 } else {
112 return "darkred";
113 }
114 } else {
115 return "darkred";
116 }
117 }
118 width: height
119 height: appIdLabel.height * 0.7
120 anchors.verticalCenter: parent.verticalCenter
121 }
123 MouseArea {
124 width: height
125 height: appIdLabel.height * 0.7
126 anchors.verticalCenter: parent.verticalCenter
127 onClicked: root.createSurface()
128 enabled: d.application && d.application.state === ApplicationInfoInterface.Running
129 visible: enabled
130 Label {
131 text: "➕"
132 anchors.centerIn: parent
133 }
134 }
135 }
137 // Prompts controls row
138 RowLayout {
139 anchors.left: root.left
140 anchors.leftMargin: units.gu(2)
141 visible: root.checked === true && d.application !== null && root.enabled
142 spacing: units.gu(1)
143 Label {
144 property int promptCount: d.application ? d.application.promptSurfaceList.count : 0
145 id: promptsLabel
146 text: promptCount + " prompts"
147 }
148 MouseArea {
149 width: height
150 height: promptsLabel.height * 0.7
151 anchors.verticalCenter: parent.verticalCenter
152 onClicked: d.application.createPromptSurface()
153 Label { text: "➕"; anchors.centerIn: parent }
154 }
155 MouseArea {
156 width: height
157 height: promptsLabel.height * 0.7
158 anchors.verticalCenter: parent.verticalCenter
159 onClicked: d.application.promptSurfaceList.get(0).close()
160 enabled: d.application && d.application.promptSurfaceList.count > 0
161 Label { text: "➖"; anchors.centerIn: parent; enabled: parent.enabled }
162 }
163 }
165 // Rows of top-level application surfaces
166 Repeater {
167 model: d.application ? d.application.surfaceList : null
168 RowLayout {
169 anchors.left: root.left
170 anchors.leftMargin: units.gu(2)
171 spacing: units.gu(1)
172 Label {
173 text: "- " + model.surface.name
174 }
175 MouseArea {
176 width: height
177 height: appIdLabel.height * 0.7
178 anchors.verticalCenter: parent.verticalCenter
179 enabled: model.surface.live
180 visible: enabled
181 onClicked: model.surface.setLive(false);
182 Label {
183 text: "⛒"
184 anchors.centerIn: parent
185 }
186 }
187 }
188 }