-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMain.qml
132 lines (111 loc) · 3.52 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
/*
** Copyright (C) 2023 Victron Energy B.V.
** See LICENSE.txt for license information.
*/
import QtQuick
import QtQuick.Window
// *** This file cannot be edited directly on the cerbo filesystem. It is loaded from the binary ***
Window {
id: root
//: Application title
//% "Venus OS GUI"
//~ Context only shown on desktop systems
title: qsTrId("venus_os_gui")
color: Global.allPagesLoaded && !!guiLoader.item ? guiLoader.item.mainView.backgroundColor : Theme.color_page_background
width: Qt.platform.os != "wasm" ? Theme.geometry_screen_width/scaleFactor : Screen.width/scaleFactor
height: Qt.platform.os != "wasm" ? Theme.geometry_screen_height/scaleFactor : Screen.height/scaleFactor
property bool isDesktop: false
property real scaleFactor: 1.0
onIsDesktopChanged: Global.isDesktop = root.isDesktop
function skipSplashScreen() {
Global.splashScreenVisible = false
}
function rebuildUi() {
console.warn("Rebuilding UI")
if (Global.mainView) {
Global.mainView.clearUi()
}
Global.reset()
if (dataManagerLoader.active && dataManagerLoader.connectionReady) {
// we haven't lost backend connection.
// we must be rebuilding UI due to demo mode change.
// manually cycle the data manager loader.
dataManagerLoader.active = false
dataManagerLoader.active = true
}
gc()
console.warn("Rebuilding complete")
}
Component.onCompleted: Global.main = root
Loader {
id: dataManagerLoader
readonly property bool connectionReady: BackendConnection.state === BackendConnection.Ready
onConnectionReadyChanged: {
if (connectionReady) {
active = true
} else if (active && !Global.needPageReload) {
root.rebuildUi()
active = false
}
}
asynchronous: true
active: false
sourceComponent: Component {
DataManager { }
}
}
contentItem {
// on wasm just show the GUI at the top of the screen
transformOrigin: Qt.platform.os !== "wasm" ? Item.Center : Item.Top
// In WebAssembly builds, if we are displaying on a low-dpi mobile
// device, it may not have enough pixels to display the UI natively.
// To fix, we need to downscale everything by the appropriate factor,
// and take into account browser chrome stealing real-estate also.
onScaleChanged: Global.scalingRatio = contentItem.scale
scale: Math.min(root.width/Theme.geometry_screen_width, root.height/Theme.geometry_screen_height)
// Ideally each item would use focus handling to get its own key events, but in wasm the
// pagestack's pages do not reliably receive key events even when focused.
Keys.onPressed: function(event) {
Global.keyPressed(event)
event.accepted = false
}
}
Loader {
id: guiLoader
clip: Qt.platform.os == "wasm"
width: Theme.geometry_screen_width
height: Theme.geometry_screen_height
anchors.horizontalCenter: parent.horizontalCenter
states: State {
when: Qt.platform.os !== "wasm"
AnchorChanges {
target: guiLoader
anchors.verticalCenter: parent.verticalCenter
}
}
asynchronous: true
active: Global.dataManagerLoaded
sourceComponent: ApplicationContent {
anchors.centerIn: parent
}
}
Loader {
id: splashLoader
clip: Qt.platform.os == "wasm"
width: Theme.geometry_screen_width
height: Theme.geometry_screen_height
anchors.horizontalCenter: parent.horizontalCenter
states: State {
when: Qt.platform.os !== "wasm"
AnchorChanges {
target: splashLoader
anchors.verticalCenter: parent.verticalCenter
}
}
active: Global.splashScreenVisible
sourceComponent: SplashView {
anchors.centerIn: parent
}
}
FrameRateVisualizer {}
}