Serial-Studio/assets/qml/Widgets/GyroDelegate.qml

219 lines
6.0 KiB
QML
Raw Normal View History

/*
* Copyright (c) 2020-2021 Alex Spataru <https://github.com/alex-spataru>
*
* 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.
*/
import QtQuick 2.12
2020-12-27 17:21:19 -06:00
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.12
import QtGraphicalEffects 1.0
2020-12-27 17:21:19 -06:00
import Group 1.0
import Dataset 1.0
2020-12-27 17:21:19 -06:00
import "."
Window {
id: root
2020-12-27 17:21:19 -06:00
//
// Window properties
//
spacing: -1
2020-12-30 16:11:51 -06:00
gradient: true
2020-12-27 17:21:19 -06:00
implicitWidth: 260
visible: opacity > 0
opacity: enabled ? 1 : 0
implicitHeight: implicitWidth + 96
2020-12-27 20:20:01 -06:00
icon.source: "qrc:/icons/refresh.svg"
2020-12-27 17:21:19 -06:00
backgroundColor: Qt.rgba(9 / 255, 9 / 255, 12 / 255, 1)
//
// Custom properties
//
property real yawAngle: 0
property real rollAngle: 0
property real pitchAngle: 0
2020-12-27 17:21:19 -06:00
property int groupIndex: 0
2020-12-27 20:20:01 -06:00
property real gaugeSize: calculateGaugeSize()
property color valueColor: Qt.rgba(142/255, 205/255, 157/255, 1)
2020-12-27 17:21:19 -06:00
//
2020-12-27 20:20:01 -06:00
// Update root size automatically
2020-12-27 17:21:19 -06:00
//
2020-12-27 20:20:01 -06:00
onWidthChanged: calculateGaugeSize()
onHeightChanged: calculateGaugeSize()
2020-12-27 17:21:19 -06:00
//
// Connections with widget manager
//
Connections {
target: CppWidgets
function onDataChanged() {
root.updateValues()
2020-12-27 17:21:19 -06:00
}
}
//
// Updates the internal values of the bar widget
//
function updateValues() {
if (CppWidgets.gyroGroupCount() > root.groupIndex) {
2020-12-27 23:42:23 -06:00
root.yawAngle = CppWidgets.gyroYaw(root.groupIndex)
root.rollAngle = CppWidgets.gyroRoll(root.groupIndex)
2020-12-27 20:20:01 -06:00
root.pitchAngle = CppWidgets.gyroPitch(root.groupIndex)
2020-12-27 23:42:23 -06:00
root.title = CppWidgets.gyroGroupAt(root.groupIndex).title
2020-12-27 17:21:19 -06:00
}
else {
2020-12-27 23:42:23 -06:00
root.title = ""
root.yawAngle = 0
root.rollAngle = 0
root.pitchAngle = 0
2020-12-27 17:21:19 -06:00
}
2020-12-27 20:20:01 -06:00
calculateGaugeSize()
}
//
// Redraws accelerator root
//
function calculateGaugeSize() {
if (root.width < root.height)
root.gaugeSize = Math.max(120, root.width - controls.implicitWidth - 12 * app.spacing)
else
root.gaugeSize = Math.max(120, root.height - controls.implicitWidth - 4 * app.spacing)
2020-12-27 17:21:19 -06:00
}
//
// Animations
//
Behavior on yawAngle {NumberAnimation{}}
Behavior on rollAngle {NumberAnimation{}}
Behavior on pitchAngle {NumberAnimation{}}
2020-12-27 17:21:19 -06:00
//
2020-12-27 20:20:01 -06:00
// Layout
2020-12-27 17:21:19 -06:00
//
2020-12-27 20:20:01 -06:00
RowLayout {
anchors.fill: parent
anchors.margins: app.spacing
2020-12-27 17:21:19 -06:00
//
2020-12-27 20:20:01 -06:00
// Spacer
//
Item {
2020-12-27 20:20:01 -06:00
Layout.fillWidth: true
}
//
// Artificial horizon
//
ArtificialHorizonDelegate {
id: artificialHorizon
2020-12-27 20:20:01 -06:00
rollAngle: root.rollAngle
pitchAngle: root.pitchAngle
Layout.alignment: Qt.AlignHCenter
Layout.minimumWidth: root.gaugeSize
Layout.maximumWidth: root.gaugeSize
Layout.minimumHeight: root.gaugeSize
Layout.maximumHeight: root.gaugeSize
}
//
// Spacer
//
Item {
Layout.fillWidth: true
}
2020-12-27 20:20:01 -06:00
//
// Values
//
Rectangle {
id: controls
border.width: 1
color: "transparent"
implicitWidth: 120
Layout.minimumWidth: 120
Layout.maximumWidth: 120
Layout.minimumHeight: 120
Layout.maximumHeight: 120
border.color: root.valueColor
Layout.alignment: Qt.AlignVCenter
function formatAngle(angle) {
var str
if (angle < 0)
str = '- '
else
str = '+ '
if (Math.abs(angle) < 100)
str += '0'
if (Math.abs(angle) < 10)
str += '0'
return str + Math.abs(Math.floor(angle))
}
2020-12-27 20:20:01 -06:00
ColumnLayout {
spacing: app.spacing
anchors.centerIn: parent
Label {
font.pixelSize: 12
color: root.valueColor
font.family: app.monoFont
Layout.alignment: Qt.AlignLeft
2021-01-04 22:11:59 -06:00
text: qsTr("%1° YAW").arg(controls.formatAngle(root.yawAngle)) + CppTranslator.dummy
}
2020-12-27 20:20:01 -06:00
Label {
font.pixelSize: 12
color: root.valueColor
font.family: app.monoFont
Layout.alignment: Qt.AlignLeft
2021-01-04 22:11:59 -06:00
text: qsTr("%1° ROLL").arg(controls.formatAngle(root.rollAngle)) + CppTranslator.dummy
}
2020-12-27 20:20:01 -06:00
Label {
font.pixelSize: 12
color: root.valueColor
font.family: app.monoFont
Layout.alignment: Qt.AlignLeft
2021-01-04 22:11:59 -06:00
text: qsTr("%1° PITCH").arg(controls.formatAngle(root.pitchAngle)) + CppTranslator.dummy
2020-12-27 20:20:01 -06:00
}
}
}
2020-12-27 20:20:01 -06:00
//
// Spacer
//
Item {
Layout.fillWidth: true
}
}
}