moment/src/qml/Chat/SendBox.qml

79 lines
2.4 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"
import "../utils.js" as Utils
2019-03-22 14:28:14 +11:00
HRectangle {
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
Layout.minimumHeight: theme.bottomElementsHeight
2019-03-26 09:29:46 +11:00
Layout.preferredHeight: textArea.implicitHeight
2019-03-22 14:28:14 +11:00
// parent.height / 2 causes binding loop?
Layout.maximumHeight: pageStack.height / 2
color: theme.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: chatPage.sender.displayName ||
Utils.stripUserId(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
2019-07-07 07:29:32 +10:00
Layout.topMargin: Math.max(0, root.Layout.minimumHeight - 34)
2019-03-22 14:28:14 +11:00
id: textArea
placeholderText: qsTr("Type a message...")
2019-04-29 05:13:18 +10:00
backgroundColor: "transparent"
area.focus: true
property bool textChangedSinceLostFocus: false
function setTyping(typing) {
2019-07-04 11:20:49 +10:00
return
Backend.clients.get(chatPage.userId)
.setTypingState(chatPage.roomId, typing)
}
onTextChanged: {
setTyping(Boolean(text))
textChangedSinceLostFocus = true
}
area.onEditingFinished: { // when lost focus
if (text && textChangedSinceLostFocus) {
setTyping(false)
textChangedSinceLostFocus = false
}
}
2019-03-22 14:28:14 +11:00
Component.onCompleted: {
area.Keys.onReturnPressed.connect(function (event) {
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
}
if (textArea.text === "") { return }
2019-07-04 11:20:49 +10:00
var args = [chatPage.roomId, textArea.text]
py.callClientCoro(chatPage.userId, "send_markdown", args)
area.clear()
})
area.Keys.onEnterPressed.connect(area.Keys.onReturnPressed)
}
2019-03-22 14:28:14 +11:00
}
}
}