QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MainWindowSavedState.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Window
3import QtQuick.Controls
4import QtCore
5
6import QGroundControl
7import QGroundControl.Controls
8
9Item {
10 property Window window
11
12 property bool _enabled: !ScreenTools.isMobile && !ScreenTools.isFakeMobile && QGroundControl.corePlugin.options.enableSaveMainWindowPosition
13
14 Settings {
15 id: s
16 category: "MainWindowState"
17
18 property int x
19 property int y
20 property int width
21 property int height
22 property int visibility
23 }
24
25 function _setDefaultDesktopWindowSize() {
26 window.width = Math.min(250 * Screen.pixelDensity, Screen.width);
27 window.height = Math.min(150 * Screen.pixelDensity, Screen.height);
28 window.x = Screen.virtualX + (Screen.width - window.width) / 2;
29 window.y = Screen.virtualY + (Screen.height - window.height) / 2;
30 }
31
32 Component.onCompleted: {
33 if (ScreenTools.isFakeMobile) {
34 window.width = ScreenTools.screenWidth
35 window.height = ScreenTools.screenHeight
36 } else if (ScreenTools.isMobile) {
37 window.showFullScreen();
38 } else if (QGroundControl.corePlugin.options.enableSaveMainWindowPosition) {
39 window.minimumWidth = Math.min(ScreenTools.defaultFontPixelWidth * 100, Screen.width)
40 window.minimumHeight = Math.min(ScreenTools.defaultFontPixelWidth * 50, Screen.height)
41 if (s.width && s.height) {
42 window.x = s.x;
43 window.y = s.y;
44 window.width = s.width;
45 window.height = s.height;
46 window.visibility = s.visibility;
47 } else {
48 _setDefaultDesktopWindowSize()
49 }
50 } else {
51 _setDefaultDesktopWindowSize()
52 }
53 }
54
55 Connections {
56 target: window
57 function onXChanged() { if(_enabled) saveSettingsTimer.restart() }
58 function onYChanged() { if(_enabled) saveSettingsTimer.restart() }
59 function onWidthChanged() { if(_enabled) saveSettingsTimer.restart() }
60 function onHeightChanged() { if(_enabled) saveSettingsTimer.restart() }
61 function onVisibilityChanged() { if(_enabled) saveSettingsTimer.restart() }
62 }
63
64 Timer {
65 id: saveSettingsTimer
66 interval: 500
67 repeat: false
68 onTriggered: saveSettings()
69 }
70
71 function saveSettings() {
72 if (_enabled) {
73 switch(window.visibility) {
74 case ApplicationWindow.Windowed:
75 s.x = window.x;
76 s.y = window.y;
77 s.width = window.width;
78 s.height = window.height;
79 s.visibility = window.visibility;
80 break;
81 case ApplicationWindow.FullScreen:
82 s.visibility = window.visibility;
83 break;
84 case ApplicationWindow.Maximized:
85 s.visibility = window.visibility;
86 break;
87 }
88 }
89 }
90}