moment/harmonyqml/components/chat/SendBox.qml
miruka 8f35e60801 Capitalization, list model and room header work
- Standardized capitalization for variables and file names everywhere in
  QML and JS, get rid of mixed camelCase/snakeCase,
  use camelCase like everywhere in Qt

- ListModel items are now stored and returned as real QObjects with
  PyQt properties and signals.
  This makes dynamic property binding a lot easier and eliminates the need
  for many hacks.

- New update(), updateOrAppendWhere() methods and roles property
  for ListModel

- RoomHeader now properly updates when the room title or topic changes

- Add Backend.pdb(), to make it easier to start the debugger from QML
2019-04-20 17:43:57 -04:00

75 lines
2.3 KiB
QML

import QtQuick 2.7
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.4
import "../base" as Base
Rectangle {
function setFocus() { textArea.forceActiveFocus() }
id: "root"
Layout.fillWidth: true
Layout.minimumHeight: 32
Layout.preferredHeight: textArea.implicitHeight
// parent.height / 2 causes binding loop?
Layout.maximumHeight: pageStack.height / 2
color: "#BBB"
RowLayout {
anchors.fill: parent
spacing: 0
Base.Avatar {
id: "avatar"
name: Backend.getUserDisplayName(chatPage.userId)
dimmension: root.Layout.minimumHeight
//visible: textArea.text === ""
visible: textArea.height <= root.Layout.minimumHeight
}
ScrollView {
Layout.fillHeight: true
Layout.fillWidth: true
id: sendBoxScrollView
clip: true
TextArea {
property string typedText: text
id: textArea
placeholderText: qsTr("Type a message...")
wrapMode: TextEdit.Wrap
selectByMouse: true
font.family: "Roboto"
font.pixelSize: 16
focus: true
function setTyping(typing) {
Backend.clientManager.clients[chatPage.userId]
.setTypingState(chatPage.roomId, typing)
}
onTypedTextChanged: setTyping(Boolean(text))
onEditingFinished: setTyping(false) // when lost focus
Keys.onReturnPressed: {
event.accepted = true
if (event.modifiers & Qt.ShiftModifier ||
event.modifiers & Qt.ControlModifier ||
event.modifiers & Qt.AltModifier) {
textArea.insert(textArea.cursorPosition, "\n")
return
}
if (textArea.text === "") { return }
Backend.clientManager.clients[chatPage.userId]
.sendMarkdown(chatPage.roomId, textArea.text)
textArea.clear()
}
Keys.onEnterPressed: Keys.onReturnPressed(event) // numpad enter
}
}
}
}