From 004d10bfeedb5e4278beafbd6b2f288b9b106a26 Mon Sep 17 00:00:00 2001
From: Nicolas Werner <nicolas.werner@hotmail.de>
Date: Wed, 13 May 2020 01:09:40 +0200
Subject: [PATCH] Clip replies by default

In the future we should probably add a gradient when clipped...
---
 resources/qml/delegates/ImageMessage.qml         |  7 ++++---
 resources/qml/delegates/MessageDelegate.qml      |  2 ++
 resources/qml/delegates/NoticeMessage.qml        |  2 ++
 resources/qml/delegates/PlayableMediaMessage.qml | 10 ++++++++--
 resources/qml/delegates/Reply.qml                |  1 +
 resources/qml/delegates/TextMessage.qml          |  2 ++
 6 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/resources/qml/delegates/ImageMessage.qml b/resources/qml/delegates/ImageMessage.qml
index c7e6d1273..62d9de600 100644
--- a/resources/qml/delegates/ImageMessage.qml
+++ b/resources/qml/delegates/ImageMessage.qml
@@ -6,10 +6,11 @@ Item {
 	property double tempWidth: Math.min(parent ? parent.width : undefined, model.data.width < 1 ? parent.width : model.data.width)
 	property double tempHeight: tempWidth * model.data.proportionalHeight
 
-	property bool tooHigh: tempHeight > timelineRoot.height / 2
+	property double divisor: model.isReply ? 4 : 2
+	property bool tooHigh: tempHeight > timelineRoot.height / divisor
 
-	height: tooHigh ? timelineRoot.height / 2 : tempHeight
-	width: tooHigh ? (timelineRoot.height / 2) / model.data.proportionalHeight : tempWidth
+	height: tooHigh ? timelineRoot.height / divisor : tempHeight
+	width: tooHigh ? (timelineRoot.height / divisor) / model.data.proportionalHeight : tempWidth
 
 	Image {
 		id: blurhash
diff --git a/resources/qml/delegates/MessageDelegate.qml b/resources/qml/delegates/MessageDelegate.qml
index ff1034598..17fe7360b 100644
--- a/resources/qml/delegates/MessageDelegate.qml
+++ b/resources/qml/delegates/MessageDelegate.qml
@@ -6,9 +6,11 @@ Item {
 	Item {
 		id: model
 		property var data;
+		property bool isReply: false
 	}
 	
 	property alias modelData: model.data
+	property alias isReply: model.isReply
 
 	height: chooser.childrenRect.height
 	property real implicitWidth: (chooser.child && chooser.child.implicitWidth) ? chooser.child.implicitWidth : width
diff --git a/resources/qml/delegates/NoticeMessage.qml b/resources/qml/delegates/NoticeMessage.qml
index 62ada6d1c..be3483298 100644
--- a/resources/qml/delegates/NoticeMessage.qml
+++ b/resources/qml/delegates/NoticeMessage.qml
@@ -1,4 +1,6 @@
 TextMessage {
 	font.italic: true
 	color: colors.buttonText
+	height: isReply ? Math.min(chat.height / 8, implicitHeight) : undefined
+	clip: true
 }
diff --git a/resources/qml/delegates/PlayableMediaMessage.qml b/resources/qml/delegates/PlayableMediaMessage.qml
index 20177a048..bab524eb2 100644
--- a/resources/qml/delegates/PlayableMediaMessage.qml
+++ b/resources/qml/delegates/PlayableMediaMessage.qml
@@ -20,8 +20,14 @@ Rectangle {
 		Rectangle {
 			id: videoContainer
 			visible: model.data.type == MtxEvent.VideoMessage
-			width: Math.min(parent.width, model.data.width ? model.data.width : 400) // some media has 0 as size...
-			height: width*model.data.proportionalHeight
+			property double tempWidth: Math.min(parent ? parent.width : undefined, model.data.width < 1 ? 400 : model.data.width)
+			property double tempHeight: tempWidth * model.data.proportionalHeight
+
+			property double divisor: model.isReply ? 4 : 2
+			property bool tooHigh: tempHeight > timelineRoot.height / divisor
+
+			height: tooHigh ? timelineRoot.height / divisor : tempHeight
+			width: tooHigh ? (timelineRoot.height / divisor) / model.data.proportionalHeight : tempWidth
 			Image {
 				anchors.fill: parent
 				source: model.data.thumbnailUrl.replace("mxc://", "image://MxcImage/")
diff --git a/resources/qml/delegates/Reply.qml b/resources/qml/delegates/Reply.qml
index 90013de93..f9fd3f111 100644
--- a/resources/qml/delegates/Reply.qml
+++ b/resources/qml/delegates/Reply.qml
@@ -51,6 +51,7 @@ Item {
 		MessageDelegate {
 			id: reply
 			width: parent.width
+			isReply: true
 		}
 	}
 
diff --git a/resources/qml/delegates/TextMessage.qml b/resources/qml/delegates/TextMessage.qml
index 7e4b1f295..bef4f76d0 100644
--- a/resources/qml/delegates/TextMessage.qml
+++ b/resources/qml/delegates/TextMessage.qml
@@ -4,4 +4,6 @@ MatrixText {
 	property string formatted: model.data.formattedBody
 	text: "<style type=\"text/css\">a { color:"+colors.link+";}</style>" + formatted.replace("<pre>", "<pre style='white-space: pre-wrap'>")
 	width: parent ? parent.width : undefined
+	height: isReply ? Math.min(chat.height / 8, implicitHeight) : undefined
+	clip: true
 }
-- 
GitLab