ui/qml/widgets/Message.qml

115 lines
2.8 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
2018-10-29 18:00:21 +00:00
//Layout.alignment: from == "me" ? Qt.AlignRight : Qt.AlignLeft
anchors.left: from == "me" ? undefined : parent.left
anchors.right: from == "me" ? parent.right : undefined
height: Math.max(imgProfile.height, rectMessageBubble.height)
2018-10-23 18:52:13 +00:00
property alias message: lbl.text
property string from
2018-10-29 18:00:21 +00:00
property string displayname
2018-10-28 02:49:14 +00:00
property int messageID
property alias timestamp: ts.text
2018-10-29 18:00:21 +00:00
property alias source: imgProfile.source
property alias status: imgProfile.status
2018-10-28 02:49:14 +00:00
Connections {
target: gcd
onAcknowledged: function(mid) {
if (mid == messageID) {
ack.text = awesome.icons.fa_check
}
}
}
2018-10-23 18:52:13 +00:00
2018-10-29 18:00:21 +00:00
ContactPicture {
id: imgProfile
anchors.left: parent.left
visible: from != "me"
}
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
height: lbl.height + ts.height + 4
width: colMessageBubble.width + 6
2018-10-23 18:52:13 +00:00
color: from == "me" ? "#B09CBC" : "#4B3557"
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
2018-10-29 18:00:21 +00:00
anchors.left: from == "me" ? undefined : imgProfile.right //parent.left
2018-10-23 18:52:13 +00:00
anchors.right: from == "me" ? 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
font.pixelSize: 12
wrapMode: TextEdit.NoWrap
text: message
textFormat: Text.RichText
}
TextEdit { // this is the actual text display
id: lbl
color: "#FFFFFF"
padding: 6
leftPadding: 10
font.pixelSize: 12
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-29 18:00:21 +00:00
Label { text: dummy.width+", "+root.width }
Label { // MESSAGE ACKNOWLEDGMENT
2018-10-28 02:49:14 +00:00
id: ack
color: "#FFFFFF"
font.pixelSize: 10
anchors.right: parent.right
font.family: "FontAwesome"
2018-10-29 18:00:21 +00:00
text: from == "me" ? awesome.icons.fa_ellipsis_h : displayname
2018-10-28 02:49:14 +00:00
}
2018-10-23 18:52:13 +00:00
}
}
}
}