diff --git a/src/apps/qml/qml/MessageLine.qml b/src/apps/qml/qml/MessageLine.qml index 5a82a7c5..4c26623d 100644 --- a/src/apps/qml/qml/MessageLine.qml +++ b/src/apps/qml/qml/MessageLine.qml @@ -1,207 +1,231 @@ /* * Copyright 2016 Riccardo Iaconelli * Copyright (C) 2017-2020 Laurent Montel * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ import QtQuick 2.9 import QtQuick.Controls 2.5 as QQC2 import QtQuick.Layouts 1.12 import Ruqola 1.0 import org.kde.kirigami 2.7 as Kirigami ColumnLayout { id: messageLineItem property alias messageLineText: messageLine.text property string savePreviousMessage readonly property int popupheight: 100 property string selectedRoomId property string messageId property string threadmessageId property string selectedThreadMessage property QtObject inputCompleterModel function sendMessage() { var text = messageLine.text; if (text === "") return; if (appid.rocketChatAccount.loginStatus !== DDPClient.LoggedIn) return; if (messageLineItem.selectedThreadMessage !== "") { //console.log("In thread message" + messageLineItem.selectedThreadMessage + messageLineItem.selectedRoomId) appid.rocketChatAccount.replyOnThread(messageLineItem.selectedRoomId, messageLineItem.selectedThreadMessage, text); } else if (messageLineItem.selectedRoomId !== "") { //Modify text. if (messageId !== "") { //Reply against message if (savePreviousMessage == "") { //console.log("Previous message empty") appid.rocketChatAccount.sendMessage(messageLineItem.selectedRoomId, text, messageId); } else if (text !== savePreviousMessage) { //console.log("Previous message empty text different") appid.rocketChatAccount.updateMessage(messageLineItem.selectedRoomId, messageId, text); } } else if (threadmessageId !== "") { //Reply in thread appid.rocketChatAccount.replyOnThread(messageLineItem.selectedRoomId, threadmessageId, text); } else { appid.rocketChatAccount.sendMessage(messageLineItem.selectedRoomId, text); } } //clear all element messageLine.text = ""; threadmessageId = ""; savePreviousMessage = ""; } function setOriginalMessage(messageStr) { messageLine.text = messageStr savePreviousMessage = messageStr messageLine.selectAll() } function insertEmoticon(emotiStr) { messageLine.insert(messageLine.cursorPosition, emotiStr) } - QQC2.TextField { - id: messageLine - selectByMouse: true - //FIXME add multiline !!! - inputMethodHints: Qt.ImhMultiLine + QQC2.ScrollView { + id: messageLineScrollView + anchors.fill: parent Layout.fillWidth: true - placeholderText: i18n("Enter message...") - onTextChanged: { - appid.rocketChatAccount.setInputTextChanged(text, cursorPosition); - if (listView.count > 0) { - showPopupCompleting() - } else { - popup.close() + Layout.maximumHeight: Kirigami.Units.gridUnit * 5 // maximum line count, roughly + Layout.preferredHeight: messageLine.implicitHeight + + QQC2.TextArea { + id: messageLine + selectByMouse: true + inputMethodHints: Qt.ImhMultiLine + + width: parent.width + height: parent.height + + placeholderText: i18n("Enter message...") + background: Rectangle { + anchors.fill: parent + Kirigami.Theme.inherit: false + Kirigami.Theme.colorSet: Kirigami.Theme.Window + border.color: parent.activeFocus ? Kirigami.Theme.activeTextColor : Kirigami.Theme.textColor + color: Kirigami.Theme.backgroundColor } - footerItem.textEditing(text) - } - Keys.onDownPressed: { - listView.incrementCurrentIndex() - } - Keys.onUpPressed: { - listView.decrementCurrentIndex() - } - Keys.onTabPressed: { - if (listView.currentItem) { - textSelected(listView.currentItem.myData.completername) - } - } - Keys.onEnterPressed: enterOrReturnPressed(event) - Keys.onReturnPressed: enterOrReturnPressed(event) - function enterOrReturnPressed(event) { - if (event.modifiers & Qt.ShiftModifier) { - event.accepted = false; - return; // composing a multi-line message + onTextChanged: { + appid.rocketChatAccount.setInputTextChanged(text, cursorPosition); + if (listView.count > 0) { + showPopupCompleting() + } else { + popup.close() + } + footerItem.textEditing(text) } - - if (listView.currentItem) { - textSelected(listView.currentItem.myData.completername) - } else { - messageLineItem.sendMessage() + Keys.onDownPressed: { + listView.incrementCurrentIndex() } - } + Keys.onUpPressed: { + listView.decrementCurrentIndex() + } + Keys.onTabPressed: { + if (listView.currentItem) { + textSelected(listView.currentItem.myData.completername) + } + } + Keys.onEnterPressed: enterOrReturnPressed(event) + Keys.onReturnPressed: enterOrReturnPressed(event) - QQC2.Popup { - id: popup + function enterOrReturnPressed(event) { + if (event.modifiers & Qt.ShiftModifier) { + event.accepted = false; + return; // composing a multi-line message + } - x: 0 - height: listView.delegateHeight * listView.count - y: -height - 10 - padding: 0 - width: messageLine.width - contentHeight: rect.height - visible: listView.count > 0 + if (listView.currentItem) { + textSelected(listView.currentItem.myData.completername) + } else { + messageLineItem.sendMessage() + } + } Rectangle { - id: rect + anchors.fill: parent + opacity: 0.5 + } - anchors.top: popup.top - anchors.left: popup.left + QQC2.Popup { + id: popup - height: popup.height - width: popup.width + x: 0 + height: listView.delegateHeight * listView.count + y: -height - 10 + padding: 0 + width: messageLine.width + contentHeight: rect.height + visible: listView.count > 0 - ListView { - id: listView + Rectangle { + id: rect - readonly property int delegateHeight: count > 0 ? contentItem.children[0].height : 0 + anchors.top: popup.top + anchors.left: popup.left height: popup.height - width: parent.width - interactive: true - clip: true - model: inputCompleterModel - delegate: Kirigami.BasicListItem { - readonly property variant myData: model - - icon: model.iconname - - label: model.displayname - onClicked: { - listView.currentIndex = model.index - textSelected(model.completername) + width: popup.width + + ListView { + id: listView + + readonly property int delegateHeight: count > 0 ? contentItem.children[0].height : 0 + + height: popup.height + width: parent.width + interactive: true + clip: true + model: inputCompleterModel + delegate: Kirigami.BasicListItem { + readonly property variant myData: model + + icon: model.iconname + + label: model.displayname + onClicked: { + listView.currentIndex = model.index + textSelected(model.completername) + } + highlighted: focus && ListView.isCurrentItem } - highlighted: focus && ListView.isCurrentItem + QQC2.ScrollIndicator.vertical: QQC2.ScrollIndicator { } } - QQC2.ScrollIndicator.vertical: QQC2.ScrollIndicator { } } } - } - function showPopupCompleting() { - if (!popup.visible) { - popup.open() - listView.currentIndex = 0 + function showPopupCompleting() { + if (!popup.visible) { + popup.open() + listView.currentIndex = 0 + } } } + } function textSelected(completerName) { if (listView.currentItem) { messageLine.text = appid.rocketChatAccount.replaceWord(completerName + " ", messageLine.text, messageLine.cursorPosition) } popup.close() } Keys.onEscapePressed: { if (popup.visible) { popup.close() //Clear modified message } else if (savePreviousMessage !== "" || threadmessageId !== "") { savePreviousMessage = ""; messageId = ""; threadmessageId = ""; messageLine.text = ""; } else { clearUnreadMessages(); } } } diff --git a/src/apps/qml/qml/UserInput.qml b/src/apps/qml/qml/UserInput.qml index 072bf205..65dd57c3 100644 --- a/src/apps/qml/qml/UserInput.qml +++ b/src/apps/qml/qml/UserInput.qml @@ -1,138 +1,138 @@ /* * Copyright 2016 Riccardo Iaconelli * Copyright (c) 2017-2020 Laurent Montel * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ import QtQuick 2.9 import QtQuick.Layouts 1.12 import QtQuick.Controls 2.5 as QQC2 import org.kde.kirigami 2.7 as Kirigami import "common" RowLayout { id: footerItem property QtObject rcAccount property alias messageLineText: messageLine.messageLineText property alias messageId: messageLine.messageId property string threadmessageId property string selectedRoomId property string selectedThreadMessage property QtObject inputCompleterModel signal textEditing(string str) signal uploadFile() signal clearUnreadMessages() height: 2*Kirigami.Units.largeSpacing function setOriginalMessage(messageStr) { messageLine.setOriginalMessage(messageStr) } Kirigami.Icon { id: attachment MouseArea { hoverEnabled: true anchors.fill: parent QQC2.ToolTip { text: i18n("Attach Files") } } enabled: selectedRoomId !== "" source: "document-send-symbolic" width: height height: messageLine.height MouseArea { anchors.fill: parent onClicked: { footerItem.uploadFile() } } } MessageLine { id: messageLine inputCompleterModel: footerItem.inputCompleterModel selectedRoomId: footerItem.selectedRoomId messageId: footerItem.messageId threadmessageId: footerItem.threadmessageId selectedThreadMessage: footerItem.selectedThreadMessage } Loader { id: emoticonMenuLoader active: false sourceComponent :EmoticonMenu { id: emoticonMenu emojiPopupModel: appid.emojiModel width: Kirigami.Units.gridUnit * 20 height: Kirigami.Units.gridUnit * 15 x: -width + emojiIcon.x + emojiIcon.width y: -height Component.onCompleted: { open() } onInsertEmoticon: { messageLine.insertEmoticon(emoti) } } } Kirigami.Icon { id: emojiIcon source: "face-smile" width: height - height: messageLine.height + height: Kirigami.Units.gridUnit*2 MouseArea { hoverEnabled: true anchors.fill: parent QQC2.ToolTip { text: i18n("Insert Emoji") } } MouseArea { anchors.fill: parent onClicked: { if (emoticonMenuLoader.active) emoticonMenuLoader.active = false else emoticonMenuLoader.active = true } } } Kirigami.Icon { source: messageLine.savePreviousMessage == "" ? "mail-sent" : "edit-symbolic" width: height - height: messageLine.height + height: Kirigami.Units.gridUnit*2 MouseArea { hoverEnabled: true QQC2.ToolTip { text: i18n("Send Message") } anchors.fill: parent onClicked: { messageLine.sendMessage() } } } }