2019-03-21 23:28:14 -04:00
|
|
|
import QtQuick 2.7
|
2019-04-28 15:45:42 -04:00
|
|
|
import QtQuick.Layouts 1.3
|
2019-04-28 15:18:36 -04:00
|
|
|
import "../Base"
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-05-11 17:51:00 -04:00
|
|
|
HRectangle {
|
2019-03-21 23:28:14 -04:00
|
|
|
function setFocus() { textArea.forceActiveFocus() }
|
|
|
|
|
2019-04-20 17:45:51 -04:00
|
|
|
id: root
|
2019-03-21 23:28:14 -04:00
|
|
|
Layout.fillWidth: true
|
2019-05-12 15:57:18 -04:00
|
|
|
Layout.minimumHeight: HStyle.bottomElementsHeight
|
2019-03-25 18:29:46 -04:00
|
|
|
Layout.preferredHeight: textArea.implicitHeight
|
2019-03-21 23:28:14 -04:00
|
|
|
// parent.height / 2 causes binding loop?
|
|
|
|
Layout.maximumHeight: pageStack.height / 2
|
2019-04-28 15:18:36 -04:00
|
|
|
color: HStyle.chat.sendBox.background
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-04-28 15:18:36 -04:00
|
|
|
HRowLayout {
|
2019-03-21 23:28:14 -04:00
|
|
|
anchors.fill: parent
|
|
|
|
|
2019-04-28 15:18:36 -04:00
|
|
|
HAvatar {
|
2019-04-20 17:45:51 -04:00
|
|
|
id: avatar
|
2019-05-11 15:52:56 -04:00
|
|
|
name: chatPage.sender.displayName.value
|
2019-04-28 11:32:02 -04:00
|
|
|
dimension: root.Layout.minimumHeight
|
2019-03-21 23:28:14 -04:00
|
|
|
}
|
|
|
|
|
2019-04-28 15:18:36 -04:00
|
|
|
HScrollableTextArea {
|
2019-03-21 23:28:14 -04:00
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
2019-04-28 11:50:46 -04:00
|
|
|
id: textArea
|
|
|
|
placeholderText: qsTr("Type a message...")
|
2019-04-28 15:13:18 -04:00
|
|
|
backgroundColor: "transparent"
|
2019-04-28 11:50:46 -04:00
|
|
|
area.focus: true
|
2019-04-19 03:11:56 -04:00
|
|
|
|
2019-05-17 16:01:42 -04:00
|
|
|
property bool textChangedSinceLostFocus: false
|
|
|
|
|
2019-04-28 11:50:46 -04:00
|
|
|
function setTyping(typing) {
|
2019-05-02 14:54:37 -04:00
|
|
|
Backend.clients.get(chatPage.userId)
|
2019-04-28 11:50:46 -04:00
|
|
|
.setTypingState(chatPage.roomId, typing)
|
|
|
|
}
|
2019-04-19 03:11:56 -04:00
|
|
|
|
2019-05-17 16:01:42 -04:00
|
|
|
onTextChanged: {
|
|
|
|
setTyping(Boolean(text))
|
|
|
|
textChangedSinceLostFocus = true
|
|
|
|
}
|
|
|
|
area.onEditingFinished: { // when lost focus
|
|
|
|
if (text && textChangedSinceLostFocus) {
|
|
|
|
setTyping(false)
|
|
|
|
textChangedSinceLostFocus = false
|
|
|
|
}
|
|
|
|
}
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-04-28 11:50:46 -04:00
|
|
|
Keys.onReturnPressed: {
|
|
|
|
event.accepted = true
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-04-28 11:50:46 -04:00
|
|
|
if (event.modifiers & Qt.ShiftModifier ||
|
|
|
|
event.modifiers & Qt.ControlModifier ||
|
|
|
|
event.modifiers & Qt.AltModifier) {
|
|
|
|
textArea.insert(textArea.cursorPosition, "\n")
|
|
|
|
return
|
2019-03-21 23:28:14 -04:00
|
|
|
}
|
2019-04-19 03:11:56 -04:00
|
|
|
|
2019-04-28 11:50:46 -04:00
|
|
|
if (textArea.text === "") { return }
|
2019-05-02 14:54:37 -04:00
|
|
|
Backend.clients.get(chatPage.userId)
|
2019-04-28 11:50:46 -04:00
|
|
|
.sendMarkdown(chatPage.roomId, textArea.text)
|
2019-05-06 21:07:59 -04:00
|
|
|
area.clear()
|
2019-03-21 23:28:14 -04:00
|
|
|
}
|
2019-04-28 11:50:46 -04:00
|
|
|
|
2019-05-06 21:07:59 -04:00
|
|
|
// Numpad enter
|
|
|
|
Keys.onEnterPressed: Keys.onReturnPressed(event)
|
2019-03-21 23:28:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|