moment/harmonyqml/components/Chat/SendBox.qml

63 lines
1.8 KiB
QML
Raw Normal View History

2019-03-22 14:28:14 +11:00
import QtQuick 2.7
import QtQuick.Layouts 1.3
import "../Base"
2019-03-22 14:28:14 +11:00
HGlassRectangle {
2019-03-22 14:28:14 +11:00
function setFocus() { textArea.forceActiveFocus() }
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: HStyle.chat.sendBox.background
2019-03-22 14:28:14 +11:00
HRowLayout {
2019-03-22 14:28:14 +11:00
anchors.fill: parent
HAvatar {
id: avatar
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
}
HScrollableTextArea {
2019-03-22 14:28:14 +11:00
Layout.fillHeight: true
Layout.fillWidth: true
id: textArea
placeholderText: qsTr("Type a message...")
2019-04-29 05:13:18 +10:00
backgroundColor: "transparent"
area.focus: true
function setTyping(typing) {
Backend.clients.get(chatPage.userId)
.setTypingState(chatPage.roomId, typing)
}
onTextChanged: setTyping(Boolean(text))
area.onEditingFinished: setTyping(false) // when lost focus
2019-03-22 14:28:14 +11:00
Keys.onReturnPressed: {
event.accepted = true
2019-03-22 14:28:14 +11: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
}
if (textArea.text === "") { return }
Backend.clients.get(chatPage.userId)
.sendMarkdown(chatPage.roomId, textArea.text)
2019-05-07 11:07:59 +10:00
area.clear()
2019-03-22 14:28:14 +11:00
}
2019-05-07 11:07:59 +10:00
// Numpad enter
Keys.onEnterPressed: Keys.onReturnPressed(event)
2019-03-22 14:28:14 +11:00
}
}
}