Size images/videos by timeline width

This commit is contained in:
Nicolas Werner 2019-10-09 00:36:03 +02:00
parent d90038cf20
commit 8ebef4eed2
6 changed files with 46 additions and 12 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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(

View File

@ -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();

View File

@ -106,6 +106,21 @@ eventUrl(const mtx::events::RoomEvent<T> &e)
return QString::fromStdString(e.content.url);
}
template<class T>
QString
eventThumbnailUrl(const mtx::events::Event<T> &)
{
return "";
}
template<class T>
auto
eventThumbnailUrl(const mtx::events::RoomEvent<T> &e)
-> std::enable_if_t<std::is_same<decltype(e.content.info.thumbnail_url), std::string>::value,
QString>
{
return QString::fromStdString(e.content.info.thumbnail_url);
}
template<class T>
QString
eventFilename(const mtx::events::Event<T> &)
@ -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));

View File

@ -129,6 +129,7 @@ public:
UserName,
Timestamp,
Url,
ThumbnailUrl,
Filename,
Filesize,
MimeType,