Implement compass widget #44

This commit is contained in:
Alex Spataru 2021-03-12 09:56:17 -05:00
parent 5b71b86179
commit 1a68c4f8d9
8 changed files with 8604 additions and 41 deletions

View File

@ -97,5 +97,7 @@
<file>qml/SetupPanes/MQTT.qml</file>
<file>qml/Widgets/CompassDelegate.qml</file>
<file>icons/compass.svg</file>
<file>instruments/Compass.svg</file>
<file>instruments/CompassCase.svg</file>
</qresource>
</RCC>

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 186 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 149 KiB

View File

@ -57,6 +57,28 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
## QFlightInstruments
Copyright (C) 2013 Marek M. Cel
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
## qmqtt
This project is dual licensed under the Eclipse Public License 1.0 and the
@ -312,4 +334,4 @@ including all Contributors.
intellectual property laws of the United States of America. No party to this
Agreement will bring a legal action under this Agreement more than one year
after the cause of action arose. Each party waives its rights to a jury trial
in any resulting litigation.
in any resulting litigation.

View File

@ -129,10 +129,10 @@ Window {
//
function calculateGaugeSize() {
if (root.width < root.height)
root.gaugeSize = Math.max(120, root.width - controls.implicitWidth - 12 * app.spacing)
root.gaugeSize = Math.max(120, root.width - controls.implicitWidth - 12 * app.spacing) * 0.8
else
root.gaugeSize = Math.max(120, root.height - controls.implicitWidth - 4 * app.spacing)
root.gaugeSize = Math.max(120, root.height - controls.implicitWidth - 4 * app.spacing) * 0.8
}
//

View File

@ -46,5 +46,95 @@ Window {
//
// Custom properties
//
property int angle: 0
property int datasetIndex: 0
property string direction: "0 N"
property int widgetSize: Math.min(root.height, root.width) * 0.6
//
// Connections with widget manager
//
Connections {
target: Cpp_UI_WidgetProvider
//*! Optimize this function
function onDataChanged() {
root.updateValues()
}
}
//
// Updates the internal values of the compass widget
//
//*! Optimize this function
// About 6% of the UI thread is spent here
function updateValues() {
if (Cpp_UI_WidgetProvider.compassDatasetCount() > root.datasetIndex) {
root.angle = Cpp_UI_WidgetProvider.compass(root.datasetIndex)
root.title = Cpp_UI_WidgetProvider.compassDatasetAt(root.datasetIndex).title
if (root.angle <= 22)
root.direction = root.angle + "° N"
else if (root.angle > 22 && root.angle <= 67)
root.direction = root.angle + "° NE"
else if (root.angle > 67 && root.angle <= 112)
root.direction = root.angle + "° E"
else if (root.angle > 112 && root.angle <= 157)
root.direction = root.angle + "° SE"
else if (root.angle > 157 && root.angle <= 203)
root.direction = root.angle + "° S"
else if (root.angle > 203 && root.angle <= 247)
root.direction = root.angle + "° SW"
else if (root.angle > 247 && root.angle <= 292)
root.direction = root.angle + "° W"
else if (root.angle > 292 && root.angle <= 337)
root.direction = root.angle + "° NW"
else
root.direction = root.angle + "° N"
}
else {
root.angle = 0
root.title = ""
root.direction = "0° N"
}
}
//
// Compass image
//
ColumnLayout {
anchors.centerIn: parent
spacing: app.spacing * 2
Item {
Layout.alignment: Qt.AlignHCenter
Layout.minimumWidth: root.widgetSize
Layout.maximumWidth: root.widgetSize
Layout.minimumHeight: root.widgetSize
Layout.maximumHeight: root.widgetSize
Image {
anchors.fill: parent
rotation: 360 - root.angle
source: "qrc:/instruments/Compass.svg"
sourceSize: Qt.size(root.widgetSize, root.widgetSize)
}
Image {
anchors.fill: parent
source: "qrc:/instruments/CompassCase.svg"
sourceSize: Qt.size(root.widgetSize, root.widgetSize)
}
}
Label {
color: "#8ecd9d"
font.bold: true
font.pixelSize: 24
text: root.direction
font.family: app.monoFont
Layout.alignment: Qt.AlignHCenter
}
}
}

View File

@ -263,54 +263,54 @@ Control {
}
}
}
}
Repeater {
id: compassGenerator
Repeater {
id: compassGenerator
delegate: Item {
Layout.fillWidth: true
Layout.fillHeight: true
Layout.minimumWidth: root.minimumWidgetSize
Layout.minimumHeight: root.minimumWidgetSize
Widgets.CompassDelegate {
datasetIndex: index
anchors.fill: parent
onHeaderDoubleClicked: windowCompass.show()
}
QtWindow.Window {
id: windowCompass
width: 640
height: 480
minimumWidth: root.minimumWidgetSize * 1.2
minimumHeight: root.minimumWidgetSize * 1.2
title: compass.title
Rectangle {
anchors.fill: parent
color: compass.backgroundColor
}
delegate: Item {
Layout.fillWidth: true
Layout.fillHeight: true
Layout.minimumWidth: root.minimumWidgetSize
Layout.minimumHeight: root.minimumWidgetSize
Widgets.CompassDelegate {
id: compass
showIcon: true
gradient: false
headerHeight: 48
datasetIndex: index
anchors.margins: 0
anchors.fill: parent
borderColor: backgroundColor
headerDoubleClickEnabled: false
onHeaderDoubleClicked: windowCompass.show()
}
QtWindow.Window {
id: windowCompass
width: 640
height: 480
minimumWidth: root.minimumWidgetSize * 1.2
minimumHeight: root.minimumWidgetSize * 1.2
title: compass.title
Rectangle {
anchors.fill: parent
color: compass.backgroundColor
}
Widgets.CompassDelegate {
id: compass
showIcon: true
gradient: false
headerHeight: 48
datasetIndex: index
anchors.margins: 0
anchors.fill: parent
borderColor: backgroundColor
headerDoubleClickEnabled: false
}
}
}
}
}
}
Item {
Layout.minimumHeight: 10
Item {
Layout.minimumHeight: 10
}
}
}
}

View File

@ -228,7 +228,7 @@ int WidgetProvider::compass(const int index)
{
auto compass = compassDatasetAt(index);
if (compass)
return compass->value().toInt();
return qMax(0, qMin(360, compass->value().toInt()));
return INT_MAX;
}