Add heading indicator for live locations

Heading isn't covered by any MSC so far, so that is using Itinerary's
vendor prefix for now.
This commit is contained in:
Volker Krause
2023-07-28 10:34:55 +02:00
parent 0162d91b60
commit 00c0d1c276
6 changed files with 29 additions and 0 deletions

View File

@@ -8,6 +8,8 @@
#include <QDebug> #include <QDebug>
#include <cmath>
using namespace Quotient; using namespace Quotient;
bool operator<(const LiveLocationData &lhs, const LiveLocationData &rhs) bool operator<(const LiveLocationData &lhs, const LiveLocationData &rhs)
@@ -88,6 +90,11 @@ QVariant LiveLocationsModel::data(const QModelIndex &index, int roleName) const
const auto timeout = data.beaconInfo.value("timeout"_ls).toDouble(600000); const auto timeout = data.beaconInfo.value("timeout"_ls).toDouble(600000);
return lastTs + timeout >= QDateTime::currentDateTime().toMSecsSinceEpoch(); return lastTs + timeout >= QDateTime::currentDateTime().toMSecsSinceEpoch();
} }
case HeadingRole: {
bool success = false;
const auto heading = data.beacon["org.matrix.msc3488.location"_ls].toObject()["org.kde.itinerary.heading"_ls].toString().toDouble(&success);
return success ? heading : NAN;
}
} }
return {}; return {};
@@ -101,6 +108,7 @@ QHash<int, QByteArray> LiveLocationsModel::roleNames() const
r.insert(AssetRole, "asset"); r.insert(AssetRole, "asset");
r.insert(AuthorRole, "author"); r.insert(AuthorRole, "author");
r.insert(IsLiveRole, "isLive"); r.insert(IsLiveRole, "isLive");
r.insert(HeadingRole, "heading");
return r; return r;
} }

View File

@@ -49,6 +49,7 @@ public:
AssetRole, /**< Type of location event, e.g. self pin of the user location. */ AssetRole, /**< Type of location event, e.g. self pin of the user location. */
AuthorRole, /**< The author of the event. */ AuthorRole, /**< The author of the event. */
IsLiveRole, /**< Boolean that indicates whether a live location beacon is still live. */ IsLiveRole, /**< Boolean that indicates whether a live location beacon is still live. */
HeadingRole, /**< Heading in degree (not part of any MSC yet, using an Itinerary extension). */
}; };
Q_ENUM(Roles) Q_ENUM(Roles)

View File

@@ -46,6 +46,7 @@ ApplicationWindow {
asset: root.asset asset: root.asset
author: root.author author: root.author
isLive: true isLive: true
heading: NaN
visible: !isNaN(root.latitude) && !isNaN(root.longitude) visible: !isNaN(root.latitude) && !isNaN(root.longitude)
} }
MapItemView { MapItemView {

View File

@@ -24,11 +24,14 @@ MapQuickItem {
required property bool isLive required property bool isLive
required property real heading
anchorPoint.x: sourceItem.width / 2 anchorPoint.x: sourceItem.width / 2
anchorPoint.y: sourceItem.height anchorPoint.y: sourceItem.height
coordinate: QtPositioning.coordinate(root.latitude, root.longitude) coordinate: QtPositioning.coordinate(root.latitude, root.longitude)
autoFadeIn: false autoFadeIn: false
sourceItem: Kirigami.Icon { sourceItem: Kirigami.Icon {
id: mainIcon
width: height width: height
height: Kirigami.Units.iconSizes.huge height: Kirigami.Units.iconSizes.huge
source: "gps" source: "gps"
@@ -55,5 +58,19 @@ MapQuickItem {
source: root.author.avatarSource source: root.author.avatarSource
color: root.author.color color: root.author.color
} }
Kirigami.Icon {
id: headingIcon
source: "go-up-symbolic"
color: parent.color
visible: !isNaN(root.heading) && root.isLive
anchors.bottom: mainIcon.top
anchors.horizontalCenter: mainIcon.horizontalCenter
transform: Rotation {
origin.x: headingIcon.width/2
origin.y: headingIcon.height + mainIcon.height/2
angle: root.heading
}
}
} }
} }

View File

@@ -36,6 +36,7 @@ Kirigami.Page {
} }
delegate: LocationMapItem { delegate: LocationMapItem {
isLive: true isLive: true
heading: NaN
} }
} }

View File

@@ -57,6 +57,7 @@ TimelineContainer {
asset: root.asset asset: root.asset
author: root.author author: root.author
isLive: true isLive: true
heading: NaN
} }
TapHandler { TapHandler {