elide usernames in timeline (#997)

* Use advanceWidth to get the with of the original text

Co-authored-by: Nicolas Werner <nicolas.werner@hotmail.de>
This commit is contained in:
Malte E 2022-03-20 05:12:41 +01:00 committed by GitHub
parent 887b26d72c
commit a42335aed2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 13 deletions

View file

@ -12,6 +12,7 @@ Label {
property alias fullText: metrics.text property alias fullText: metrics.text
property alias elideWidth: metrics.elideWidth property alias elideWidth: metrics.elideWidth
property int fullTextWidth: Math.ceil(metrics.advanceWidth)
color: Nheko.colors.text color: Nheko.colors.text
text: (textFormat == Text.PlainText) ? metrics.elidedText : TimelineManager.escapeEmoji(TimelineManager.htmlEscape(metrics.elidedText)) text: (textFormat == Text.PlainText) ? metrics.elidedText : TimelineManager.escapeEmoji(TimelineManager.htmlEscape(metrics.elidedText))

View file

@ -285,6 +285,7 @@ Item {
height: userName_.height height: userName_.height
spacing: 8 spacing: 8
visible: !isStateEvent && (!isSender || !Settings.bubbles) visible: !isStateEvent && (!isSender || !Settings.bubbles)
id: userInfo
Avatar { Avatar {
id: messageUserAvatar id: messageUserAvatar
@ -311,17 +312,23 @@ Item {
target: chat.model target: chat.model
} }
property int remainingWidth: chat.delegateMaxWidth - spacing - messageUserAvatar.width
AbstractButton { AbstractButton {
contentItem: Label { contentItem: ElidedLabel {
id: userName_ id: userName_
text: TimelineManager.escapeEmoji(userName) fullText: userName
color: TimelineManager.userColor(userId, Nheko.colors.base) color: TimelineManager.userColor(userId, Nheko.colors.base)
textFormat: Text.RichText textFormat: Text.RichText
elideWidth: Math.min(userInfo.remainingWidth-Math.min(statusMsg.implicitWidth,userInfo.remainingWidth/3), userName_.fullTextWidth)
} }
ToolTip.visible: hovered ToolTip.visible: hovered
ToolTip.delay: Nheko.tooltipDelay ToolTip.delay: Nheko.tooltipDelay
ToolTip.text: userId ToolTip.text: userId
onClicked: chat.model.openUserProfile(userId) onClicked: chat.model.openUserProfile(userId)
leftInset: 0
rightInset: 0
leftPadding: 0
rightPadding: 0
CursorShape { CursorShape {
anchors.fill: parent anchors.fill: parent
@ -336,7 +343,7 @@ Item {
text: Presence.userStatus(userId) text: Presence.userStatus(userId)
textFormat: Text.PlainText textFormat: Text.PlainText
elide: Text.ElideRight elide: Text.ElideRight
width: chat.delegateMaxWidth - parent.spacing * 2 - userName.implicitWidth - Nheko.avatarSize width: userInfo.remainingWidth - userName_.width - parent.spacing
font.italic: true font.italic: true
Connections { Connections {

View file

@ -71,17 +71,16 @@ Item {
Control { Control {
id: row id: row
property bool bubbleOnRight : isSender && Settings.bubbles property bool bubbleOnRight : isSender && Settings.bubbles
property int bubblePadding: (parent.width-(Settings.smallAvatars? 0 : Nheko.avatarSize+8))/10 anchors.leftMargin: isStateEvent || Settings.smallAvatars? 0 : Nheko.avatarSize+8 // align bubble with section header
anchors.rightMargin: isStateEvent? 0 : (isSender || !Settings.bubbles? 0 : bubblePadding)
anchors.leftMargin: isStateEvent? 0 :((Settings.smallAvatars? 0 : Nheko.avatarSize+8) + (bubbleOnRight? bubblePadding : 0)) // align bubble with section header
anchors.left: isStateEvent? undefined : (bubbleOnRight? undefined : parent.left) anchors.left: isStateEvent? undefined : (bubbleOnRight? undefined : parent.left)
anchors.right: isStateEvent? undefined: (bubbleOnRight? parent.right : undefined) anchors.right: isStateEvent? undefined: (bubbleOnRight? parent.right : undefined)
anchors.horizontalCenter: isStateEvent? parent.horizontalCenter : undefined anchors.horizontalCenter: isStateEvent? parent.horizontalCenter : undefined
property int maxWidth: parent.width-anchors.leftMargin-anchors.rightMargin property int maxWidth: (parent.width-(Settings.smallAvatars || isStateEvent? 0 : Nheko.avatarSize+8))*(Settings.bubbles && !isStateEvent? 0.9 : 1)
width: Settings.bubbles? Math.min(maxWidth,Math.max(reply.implicitWidth+8,contentItem.implicitWidth+metadata.width+20)) : maxWidth width: Settings.bubbles? Math.min(maxWidth,Math.max(reply.implicitWidth+8,contentItem.implicitWidth+metadata.width+20)) : maxWidth
leftPadding: 4 leftPadding: 4
rightPadding: (Settings.bubbles && !isStateEvent)? 4: 2 rightPadding: (Settings.bubbles && !isStateEvent)? 4: 2
topPadding: (Settings.bubbles && !isStateEvent)? 4: 2 topPadding: rightPadding
bottomPadding: topPadding bottomPadding: topPadding
background: Rectangle { background: Rectangle {
property color userColor: TimelineManager.userColor(userId, Nheko.colors.base) property color userColor: TimelineManager.userColor(userId, Nheko.colors.base)

View file

@ -9,6 +9,7 @@ import QtQuick.Controls 2.3
import QtQuick.Layouts 1.2 import QtQuick.Layouts 1.2
import QtQuick.Window 2.13 import QtQuick.Window 2.13
import im.nheko 1.0 import im.nheko 1.0
import "../"
Item { Item {
id: r id: r
@ -39,7 +40,7 @@ Item {
height: replyContainer.height height: replyContainer.height
implicitHeight: replyContainer.height implicitHeight: replyContainer.height
implicitWidth: visible? colorLine.width+replyContainer.implicitWidth : 0 implicitWidth: visible? colorLine.width+Math.max(replyContainer.implicitWidth,userName_.fullTextWidth) : 0 // visible? seems to be causing issues
CursorShape { CursorShape {
anchors.fill: parent anchors.fill: parent
@ -83,13 +84,15 @@ Item {
} }
AbstractButton { AbstractButton {
id: userName_
Layout.leftMargin: 4 Layout.leftMargin: 4
contentItem: Text { Layout.fillWidth: true
contentItem: ElidedLabel {
text: TimelineManager.escapeEmoji(userName) id: userName_
fullText: userName
color: r.userColor color: r.userColor
textFormat: Text.RichText textFormat: Text.RichText
width: parent.width
elideWidth: width
} }
onClicked: room.openUserProfile(userId) onClicked: room.openUserProfile(userId)
} }