2019-03-22 14:28:14 +11:00
|
|
|
import QtQuick 2.7
|
|
|
|
import QtQuick.Controls 2.2
|
|
|
|
import QtQuick.Layouts 1.4
|
2019-03-26 20:52:43 +11:00
|
|
|
import "../base" as Base
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-04-29 01:01:38 +10:00
|
|
|
Base.HGlassRectangle {
|
2019-03-22 14:28:14 +11:00
|
|
|
function setFocus() { textArea.forceActiveFocus() }
|
|
|
|
|
2019-04-21 07:45:51 +10:00
|
|
|
id: root
|
2019-03-22 14:28:14 +11:00
|
|
|
Layout.fillWidth: true
|
2019-03-26 09:29:46 +11:00
|
|
|
Layout.minimumHeight: 32
|
|
|
|
Layout.preferredHeight: textArea.implicitHeight
|
2019-03-22 14:28:14 +11:00
|
|
|
// parent.height / 2 causes binding loop?
|
|
|
|
Layout.maximumHeight: pageStack.height / 2
|
2019-04-29 01:01:38 +10:00
|
|
|
color: Base.HStyle.chat.sendBox.background
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-04-29 01:50:46 +10:00
|
|
|
Base.HRowLayout {
|
2019-03-22 14:28:14 +11:00
|
|
|
anchors.fill: parent
|
|
|
|
spacing: 0
|
|
|
|
|
2019-04-29 01:21:19 +10:00
|
|
|
Base.HAvatar {
|
2019-04-21 07:45:51 +10:00
|
|
|
id: avatar
|
2019-04-21 07:36:21 +10:00
|
|
|
name: Backend.getUserDisplayName(chatPage.userId)
|
2019-04-29 01:32:02 +10:00
|
|
|
dimension: root.Layout.minimumHeight
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|
|
|
|
|
2019-04-29 01:50:46 +10:00
|
|
|
Base.HScrollableTextArea {
|
2019-03-22 14:28:14 +11:00
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
2019-04-29 01:50:46 +10:00
|
|
|
id: textArea
|
|
|
|
placeholderText: qsTr("Type a message...")
|
|
|
|
area.focus: true
|
2019-04-19 17:11:56 +10:00
|
|
|
|
2019-04-29 01:50:46 +10:00
|
|
|
function setTyping(typing) {
|
|
|
|
Backend.clientManager.clients[chatPage.userId]
|
|
|
|
.setTypingState(chatPage.roomId, typing)
|
|
|
|
}
|
2019-04-19 17:11:56 +10:00
|
|
|
|
2019-04-29 01:50:46 +10:00
|
|
|
onTextChanged: setTyping(Boolean(text))
|
|
|
|
area.onEditingFinished: setTyping(false) // when lost focus
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-04-29 01:50:46 +10:00
|
|
|
Keys.onReturnPressed: {
|
|
|
|
event.accepted = true
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-04-29 01:50:46 +10:00
|
|
|
if (event.modifiers & Qt.ShiftModifier ||
|
|
|
|
event.modifiers & Qt.ControlModifier ||
|
|
|
|
event.modifiers & Qt.AltModifier) {
|
|
|
|
textArea.insert(textArea.cursorPosition, "\n")
|
|
|
|
return
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|
2019-04-19 17:11:56 +10:00
|
|
|
|
2019-04-29 01:50:46 +10:00
|
|
|
if (textArea.text === "") { return }
|
|
|
|
Backend.clientManager.clients[chatPage.userId]
|
|
|
|
.sendMarkdown(chatPage.roomId, textArea.text)
|
|
|
|
textArea.clear()
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|
2019-04-29 01:50:46 +10:00
|
|
|
|
|
|
|
Keys.onEnterPressed: Keys.onReturnPressed(event) // numpad enter
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|