2019-07-08 13:52:41 +10:00
|
|
|
// Copyright 2019 miruka
|
|
|
|
// This file is part of harmonyqml, licensed under LGPLv3.
|
|
|
|
|
2019-07-13 19:39:01 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2019-04-29 05:18:36 +10:00
|
|
|
import "../Base"
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-05-12 07:51:00 +10:00
|
|
|
HRectangle {
|
2019-03-22 14:28:14 +11:00
|
|
|
function setFocus() { textArea.forceActiveFocus() }
|
|
|
|
|
2019-07-07 07:56:04 +10:00
|
|
|
id: sendBox
|
2019-03-22 14:28:14 +11:00
|
|
|
Layout.fillWidth: true
|
2019-07-07 07:50:55 +10:00
|
|
|
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
|
2019-07-07 07:50:55 +10:00
|
|
|
color: theme.chat.sendBox.background
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-04-29 05:18:36 +10:00
|
|
|
HRowLayout {
|
2019-03-22 14:28:14 +11:00
|
|
|
anchors.fill: parent
|
|
|
|
|
2019-07-07 14:24:23 +10:00
|
|
|
HUserAvatar {
|
2019-04-21 07:45:51 +10:00
|
|
|
id: avatar
|
2019-07-07 14:24:23 +10:00
|
|
|
userId: chatPage.userId
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|
|
|
|
|
2019-04-29 05:18:36 +10:00
|
|
|
HScrollableTextArea {
|
2019-03-22 14:28:14 +11:00
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.fillWidth: true
|
2019-07-07 07:56:04 +10:00
|
|
|
Layout.topMargin: Math.max(0, sendBox.Layout.minimumHeight - 34)
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-04-29 01:50:46 +10:00
|
|
|
id: textArea
|
|
|
|
placeholderText: qsTr("Type a message...")
|
2019-04-29 05:13:18 +10:00
|
|
|
backgroundColor: "transparent"
|
2019-04-29 01:50:46 +10:00
|
|
|
area.focus: true
|
2019-04-19 17:11:56 +10:00
|
|
|
|
2019-05-18 06:01:42 +10:00
|
|
|
property bool textChangedSinceLostFocus: false
|
|
|
|
|
2019-04-29 01:50:46 +10:00
|
|
|
function setTyping(typing) {
|
2019-07-08 13:28:10 +10:00
|
|
|
py.callClientCoro(
|
|
|
|
chatPage.userId,
|
|
|
|
"room_typing",
|
|
|
|
[chatPage.roomId, typing, 5000]
|
|
|
|
)
|
2019-04-29 01:50:46 +10:00
|
|
|
}
|
2019-04-19 17:11:56 +10:00
|
|
|
|
2019-05-18 06:01:42 +10:00
|
|
|
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
|
|
|
|
2019-07-05 17:16:52 +10:00
|
|
|
Component.onCompleted: {
|
|
|
|
area.Keys.onReturnPressed.connect(function (event) {
|
|
|
|
event.accepted = true
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-07-05 17:16:52 +10:00
|
|
|
if (event.modifiers & Qt.ShiftModifier ||
|
|
|
|
event.modifiers & Qt.ControlModifier ||
|
|
|
|
event.modifiers & Qt.AltModifier) {
|
|
|
|
textArea.insert(textArea.cursorPosition, "\n")
|
|
|
|
return
|
|
|
|
}
|
2019-04-19 17:11:56 +10:00
|
|
|
|
2019-07-05 17:16:52 +10:00
|
|
|
if (textArea.text === "") { return }
|
2019-07-04 11:20:49 +10:00
|
|
|
|
2019-07-05 17:16:52 +10:00
|
|
|
var args = [chatPage.roomId, textArea.text]
|
|
|
|
py.callClientCoro(chatPage.userId, "send_markdown", args)
|
|
|
|
area.clear()
|
|
|
|
})
|
2019-04-29 01:50:46 +10:00
|
|
|
|
2019-07-05 17:16:52 +10:00
|
|
|
area.Keys.onEnterPressed.connect(area.Keys.onReturnPressed)
|
|
|
|
}
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|