From 8ebef4eed2134179e5609104eb72fe8f055a35f1 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 9 Oct 2019 00:36:03 +0200 Subject: [PATCH] Size images/videos by timeline width --- resources/qml/delegates/ImageMessage.qml | 4 +-- .../qml/delegates/PlayableMediaMessage.qml | 27 ++++++++++++++----- src/AvatarProvider.cpp | 4 +-- src/MxcImageProvider.cpp | 3 ++- src/timeline2/TimelineModel.cpp | 19 +++++++++++++ src/timeline2/TimelineModel.h | 1 + 6 files changed, 46 insertions(+), 12 deletions(-) diff --git a/resources/qml/delegates/ImageMessage.qml b/resources/qml/delegates/ImageMessage.qml index 70d2debe..f1e95e3d 100644 --- a/resources/qml/delegates/ImageMessage.qml +++ b/resources/qml/delegates/ImageMessage.qml @@ -3,8 +3,8 @@ import QtQuick 2.6 import com.github.nheko 1.0 Item { - width: 300 - height: 300 * model.proportionalHeight + width: Math.min(parent.width, model.width) + height: width * model.proportionalHeight Image { id: img diff --git a/resources/qml/delegates/PlayableMediaMessage.qml b/resources/qml/delegates/PlayableMediaMessage.qml index c716d21d..3a518617 100644 --- a/resources/qml/delegates/PlayableMediaMessage.qml +++ b/resources/qml/delegates/PlayableMediaMessage.qml @@ -6,26 +6,38 @@ import QtMultimedia 5.6 import com.github.nheko 1.0 Rectangle { + id: bg radius: 10 color: colors.dark height: content.height + 24 width: parent.width - ColumnLayout { + Column { id: content width: parent.width - 24 anchors.centerIn: parent - VideoOutput { + Rectangle { + id: videoContainer visible: model.type == MtxEvent.VideoMessage - Layout.maximumHeight: 300 - Layout.minimumHeight: 300 - Layout.maximumWidth: 500 - fillMode: VideoOutput.PreserveAspectFit - source: media + width: Math.min(parent.width, model.width) + height: width*model.proportionalHeight + Image { + anchors.fill: parent + source: model.thumbnailUrl.replace("mxc://", "image://MxcImage/") + asynchronous: true + fillMode: Image.PreserveAspectFit + + VideoOutput { + anchors.fill: parent + fillMode: VideoOutput.PreserveAspectFit + source: media + } + } } RowLayout { + width: parent.width Text { id: positionText text: "--:--:--" @@ -102,6 +114,7 @@ Rectangle { id: media onError: console.log(errorString) onStatusChanged: if(status == MediaPlayer.Loaded) progress.updatePositionTexts() + onStopped: button.state = "stopped" } Connections { diff --git a/src/AvatarProvider.cpp b/src/AvatarProvider.cpp index c83ffe0f..68b6901e 100644 --- a/src/AvatarProvider.cpp +++ b/src/AvatarProvider.cpp @@ -67,8 +67,8 @@ resolve(const QString &avatarUrl, int size, QObject *receiver, AvatarCallback ca }); mtx::http::ThumbOpts opts; - opts.width = 256; - opts.height = 256; + opts.width = size; + opts.height = size; opts.mxc_url = avatarUrl.toStdString(); http::client()->get_thumbnail( diff --git a/src/MxcImageProvider.cpp b/src/MxcImageProvider.cpp index 305439fc..86dbcabc 100644 --- a/src/MxcImageProvider.cpp +++ b/src/MxcImageProvider.cpp @@ -38,7 +38,8 @@ MxcImageResponse::run() auto data = QByteArray(res.data(), res.size()); cache::client()->saveImage(fileName, data); m_image.loadFromData(data); - m_image = m_image.scaled(m_requestedSize, Qt::KeepAspectRatio); + m_image = m_image.scaled( + m_requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); m_image.setText("mxc url", "mxc://" + m_id); emit finished(); diff --git a/src/timeline2/TimelineModel.cpp b/src/timeline2/TimelineModel.cpp index b3ddf899..27bd09b6 100644 --- a/src/timeline2/TimelineModel.cpp +++ b/src/timeline2/TimelineModel.cpp @@ -106,6 +106,21 @@ eventUrl(const mtx::events::RoomEvent &e) return QString::fromStdString(e.content.url); } +template +QString +eventThumbnailUrl(const mtx::events::Event &) +{ + return ""; +} +template +auto +eventThumbnailUrl(const mtx::events::RoomEvent &e) + -> std::enable_if_t::value, + QString> +{ + return QString::fromStdString(e.content.info.thumbnail_url); +} + template QString eventFilename(const mtx::events::Event &) @@ -355,6 +370,7 @@ TimelineModel::roleNames() const {UserName, "userName"}, {Timestamp, "timestamp"}, {Url, "url"}, + {ThumbnailUrl, "thumbnailUrl"}, {Filename, "filename"}, {Filesize, "filesize"}, {MimeType, "mimetype"}, @@ -436,6 +452,9 @@ TimelineModel::data(const QModelIndex &index, int role) const case Url: return QVariant(boost::apply_visitor( [](const auto &e) -> QString { return eventUrl(e); }, event)); + case ThumbnailUrl: + return QVariant(boost::apply_visitor( + [](const auto &e) -> QString { return eventThumbnailUrl(e); }, event)); case Filename: return QVariant(boost::apply_visitor( [](const auto &e) -> QString { return eventFilename(e); }, event)); diff --git a/src/timeline2/TimelineModel.h b/src/timeline2/TimelineModel.h index 35ec325d..b7ff546b 100644 --- a/src/timeline2/TimelineModel.h +++ b/src/timeline2/TimelineModel.h @@ -129,6 +129,7 @@ public: UserName, Timestamp, Url, + ThumbnailUrl, Filename, Filesize, MimeType,