2020-07-01 20:15:45 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2020 Nicolas Fella <nicolas.fella@gmx.de>
|
2018-10-30 20:01:13 +00:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2018-10-30 20:01:13 +00:00
|
|
|
*/
|
|
|
|
|
2023-12-23 16:48:04 +00:00
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Layouts
|
|
|
|
import QtQuick.Controls
|
2023-09-21 18:23:06 +01:00
|
|
|
import Qt5Compat.GraphicalEffects
|
2023-12-23 16:48:04 +00:00
|
|
|
import org.kde.kirigami as Kirigami
|
2023-09-21 18:23:06 +01:00
|
|
|
import org.kde.kirigamiaddons.components as KirigamiComponents
|
2020-07-01 20:15:45 +01:00
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
height: Math.max(avatar.height, messageBubble.height)
|
|
|
|
|
|
|
|
property string messageBody
|
|
|
|
property bool sentByMe
|
2020-07-05 01:49:31 +01:00
|
|
|
property string selectedText
|
2020-07-01 20:15:45 +01:00
|
|
|
property date dateTime
|
|
|
|
property string name
|
2020-06-27 17:37:59 +01:00
|
|
|
property bool multiTarget
|
2023-04-21 17:28:58 +01:00
|
|
|
property var attachmentList: []
|
2020-07-01 20:15:45 +01:00
|
|
|
|
|
|
|
signal messageCopyRequested(string message)
|
|
|
|
|
2023-09-21 18:23:06 +01:00
|
|
|
KirigamiComponents.Avatar {
|
2020-07-01 20:15:45 +01:00
|
|
|
id: avatar
|
2020-06-27 17:37:59 +01:00
|
|
|
width: visible ? Kirigami.Units.gridUnit * 2 : 0
|
2020-07-01 20:15:45 +01:00
|
|
|
height: width
|
2020-06-27 17:37:59 +01:00
|
|
|
visible: !root.sentByMe && multiTarget
|
2020-07-01 20:15:45 +01:00
|
|
|
name: root.name
|
|
|
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: Kirigami.Units.largeSpacing
|
2020-04-24 02:54:44 +01:00
|
|
|
}
|
|
|
|
|
2020-07-01 20:15:45 +01:00
|
|
|
RowLayout {
|
|
|
|
id: messageBubble
|
|
|
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Kirigami.Units.largeSpacing
|
|
|
|
anchors.left: avatar.right
|
|
|
|
anchors.leftMargin: Kirigami.Units.largeSpacing
|
|
|
|
|
|
|
|
height: messageColumn.height
|
|
|
|
|
|
|
|
Rectangle {
|
2020-08-09 20:00:57 +01:00
|
|
|
id: messageBox
|
2020-07-01 20:15:45 +01:00
|
|
|
Layout.maximumWidth: applicationWindow().wideScreen ? Math.min(messageColumn.contentWidth, root.width * 0.6) : messageColumn.contentWidth
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.alignment: root.sentByMe ? Qt.AlignRight : Qt.AlignLeft
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.minimumWidth: dateLabel.implicitWidth
|
|
|
|
|
|
|
|
color: {
|
|
|
|
Kirigami.Theme.colorSet = Kirigami.Theme.View
|
|
|
|
var accentColor = Kirigami.Theme.highlightColor
|
|
|
|
return Qt.tint(Kirigami.Theme.backgroundColor, Qt.rgba(accentColor.r, accentColor.g, accentColor.b, root.sentByMe ? 0.1 : 0.4))
|
|
|
|
}
|
|
|
|
radius: 6
|
|
|
|
|
2020-07-05 01:49:31 +01:00
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
|
|
onClicked: mouse => {
|
|
|
|
if (mouse.button === Qt.RightButton) {
|
|
|
|
var selectStart = messageLabel.selectionStart;
|
|
|
|
var selectEnd = messageLabel.selectionEnd;
|
|
|
|
selectedText = messageLabel.selectedText;
|
|
|
|
contextMenu.x = mouse.x;
|
|
|
|
contextMenu.y = mouse.y;
|
|
|
|
messageLabel.persistentSelection = true;
|
|
|
|
contextMenu.open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onPressAndHold: {
|
|
|
|
var selectStart = messageLabel.selectionStart;
|
|
|
|
var selectEnd = messageLabel.selectionEnd;
|
|
|
|
selectedText = messageLabel.selectedText;
|
|
|
|
contextMenu.x = mouse.x;
|
|
|
|
contextMenu.y = mouse.y;
|
|
|
|
messageLabel.persistentSelection = true;
|
|
|
|
contextMenu.open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-01 20:15:45 +01:00
|
|
|
Column {
|
|
|
|
id: messageColumn
|
|
|
|
width: parent.width
|
|
|
|
height: childrenRect.height
|
|
|
|
|
2020-08-09 20:00:57 +01:00
|
|
|
property int contentWidth: Math.max(Math.max(messageLabel.implicitWidth, attachmentGrid.implicitWidth), dateLabel.implicitWidth)
|
2020-06-27 17:37:59 +01:00
|
|
|
Label {
|
|
|
|
id: authorLabel
|
|
|
|
width: parent.width
|
|
|
|
text: root.name
|
|
|
|
leftPadding: Kirigami.Units.largeSpacing
|
|
|
|
topPadding: Kirigami.Units.smallSpacing
|
|
|
|
visible: multiTarget
|
|
|
|
color: Kirigami.Theme.disabledTextColor
|
|
|
|
horizontalAlignment: messageLabel.horizontalAlignment
|
|
|
|
}
|
2020-07-01 20:15:45 +01:00
|
|
|
|
2020-08-09 20:00:57 +01:00
|
|
|
Grid {
|
|
|
|
id: attachmentGrid
|
|
|
|
columns: 2
|
|
|
|
padding: attachmentList.length > 0 ? Kirigami.Units.largeSpacing : 0
|
|
|
|
layoutDirection: root.sentByMe ? Qt.RightToLeft : Qt.LeftToRight
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
model: attachmentList
|
|
|
|
|
|
|
|
delegate: MessageAttachments {
|
|
|
|
mimeType: modelData.mimeType
|
|
|
|
partID: modelData.partID
|
|
|
|
uniqueIdentifier: modelData.uniqueIdentifier
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-05 01:49:31 +01:00
|
|
|
TextEdit {
|
2020-07-01 20:15:45 +01:00
|
|
|
id: messageLabel
|
2020-08-09 20:00:57 +01:00
|
|
|
visible: messageBody != ""
|
2020-07-05 01:49:31 +01:00
|
|
|
selectByMouse: true
|
|
|
|
readOnly: true
|
2020-07-01 20:15:45 +01:00
|
|
|
leftPadding: Kirigami.Units.largeSpacing
|
|
|
|
rightPadding: Kirigami.Units.largeSpacing
|
2020-06-27 17:37:59 +01:00
|
|
|
topPadding: authorLabel.visible ? 0 : Kirigami.Units.largeSpacing
|
2020-07-01 20:15:45 +01:00
|
|
|
width: parent.width
|
|
|
|
horizontalAlignment: root.sentByMe ? Text.AlignRight : Text.AlignLeft
|
|
|
|
wrapMode: Text.Wrap
|
2020-07-05 01:49:31 +01:00
|
|
|
color: Kirigami.Theme.textColor
|
2020-07-01 20:15:45 +01:00
|
|
|
text: root.messageBody
|
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
|
|
|
id: dateLabel
|
|
|
|
width: parent.width
|
|
|
|
text: Qt.formatDateTime(root.dateTime, "dd. MMM, hh:mm")
|
|
|
|
leftPadding: Kirigami.Units.largeSpacing
|
|
|
|
rightPadding: Kirigami.Units.largeSpacing
|
|
|
|
bottomPadding: Kirigami.Units.smallSpacing
|
|
|
|
color: Kirigami.Theme.disabledTextColor
|
|
|
|
horizontalAlignment: messageLabel.horizontalAlignment
|
|
|
|
}
|
2020-04-24 02:54:44 +01:00
|
|
|
}
|
|
|
|
|
2020-07-01 20:15:45 +01:00
|
|
|
Menu {
|
|
|
|
id: contextMenu
|
2020-07-05 01:49:31 +01:00
|
|
|
exit: Transition {PropertyAction { target: messageLabel; property: "persistentSelection"; value: false }}
|
2020-07-01 20:15:45 +01:00
|
|
|
MenuItem {
|
|
|
|
text: i18nd("kdeconnect-sms", "Copy Message")
|
|
|
|
enabled: messageLabel.visible
|
|
|
|
onTriggered: root.messageCopyRequested(root.messageBody)
|
|
|
|
}
|
2020-07-05 01:49:31 +01:00
|
|
|
MenuItem {
|
|
|
|
text: i18nd("kdeconnect-sms", "Copy Selection")
|
|
|
|
visible: selectedText != ""
|
|
|
|
onTriggered: {
|
|
|
|
root.messageCopyRequested(selectedText)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-01 20:15:45 +01:00
|
|
|
}
|
2020-04-24 02:54:44 +01:00
|
|
|
}
|
|
|
|
}
|
2018-10-30 20:01:13 +00:00
|
|
|
}
|