Warning, /network/kdeconnect-kde/smsapp/qml/ChatMessage.qml is written in an unsupported language. File is not indexed.

0001 /**
0002  * SPDX-FileCopyrightText: 2020 Nicolas Fella <nicolas.fella@gmx.de>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 import QtQuick
0008 import QtQuick.Layouts
0009 import QtQuick.Controls
0010 import Qt5Compat.GraphicalEffects
0011 import org.kde.kirigami as Kirigami
0012 import org.kde.kirigamiaddons.components as KirigamiComponents
0013 
0014 Item {
0015     id: root
0016 
0017     height: Math.max(avatar.height, messageBubble.height)
0018 
0019     property string messageBody
0020     property bool sentByMe
0021     property string selectedText
0022     property date dateTime
0023     property string name
0024     property bool multiTarget
0025     property var attachmentList: []
0026 
0027     signal messageCopyRequested(string message)
0028 
0029     KirigamiComponents.Avatar {
0030         id: avatar
0031         width: visible ? Kirigami.Units.gridUnit * 2 : 0
0032         height: width
0033         visible: !root.sentByMe && multiTarget
0034         name: root.name
0035 
0036         anchors.left: parent.left
0037         anchors.leftMargin: Kirigami.Units.largeSpacing
0038     }
0039 
0040     RowLayout {
0041         id: messageBubble
0042 
0043         anchors.right: parent.right
0044         anchors.rightMargin: Kirigami.Units.largeSpacing
0045         anchors.left: avatar.right
0046         anchors.leftMargin: Kirigami.Units.largeSpacing
0047 
0048         height: messageColumn.height
0049 
0050         Rectangle {
0051             id: messageBox
0052             Layout.maximumWidth: applicationWindow().wideScreen ? Math.min(messageColumn.contentWidth, root.width * 0.6) : messageColumn.contentWidth
0053             Layout.fillWidth: true
0054             Layout.alignment: root.sentByMe ? Qt.AlignRight : Qt.AlignLeft
0055             Layout.fillHeight: true
0056             Layout.minimumWidth: dateLabel.implicitWidth
0057 
0058             color: {
0059                 Kirigami.Theme.colorSet = Kirigami.Theme.View
0060                 var accentColor = Kirigami.Theme.highlightColor
0061                 return Qt.tint(Kirigami.Theme.backgroundColor, Qt.rgba(accentColor.r, accentColor.g, accentColor.b, root.sentByMe ? 0.1 : 0.4))
0062             }
0063             radius: 6
0064 
0065             MouseArea {
0066                 anchors.fill: parent
0067                 acceptedButtons: Qt.LeftButton | Qt.RightButton
0068                 onClicked: mouse => {
0069                     if (mouse.button === Qt.RightButton) {
0070                         var selectStart = messageLabel.selectionStart;
0071                         var selectEnd = messageLabel.selectionEnd;
0072                         selectedText = messageLabel.selectedText;
0073                         contextMenu.x = mouse.x;
0074                         contextMenu.y = mouse.y;
0075                         messageLabel.persistentSelection = true;
0076                         contextMenu.open();
0077                     }
0078                 }
0079                 onPressAndHold: {
0080                     var selectStart = messageLabel.selectionStart;
0081                     var selectEnd = messageLabel.selectionEnd;
0082                     selectedText = messageLabel.selectedText;
0083                     contextMenu.x = mouse.x;
0084                     contextMenu.y = mouse.y;
0085                     messageLabel.persistentSelection = true;
0086                     contextMenu.open();
0087                 }
0088             }
0089 
0090             Column {
0091                 id: messageColumn
0092                 width: parent.width
0093                 height: childrenRect.height
0094 
0095                 property int contentWidth: Math.max(Math.max(messageLabel.implicitWidth, attachmentGrid.implicitWidth), dateLabel.implicitWidth)
0096                 Label {
0097                     id: authorLabel
0098                     width: parent.width
0099                     text: root.name
0100                     leftPadding: Kirigami.Units.largeSpacing
0101                     topPadding: Kirigami.Units.smallSpacing
0102                     visible: multiTarget
0103                     color: Kirigami.Theme.disabledTextColor
0104                     horizontalAlignment: messageLabel.horizontalAlignment
0105                 }
0106 
0107                 Grid {
0108                     id: attachmentGrid
0109                     columns: 2
0110                     padding: attachmentList.length > 0 ? Kirigami.Units.largeSpacing : 0
0111                     layoutDirection: root.sentByMe ? Qt.RightToLeft : Qt.LeftToRight
0112 
0113                     Repeater {
0114                         model: attachmentList
0115 
0116                         delegate: MessageAttachments {
0117                             mimeType: modelData.mimeType
0118                             partID: modelData.partID
0119                             uniqueIdentifier: modelData.uniqueIdentifier
0120                         }
0121                     }
0122                 }
0123 
0124                 TextEdit {
0125                     id: messageLabel
0126                     visible: messageBody != ""
0127                     selectByMouse: true
0128                     readOnly: true
0129                     leftPadding: Kirigami.Units.largeSpacing
0130                     rightPadding: Kirigami.Units.largeSpacing
0131                     topPadding: authorLabel.visible ? 0 : Kirigami.Units.largeSpacing
0132                     width: parent.width
0133                     horizontalAlignment: root.sentByMe ? Text.AlignRight : Text.AlignLeft
0134                     wrapMode: Text.Wrap
0135                     color: Kirigami.Theme.textColor
0136                     text: root.messageBody
0137                 }
0138 
0139                 Label {
0140                     id: dateLabel
0141                     width: parent.width
0142                     text: Qt.formatDateTime(root.dateTime, "dd. MMM, hh:mm")
0143                     leftPadding: Kirigami.Units.largeSpacing
0144                     rightPadding: Kirigami.Units.largeSpacing
0145                     bottomPadding: Kirigami.Units.smallSpacing
0146                     color: Kirigami.Theme.disabledTextColor
0147                     horizontalAlignment: messageLabel.horizontalAlignment
0148                 }
0149             }
0150 
0151             Menu {
0152                 id: contextMenu
0153                 exit: Transition {PropertyAction { target: messageLabel; property: "persistentSelection"; value: false }}
0154                 MenuItem {
0155                     text: i18nd("kdeconnect-sms", "Copy Message")
0156                     enabled: messageLabel.visible
0157                     onTriggered: root.messageCopyRequested(root.messageBody)
0158                 }
0159                 MenuItem {
0160                     text: i18nd("kdeconnect-sms", "Copy Selection")
0161                     visible: selectedText != ""
0162                     onTriggered: {
0163                             root.messageCopyRequested(selectedText)
0164                     }
0165                 }
0166 
0167             }
0168         }
0169     }
0170 }