-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathMain.qml
387 lines (348 loc) · 9.77 KB
/
Main.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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
/*
* Copyright (C) 2018 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.1
import QtQuick.Dialogs 1.0
import QtQuick.Layouts 1.3
import ExitAction 1.0
import "qrc:/qml"
ApplicationWindow
{
title: qsTr("Gazebo GUI")
width: 1200
height: 1000
minimumWidth: 300
minimumHeight: 300
visible: true
id: window
objectName: "window"
font.family: "Roboto"
// Expose material properties to C++
property string materialTheme: window.Material.theme
property string materialPrimary: window.Material.primary
property string materialAccent: window.Material.accent
property string toolBarColorLight: MainWindow.toolBarColorLight
property string toolBarTextColorLight: MainWindow.toolBarTextColorLight
property string toolBarColorDark: MainWindow.toolBarColorDark
property string toolBarTextColorDark: MainWindow.toolBarTextColorDark
property string pluginToolBarColorLight: MainWindow.pluginToolBarColorLight
property string pluginToolBarTextColorLight: MainWindow.pluginToolBarTextColorLight
property string pluginToolBarColorDark: MainWindow.pluginToolBarColorDark
property string pluginToolBarTextColorDark: MainWindow.pluginToolBarTextColorDark
// Expose config properties to C++
property int defaultExitAction: MainWindow.defaultExitAction
property bool showDialogOnExit: MainWindow.showDialogOnExit
property string dialogOnExitText: MainWindow.dialogOnExitText
property bool exitDialogShowShutdown: MainWindow.exitDialogShowShutdown
property bool exitDialogShowCloseGui: MainWindow.exitDialogShowCloseGui
property string exitDialogShutdownText: MainWindow.exitDialogShutdownText
property string exitDialogCloseGuiText: MainWindow.exitDialogCloseGuiText
/**
* Flag to indicate if the close event was triggered by the close dialog.
*/
property bool closingFromDialog: false
/**
* Tool bar background color
*/
property string toolBarColor:
MainWindow.toolBarColorLight === "" ||
MainWindow.toolBarColorDark === "" ?
Material.primary :
(Material.theme === Material.Light) ?
MainWindow.toolBarColorLight : MainWindow.toolBarColorDark
/**
* Tool bar text color
*/
property string toolBarTextColor:
MainWindow.toolBarTextColorLight === "" ||
MainWindow.toolBarTextColorDark === "" ?
Material.background :
(Material.theme === Material.Light) ?
MainWindow.toolBarTextColorLight : MainWindow.toolBarTextColorDark
// Not sure why the binding doesn't take care of this
onTitleChanged: {
titleLabel.text = window.title
}
// Handler for window closing
onClosing: {
close.accepted = !showDialogOnExit
if(showDialogOnExit){
if (closingFromDialog) {
close.accepted = true;
} else {
confirmationDialogOnExit.open()
}
} else if (defaultExitAction == ExitAction.SHUTDOWN_SERVER) {
MainWindow.OnStopServer()
}
}
// C++ signals to QML slots
Connections {
target: MainWindow
function onNotify(_message) {
notificationDialog.setTextDuration(_message, 0)
}
function onNotifyWithDuration(_message, _duration) {
notificationDialog.setTextDuration(_message, _duration)
}
}
/**
* Load a configuration file
*/
function loadConfig() {
loadFileDialog.open()
}
/**
* Save a configuration file
*/
function saveConfig() {
MainWindow.OnSaveConfig()
}
/**
* Save a configuration file to a given file
*/
function saveConfigAs() {
saveFileDialog.open()
}
// Shortcuts (why not working on menu?)
Shortcut {
sequence: "Ctrl+O"
onActivated: loadConfig()
}
Shortcut {
sequence: "Ctrl+S"
onActivated: saveConfig()
}
Shortcut {
sequence: "Ctrl+Shift+S"
onActivated: saveConfigAs()
}
Shortcut {
sequence: "Ctrl+Q"
onActivated: close()
}
Shortcut {
sequence: "/"
onActivated: pluginMenu.open()
}
/**
* Top toolbar
*/
header: ToolBar {
Material.background: toolBarColor
Material.foreground: Material.foreground
MouseArea {
anchors.fill: parent;
property variant clickPos: "1,1"
onPressed: {
clickPos = Qt.point(mouse.x,mouse.y)
}
onPositionChanged: {
var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
window.x += delta.x;
window.y += delta.y;
}
onDoubleClicked: {
window.showMaximized()
}
}
RowLayout {
spacing: 20
anchors.fill: parent
ToolButton {
highlighted: true
visible: MainWindow.showDrawer
contentItem: Image {
fillMode: Image.Pad
horizontalAlignment: Image.AlignHCenter
verticalAlignment: Image.AlignVCenter
source: Material.theme === Material.Light ? "images/drawer.png" : "images/drawer_dark.png"
}
onClicked: drawer.open()
}
// Padding for title
Rectangle {
height: 1
width: 1
visible: !MainWindow.showDrawer
color: "transparent"
}
Label {
id: titleLabel
text: window.title
font.pixelSize: 18
color: toolBarTextColor
elide: Label.ElideRight
horizontalAlignment: Qt.AlignHLeft
verticalAlignment: Qt.AlignVCenter
Layout.fillWidth: true
}
ToolButton {
highlighted: true
visible: MainWindow.showPluginMenu
contentItem: Image {
fillMode: Image.Pad
horizontalAlignment: Image.AlignHCenter
verticalAlignment: Image.AlignVCenter
source: Material.theme === Material.Light ? "images/menu.png" : "images/menu_dark.png"
}
onClicked: pluginMenu.open()
PluginMenu {
id: pluginMenu
width: 200
x: parent.width - width
height: window.height * 0.3
transformOrigin: Popup.TopRight
}
}
}
}
/**
* Background
*/
GzSplit {
anchors.fill: parent
}
/**
* Left menu
*/
SideDrawer {
id: drawer
interactive: MainWindow.showDrawer
width: Math.min(window.width * 0.3, 500)
height: window.height
}
/**
* About dialog
*/
Dialog {
id: aboutDialog
modal: true
focus: true
title: "Gazebo GUI"
x: (window.width - width) / 2
y: window.height / 6
width: Math.min(window.width, window.height) / 3 * 2
contentHeight: aboutColumn.height
Column {
id: aboutColumn
spacing: 20
Label {
width: aboutDialog.availableWidth
text: "Gorgeous robotic interfaces since 2018."
wrapMode: Label.Wrap
font.pixelSize: 12
}
}
}
/**
* Style dialog
*/
StyleDialog {
id: styleDialog
x: (window.width - width) / 2
y: window.height / 6
width: Math.min(window.width, window.height) * 0.5
}
/**
* Load file dialog
*/
FileDialog {
id: loadFileDialog
title: "Load configuration"
folder: shortcuts.home
nameFilters: [ "Config files (*.config)" ]
selectMultiple: false
selectExisting: true
onAccepted: {
MainWindow.OnLoadConfig(fileUrl)
}
}
/**
* Save file dialog
*/
FileDialog {
id: saveFileDialog
title: "Save configuration"
folder: shortcuts.home
nameFilters: [ "Config files (*.config)" ]
selectMultiple: false
selectExisting: false
onAccepted: {
var selected = fileUrl.toString();
if (!selected.endsWith(".config"))
{
selected += ".config";
}
MainWindow.OnSaveConfigAs(selected);
}
}
GzSnackBar {
id: notificationDialog
}
Timer {
id: timer
}
/**
* Confirmation dialog on close button
*/
Dialog {
id: confirmationDialogOnExit
title: (dialogOnExitText ? dialogOnExitText : "Do you really want to exit?")
objectName: "confirmationDialogOnExit"
modal: true
focus: true
parent: ApplicationWindow.overlay
width: 500
x: (parent.width - width) / 2
y: (parent.height - height) / 2
closePolicy: Popup.CloseOnEscape
standardButtons:
(exitDialogShowCloseGui ? Dialog.Ok : Dialog.NoButton) |
(exitDialogShowShutdown ? Dialog.Discard : Dialog.NoButton) |
Dialog.Cancel
// The button texts need to be changed later than in onCompleted as standardButtons change later
onAboutToShow: function () {
if (exitDialogShowCloseGui && exitDialogCloseGuiText)
footer.standardButton(Dialog.Ok).text = exitDialogCloseGuiText
if (exitDialogShowShutdown)
footer.standardButton(Dialog.Discard).text =
(exitDialogShutdownText ? exitDialogShutdownText : "Shutdown server and GUI")
}
footer:
DialogButtonBox {
onClicked: function (btn) {
if (btn == this.standardButton(Dialog.Ok)) {
closingFromDialog = true;
window.close();
}
else if (btn == this.standardButton(Dialog.Discard)) {
MainWindow.OnStopServer()
// if GUI and server run in the same process, give server opportunity to kill the GUI
timer.interval = 100;
timer.repeat = false;
timer.triggered.connect(function() {
closingFromDialog = true;
window.close();
});
timer.start();
}
}
}
}
}