ui/qml/widgets/Message.qml

140 lines
3.4 KiB
QML
Raw Normal View History

2018-10-23 18:52:13 +00:00
import QtGraphicalEffects 1.0
import QtQuick 2.7
import QtQuick.Controls 2.4
import QtQuick.Controls.Material 2.0
import QtQuick.Layouts 1.3
2018-10-28 02:49:14 +00:00
import "controls" as Awesome
2018-10-23 18:52:13 +00:00
RowLayout {
id: root
2019-02-04 23:05:38 +00:00
anchors.left: fromMe ? undefined : parent.left
anchors.right: fromMe ? parent.right : undefined
2018-10-29 18:00:21 +00:00
height: Math.max(imgProfile.height, rectMessageBubble.height)
2018-10-23 18:52:13 +00:00
property alias message: lbl.text
property string from
2018-11-22 00:01:17 +00:00
property string handle
property string displayName
2018-10-28 02:49:14 +00:00
property int messageID
2018-11-22 00:01:17 +00:00
property bool fromMe
2018-10-28 02:49:14 +00:00
property alias timestamp: ts.text
2018-11-22 00:01:17 +00:00
property alias image: imgProfile.source
2018-10-29 18:00:21 +00:00
property alias status: imgProfile.status
2018-10-28 02:49:14 +00:00
Connections {
target: gcd
onAcknowledged: function(mid) {
if (mid == messageID) {
2018-10-31 05:43:22 +00:00
ack.source = "qrc:/qml/images/fontawesome/regular/check-circle.svg"
2018-10-28 02:49:14 +00:00
}
}
2018-10-28 02:49:14 +00:00
}
2018-10-23 18:52:13 +00:00
2018-10-29 18:00:21 +00:00
ContactPicture {
id: imgProfile
anchors.left: parent.left
handle: root.from
2019-02-04 23:05:38 +00:00
visible: !fromMe
showStatus: false
MouseArea {
anchors.fill: parent
onClicked: {
gcd.broadcast("ResetMessagePane")
theStack.pane = theStack.messagePane
gcd.loadMessagesPane(from)
overlayStack.overlay = overlayStack.chatOverlay
}
}
2018-10-29 18:00:21 +00:00
}
2018-10-23 18:52:13 +00:00
Rectangle { // THIS IS JUST A PRETTY MESSAGE-HOLDING RECTANGLE
2018-10-29 18:00:21 +00:00
id: rectMessageBubble
2018-10-30 19:48:37 +00:00
height: lbl.height + ts.height + 8
Layout.minimumHeight: height
Layout.maximumHeight: height
2018-10-29 18:00:21 +00:00
width: colMessageBubble.width + 6
2018-10-30 19:48:37 +00:00
Layout.minimumWidth: width
Layout.maximumWidth: width
2019-02-04 23:05:38 +00:00
color: fromMe ? "#B09CBC" : "#4B3557"
2018-10-23 18:52:13 +00:00
radius: 5
// the console will complain constantly about me setting these anchors, but qt only allows margins if they've been set to something
// a kludge to fix this would be to have spacers before/after and set the widths according to the side they're on ^ea
2019-02-04 23:05:38 +00:00
anchors.left: fromMe ? undefined : imgProfile.right //parent.left
anchors.right: fromMe ? parent.right : undefined
2018-10-28 02:49:14 +00:00
anchors.leftMargin: 5
anchors.rightMargin: 9
anchors.topMargin: 5
ColumnLayout {
2018-10-29 18:00:21 +00:00
id: colMessageBubble
2018-10-28 02:49:14 +00:00
Column { // combine these into one element or else childrenRect won't play nicely
TextEdit { // this is used as a helper to calculate the message box width
id: dummy
visible: false
padding: 6
leftPadding: 10
2019-02-14 02:53:36 +00:00
font.pixelSize: gcd.themeScale * 12
2018-10-28 02:49:14 +00:00
wrapMode: TextEdit.NoWrap
text: message
textFormat: Text.RichText
}
TextEdit { // this is the actual text display
id: lbl
color: "#FFFFFF"
padding: 6
leftPadding: 10
2019-02-14 02:53:36 +00:00
font.pixelSize: gcd.themeScale * 12
2018-10-28 02:49:14 +00:00
selectByMouse: true
readOnly: true
2018-10-29 18:00:21 +00:00
width: Math.min(dummy.width, root.parent.width - (imgProfile.visible ? imgProfile.width : 0) - 40)
2018-10-28 02:49:14 +00:00
wrapMode: TextEdit.Wrap
textFormat: Text.RichText
}
2018-10-23 18:52:13 +00:00
}
2018-10-28 02:49:14 +00:00
RowLayout {
2018-10-29 18:00:21 +00:00
id: rowBottom
2018-10-28 02:49:14 +00:00
anchors.left: parent.left
anchors.right: parent.right
2018-10-29 18:00:21 +00:00
Label { // TIMESTAMP
2018-10-28 02:49:14 +00:00
id: ts
color: "#FFFFFF"
font.pixelSize: 10
anchors.left: parent.left
leftPadding: 10
}
2018-10-31 05:43:22 +00:00
Label { // DISPLAY NAME FOR GROUPS
2018-10-28 02:49:14 +00:00
color: "#FFFFFF"
font.pixelSize: 10
anchors.right: parent.right
2018-11-22 00:01:17 +00:00
text: displayName
2019-02-04 23:05:38 +00:00
visible: !fromMe
2018-10-31 05:43:22 +00:00
}
Image { // ACKNOWLEDGEMENT ICON
id: ack
anchors.right: parent.right
2019-02-04 23:05:38 +00:00
source: from == "me" ? "qrc:/qml/images/fontawesome/regular/hourglass.svg" : "qrc:/qml/images/fontawesome/regular/check-circle.svg"
2018-10-31 05:43:22 +00:00
height: 10
sourceSize.height: 10
2019-02-04 23:05:38 +00:00
visible: fromMe
2018-10-28 02:49:14 +00:00
}
2018-10-23 18:52:13 +00:00
}
}
}
}