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 <cmath>
using namespace Quotient;
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);
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 {};
@@ -101,6 +108,7 @@ QHash<int, QByteArray> LiveLocationsModel::roleNames() const
r.insert(AssetRole, "asset");
r.insert(AuthorRole, "author");
r.insert(IsLiveRole, "isLive");
r.insert(HeadingRole, "heading");
return r;
}

View File

@@ -49,6 +49,7 @@ public:
AssetRole, /**< Type of location event, e.g. self pin of the user location. */
AuthorRole, /**< The author of the event. */
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)

View File

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

View File

@@ -24,11 +24,14 @@ MapQuickItem {
required property bool isLive
required property real heading
anchorPoint.x: sourceItem.width / 2
anchorPoint.y: sourceItem.height
coordinate: QtPositioning.coordinate(root.latitude, root.longitude)
autoFadeIn: false
sourceItem: Kirigami.Icon {
id: mainIcon
width: height
height: Kirigami.Units.iconSizes.huge
source: "gps"
@@ -55,5 +58,19 @@ MapQuickItem {
source: root.author.avatarSource
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 {
isLive: true
heading: NaN
}
}

View File

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