Page MenuHomePhorge

D385.1795981011.diff
No OneTemporary

Authored By
Unknown
Size
18 KB
Referenced Files
None
Subscribers
None

D385.1795981011.diff

diff --git a/src/contents/ui/Bubble.qml b/src/contents/ui/Bubble.qml
--- a/src/contents/ui/Bubble.qml
+++ b/src/contents/ui/Bubble.qml
@@ -30,6 +30,23 @@
readonly property double replyMaxHeight: Kirigami.Units.gridUnit * 7
Layout.fillWidth: true
+ // Width taken by the metadata row and the context menu button, which are
+ // laid out next to (or below) the event content.
+ readonly property var trailingWidth: {
+ const spacing = bubbleRootLayout.columnSpacing;
+ if (pageStack.wideMode) {
+ return metadataRow.implicitWidth + spacing
+ + (moreButton.visible ? moreButton.implicitWidth + spacing : 0);
+ }
+ return moreButton.visible ? moreButton.implicitWidth + spacing : 0;
+ }
+
+ // Width available to the event content, excluding the trailing columns.
+ readonly property var eventContentWidth: {
+ const available = contentItem ? contentItem.width : width - bubbleSpacing;
+ return Math.max(available - trailingWidth, 0);
+ }
+
property var backgroundItem: Rectangle {
anchors.fill: parent
color: (hovered || isSelected) ? Kirigami.Theme.activeBackgroundColor : Kirigami.Theme.backgroundColor
@@ -194,6 +211,7 @@
}
RowLayout {
+ id: metadataRow
Layout.alignment: Qt.AlignBottom
Layout.row: pageStack.wideMode ? 0 : 1
Layout.column: pageStack.wideMode ? 1 : 0
diff --git a/src/contents/ui/event-types/Image.qml b/src/contents/ui/event-types/Image.qml
--- a/src/contents/ui/event-types/Image.qml
+++ b/src/contents/ui/event-types/Image.qml
@@ -99,6 +99,7 @@
property var preferredSize: MatrixHelpers.getPreferredSize({
iWidth: Math.max(upper.thumbnailWidth || upper.imageWidth || image.implicitWidth || 1, Kirigami.Units.gridUnit),
iHeight: Math.max(upper.thumbnailHeight || upper.imageHeight || image.implicitHeight || 1, Kirigami.Units.gridUnit),
+ maxWidth: Math.max(bubble.eventContentWidth - 2 * imgButton.padding, 0),
maxHeight: upper.imageMaxHeight,
minWidth: upper.imageMinWidth,
minHeight: upper.imageMinHeight,
diff --git a/src/contents/ui/event-types/MediaBubble.qml b/src/contents/ui/event-types/MediaBubble.qml
--- a/src/contents/ui/event-types/MediaBubble.qml
+++ b/src/contents/ui/event-types/MediaBubble.qml
@@ -32,6 +32,10 @@
kazvIOJob: mediaFileMenu.fileHandler.kazvIOJob
jobId: bubble.mediaFileMenu.fileHandler.getMediaId(bubble.mediaFileMenu.fileHandler.getFile().mxcUri)
isUpload: false
- width: parent.width
+ // The menu is a ColumnLayout whose children fill its width. Let the
+ // enclosing column size it instead of feeding a parent-dependent
+ // preferred width back into that column.
+ Layout.fillWidth: true
+ Layout.preferredWidth: 0
}
}
diff --git a/src/contents/ui/event-types/Video.qml b/src/contents/ui/event-types/Video.qml
--- a/src/contents/ui/event-types/Video.qml
+++ b/src/contents/ui/event-types/Video.qml
@@ -106,6 +106,7 @@
property var preferredSize: MatrixHelpers.getPreferredSize({
iWidth: Math.max(upper.thumbnailWidth || upper.videoWidth || video.implicitWidth || 1, Kirigami.Units.gridUnit),
iHeight: Math.max(upper.thumbnailHeight || upper.videoHeight || video.implicitHeight || 1, Kirigami.Units.gridUnit),
+ maxWidth: Math.max(bubble.eventContentWidth - 2 * videoBtn.padding, 0),
maxHeight: upper.videoMaxHeight,
minWidth: upper.videoMinWidth,
minHeight: upper.videoMinHeight,
diff --git a/src/js/matrix-helpers.js b/src/js/matrix-helpers.js
--- a/src/js/matrix-helpers.js
+++ b/src/js/matrix-helpers.js
@@ -131,7 +131,7 @@
iWidth,
iHeight,
// maximum size
- maxWidth,
+ maxWidth = Number.POSITIVE_INFINITY,
maxHeight,
// minimum size
minWidth,
@@ -142,12 +142,12 @@
const privHeight = Math.min(maxHeight, iHeight);
// the width is scaled to proportion
const privWidth = privHeight / iHeight * iWidth;
- // then, bound the width by the minimum
- const width = Math.max(privWidth, minWidth);
+ // then, bound the width by the minimum and maximum
+ const width = Math.min(Math.max(privWidth, minWidth), maxWidth);
const height = Math.min(
Math.max(
- // if width is clamped to the minimum, scale height accordingly
- width > privWidth ? privHeight / privWidth * width : privHeight,
+ // if width is clamped, scale height accordingly
+ width !== privWidth ? privHeight / privWidth * width : privHeight,
// then clamp the height
minHeight
), maxHeight);
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -86,6 +86,7 @@
tst_EventReadIndicator.qml
tst_EventSourceView.qml
tst_EventView.qml
+ tst_EventViewImage.qml
tst_EventViewRedacted.qml
tst_EventViewVideo.qml
tst_FileHandler.qml
diff --git a/src/tests/quick-tests/tst_EventViewImage.qml b/src/tests/quick-tests/tst_EventViewImage.qml
new file mode 100644
--- /dev/null
+++ b/src/tests/quick-tests/tst_EventViewImage.qml
@@ -0,0 +1,375 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import QtQuick 2.15
+import QtQuick.Layouts 1.15
+import QtTest 1.0
+
+import org.kde.kirigami 2.13 as Kirigami
+import '../../contents/ui' as Kazv
+import 'test-helpers' as QmlHelpers
+
+QmlHelpers.TestItem {
+ id: item
+
+ property var mockPageStack: QtObject {
+ property bool wideMode: false
+ property var removePage: mockHelper.noop()
+ }
+ pageStack: mockPageStack
+
+ property var wideImageEvent: ({
+ eventId: '',
+ sender: '@foo:tusooa.xyz',
+ type: 'm.room.message',
+ stateKey: '',
+ content: {
+ msgtype: 'm.image',
+ body: 'wide and short image',
+ info: {
+ h: 10,
+ w: 10000,
+ }
+ },
+ isAvailable: true,
+ isEdited: false,
+ encrypted: false,
+ readers: () => ({ count: 0 }),
+ reactions: () => [],
+ formattedTime: '4:06 P.M.',
+ })
+
+ property var normalImageEvent: ({
+ eventId: '',
+ sender: '@foo:tusooa.xyz',
+ type: 'm.room.message',
+ stateKey: '',
+ content: {
+ msgtype: 'm.image',
+ body: 'normal image',
+ info: {
+ h: Kirigami.Units.gridUnit * 10,
+ w: Kirigami.Units.gridUnit * 30,
+ }
+ },
+ isAvailable: true,
+ isEdited: false,
+ encrypted: false,
+ readers: () => ({ count: 0 }),
+ reactions: () => [],
+ formattedTime: '4:06 P.M.',
+ })
+
+ property var tinyImageEvent: ({
+ eventId: '',
+ sender: '@foo:tusooa.xyz',
+ type: 'm.room.message',
+ stateKey: '',
+ content: {
+ msgtype: 'm.image',
+ body: 'tiny image',
+ info: {
+ h: 10,
+ w: 10,
+ }
+ },
+ isAvailable: true,
+ isEdited: false,
+ encrypted: false,
+ readers: () => ({ count: 0 }),
+ reactions: () => [],
+ formattedTime: '4:06 P.M.',
+ })
+
+ property var wideVideoEvent: ({
+ eventId: '',
+ sender: '@foo:tusooa.xyz',
+ type: 'm.room.message',
+ stateKey: '',
+ content: {
+ msgtype: 'm.video',
+ body: 'wide and short video',
+ info: {
+ h: 10,
+ w: 10000,
+ }
+ },
+ isAvailable: true,
+ isEdited: false,
+ encrypted: false,
+ readers: () => ({ count: 0 }),
+ reactions: () => [],
+ formattedTime: '4:06 P.M.',
+ })
+
+ property var normalVideoEvent: ({
+ eventId: '',
+ sender: '@foo:tusooa.xyz',
+ type: 'm.room.message',
+ stateKey: '',
+ content: {
+ msgtype: 'm.video',
+ body: 'normal video',
+ info: {
+ h: Kirigami.Units.gridUnit * 10,
+ w: Kirigami.Units.gridUnit * 30,
+ }
+ },
+ isAvailable: true,
+ isEdited: false,
+ encrypted: false,
+ readers: () => ({ count: 0 }),
+ reactions: () => [],
+ formattedTime: '4:06 P.M.',
+ })
+
+ ColumnLayout {
+ anchors.fill: parent
+
+ Kazv.EventView {
+ id: eventViewWideImage
+ Layout.fillWidth: true
+ event: item.wideImageEvent
+ sender: item.sender
+ }
+
+ Kazv.EventView {
+ id: eventViewNormalImage
+ Layout.fillWidth: true
+ event: item.normalImageEvent
+ sender: item.sender
+ }
+
+ Kazv.EventView {
+ id: eventViewTinyImage
+ Layout.fillWidth: true
+ event: item.tinyImageEvent
+ sender: item.sender
+ }
+
+ Kazv.EventView {
+ id: eventViewWideVideo
+ Layout.fillWidth: true
+ event: item.wideVideoEvent
+ sender: item.sender
+ }
+
+ Kazv.EventView {
+ id: eventViewNormalVideo
+ Layout.fillWidth: true
+ event: item.normalVideoEvent
+ sender: item.sender
+ }
+
+ Kazv.EventView {
+ id: eventViewWideImageCompact
+ Layout.fillWidth: true
+ compactMode: true
+ event: item.wideImageEvent
+ sender: item.sender
+ }
+
+ Kazv.EventView {
+ id: eventViewWideVideoCompact
+ Layout.fillWidth: true
+ compactMode: true
+ event: item.wideVideoEvent
+ sender: item.sender
+ }
+ }
+
+ // The sizing algorithm before maximum-width bounding was added. It is used
+ // to verify that media which already fit keeps its exact size.
+ function unboundedPreferredSize({ iWidth, iHeight, maxHeight, minWidth, minHeight }) {
+ const privHeight = Math.min(maxHeight, iHeight);
+ const privWidth = privHeight / iHeight * iWidth;
+ const width = Math.max(privWidth, minWidth);
+ const height = Math.min(
+ Math.max(
+ width > privWidth ? privHeight / privWidth * width : privHeight,
+ minHeight
+ ), maxHeight);
+ return { width, height };
+ }
+
+ function expectedSize(eventView, media, kind) {
+ const isVideo = kind === 'video';
+ return unboundedPreferredSize({
+ iWidth: Math.max(
+ eventView.thumbnailWidth || (isVideo ? eventView.videoWidth : eventView.imageWidth) || media.implicitWidth || 1,
+ Kirigami.Units.gridUnit
+ ),
+ iHeight: Math.max(
+ eventView.thumbnailHeight || (isVideo ? eventView.videoHeight : eventView.imageHeight) || media.implicitHeight || 1,
+ Kirigami.Units.gridUnit
+ ),
+ maxHeight: isVideo ? eventView.videoMaxHeight : eventView.imageMaxHeight,
+ minWidth: isVideo ? eventView.videoMinWidth : eventView.imageMinWidth,
+ minHeight: isVideo ? eventView.videoMinHeight : eventView.imageMinHeight,
+ });
+ }
+
+ TestCase {
+ id: eventViewImageTest
+ name: 'EventViewImageTest'
+ when: windowShown
+
+ function rightEdgeInView(child, view) {
+ return child.mapToItem(view, child.width, 0).x;
+ }
+
+ function simpleItem(eventView) {
+ const simple = findChild(eventView, 'eventViewMainItem');
+ verify(simple);
+ return simple;
+ }
+
+ function verifyInsideView(child, view) {
+ verify(child.width <= view.width);
+ verify(rightEdgeInView(child, view) <= view.width);
+ // The button hosting the media adds padding around it.
+ const button = child.parent.parent;
+ verify(button.width <= view.width);
+ verify(rightEdgeInView(button, view) <= view.width);
+ }
+
+ function verifyMediaInsideView(eventView, objectName) {
+ const media = findChild(eventView, objectName);
+ verify(media);
+ tryVerify(() => media.width > 0);
+ verifyInsideView(media, eventView);
+ }
+
+ // Timestamp, read indicator and context menu button share the row with
+ // the event content; none of them may stick out of the event view.
+ function verifyTrailingInsideView(eventView, objectName) {
+ const element = findChild(eventView, objectName);
+ verify(element);
+ if (!element.visible) {
+ return;
+ }
+ tryVerify(() => rightEdgeInView(element, eventView) <= eventView.width);
+ verify(element.width <= eventView.width);
+ }
+
+ function verifyBubbleInsideView(eventView) {
+ verifyTrailingInsideView(eventView, 'timeIndicator');
+ verifyTrailingInsideView(eventView, 'eventReadIndicator');
+ verifyTrailingInsideView(eventView, 'moreButton');
+ }
+
+ function test_wideImageDoesNotOverflow() {
+ verifyMediaInsideView(eventViewWideImage, 'mainImage');
+ }
+
+ function test_wideVideoDoesNotOverflow() {
+ verifyMediaInsideView(eventViewWideVideo, 'video');
+ }
+
+ function test_wideCompactImageDoesNotOverflow() {
+ verifyMediaInsideView(eventViewWideImageCompact, 'mainImage');
+ }
+
+ function test_wideCompactVideoDoesNotOverflow() {
+ verifyMediaInsideView(eventViewWideVideoCompact, 'video');
+ }
+
+ function test_sizeUnchanged_data() {
+ return [
+ { tag: 'normalImage', view: 'eventViewNormalImage', objectName: 'mainImage', kind: 'image' },
+ { tag: 'tinyImage', view: 'eventViewTinyImage', objectName: 'mainImage', kind: 'image' },
+ { tag: 'normalVideo', view: 'eventViewNormalVideo', objectName: 'video', kind: 'video' },
+ ];
+ }
+
+ function test_sizeUnchanged(data) {
+ const views = {
+ eventViewNormalImage: eventViewNormalImage,
+ eventViewTinyImage: eventViewTinyImage,
+ eventViewNormalVideo: eventViewNormalVideo,
+ };
+ const eventView = views[data.view];
+ const simple = simpleItem(eventView);
+ const media = findChild(eventView, data.objectName);
+ verify(media);
+ tryVerify(() => media.width > 0);
+ const expected = expectedSize(simple, media, data.kind);
+ // Only sizes that already fit are expected to be left untouched.
+ verify(expected.width < simple.innerContentWidth);
+ compare(media.width, expected.width);
+ compare(media.height, expected.height);
+ }
+
+ function test_noOverflowAfterResize_data() {
+ return [
+ { tag: 'narrow800Image', view: 'eventViewWideImage', objectName: 'mainImage', width: 800, wideMode: false },
+ { tag: 'narrow600Video', view: 'eventViewWideVideo', objectName: 'video', width: 600, wideMode: false },
+ { tag: 'narrow400Image', view: 'eventViewWideImage', objectName: 'mainImage', width: 400, wideMode: false },
+ { tag: 'narrow300Video', view: 'eventViewWideVideo', objectName: 'video', width: 300, wideMode: false },
+ { tag: 'narrow300CompactImage', view: 'eventViewWideImageCompact', objectName: 'mainImage', width: 300, wideMode: false },
+ { tag: 'narrow300CompactVideo', view: 'eventViewWideVideoCompact', objectName: 'video', width: 300, wideMode: false },
+ { tag: 'wide800Image', view: 'eventViewWideImage', objectName: 'mainImage', width: 800, wideMode: true },
+ { tag: 'wide600Video', view: 'eventViewWideVideo', objectName: 'video', width: 600, wideMode: true },
+ { tag: 'wide400Image', view: 'eventViewWideImage', objectName: 'mainImage', width: 400, wideMode: true },
+ { tag: 'wide300Video', view: 'eventViewWideVideo', objectName: 'video', width: 300, wideMode: true },
+ { tag: 'wide1100Image', view: 'eventViewWideImage', objectName: 'mainImage', width: 1100, wideMode: true },
+ ];
+ }
+
+ function test_noOverflowAfterResize(data) {
+ const views = {
+ eventViewWideImage: eventViewWideImage,
+ eventViewWideVideo: eventViewWideVideo,
+ eventViewWideImageCompact: eventViewWideImageCompact,
+ eventViewWideVideoCompact: eventViewWideVideoCompact,
+ };
+ const eventView = views[data.view];
+ const media = findChild(eventView, data.objectName);
+ verify(media);
+ item.width = data.width;
+ item.mockPageStack.wideMode = data.wideMode;
+ tryVerify(() => eventView.width === data.width);
+ tryVerify(() => media.width > 0);
+ verifyInsideView(media, eventView);
+ verifyBubbleInsideView(eventView);
+ }
+
+ function test_trailingInsideView_data() {
+ return [
+ { tag: 'narrow800Image', view: 'eventViewWideImage', width: 800, wideMode: false },
+ { tag: 'narrow600Image', view: 'eventViewWideImage', width: 600, wideMode: false },
+ { tag: 'narrow400Image', view: 'eventViewWideImage', width: 400, wideMode: false },
+ { tag: 'narrow300Image', view: 'eventViewWideImage', width: 300, wideMode: false },
+ { tag: 'narrow300Video', view: 'eventViewWideVideo', width: 300, wideMode: false },
+ { tag: 'narrow400NormalImage', view: 'eventViewNormalImage', width: 400, wideMode: false },
+ { tag: 'wide800Image', view: 'eventViewWideImage', width: 800, wideMode: true },
+ { tag: 'wide600Image', view: 'eventViewWideImage', width: 600, wideMode: true },
+ { tag: 'wide400Image', view: 'eventViewWideImage', width: 400, wideMode: true },
+ { tag: 'wide300Image', view: 'eventViewWideImage', width: 300, wideMode: true },
+ { tag: 'wide300Video', view: 'eventViewWideVideo', width: 300, wideMode: true },
+ { tag: 'wide400NormalImage', view: 'eventViewNormalImage', width: 400, wideMode: true },
+ ];
+ }
+
+ function test_trailingInsideView(data) {
+ const views = {
+ eventViewWideImage: eventViewWideImage,
+ eventViewWideVideo: eventViewWideVideo,
+ eventViewNormalImage: eventViewNormalImage,
+ };
+ const eventView = views[data.view];
+ item.width = data.width;
+ item.mockPageStack.wideMode = data.wideMode;
+ tryVerify(() => eventView.width === data.width);
+ verifyBubbleInsideView(eventView);
+ }
+
+ function cleanup() {
+ item.width = 800;
+ item.mockPageStack.wideMode = false;
+ }
+ }
+}
diff --git a/src/tests/quick-tests/tst_MatrixHelpers.qml b/src/tests/quick-tests/tst_MatrixHelpers.qml
--- a/src/tests/quick-tests/tst_MatrixHelpers.qml
+++ b/src/tests/quick-tests/tst_MatrixHelpers.qml
@@ -64,4 +64,35 @@
compare(Helpers.getEventBodyForEditing(event), expected);
}
}
+
+ function test_getPreferredSize_data() {
+ return [
+ {
+ tag: 'noClamping',
+ input: { iWidth: 400, iHeight: 300, maxWidth: 1000, maxHeight: 96, minWidth: 64, minHeight: 64 },
+ expected: { width: 128, height: 96 },
+ },
+ {
+ tag: 'defaultMaxWidth',
+ input: { iWidth: 400, iHeight: 300, maxHeight: 96, minWidth: 64, minHeight: 64 },
+ expected: { width: 128, height: 96 },
+ },
+ {
+ tag: 'minWidthClamping',
+ input: { iWidth: 10, iHeight: 10, maxWidth: 600, maxHeight: 96, minWidth: 64, minHeight: 64 },
+ expected: { width: 64, height: 64 },
+ },
+ {
+ tag: 'wideShortClamped',
+ input: { iWidth: 10000, iHeight: 10, maxWidth: 600, maxHeight: 96, minWidth: 64, minHeight: 64 },
+ expected: { width: 600, height: 64 },
+ },
+ ];
+ }
+
+ function test_getPreferredSize(data) {
+ const size = Helpers.getPreferredSize(data.input);
+ compare(size.width, data.expected.width);
+ compare(size.height, data.expected.height);
+ }
}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 29, 11:36 AM (16 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1853224
Default Alt Text
D385.1795981011.diff (18 KB)

Event Timeline