From e658c4a0e094d2af82d5f425e90d4c73d5cfc9ef Mon Sep 17 00:00:00 2001 From: Snowknight26 Date: Thu, 14 Jul 2022 09:53:04 -0500 Subject: FEAT(client): Add shortcut to send plain text messages Add the ability to press Ctrl+Enter to send a plain text message while preserving line breaks. This adds an easy way of preserving messages with line breaks without having to resort to using Markdown. Implements #5707 --- src/mumble/CustomElements.cpp | 6 +++++- src/mumble/CustomElements.h | 1 + src/mumble/MainWindow.cpp | 24 ++++++++++++++++++------ src/mumble/MainWindow.h | 2 +- 4 files changed, 25 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/mumble/CustomElements.cpp b/src/mumble/CustomElements.cpp index 085da4c82..43b1d033d 100644 --- a/src/mumble/CustomElements.cpp +++ b/src/mumble/CustomElements.cpp @@ -237,7 +237,11 @@ bool ChatbarTextEdit::event(QEvent *evt) { const QString msg = toPlainText(); if (!msg.isEmpty()) { addToHistory(msg); - emit entered(msg); + if (kev->modifiers() & Qt::ControlModifier) { + emit ctrlEnterPressed(msg); + } else { + emit entered(msg); + } } return true; } diff --git a/src/mumble/CustomElements.h b/src/mumble/CustomElements.h index dcbd63ab6..0de30fbb3 100644 --- a/src/mumble/CustomElements.h +++ b/src/mumble/CustomElements.h @@ -63,6 +63,7 @@ signals: void backtabPressed(void); void ctrlSpacePressed(void); void entered(QString); + void ctrlEnterPressed(QString); void pastedImage(QString); public slots: void pasteAndSend_triggered(); diff --git a/src/mumble/MainWindow.cpp b/src/mumble/MainWindow.cpp index 2019fb924..cec90ccbc 100644 --- a/src/mumble/MainWindow.cpp +++ b/src/mumble/MainWindow.cpp @@ -167,6 +167,7 @@ MainWindow::MainWindow(QWidget *p) : QMainWindow(p) { connect(qmChannel, SIGNAL(aboutToShow()), this, SLOT(qmChannel_aboutToShow())); connect(qmListener, SIGNAL(aboutToShow()), this, SLOT(qmListener_aboutToShow())); connect(qteChat, SIGNAL(entered(QString)), this, SLOT(sendChatbarText(QString))); + connect(qteChat, &ChatbarTextEdit::ctrlEnterPressed, [this](const QString &msg) { sendChatbarText(msg, true); }); connect(qteChat, SIGNAL(pastedImage(QString)), this, SLOT(sendChatbarMessage(QString))); // Tray @@ -2062,12 +2063,23 @@ void MainWindow::on_qaQuit_triggered() { this->close(); } -void MainWindow::sendChatbarText(QString qsText) { - // Markdown::markdownToHTML also takes care of replacing line breaks (\n) with the respective - // HTML code
. Therefore if Markdown support is ever going to be removed from this - // function, this job has to be done explicitly as otherwise line breaks won't be shown on - // the receiving end of this text message. - qsText = Markdown::markdownToHTML(qsText); +void MainWindow::sendChatbarText(QString qsText, bool plainText) { + if (plainText) { + // Escape HTML, unify line endings, then convert spaces to non-breaking ones to prevent multiple + // simultaneous ones from being collapsed into one (as a normal HTML renderer does). + qsText = qsText.toHtmlEscaped() + .replace("\r\n", "\n") + .replace("\r", "\n") + .replace("\n", "
") + .replace(" ", " "); + } else { + // Markdown::markdownToHTML also takes care of replacing line breaks (\n) with the respective + // HTML code
. Therefore if Markdown support is ever going to be removed from this + // function, this job has to be done explicitly as otherwise line breaks won't be shown on + // the receiving end of this text message. + qsText = Markdown::markdownToHTML(qsText); + } + sendChatbarMessage(qsText); qteChat->clear(); diff --git a/src/mumble/MainWindow.h b/src/mumble/MainWindow.h index 00eb98e19..292aac84e 100644 --- a/src/mumble/MainWindow.h +++ b/src/mumble/MainWindow.h @@ -313,7 +313,7 @@ public slots: void destroyUserInformation(); void trayAboutToShow(); void sendChatbarMessage(QString msg); - void sendChatbarText(QString msg); + void sendChatbarText(QString msg, bool plainText = false); void pttReleased(); void whisperReleased(QVariant scdata); void onResetAudio(); -- cgit v1.2.3