diff --git a/assets/assets.qrc b/assets/assets.qrc
index 7ef0757a..9c084cfc 100644
--- a/assets/assets.qrc
+++ b/assets/assets.qrc
@@ -95,5 +95,7 @@
qml/PlatformDependent/Menubar.qml
qml/PlatformDependent/DecentMenuItem.qml
qml/SetupPanes/MQTT.qml
+ qml/Widgets/CompassDelegate.qml
+ icons/compass.svg
diff --git a/assets/icons/compass.svg b/assets/icons/compass.svg
new file mode 100644
index 00000000..53b43f03
--- /dev/null
+++ b/assets/icons/compass.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/assets/qml/Widgets/CompassDelegate.qml b/assets/qml/Widgets/CompassDelegate.qml
new file mode 100644
index 00000000..5ccfe19e
--- /dev/null
+++ b/assets/qml/Widgets/CompassDelegate.qml
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2020-2021 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
+import QtQuick.Layouts 1.12
+import QtQuick.Controls 2.12
+
+import SerialStudio 1.0
+
+import "."
+
+Window {
+ id: root
+
+ //
+ // Window properties
+ //
+ spacing: -1
+ gradient: true
+ implicitWidth: 260
+ visible: opacity > 0
+ opacity: enabled ? 1 : 0
+ backgroundColor: "#09090c"
+ implicitHeight: implicitWidth + 96
+ icon.source: "qrc:/icons/compass.svg"
+
+ //
+ // Custom properties
+ //
+ property int datasetIndex: 0
+}
diff --git a/assets/qml/Windows/Widgets.qml b/assets/qml/Windows/Widgets.qml
index bd154d19..e2527044 100644
--- a/assets/qml/Windows/Widgets.qml
+++ b/assets/qml/Windows/Widgets.qml
@@ -59,6 +59,10 @@ Control {
barGenerator.model = 0
barGenerator.model = Cpp_UI_WidgetProvider.barDatasetCount()
+ // Generate compass widgets
+ compassGenerator.model = 0
+ compassGenerator.model = Cpp_UI_WidgetProvider.compassDatasetCount()
+
// Generate map widgets
mapGenerator.model = 0
mapGenerator.model = Cpp_UI_WidgetProvider.mapGroupCount()
@@ -261,9 +265,52 @@ Control {
}
}
- Item {
- Layout.minimumHeight: 10
+ 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
+ }
+
+ 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
+ }
}
}
diff --git a/src/UI/WidgetProvider.cpp b/src/UI/WidgetProvider.cpp
index 147c2584..7e85c9a2 100644
--- a/src/UI/WidgetProvider.cpp
+++ b/src/UI/WidgetProvider.cpp
@@ -74,6 +74,14 @@ QList WidgetProvider::barDatasets() const
return m_barDatasets;
}
+/**
+ * Returns a list with all the JSON datasets that implement a compass widget
+ */
+QList WidgetProvider::compassDatasets() const
+{
+ return m_compassDatasets;
+}
+
/**
* Returns a list with all the JSON groups that implement a map widget
*/
@@ -106,9 +114,10 @@ int WidgetProvider::totalWidgetCount() const
{
// clang-format off
return mapGroupCount() +
- gyroGroupCount() +
- barDatasetCount() +
- accelerometerGroupCount();
+ gyroGroupCount() +
+ barDatasetCount() +
+ compassDatasetCount() +
+ accelerometerGroupCount();
// clang-format on
}
@@ -136,6 +145,14 @@ int WidgetProvider::gyroGroupCount() const
return gyroGroup().count();
}
+/**
+ * Returns the number of JSON datasets that implement a compass widget
+ */
+int WidgetProvider::compassDatasetCount() const
+{
+ return compassDatasets().count();
+}
+
/**
* Returns the number of JSON groups that implement an accelerometer widget
*/
@@ -156,6 +173,18 @@ JSON::Dataset *WidgetProvider::barDatasetAt(const int index)
return Q_NULLPTR;
}
+/**
+ * Returns a pointer to the JSON dataset that implements a compass widget
+ * with the given @a index.
+ */
+JSON::Dataset *WidgetProvider::compassDatasetAt(const int index)
+{
+ if (compassDatasets().count() > index)
+ return compassDatasets().at(index);
+
+ return Q_NULLPTR;
+}
+
/**
* Returns a pointer to the JSON group that implements a map widget
* with the given @a index
@@ -192,6 +221,18 @@ JSON::Group *WidgetProvider::accelerometerGroupAt(const int index)
return Q_NULLPTR;
}
+/**
+ * Returns the direction in degrees for the compass widget at the given @a index
+ */
+int WidgetProvider::compass(const int index)
+{
+ auto compass = compassDatasetAt(index);
+ if (compass)
+ return compass->value().toInt();
+
+ return INT_MAX;
+}
+
/**
* Returns the yaw angle for the gyro widget at the given @a index
*/
@@ -397,9 +438,10 @@ double WidgetProvider::mapLongitude(const int index)
void WidgetProvider::resetData()
{
m_widgetCount = 0;
- m_barDatasets.clear();
m_mapGroups.clear();
m_gyroGroups.clear();
+ m_barDatasets.clear();
+ m_compassDatasets.clear();
m_accelerometerGroups.clear();
emit dataChanged();
@@ -412,9 +454,10 @@ void WidgetProvider::resetData()
void WidgetProvider::updateModels()
{
// Clear current groups
- m_barDatasets.clear();
m_mapGroups.clear();
m_gyroGroups.clear();
+ m_barDatasets.clear();
+ m_compassDatasets.clear();
m_accelerometerGroups.clear();
// Check if frame is valid
@@ -425,11 +468,19 @@ void WidgetProvider::updateModels()
m_mapGroups = getWidgetGroup("map");
m_gyroGroups = getWidgetGroup("gyro");
m_barDatasets = getWidgetDatasets("bar");
+ m_compassDatasets = getWidgetDatasets("compass");
m_accelerometerGroups = getWidgetGroup("accelerometer");
- // Check if widget count has changed
- auto count = mapGroupCount() + gyroGroupCount() + barDatasetCount()
- + accelerometerGroupCount();
+ // Calculate total widget count
+ // clang-format off
+ auto count = mapGroupCount() +
+ gyroGroupCount() +
+ barDatasetCount() +
+ compassDatasetCount() +
+ accelerometerGroupCount();
+ // clang-format on
+
+ // Tell UI to regenerate widget models if widget count has changed from last frame
if (count != m_widgetCount)
{
m_widgetCount = count;
diff --git a/src/UI/WidgetProvider.h b/src/UI/WidgetProvider.h
index b6de19c9..a9e6c64a 100644
--- a/src/UI/WidgetProvider.h
+++ b/src/UI/WidgetProvider.h
@@ -49,6 +49,7 @@ public:
QList mapGroup() const;
QList gyroGroup() const;
QList barDatasets() const;
+ QList compassDatasets() const;
QList accelerometerGroup() const;
int totalWidgetCount() const;
@@ -56,13 +57,17 @@ public:
Q_INVOKABLE int mapGroupCount() const;
Q_INVOKABLE int gyroGroupCount() const;
Q_INVOKABLE int barDatasetCount() const;
+ Q_INVOKABLE int compassDatasetCount() const;
Q_INVOKABLE int accelerometerGroupCount() const;
Q_INVOKABLE JSON::Group *mapGroupAt(const int index);
Q_INVOKABLE JSON::Group *gyroGroupAt(const int index);
Q_INVOKABLE JSON::Dataset *barDatasetAt(const int index);
+ Q_INVOKABLE JSON::Dataset *compassDatasetAt(const int index);
Q_INVOKABLE JSON::Group *accelerometerGroupAt(const int index);
+ Q_INVOKABLE int compass(const int index);
+
Q_INVOKABLE double gyroYaw(const int index);
Q_INVOKABLE double gyroRoll(const int index);
Q_INVOKABLE double gyroPitch(const int index);
@@ -92,6 +97,7 @@ private:
QList m_mapGroups;
QList m_gyroGroups;
QList m_barDatasets;
+ QList m_compassDatasets;
QList m_accelerometerGroups;
};
}