Newer
Older
// SPDX-FileCopyrightText: 2021 Nheko Contributors
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.2
import QtQuick.Window 2.13
Layout.preferredHeight: row.implicitHeight
Layout.minimumHeight: 40
Component {
id: placeCallDialog
PlaceCall {
}
visible: room ? room.permissions.canSend(MtxEvent.TextMessage) : false
anchors.fill: parent
ImageButton {
visible: CallManager.callsSupported
opacity: CallManager.haveCallInvite ? 0.3 : 1
Layout.alignment: Qt.AlignBottom
hoverEnabled: true
width: 22
height: 22
image: CallManager.isOnCall ? ":/icons/icons/ui/end-call.png" : ":/icons/icons/ui/place-call.png"
ToolTip.text: CallManager.isOnCall ? qsTr("Hang up") : qsTr("Place a call")
return ;
} else if (CallManager.isOnCall) {
var dialog = placeCallDialog.createObject(timelineRoot);
}
ImageButton {
Layout.alignment: Qt.AlignBottom
hoverEnabled: true
width: 22
height: 22
image: ":/icons/icons/ui/paper-clip-outline.png"
onClicked: room.input.openFileSelection()
ToolTip.visible: hovered
ToolTip.text: qsTr("Send a file")
visible: room && room.input.uploading
NhekoBusyIndicator {
anchors.fill: parent
running: parent.visible
}
}
Layout.alignment: Qt.AlignBottom // | Qt.AlignHCenter
Layout.maximumHeight: Window.height / 4
implicitWidth: inputBar.width - 5 * (22 + 16) - 24
property int completerTriggeredAt: 0
messageInput.remove(completerTriggeredAt, cursorPosition);
messageInput.insert(cursorPosition, completion);
function openCompleter(pos, type) {
completerTriggeredAt = pos;
popup.completerName = type;
popup.open();
popup.completer.setSearchString(messageInput.getText(completerTriggeredAt, cursorPosition));
function positionCursorAtEnd() {
cursorPosition = messageInput.length;
}
function positionCursorAtStart() {
cursorPosition = 0;
}
placeholderText: qsTr("Write a message...")
placeholderTextColor: Nheko.colors.buttonText
color: Nheko.colors.text
if (room)
room.input.updateState(selectionStart, selectionEnd, cursorPosition, text);
room.input.updateState(selectionStart, selectionEnd, cursorPosition, text);
if (popup.opened && cursorPosition <= completerTriggeredAt) {
popup.completer.setSearchString(messageInput.getText(completerTriggeredAt, cursorPosition));
onSelectionStartChanged: room.input.updateState(selectionStart, selectionEnd, cursorPosition, text)
onSelectionEndChanged: room.input.updateState(selectionStart, selectionEnd, cursorPosition, text)
// Ensure that we get escape key press events first.
Keys.onShortcutOverride: event.accepted = (popup.opened && (event.key === Qt.Key_Escape || event.key === Qt.Key_Tab || event.key === Qt.Key_Enter))
Keys.onPressed: {
if (event.matches(StandardKey.Paste)) {
room.input.paste(false);
} else if (event.key == Qt.Key_Space) {
// close popup if user enters space after colon
if (cursorPosition == completerTriggeredAt + 1)
popup.close();
if (popup.opened && popup.count <= 0)
popup.close();
} else if (event.modifiers == Qt.ControlModifier && event.key == Qt.Key_U) {
messageInput.clear();
} else if (event.modifiers == Qt.ControlModifier && event.key == Qt.Key_P) {
messageInput.text = room.input.previousText();
} else if (event.modifiers == Qt.ControlModifier && event.key == Qt.Key_N) {
messageInput.text = room.input.nextText();
messageInput.openCompleter(selectionStart, "user");
messageInput.openCompleter(selectionStart, "emoji");
} else if (event.key == Qt.Key_NumberSign) {
messageInput.openCompleter(selectionStart, "roomAliases");
} else if (event.key == Qt.Key_Escape && popup.opened) {
} else if (event.matches(StandardKey.SelectAll) && popup.opened) {
popup.completerName = "";
} else if (event.matches(StandardKey.InsertParagraphSeparator)) {
if (popup.opened) {
var currentCompletion = popup.currentCompletion();
popup.completerName = "";
popup.close();
if (currentCompletion) {
messageInput.insertCompletion(currentCompletion);
event.accepted = true;
return ;
}
if (event.modifiers & Qt.ShiftModifier) {
popup.down();
} else {
popup.up();
}
} else {
var pos = cursorPosition - 1;
while (pos > -1) {
var t = messageInput.getText(pos, pos + 1);
messageInput.openCompleter(pos, "user");
} else if (t == ' ' || t == '\t') {
messageInput.openCompleter(pos + 1, "user");
return ;
messageInput.openCompleter(pos, "emoji");
return ;
}
pos = pos - 1;
}
// At start of input
messageInput.openCompleter(0, "user");
} else if (event.key == Qt.Key_Up && popup.opened) {
event.accepted = true;
popup.up();
} else if ((event.key == Qt.Key_Down || event.key == Qt.Key_Backtab) && popup.opened) {
} else if (event.key == Qt.Key_Up && event.modifiers == Qt.NoModifier) {
if (cursorPosition == 0) {
event.accepted = true;
var idx = room.edit ? room.idToIndex(room.edit) + 1 : 0;
var id = room.indexToId(idx);
if (!id || room.getDump(id, "").isEditable) {
room.edit = id;
} else if (positionAt(0, cursorRectangle.y) === 0) {
} else if (event.key == Qt.Key_Down && event.modifiers == Qt.NoModifier) {
if (cursorPosition == messageInput.length && room.edit) {
var idx = room.idToIndex(room.edit) - 1;
var id = room.indexToId(idx);
if (!id || room.getDump(id, "").isEditable) {
room.edit = id;
} else if (positionAt(width, cursorRectangle.y + 2) === messageInput.length) {
event.accepted = true;
positionCursorAtEnd();
messageInput.clear();
if (room)
messageInput.append(room.input.text());
messageInput.forceActiveFocus();
function onCompletionClicked(completion) {
messageInput.insertCompletion(completion);
}
x: messageInput.positionToRectangle(messageInput.completerTriggeredAt).x
y: messageInput.positionToRectangle(messageInput.completerTriggeredAt).y - height
messageInput.remove(messageInput.selectionStart, messageInput.selectionEnd);
messageInput.insert(messageInput.cursorPosition, text);
}
messageInput.text = newText;
messageInput.cursorPosition = newText.length;
}
target: room ? room.input : null
function onReplyChanged() {
messageInput.forceActiveFocus();
}
function onEditChanged() {
messageInput.forceActiveFocus();
}
ignoreUnknownSignals: true
function onFocusInput() {
messageInput.forceActiveFocus();
}
target: TimelineManager
}
MouseArea {
// workaround for wrong cursor shape on some platforms
anchors.fill: parent
cursorShape: Qt.IBeamCursor
onClicked: room.input.paste(true)
ImageButton {
id: stickerButton
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
Layout.margins: 8
hoverEnabled: true
width: 22
height: 22
image: ":/icons/icons/ui/sticky-note-solid.svg"
ToolTip.visible: hovered
ToolTip.text: qsTr("Stickers")
onClicked: stickerPopup.visible ? stickerPopup.close() : stickerPopup.show(stickerButton, room.roomId, function(row) {
room.input.sticker(stickerPopup.model.sourceModel, row);
TimelineManager.focusMessageInput();
})
StickerPicker {
id: stickerPopup
colors: Nheko.colors
}
}
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
hoverEnabled: true
width: 22
height: 22
image: ":/icons/icons/ui/smile.png"
ToolTip.visible: hovered
ToolTip.text: qsTr("Emoji")
onClicked: emojiPopup.visible ? emojiPopup.close() : emojiPopup.show(emojiButton, function(emoji) {
messageInput.insert(messageInput.cursorPosition, emoji);
TimelineManager.focusMessageInput();
}
ImageButton {
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
hoverEnabled: true
width: 22
height: 22
image: ":/icons/icons/ui/cursor.png"
ToolTip.visible: hovered
ToolTip.text: qsTr("Send")
Text {
anchors.centerIn: parent
visible: room ? (!room.permissions.canSend(MtxEvent.TextMessage)) : false
text: qsTr("You don't have permission to send messages in this room")