feat: new design for the chat bubble

This commit is contained in:
Jonathan Rainville 2020-05-28 15:32:14 -04:00 committed by Iuri Matias
parent b0f1bfc4fc
commit 4fa3c34199
2 changed files with 82 additions and 55 deletions

View File

@ -9,6 +9,7 @@ import "./samples/"
ListView { ListView {
property var messageList: MessagesData {} property var messageList: MessagesData {}
spacing: 4
id: chatLogView id: chatLogView
model: messageList model: messageList
Layout.fillWidth: true Layout.fillWidth: true

View File

@ -6,7 +6,7 @@ import Qt.labs.platform 1.1
import "../../../../shared" import "../../../../shared"
import "../../../../imports" import "../../../../imports"
Rectangle { Item {
property string userName: "Jotaro Kujo" property string userName: "Jotaro Kujo"
property string message: "That's right. We're friends... Of justice, that is." property string message: "That's right. We're friends... Of justice, that is."
property string identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=" property string identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
@ -14,84 +14,110 @@ Rectangle {
property bool repeatMessageInfo: true property bool repeatMessageInfo: true
property int timestamp: 1234567 property int timestamp: 1234567
id: chatBox width: parent.width
height: repeatMessageInfo ? 60 + chatText.height : 5 + chatText.height height: isCurrentUser || (!isCurrentUser && !repeatMessageInfo) ? chatBox.height : 24 + chatBox.height
color: "#00000000"
border.color: "#00000000"
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillWidth: true
width: chatLogView.width
Image { Image {
id: chatImage id: chatImage
width: 30 width: 36
height: 30 height: 36
anchors.left: !isCurrentUser ? parent.left : undefined anchors.topMargin: 20
anchors.leftMargin: !isCurrentUser ? Theme.padding : 0 anchors.left: parent.left
anchors.right: !isCurrentUser ? undefined : parent.right anchors.leftMargin: Theme.padding
anchors.rightMargin: !isCurrentUser ? 0 : Theme.padding
anchors.top: parent.top anchors.top: parent.top
anchors.topMargin: Theme.padding
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
source: identicon source: identicon
visible: repeatMessageInfo visible: repeatMessageInfo && !isCurrentUser
} }
TextEdit { TextEdit {
id: chatName id: chatName
text: userName text: userName
anchors.leftMargin: 20
anchors.top: parent.top anchors.top: parent.top
anchors.topMargin: 22 anchors.topMargin: 0
anchors.left: !isCurrentUser ? chatImage.right : undefined anchors.left: chatImage.right
anchors.leftMargin: Theme.padding
anchors.right: !isCurrentUser ? undefined : chatImage.left
anchors.rightMargin: !isCurrentUser ? 0 : Theme.padding
font.bold: true font.bold: true
font.pixelSize: 14 font.pixelSize: 14
readOnly: true readOnly: true
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
selectByMouse: true selectByMouse: true
visible: repeatMessageInfo visible: repeatMessageInfo && !isCurrentUser
} }
TextEdit { Rectangle {
id: chatText property int chatVerticalPadding: 7
text: message property int chatHorizontalPadding: 12
horizontalAlignment: !isCurrentUser ? Text.AlignLeft : Text.AlignRight
font.family: "Inter"
wrapMode: Text.WordWrap
anchors.right: !isCurrentUser ? parent.right : chatName.right
anchors.rightMargin: !isCurrentUser ? 60 : 0
anchors.left: !isCurrentUser ? chatName.left : parent.left
anchors.leftMargin: !isCurrentUser ? 0 : 60
anchors.top: repeatMessageInfo ? chatName.bottom : parent.top
anchors.topMargin: Theme.padding
font.pixelSize: 14
readOnly: true
selectByMouse: true
Layout.fillWidth: true
}
TextEdit { id: chatBox
id: chatTime height: (2 * chatVerticalPadding) + chatText.height
color: Theme.darkGrey color: isCurrentUser ? Theme.blue : Theme.lightBlue
font.family: "Inter" border.color: Theme.transparent
text: timestamp width: message.length > 52 ? 380 : chatText.width + 2 * chatHorizontalPadding
anchors.top: chatText.bottom radius: 16
anchors.bottomMargin: Theme.padding anchors.left: !isCurrentUser ? chatImage.right : undefined
anchors.right: !isCurrentUser ? parent.right : undefined anchors.leftMargin: !isCurrentUser ? 8 : 0
anchors.rightMargin: !isCurrentUser ? Theme.padding : 0 anchors.right: !isCurrentUser ? undefined : parent.right
anchors.left: !isCurrentUser ? undefined : parent.left anchors.rightMargin: !isCurrentUser ? 0 : Theme.padding
anchors.leftMargin: !isCurrentUser ? 0 : Theme.padding anchors.top: repeatMessageInfo && !isCurrentUser ? chatImage.top : parent.top
font.pixelSize: 10 anchors.topMargin: 0
readOnly: true
selectByMouse: true // Thi`s rectangle's only job is to mask the corner to make it less rounded... yep
visible: repeatMessageInfo Rectangle {
color: parent.color
width: 18
height: 18
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
anchors.left: !isCurrentUser ? parent.left : undefined
anchors.leftMargin: 0
anchors.right: !isCurrentUser ? undefined : parent.right
anchors.rightMargin: 0
radius: 4
z: -1
}
TextEdit {
id: chatText
text: message
anchors.left: parent.left
anchors.leftMargin: parent.chatHorizontalPadding
anchors.right: message.length > 52 ? parent.right : undefined
anchors.rightMargin: message.length > 52 ? parent.chatHorizontalPadding : 0
horizontalAlignment: !isCurrentUser ? Text.AlignLeft : Text.AlignRight
font.family: "Inter"
wrapMode: Text.WordWrap
anchors.top: parent.top
anchors.topMargin: chatBox.chatVerticalPadding
font.pixelSize: 15
readOnly: true
selectByMouse: true
color: !isCurrentUser ? Theme.black : Theme.white
}
TextEdit {
id: chatTime
color: Theme.darkGrey
font.family: "Inter"
text: timestamp
anchors.top: chatText.bottom
anchors.bottomMargin: Theme.padding
anchors.right: !isCurrentUser ? parent.right : undefined
anchors.rightMargin: !isCurrentUser ? Theme.padding : 0
anchors.left: !isCurrentUser ? undefined : parent.left
anchors.leftMargin: !isCurrentUser ? 0 : Theme.padding
font.pixelSize: 10
readOnly: true
selectByMouse: true
// Probably only want to show this when clicking?
visible: false
}
} }
} }
/*##^## /*##^##
Designer { Designer {
D{i:0;height:80;width:500} D{i:0;formeditorColor:"#ffffff";formeditorZoom:1.5;width:600}
} }
##^##*/ ##^##*/