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 }
29
30 Component.onCompleted: {
31 if (ScreenTools.isFakeMobile) {
32 window.width = ScreenTools.screenWidth
33 window.height = ScreenTools.screenHeight
34 } else if (ScreenTools.isMobile) {
35 window.showFullScreen();
36 } else if (QGroundControl.corePlugin.options.enableSaveMainWindowPosition) {
37 window.minimumWidth = Math.min(ScreenTools.defaultFontPixelWidth * 100, Screen.width)
38 window.minimumHeight = Math.min(ScreenTools.defaultFontPixelWidth * 50, Screen.height)
39 if (s.width && s.height) {
40 window.x = s.x;
41 window.y = s.y;
42 window.width = s.width;
43 window.height = s.height;
44 window.visibility = s.visibility;
45 } else {
46 _setDefaultDesktopWindowSize()
47 }
48 } else {
49 _setDefaultDesktopWindowSize()
50 }
51 }
52
53 Connections {
54 target: window
55 function onXChanged() { if(_enabled) saveSettingsTimer.restart() }
56 function onYChanged() { if(_enabled) saveSettingsTimer.restart() }
57 function onWidthChanged() { if(_enabled) saveSettingsTimer.restart() }
58 function onHeightChanged() { if(_enabled) saveSettingsTimer.restart() }
59 function onVisibilityChanged() { if(_enabled) saveSettingsTimer.restart() }
60 }
61
62 Timer {
63 id: saveSettingsTimer
64 interval: 500
65 repeat: false
66 onTriggered: saveSettings()
67 }
68
69 function saveSettings() {
70 if (_enabled) {
71 switch(window.visibility) {
72 case ApplicationWindow.Windowed:
73 s.x = window.x;
74 s.y = window.y;
75 s.width = window.width;
76 s.height = window.height;
77 s.visibility = window.visibility;
78 break;
79 case ApplicationWindow.FullScreen:
80 s.visibility = window.visibility;
81 break;
82 case ApplicationWindow.Maximized:
83 s.visibility = window.visibility;
84 break;
85 }
86 }
87 }
88}