-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.qml
167 lines (155 loc) · 4.67 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
/*
* Copyright (C) 2023 Nicolas Morais
* This program is free software; you can redistribute
* it and/or modify it under the terms of the GNU
* General Public License as published by the Free
* Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program 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
* General Public License for more details.
* You should have received a copy of the GNU General
* Public License along with this program; if not, see
* <https://www.gnu.org/licenses>.
*/
import QtQuick
import QtQuick.Window
import QtSensors
import QtQuick.Controls
import QtQuick.Controls.Material
ApplicationWindow {
width: Screen.width
height: Screen.height
visible: true
color: Theme.background
// property real lastAzimuth
Compass {
id: compass
}
Timer {
id: timer
interval: 200
triggeredOnStart: true
repeat: true
onTriggered: {
let azimuth = compass.reading.azimuth
//trick below prevents the number animation on
//rotation from doing a great turn when degrees
//change between positive and negative values
if(Math.sign(degreesIndicator.rotation) !== Math.sign(azimuth)) {
rotationSmoother.enabled = false
} else {
rotationSmoother.enabled = true
}
degreesIndicator.rotation = azimuth
degreesText.text = Math.round(azimuth) + "°"
calibrationLevel.text = "Calibration Level: " + Math.floor(
compass.reading.calibrationLevel * 100) + " %"
}
}
Component.onCompleted: {
compass.start()
timer.start()
}
Image {
id: degreesIndicator
anchors.centerIn: parent
height: Math.max(parent.width, parent.height) / 2
width: height
source: Theme.isDark ? "qrc:/images/degrees_indicator_dark_theme.svg" : "qrc:/images/degrees_indicator.svg"
Behavior on rotation {
id: rotationSmoother
NumberAnimation {
duration: 200
}
}
}
Image {
id: northIndicator
height: 50
width: 50
anchors.centerIn: degreesIndicator
source: "qrc:/images/north_indicator.svg"
}
Text {
id: degreesText
text: "Loading"
color: Theme.foreground
anchors.top: northIndicator.bottom
anchors.horizontalCenter: northIndicator.horizontalCenter
}
Button {
background: Rectangle {
anchors.fill: parent
color: Theme.background
border.width: 1
border.color: Theme.foreground
radius: width / 10
}
contentItem: Text {
text: "About"
color: Theme.foreground
}
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.rightMargin: 5
anchors.bottomMargin: 5
onPressed: aboutPopup.open()
}
Popup {
id: aboutPopup
height: parent.height * 0.8
width: parent.width * 0.8
anchors.centerIn: parent
dim: true
background: Rectangle {
color: Theme.background
anchors.fill: parent
}
Column {
width: parent.width
Text {
width: parent.width
text: "Author: Nicolas Morais"
color: Theme.foreground
font.pixelSize: 15
font.bold: true
}
Text {
width: parent.width
color: Theme.foreground
wrapMode: Text.WordWrap
text: "Source code available at https://github.com/nicmorais/qompass"
}
Row {
Text {
text: "Dark Theme:"
color: Theme.foreground
}
Switch {
checked: Theme.isDark
onClicked: Theme.toggleDarkTheme()
}
}
}
Text {
text: "Version: " + Qt.application.version
color: Theme.foreground
anchors.left: parent.left
anchors.bottom: parent.bottom
}
}
Text {
id: calibrationLevel
text: "Calibration level"
color: Theme.foreground
font.pointSize: 10
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.leftMargin: 10
anchors.bottomMargin: 10
}
}