Skip to content

Commit d94b353

Browse files
authored
Merge pull request #2 from nicmorais/v1.1.0
New dark theme and others changes
2 parents 7795639 + 976b25d commit d94b353

File tree

13 files changed

+427
-57
lines changed

13 files changed

+427
-57
lines changed

CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set(CMAKE_AUTOMOC ON)
1111
set(CMAKE_AUTORCC ON)
1212
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1313

14-
find_package(Qt6 6.2 REQUIRED COMPONENTS Quick Sensors)
14+
find_package(Qt6 6.2 REQUIRED COMPONENTS Quick Sensors Svg)
1515

1616
configure_file(main.cpp.in main.cpp @ONLY)
1717

@@ -22,7 +22,7 @@ qt_add_executable(qompass
2222
qt_add_qml_module(qompass
2323
URI qompass
2424
VERSION 1.0
25-
QML_FILES Main.qml
25+
QML_FILES Main.qml Theme.qml
2626
)
2727

2828
set_property(TARGET qompass PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
@@ -31,15 +31,17 @@ set_property(TARGET qompass PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
3131
target_link_libraries(qompass
3232
PRIVATE Qt6::Quick
3333
Qt6::Sensors
34+
Qt6::Svg
3435
)
3536

3637
qt_add_resources(qompass
3738
"main"
3839
PREFIX
3940
"/"
4041
FILES
41-
images/degrees_indicator.png
42-
images/north_indicator.png
42+
images/degrees_indicator.svg
43+
images/north_indicator.svg
44+
images/degrees_indicator_dark_theme.svg
4345
)
4446

4547
install(TARGETS qompass

Main.qml

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ import QtQuick
2121
import QtQuick.Window
2222
import QtSensors
2323
import QtQuick.Controls
24+
import QtQuick.Controls.Material
2425

2526
ApplicationWindow {
26-
width: 640
27-
height: 480
27+
width: Screen.width
28+
height: Screen.height
2829
visible: true
30+
color: Theme.background
31+
// property real lastAzimuth
32+
2933
Compass {
3034
id: compass
3135
}
@@ -35,9 +39,17 @@ ApplicationWindow {
3539
triggeredOnStart: true
3640
repeat: true
3741
onTriggered: {
38-
degreesIndicator.rotation = Math.abs(compass.reading.azimuth)
39-
degreesText.text = Math.round(Math.abs(
40-
compass.reading.azimuth)) + "°"
42+
let azimuth = compass.reading.azimuth
43+
//trick below prevents the number animation on
44+
//rotation from doing a great turn when degrees
45+
//change between positive and negative values
46+
if(Math.sign(degreesIndicator.rotation) !== Math.sign(azimuth)) {
47+
rotationSmoother.enabled = false
48+
} else {
49+
rotationSmoother.enabled = true
50+
}
51+
degreesIndicator.rotation = azimuth
52+
degreesText.text = Math.round(azimuth) + "°"
4153
calibrationLevel.text = "Calibration Level: " + Math.floor(
4254
compass.reading.calibrationLevel * 100) + " %"
4355
}
@@ -53,36 +65,49 @@ ApplicationWindow {
5365
anchors.centerIn: parent
5466
height: Math.max(parent.width, parent.height) / 2
5567
width: height
56-
source: "qrc:/images/degrees_indicator.png"
68+
source: Theme.isDark ? "qrc:/images/degrees_indicator_dark_theme.svg" : "qrc:/images/degrees_indicator.svg"
5769
Behavior on rotation {
70+
id: rotationSmoother
5871
NumberAnimation {
5972
duration: 200
6073
}
6174
}
6275
}
63-
6476
Image {
6577
id: northIndicator
6678
height: 50
6779
width: 50
6880
anchors.centerIn: degreesIndicator
69-
source: "qrc:/images/north_indicator.png"
81+
source: "qrc:/images/north_indicator.svg"
7082
}
7183

7284
Text {
7385
id: degreesText
7486
text: "Loading"
87+
color: Theme.foreground
7588
anchors.top: northIndicator.bottom
7689
anchors.horizontalCenter: northIndicator.horizontalCenter
7790
}
7891

7992
Button {
80-
text: "about"
81-
onPressed: aboutPopup.open()
93+
background: Rectangle {
94+
anchors.fill: parent
95+
color: Theme.background
96+
border.width: 1
97+
border.color: Theme.foreground
98+
radius: width / 10
99+
}
100+
101+
contentItem: Text {
102+
text: "About"
103+
color: Theme.foreground
104+
}
105+
82106
anchors.right: parent.right
83107
anchors.bottom: parent.bottom
84108
anchors.rightMargin: 5
85109
anchors.bottomMargin: 5
110+
onPressed: aboutPopup.open()
86111
}
87112

88113
Popup {
@@ -92,32 +117,47 @@ ApplicationWindow {
92117
anchors.centerIn: parent
93118
dim: true
94119
background: Rectangle {
95-
color: "white"
120+
color: Theme.background
96121
anchors.fill: parent
97122
}
98123
Column {
99124
width: parent.width
100125
Text {
101126
width: parent.width
102127
text: "Author: Nicolas Morais"
128+
color: Theme.foreground
103129
font.pixelSize: 15
104130
font.bold: true
105131
}
106132
Text {
107133
width: parent.width
134+
color: Theme.foreground
108135
wrapMode: Text.WordWrap
109136
text: "Source code available at https://github.com/nicmorais/qompass"
110137
}
138+
Row {
139+
Text {
140+
text: "Dark Theme:"
141+
color: Theme.foreground
142+
}
143+
Switch {
144+
checked: Theme.isDark
145+
onClicked: Theme.toggleDarkTheme()
146+
}
147+
}
111148
}
149+
112150
Text {
151+
text: "Version: " + Qt.application.version
152+
color: Theme.foreground
113153
anchors.left: parent.left
114154
anchors.bottom: parent.bottom
115-
text: "Version: " + Qt.application.version
116155
}
117156
}
118157
Text {
119158
id: calibrationLevel
120159
text: "Calibration level"
160+
color: Theme.foreground
121161
font.pointSize: 10
122162
anchors.left: parent.left
123163
anchors.bottom: parent.bottom

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### 1.1.0 (2023-08-17)
2+
* Adds dark theme, with switching between light and dark
3+
* Fixes animation behavior when angle changes
4+
* Centers the indicator circle
5+
* Adds building guide to README
6+
* Removes deprecated Qt.labs.settings (QSettings is under QtCore)
7+
18
### 1.0.0 (2023-07-15)
29

310
* Initial release. Simple compass with angle indicator, calibration level

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This is exactly what you need: a simple compass app.
55

66
### Demo
77

8-
![Demo](doc/demo.gif)
8+
![Demo](doc/demo.jpg)
99

1010
## Downloading
1111

@@ -14,4 +14,45 @@ Go to Github Releases page and download the latest APK file.
1414
This app is not (yet) available at F-Droid.
1515

1616
## Building
17-
TODO
17+
18+
(This building guide lacks some details)
19+
20+
Make sure to have Qt 6 for Android with Qt Sensors and Qt SVG installed in your machine.
21+
22+
You'll also need Android SDK, NDK and Java JDK. My current NDK version is `25.1.8937393`.
23+
24+
If you install Qt 6 with its online installer, the android files will be at ~/Qt/${QT_VERSION}/android_${ANDROID_ABI}
25+
26+
The CMake command will be:
27+
28+
```bash
29+
30+
cd Qompass
31+
32+
cmake -S . \
33+
-B build \
34+
-DANDROID_ABI="arm64-v8a"\
35+
-DANDROID_NDK=$HOME/Android/Sdk/ndk/25.1.8937393 \
36+
-DANDROID_SDK_ROOT=$HOME/Android/Sdk \
37+
-DANDROID_PLATFORM="android-31" \
38+
-DCMAKE_GENERATOR="Ninja" \
39+
-DCMAKE_BUILD_TYPE="Debug" \
40+
-DCMAKE_TOOLCHAIN_FILE:FILEPATH=$HOME/Android/Sdk/ndk/25.1.8937393/build/cmake/android.toolchain.cmake \
41+
-DCMAKE_PREFIX_PATH=$HOME/Qt/6.5.2/android_arm64_v8a \
42+
-DCMAKE_FIND_ROOT_PATH:PATH=$HOME/Qt/6.5.2/android_arm64_v8a \
43+
-DQOMPASS_VERSION="1.1.0" \
44+
\
45+
46+
```
47+
48+
The `QOMPASS_VERSION` variable is optional, and defined by this project only at CMakeLists.txt.
49+
50+
Then:
51+
52+
```bash
53+
54+
cd build
55+
56+
ninja
57+
58+
```

Theme.qml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
/*
3+
* Copyright (C) 2023 Nicolas Morais
4+
* This program is free software; you can redistribute
5+
* it and/or modify it under the terms of the GNU
6+
* General Public License as published by the Free
7+
* Software Foundation; either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it
11+
* will be useful, but WITHOUT ANY WARRANTY;
12+
* without even the implied warranty of MERCHANTABILITY
13+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* General Public License for more details.
15+
16+
* You should have received a copy of the GNU General
17+
* Public License along with this program; if not, see
18+
* <https://www.gnu.org/licenses>.
19+
*/
20+
pragma Singleton
21+
22+
import QtQuick
23+
import QtCore
24+
25+
Item {
26+
id: root
27+
// app uses dark theme by default
28+
property bool isDark: settings.value("isDark", true)
29+
readonly property color background: isDark ? "black" : "white"
30+
readonly property color foreground: isDark ? "white" : "black"
31+
function toggleDarkTheme() {
32+
isDark = !isDark
33+
}
34+
35+
Settings {
36+
id: settings
37+
property alias isDark: root.isDark
38+
}
39+
40+
Component.onDestruction: settings.setValue("isDark", root.isDark)
41+
}

android/AndroidManifest.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="io.github.nicmorais.qompass"
44
android:installLocation="auto"
5-
android:versionCode="1"
6-
android:versionName="1.0.0">
5+
android:versionCode="2"
6+
android:versionName="1.1.0">
77
<!-- The comment below will be replaced with dependencies permissions upon deployment.
88
Remove the comment if you do not require these default permissions. -->
99
<!-- %%INSERT_PERMISSIONS -->
@@ -23,12 +23,14 @@
2323
android:hardwareAccelerated="true"
2424
android:label="Qompass"
2525
android:requestLegacyExternalStorage="true"
26+
android:appCategory="productivity"
2627
android:icon="@drawable/icon">
2728
<activity
2829
android:name="org.qtproject.qt.android.bindings.QtActivity"
2930
android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density"
3031
android:label="Qompass"
3132
android:launchMode="singleTop"
33+
android:exported="true"
3234
android:screenOrientation="portrait">
3335
<intent-filter>
3436
<action android:name="android.intent.action.MAIN"/>

doc/demo.gif

-1.56 MB
Binary file not shown.

doc/demo.jpg

20.2 KB
Loading

images/degrees_indicator.png

-10.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)