Handle properly intro key to send message and shif+intro to new line on message composer

This commit is contained in:
Angela Mazzurco 2017-06-12 17:54:53 +02:00
parent f8669b86e6
commit fbd4d3a913

View File

@ -180,6 +180,8 @@ Item
wrapMode: TextEdit.Wrap wrapMode: TextEdit.Wrap
focus: true
onTextChanged: { onTextChanged: {
if (msgField.length == 0) if (msgField.length == 0)
{ {
@ -191,9 +193,32 @@ Item
} }
} }
property bool shiftPressed: false
Keys.onPressed:
{
if ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter)
&& !shiftPressed)
{
if (sendButton.state == "SENDBTN" ) {
chatView.sendMessage ()
}
}
else if (event.key === Qt.Key_Shift)
{
shiftPressed = true
} }
} }
Keys.onReleased:
{
if (event.key === Qt.Key_Shift)
{
shiftPressed = false
}
}
}
}
} }
@ -235,9 +260,7 @@ Item
onClicked: onClicked:
{ {
if (sendButton.state == "SENDBTN" ) { if (sendButton.state == "SENDBTN" ) {
var jsonData = {"chat_id":chatView.chatId, "msg":msgField.text} chatView.sendMessage ()
rsApi.request( "/chat/send_message", JSON.stringify(jsonData),
function(par) { msgField.text = ""; } )
} }
} }
@ -262,7 +285,6 @@ Item
} }
states: [ states: [
State { State {
name: "" name: ""
@ -279,4 +301,12 @@ Item
] ]
} }
} }
function sendMessage ()
{
var jsonData = {"chat_id":chatView.chatId, "msg":msgField.text}
rsApi.request( "/chat/send_message", JSON.stringify(jsonData),
function(par) { msgField.text = ""; } )
}
} }