status-desktop/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatText.qml

163 lines
5.9 KiB
QML
Raw Normal View History

import QtQuick 2.13
import "../../../../../shared"
import "../../../../../imports"
import QtGraphicalEffects 1.0
Item {
property bool longChatText: true
property bool veryLongChatText: chatsModel.plainText(message).length >
2021-02-10 20:41:00 +00:00
(appSettings.useCompactMode ? Constants.limitLongChatTextCompactMode : Constants.limitLongChatText)
property bool readMore: false
property alias textField: chatText
id: root
visible: contentType == Constants.messageType || isEmoji
z: 51
implicitHeight: visible ? (showMoreLoader.active ? childrenRect.height - 10 : chatText.height) : 0
// This function is to avoid the binding loop warning
function setWidths() {
if (longChatText) {
root.width = undefined
chatText.width = Qt.binding(function () {return root.width})
} else {
chatText.width = Qt.binding(function () {return chatText.implicitWidth})
root.width = Qt.binding(function () {return chatText.width})
}
}
Component.onCompleted: {
root.setWidths()
}
StyledTextEdit {
id: chatText
visible: !showMoreLoader.active || root.readMore
textFormat: Text.RichText
wrapMode: Text.Wrap
font.pixelSize: Style.current.primaryTextFontSize
readOnly: true
selectByMouse: true
color: Style.current.textColor
height: root.veryLongChatText && !root.readMore ? Math.min(implicitHeight, 200) : implicitHeight
clip: true
onLinkActivated: function (link) {
if(link.startsWith("#")) {
chatsModel.joinChat(link.substring(1), Constants.chatTypePublic);
return;
}
if (link.startsWith('//')) {
let pk = link.replace("//", "");
const userProfileImage = appMain.getProfileImage(pk)
2020-11-30 17:03:52 +00:00
openProfilePopup(chatsModel.userNameOrAlias(pk), pk, userProfileImage || utilsModel.generateIdenticon(pk))
return;
}
appMain.openLink(link)
}
onLinkHovered: {
cursorShape: Qt.PointingHandCursor
}
text: {
if(contentType === Constants.stickerType) return "";
let msg = Utils.linkifyAndXSS(message);
if(isEmoji) {
2021-01-14 08:46:05 +00:00
return Emoji.parse(msg, Emoji.size.middle);
} else {
return `<style type="text/css">` +
`p, img, a, del, code, blockquote { margin: 0; padding: 0; }` +
`code {` +
`background-color: ${Style.current.codeBackground};` +
`color: ${Style.current.white};` +
`white-space: pre;` +
`}` +
`p {` +
`line-height: 22px;` +
`}` +
`a {` +
2021-02-10 20:41:00 +00:00
`color: ${isCurrentUser && !appSettings.useCompactMode ? Style.current.white : Style.current.textColor};` +
`}` +
`a.mention {` +
`color: ${Style.current.mentionColor};` +
`background-color: ${Style.current.mentionBgColor};` +
`text-decoration: none;` +
`}` +
`del {` +
`text-decoration: line-through;` +
`}` +
`table.blockquote td {` +
`padding-left: 10px;` +
`color: ${isCurrentUser ? Style.current.chatReplyCurrentUser : Style.current.secondaryText};` +
`}` +
`table.blockquote td.quoteline {` +
`background-color: ${isCurrentUser ? Style.current.chatReplyCurrentUser : Style.current.secondaryText};` +
`height: 100%;` +
`padding-left: 0;` +
`}` +
`.emoji {` +
`vertical-align: bottom;` +
`}` +
`</style>` +
`${Emoji.parse(msg)}`
}
}
}
Loader {
id: mask
anchors.fill: chatText
active: showMoreLoader.active
visible: false
sourceComponent: LinearGradient {
start: Qt.point(0, 0)
end: Qt.point(0, chatText.height)
gradient: Gradient {
GradientStop { position: 0.0; color: "white" }
GradientStop { position: 0.85; color: "white" }
GradientStop { position: 1; color: "transparent" }
}
}
}
Loader {
id: opMask
active: showMoreLoader.active && !root.readMore
anchors.fill: chatText
sourceComponent: OpacityMask {
source: chatText
maskSource: mask
}
}
Loader {
2020-09-30 18:45:45 +00:00
id: showMoreLoader
active: root.veryLongChatText
anchors.top: chatText.bottom
anchors.topMargin: - Style.current.padding
anchors.horizontalCenter: parent.horizontalCenter
2020-09-30 18:45:45 +00:00
sourceComponent: Component {
SVGImage {
id: emojiImage
width: 256
height: 44
fillMode: Image.PreserveAspectFit
2020-11-19 16:08:08 +00:00
source: "../../../../img/read-more.svg"
2020-09-30 18:45:45 +00:00
z: 100
2020-11-19 16:08:08 +00:00
rotation: root.readMore ? 180 : 0
2020-09-30 18:45:45 +00:00
MouseArea {
z: 101
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: {
root.readMore = !root.readMore
}
}
}
}
}
}