Refactor to add message text area into a flickable

This commit is contained in:
Angela Mazzurco 2017-06-10 16:02:09 +02:00
parent e2d430a82a
commit 12fef4bf8b
2 changed files with 38 additions and 24 deletions

View File

@ -117,6 +117,7 @@ Item
RowLayout { RowLayout {
id: msgComposer id: msgComposer
property var styles: StyleChat.inferiorPanel.msgComposer
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.left: attachButton.right anchors.left: attachButton.right
@ -126,37 +127,50 @@ Item
(attachButton.width + attachButton.anchors.margins) - (attachButton.width + attachButton.anchors.margins) -
(emojiButton.width + emojiButton.anchors.margins) (emojiButton.width + emojiButton.anchors.margins)
height: (flickable.contentHeight < styles.maxHeight)? flickable.contentHeight : styles.maxHeight
Flickable {
id: flickable
anchors.fill: parent
flickableDirection: Flickable.VerticalFlick
width: parent.width
contentWidth: msgField.width
contentHeight: msgField.height
contentY: contentHeight - height
ScrollBar.vertical: ScrollBar {}
clip: true
TextArea TextArea
{ {
property var styles: StyleChat.inferiorPanel.msgComposer property var styles: StyleChat.inferiorPanel.msgComposer
id: msgField id: msgField
height: height: contentHeight + font.pixelSize
(contentHeight > font.pixelSize)?
contentHeight +font.pixelSize : parent.styles.height
width: parent.width width: parent.width
Layout.maximumHeight: chatView.height / styles.maxHeight
placeholderText: styles.placeHolder placeholderText: styles.placeHolder
background: styles.background background: styles.background
wrapMode: TextEdit.Wrap wrapMode: TextEdit.Wrap
onTextChanged: { onTextChanged: {
if (msgComposer.length == 0) if (msgField.length == 0)
{ {
sendButton.state = "" sendButton.state = ""
} }
else if (msgComposer.length > 0) else if (msgField.length > 0)
{ {
sendButton.state = "SENDBTN" sendButton.state = "SENDBTN"
} }
} }
} }
}
} }
@ -199,9 +213,9 @@ Item
onClicked: onClicked:
{ {
if (sendButton.state == "SENDBTN" ) { if (sendButton.state == "SENDBTN" ) {
var jsonData = {"chat_id":chatView.chatId, "msg":msgComposer.text} var jsonData = {"chat_id":chatView.chatId, "msg":msgField.text}
rsApi.request( "/chat/send_message", JSON.stringify(jsonData), rsApi.request( "/chat/send_message", JSON.stringify(jsonData),
function(par) { msgComposer.text = ""; } ) function(par) { msgField.text = ""; } )
} }
} }

View File

@ -34,7 +34,7 @@ QtObject {
property QtObject msgComposer: QtObject{ property QtObject msgComposer: QtObject{
readonly property string placeHolder: "Send message..." readonly property string placeHolder: "Send message..."
readonly property int maxHeight: 2 // chatListView/maxHeight readonly property int maxHeight: 180
property QtObject background: Rectangle { property QtObject background: Rectangle {
color: "transparent" color: "transparent"