summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2019-09-08 12:44:46 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2019-11-23 20:06:14 +0100
commit86f4119a0502ffefd60abd5963f0d52628ba4e78 (patch)
tree0dd0981909d302d6738a30ae8f89fcffe1e5940e /src
parentImplement avatars in qml timeline (diff)
downloadnheko-86f4119a0502ffefd60abd5963f0d52628ba4e78.tar.xz
Implement basic ImageMessages in qml timeline
I suck at sizing so the images in the message are currently hardcoded to
300 pixels in width...
Diffstat (limited to 'src')
-rw-r--r--src/MxcImageProvider.h1
-rw-r--r--src/timeline2/TimelineModel.cpp66
-rw-r--r--src/timeline2/TimelineModel.h4
3 files changed, 70 insertions, 1 deletions
diff --git a/src/MxcImageProvider.h b/src/MxcImageProvider.h

index 8710171c..19d8a74e 100644 --- a/src/MxcImageProvider.h +++ b/src/MxcImageProvider.h
@@ -45,4 +45,3 @@ public: private: QThreadPool pool; }; - diff --git a/src/timeline2/TimelineModel.cpp b/src/timeline2/TimelineModel.cpp
index 310494b4..16f1dfe6 100644 --- a/src/timeline2/TimelineModel.cpp +++ b/src/timeline2/TimelineModel.cpp
@@ -59,6 +59,20 @@ eventFormattedBody(const mtx::events::RoomEvent<T> &e) } template<class T> +QString +eventUrl(const T &) +{ + return ""; +} +template<class T> +auto +eventUrl(const mtx::events::RoomEvent<T> &e) + -> std::enable_if_t<std::is_same<decltype(e.content.url), std::string>::value, QString> +{ + return QString::fromStdString(e.content.url); +} + +template<class T> qml_mtx_events::EventType toRoomEventType(const mtx::events::Event<T> &e) { @@ -146,6 +160,41 @@ toRoomEventType(const mtx::events::Event<mtx::events::msg::Video> &) } // ::EventType::Type toRoomEventType(const Event<mtx::events::msg::Location> &e) { return // ::EventType::LocationMessage; } + +template<class T> +uint64_t +eventHeight(const mtx::events::Event<T> &) +{ + return -1; +} +template<class T> +auto +eventHeight(const mtx::events::RoomEvent<T> &e) -> decltype(e.content.info.h) +{ + return e.content.info.h; +} +template<class T> +uint64_t +eventWidth(const mtx::events::Event<T> &) +{ + return -1; +} +template<class T> +auto +eventWidth(const mtx::events::RoomEvent<T> &e) -> decltype(e.content.info.w) +{ + return e.content.info.w; +} + +template<class T> +double +eventPropHeight(const mtx::events::RoomEvent<T> &e) +{ + auto w = eventWidth(e); + if (w == 0) + w = 1; + return eventHeight(e) / (double)w; +} } TimelineModel::TimelineModel(QString room_id, QObject *parent) @@ -167,6 +216,10 @@ TimelineModel::roleNames() const {UserId, "userId"}, {UserName, "userName"}, {Timestamp, "timestamp"}, + {Url, "url"}, + {Height, "height"}, + {Width, "width"}, + {ProportionalHeight, "proportionalHeight"}, }; } int @@ -228,6 +281,19 @@ TimelineModel::data(const QModelIndex &index, int role) const return QVariant(utils::replaceEmoji(boost::apply_visitor( [](const auto &e) -> QString { return eventFormattedBody(e); }, events.value(id)))); + case Url: + return QVariant(boost::apply_visitor( + [](const auto &e) -> QString { return eventUrl(e); }, events.value(id))); + case Height: + return QVariant(boost::apply_visitor( + [](const auto &e) -> qulonglong { return eventHeight(e); }, events.value(id))); + case Width: + return QVariant(boost::apply_visitor( + [](const auto &e) -> qulonglong { return eventWidth(e); }, events.value(id))); + case ProportionalHeight: + return QVariant(boost::apply_visitor( + [](const auto &e) -> double { return eventPropHeight(e); }, events.value(id))); + default: return QVariant(); } diff --git a/src/timeline2/TimelineModel.h b/src/timeline2/TimelineModel.h
index 954da5eb..66d03cf5 100644 --- a/src/timeline2/TimelineModel.h +++ b/src/timeline2/TimelineModel.h
@@ -82,6 +82,10 @@ public: UserId, UserName, Timestamp, + Url, + Height, + Width, + ProportionalHeight, }; QHash<int, QByteArray> roleNames() const override;