Skip to content

Commit

Permalink
Better ImageProvider->ThumbnailProvider
Browse files Browse the repository at this point in the history
The class handles avatars in a special way now - when passed a room id
and, optionally, a user id for a member of that room, it spawns
a newly introduced AvatarResponse that can retrieve the possibly
already cached avatar from the respective Room/User object. This
required some changes in QML, with common code moved out to the special
Avatar specialisation of Image component.

What warranted a dedicated QML component is that Quotient::Avatar
returns the first (possibly empty or smaller resolution) image
immediately while requesting the right one behind the scenes; so
QML Avatar listens on the respective signals from the library and
updates the image when the new avatar arrives - which (i.e. updating) is
in turn somewhat "idiomatic" because of QTBUG-14900. QML Avatar
encapsulates these two peculiarities.
  • Loading branch information
KitsuneRal committed Oct 16, 2023
1 parent 44d0acb commit 7eac2e5
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 216 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ message( STATUS )
set(quaternion_SRCS
client/quaternionroom.cpp
client/htmlfilter.cpp
client/imageprovider.cpp
client/thumbnailprovider.cpp
client/activitydetector.cpp
client/dialog.cpp
client/logindialog.cpp
Expand Down
160 changes: 0 additions & 160 deletions client/imageprovider.cpp

This file was deleted.

37 changes: 0 additions & 37 deletions client/imageprovider.h

This file was deleted.

2 changes: 1 addition & 1 deletion client/logging_categories.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ QUO_LOGGING_CATEGORY(EVENTMODEL, "quaternion.models.events")
QUO_LOGGING_CATEGORY(TIMELINE, "quaternion.timeline")
QUO_LOGGING_CATEGORY(HTMLFILTER, "quaternion.htmlfilter")
QUO_LOGGING_CATEGORY(MSGINPUT, "quaternion.messageinput")
QUO_LOGGING_CATEGORY(IMAGEPROVIDER, "quaternion.imageprovider")
QUO_LOGGING_CATEGORY(THUMBNAILS, "quaternion.thumbnails")

// Only to be used in QML; shows up here for documentation purpose only
[[maybe_unused]] QUO_LOGGING_CATEGORY(TIMELINEQML, "quaternion.timeline.qml")
Expand Down
27 changes: 27 additions & 0 deletions client/qml/Avatar.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import QtQuick 2.15

Image {
readonly property var forRoom: root.room
/* readonly */ property var forMember

property string sourceId: forRoom ? "image://thumbnail/" + forRoom.id
+ (forMember ? '/' + forMember.id : "")
: ""
source: sourceId
cache: false // Quotient::Avatar takes care of caching
fillMode: Image.PreserveAspectFit

function reload() {
source = ""
source = Qt.binding(function() { return sourceId })
}

Connections {
target: forRoom
function onAvatarChanged() { parent.reload() }
function onMemberAvatarChanged(member) {
if (member === parent.forMember)
parent.reload()
}
}
}
6 changes: 1 addition & 5 deletions client/qml/Timeline.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Page {

property bool showTopic: true

Image {
Avatar {
id: roomAvatar
anchors.verticalCenter: headerText.verticalCenter
anchors.left: parent.left
Expand All @@ -53,13 +53,9 @@ Page {
width: Math.min(headerText.height / implicitHeight * implicitWidth,
parent.width / 2.618) // Golden ratio - just for fun

source: room && room.avatarMediaId
? "image://mtx/" + room.avatarMediaId : ""
// Safe upper limit (see also topicField)
sourceSize: Qt.size(-1, settings.lineSpacing * 9)

fillMode: Image.PreserveAspectFit

AnimationBehavior on width {
NormalNumberAnimation { easing.type: Easing.OutQuad }
}
Expand Down
10 changes: 4 additions & 6 deletions client/qml/TimelineItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ Item {

text: "<" + time + ">"
}
Image {
Avatar {
id: authorAvatar
visible: (authorSectionVisible || settings.timelineStyleIsXChat)
&& settings.show_author_avatars && author.avatarMediaId
&& settings.show_author_avatars && paintedHeight > 0
anchors.left: timelabel.right
anchors.leftMargin: 3
height: visible ? settings.minimalTimelineItemHeight
Expand All @@ -228,11 +228,9 @@ Item {
width: settings.show_author_avatars
* settings.minimalTimelineItemHeight

fillMode: Image.PreserveAspectFit
horizontalAlignment: Image.AlignRight

source: author.avatarMediaId
? "image://mtx/" + author.avatarMediaId : ""
forMember: author
sourceSize: Qt.size(width, -1)

AuthorInteractionArea { }
Expand Down Expand Up @@ -427,7 +425,7 @@ Item {
? ""
: content.info && content.info.thumbnail_info
&& !autoload
? "image://mtx/" + content.thumbnailMediaId
? "image://thumbnail/" + content.thumbnailMediaId
: ""
maxHeight: chatView.height - textField.height -
authorLabel.height * !settings.timelineStyleIsXChat
Expand Down
1 change: 1 addition & 0 deletions client/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
<file>qml/AnimatedTransition.qml</file>
<file>qml/ScrollFinisher.qml</file>
<file>qml/Logger.qml</file>
<file>qml/Avatar.qml</file>
</qresource>
</RCC>
Loading

0 comments on commit 7eac2e5

Please sign in to comment.