diff options
author | Snowknight26 <Snowknight26@users.noreply.github.com> | 2022-07-14 17:53:04 +0300 |
---|---|---|
committer | Snowknight26 <Snowknight26@users.noreply.github.com> | 2022-07-24 22:36:18 +0300 |
commit | e658c4a0e094d2af82d5f425e90d4c73d5cfc9ef (patch) | |
tree | d2c018e6c6ecb1644704b735c0b1f41cee8e2421 | |
parent | ff3d0a6ec82bb1c0228bcc2349777cb6e2326927 (diff) |
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
-rw-r--r-- | src/mumble/CustomElements.cpp | 6 | ||||
-rw-r--r-- | src/mumble/CustomElements.h | 1 | ||||
-rw-r--r-- | src/mumble/MainWindow.cpp | 24 | ||||
-rw-r--r-- | src/mumble/MainWindow.h | 2 |
4 files changed, 25 insertions, 8 deletions
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 <br/>. 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", "<br>") + .replace(" ", " "); + } else { + // Markdown::markdownToHTML also takes care of replacing line breaks (\n) with the respective + // HTML code <br/>. 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(); |