matrixion/resources/qml/MessageInput.qml

148 lines
4.9 KiB
QML
Raw Normal View History

import QtQuick 2.9
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.2
import QtQuick.Window 2.2
2020-11-01 01:24:07 +03:00
import im.nheko 1.0
Rectangle {
color: colors.window
Layout.fillWidth: true
Layout.preferredHeight: textInput.height
Layout.minimumHeight: 40
RowLayout {
id: inputBar
anchors.fill: parent
spacing: 16
ImageButton {
2020-11-16 01:14:47 +03:00
visible: TimelineManager.callsSupported
Layout.alignment: Qt.AlignBottom
hoverEnabled: true
width: 22
height: 22
2020-11-16 01:14:47 +03:00
image: TimelineManager.isOnCall ? ":/icons/icons/ui/end-call.png" : ":/icons/icons/ui/place-call.png"
ToolTip.visible: hovered
ToolTip.text: TimelineManager.isOnCall ? qsTr("Hang up") : qsTr("Place a call")
Layout.topMargin: 8
Layout.bottomMargin: 8
Layout.leftMargin: 16
2020-11-16 01:14:47 +03:00
onClicked: TimelineManager.timeline.input.callButton()
}
ImageButton {
Layout.alignment: Qt.AlignBottom
hoverEnabled: true
width: 22
height: 22
image: ":/icons/icons/ui/paper-clip-outline.png"
Layout.topMargin: 8
Layout.bottomMargin: 8
2020-11-16 01:14:47 +03:00
Layout.leftMargin: TimelineManager.callsSupported ? 0 : 16
2020-11-15 06:52:49 +03:00
onClicked: TimelineManager.timeline.input.openFileSelection()
2020-11-16 01:14:47 +03:00
ToolTip.visible: hovered
ToolTip.text: qsTr("Send a file")
2020-11-15 06:52:49 +03:00
Rectangle {
anchors.fill: parent
color: colors.window
visible: TimelineManager.timeline.input.uploading
NhekoBusyIndicator {
anchors.fill: parent
running: parent.visible
}
}
}
ScrollView {
id: textInput
Layout.alignment: Qt.AlignBottom
Layout.maximumHeight: Window.height / 4
Layout.fillWidth: true
TextArea {
2020-11-01 01:24:07 +03:00
id: textArea
placeholderText: qsTr("Write a message...")
placeholderTextColor: colors.buttonText
color: colors.text
wrapMode: TextEdit.Wrap
2020-11-01 01:24:07 +03:00
onTextChanged: TimelineManager.timeline.input.updateState(selectionStart, selectionEnd, cursorPosition, text)
onCursorPositionChanged: TimelineManager.timeline.input.updateState(selectionStart, selectionEnd, cursorPosition, text)
onSelectionStartChanged: TimelineManager.timeline.input.updateState(selectionStart, selectionEnd, cursorPosition, text)
onSelectionEndChanged: TimelineManager.timeline.input.updateState(selectionStart, selectionEnd, cursorPosition, text)
Keys.onPressed: {
if (event.matches(StandardKey.Paste)) {
2020-11-15 06:52:49 +03:00
TimelineManager.timeline.input.paste(false);
event.accepted = true;
} else if (event.matches(StandardKey.InsertParagraphSeparator)) {
TimelineManager.timeline.input.send();
textArea.clear();
event.accepted = true;
2020-11-01 01:24:07 +03:00
}
2020-11-15 06:52:49 +03:00
}
Connections {
2020-11-16 20:41:29 +03:00
onInsertText: textArea.insert(textArea.cursorPosition, text)
2020-11-15 06:52:49 +03:00
target: TimelineManager.timeline.input
2020-11-01 01:24:07 +03:00
}
MouseArea {
// workaround for wrong cursor shape on some platforms
anchors.fill: parent
2020-11-01 01:24:07 +03:00
acceptedButtons: Qt.MiddleButton
cursorShape: Qt.IBeamCursor
2020-11-09 05:12:37 +03:00
onClicked: TimelineManager.timeline.input.paste(true)
}
background: Rectangle {
color: colors.window
}
}
}
ImageButton {
2020-11-16 20:41:29 +03:00
id: emojiButton
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
hoverEnabled: true
width: 22
height: 22
image: ":/icons/icons/ui/smile.png"
Layout.topMargin: 8
Layout.bottomMargin: 8
2020-11-16 01:14:47 +03:00
ToolTip.visible: hovered
ToolTip.text: qsTr("Emoji")
2020-11-16 20:41:29 +03:00
onClicked: emojiPopup.visible ? emojiPopup.close() : emojiPopup.show(emojiButton, function(emoji) {
textArea.insert(textArea.cursorPosition, emoji);
})
}
ImageButton {
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
hoverEnabled: true
width: 22
height: 22
image: ":/icons/icons/ui/cursor.png"
Layout.topMargin: 8
Layout.bottomMargin: 8
Layout.rightMargin: 16
2020-11-16 01:14:47 +03:00
ToolTip.visible: hovered
ToolTip.text: qsTr("Send")
2020-11-15 06:52:49 +03:00
onClicked: {
TimelineManager.timeline.input.send();
textArea.clear();
}
}
}
}