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
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
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
|
|
|
|
color: "#BBB"
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
anchors.fill: parent
|
|
|
|
spacing: 0
|
|
|
|
|
2019-03-26 20:52:43 +11:00
|
|
|
Base.Avatar {
|
2019-04-21 07:45:51 +10:00
|
|
|
id: avatar
|
2019-04-21 07:36:21 +10:00
|
|
|
name: Backend.getUserDisplayName(chatPage.userId)
|
2019-03-22 14:28:14 +11:00
|
|
|
dimmension: root.Layout.minimumHeight
|
2019-03-26 18:19:55 +11:00
|
|
|
//visible: textArea.text === ""
|
|
|
|
visible: textArea.height <= root.Layout.minimumHeight
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
ScrollView {
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.fillWidth: true
|
|
|
|
id: sendBoxScrollView
|
|
|
|
clip: true
|
|
|
|
|
|
|
|
TextArea {
|
2019-04-19 17:11:56 +10:00
|
|
|
property string typedText: text
|
|
|
|
|
2019-03-22 14:28:14 +11:00
|
|
|
id: textArea
|
|
|
|
placeholderText: qsTr("Type a message...")
|
|
|
|
wrapMode: TextEdit.Wrap
|
|
|
|
selectByMouse: true
|
2019-04-22 00:44:04 +10:00
|
|
|
readOnly: ! visible
|
2019-03-22 14:28:14 +11:00
|
|
|
font.family: "Roboto"
|
|
|
|
font.pixelSize: 16
|
|
|
|
focus: true
|
|
|
|
|
2019-04-21 07:36:21 +10:00
|
|
|
function setTyping(typing) {
|
|
|
|
Backend.clientManager.clients[chatPage.userId]
|
|
|
|
.setTypingState(chatPage.roomId, typing)
|
2019-04-19 17:11:56 +10:00
|
|
|
}
|
|
|
|
|
2019-04-21 07:36:21 +10:00
|
|
|
onTypedTextChanged: setTyping(Boolean(text))
|
|
|
|
onEditingFinished: setTyping(false) // when lost focus
|
2019-04-19 17:11:56 +10:00
|
|
|
|
2019-03-22 14:28:14 +11:00
|
|
|
Keys.onReturnPressed: {
|
|
|
|
event.accepted = true
|
|
|
|
|
|
|
|
if (event.modifiers & Qt.ShiftModifier ||
|
|
|
|
event.modifiers & Qt.ControlModifier ||
|
|
|
|
event.modifiers & Qt.AltModifier) {
|
|
|
|
textArea.insert(textArea.cursorPosition, "\n")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-03-28 10:24:28 +11:00
|
|
|
if (textArea.text === "") { return }
|
2019-04-21 07:36:21 +10:00
|
|
|
Backend.clientManager.clients[chatPage.userId]
|
|
|
|
.sendMarkdown(chatPage.roomId, textArea.text)
|
2019-03-22 14:28:14 +11:00
|
|
|
textArea.clear()
|
|
|
|
}
|
2019-04-19 17:11:56 +10:00
|
|
|
|
2019-03-22 14:28:14 +11:00
|
|
|
Keys.onEnterPressed: Keys.onReturnPressed(event) // numpad enter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|