-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathServiceWindow.qml
301 lines (244 loc) · 8.43 KB
/
ServiceWindow.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/****************************************************************************
**
** Copyright (C) 2014 Alexander Rössler
** License: LGPL version 2.1
**
** This file is part of QtQuickVcp.
**
** All rights reserved. This program and the accompanying materials
** are made available under the terms of the GNU Lesser General Public License
** (LGPL) version 2.1 which accompanies this distribution, and is available at
** http://www.gnu.org/licenses/lgpl-2.1.html
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** Contributors:
** Alexander Rössler @ The Cool Tool GmbH <mail DOT aroessler AT gmail DOT com>
**
****************************************************************************/
import QtQuick 2.0
import QtQuick.Controls 1.2
import QtQuick.Window 2.0
Rectangle {
default property alias data: container.data
/*! This property holds the title of the service window.
*/
property string title: "Window"
/*! \qmlproperty bool ready
This property holds wheter the service window is ready or not.
Per default this property is set using the internal services
if you want to overwrite the services set this property to \c true.
*/
property bool ready: false
/*! \qmlproperty list<Service> services
This property holds the services used by the application.
*/
property var services: []
/*!
\qmlproperty Item toolBar
This property holds the toolbar \l Item.
It can be set to any Item type, but is generally used with \l ToolBar.
By default, this value is not set. When you set the toolbar item, it will
be anchored automatically into the application window.
*/
property Item toolBar
/*!
\qmlproperty Item statusBar
This property holds the status bar \l Item.
It can be set to any Item type, but is generally used with \l StatusBar.
By default, this value is not set. When you set the status bar item, it
will be anchored automatically into the application window.
*/
property Item statusBar
/*!
\qmlproperty MenuBar menuBar
This property holds the \l MenuBar.
By default, this value is not set.
*/
property MenuBar menuBar
/*!
\qmlproperty Item background
This property holds the background \l Item.
The background item is shown when service discovery is in progress.
By default, this value references the default loading screen. When you set
the background item it will be reparented to the ServiceWindow automatically.
*/
property Item background: discoveryPage
/*! \internal */
property var _requiredServices: {
var required = [];
var newReady = true;
for (var i = 0; i < services.length; ++i) {
if (services[i].required) {
required.push(services[i]);
newReady = newReady && services[i].ready;
services[i].onReadyChanged.connect(_evaluateReady);
}
}
ready = newReady; // if no required service we are ready
return required;
}
/*!
Updates the services of this window.
*/
function updateServices() {
var list = [];
var nestedList = _recurseObjects(root.data, "Service");
if (nestedList.length > 0) {
list = list.concat(nestedList);
}
root.services = list;
}
/*! \internal */
function _evaluateReady() {
for (var i = 0; i < _requiredServices.length; ++i) {
if (!_requiredServices[i].ready) {
ready = false;
return;
}
}
ready = true;
return;
}
/*! \internal */
function _recurseObjects(objects, name)
{
var list = [];
if (objects !== undefined) {
for (var i = 0; i < objects.length; ++i)
{
if (objects[i].objectName === name) {
list.push(objects[i]);
}
var nestedList = _recurseObjects(objects[i].data, name);
if (nestedList.length > 0) {
list = list.concat(nestedList);
}
}
}
return list;
}
/*! \qmlsignal disconnect
Disconnects the service window if connected.
*/
signal disconnect()
/*! \qmlsignal disconnect
Signals that the application is beeing shutdown.
*/
signal shutdown()
Component.onCompleted: {
updateServices();
}
id: root
color: systemPalette.window
onBackgroundChanged: {
if (background !== discoveryPage) {
background.parent = root;
background.z = 1000;
}
}
SystemPalette {
id: systemPalette;
colorGroup: enabled ? SystemPalette.Active : SystemPalette.Disabled
}
Label {
id: dummyText
}
Item {
id: container
anchors.fill: parent
}
/* loads the default discovery page if necessary */
Loader {
id: discoveryPage
anchors.fill: parent
visible: false
z: 100
sourceComponent: defaultDiscoveryPage
active: background === discoveryPage
Behavior on opacity {
enabled: opacity === 1.0
PropertyAnimation {
duration: 500;
properties: "opacity";
easing.type: Easing.InCubic;
}
}
/* This timer is a workaround to make the discoveryPage invisible in QML designer */
Timer {
interval: 10
repeat: false
running: discoveryPage.active
onTriggered: {
discoveryPage.visible = true;
}
}
}
/* the default discovery page, overlays the window as long as Machinetalk is not ready */
Component {
id: defaultDiscoveryPage
Rectangle {
id: discoveryPage
color: systemPalette.window
Button {
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: Screen.pixelDensity
text: qsTr("Back")
onClicked: root.disconnect()
}
Label {
id: connectingLabel
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: connectingIndicator.top
anchors.bottomMargin: Screen.pixelDensity
font.pointSize: dummyText.font.pointSize * 1.3
text: qsTr("Waiting for services to appear...")
}
BusyIndicator {
id: connectingIndicator
anchors.centerIn: parent
running: true
height: Math.min(root.width, root.height) * 0.15
width: height
}
Column {
id: serviceCheckColumn
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: connectingIndicator.bottom
anchors.topMargin: Screen.pixelDensity
Repeater {
model: root._requiredServices.length
CheckBox {
id: checkBox
text: qsTr("%1 service").arg(capitalizeFirstLetter(_requiredServices[index].type))
checked: _requiredServices[index].ready
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
}
}
}
MouseArea {
// steal the clicks from the check boxes
anchors.fill: serviceCheckColumn
}
}
}
state: ready ? "connected" : "disconnected"
states: [
State {
name: "disconnected"
PropertyChanges { target: background; opacity: 1.0; enabled: true }
PropertyChanges { target: container; visible: false; enabled: false }
},
State {
name: "connected"
PropertyChanges { target: background; opacity: 0.0; enabled: false }
PropertyChanges { target: container; visible: true; enabled: true }
}
]
}