From: Alex McGrath Date: Thu, 1 Aug 2019 16:07:46 +0000 (+0100) Subject: Add button and bindings for striking through text X-Git-Tag: 0.14-rc1~50 X-Git-Url: https://git.quassel-irc.org/?a=commitdiff_plain;h=de6ee9a2a3389ebf62f181b12632e58d2ffb8879;hp=d6ac048d75fcc19f5577077d7ae625d41dbbf726;p=quassel.git Add button and bindings for striking through text This includes icons and a small regex fix from @digitalcircuit --- diff --git a/3rdparty/icons/breeze-dark/actions/16/format-text-strikethrough.svg b/3rdparty/icons/breeze-dark/actions/16/format-text-strikethrough.svg new file mode 100644 index 00000000..e5f4aab2 --- /dev/null +++ b/3rdparty/icons/breeze-dark/actions/16/format-text-strikethrough.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/3rdparty/icons/breeze-dark/actions/22/format-text-strikethrough.svg b/3rdparty/icons/breeze-dark/actions/22/format-text-strikethrough.svg new file mode 100644 index 00000000..24903dd7 --- /dev/null +++ b/3rdparty/icons/breeze-dark/actions/22/format-text-strikethrough.svg @@ -0,0 +1,14 @@ + + + + + + diff --git a/3rdparty/icons/breeze-dark/actions/24/format-text-strikethrough.svg b/3rdparty/icons/breeze-dark/actions/24/format-text-strikethrough.svg new file mode 100644 index 00000000..865f4019 --- /dev/null +++ b/3rdparty/icons/breeze-dark/actions/24/format-text-strikethrough.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/3rdparty/icons/breeze/actions/16/format-text-strikethrough.svg b/3rdparty/icons/breeze/actions/16/format-text-strikethrough.svg new file mode 100644 index 00000000..752b962d --- /dev/null +++ b/3rdparty/icons/breeze/actions/16/format-text-strikethrough.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/3rdparty/icons/breeze/actions/22/format-text-strikethrough.svg b/3rdparty/icons/breeze/actions/22/format-text-strikethrough.svg new file mode 100644 index 00000000..7f0cfc45 --- /dev/null +++ b/3rdparty/icons/breeze/actions/22/format-text-strikethrough.svg @@ -0,0 +1,14 @@ + + + + + + diff --git a/3rdparty/icons/breeze/actions/24/format-text-strikethrough.svg b/3rdparty/icons/breeze/actions/24/format-text-strikethrough.svg new file mode 100644 index 00000000..27b4f303 --- /dev/null +++ b/3rdparty/icons/breeze/actions/24/format-text-strikethrough.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/3rdparty/icons/oxygen/16x16/actions/format-text-strikethrough.png b/3rdparty/icons/oxygen/16x16/actions/format-text-strikethrough.png new file mode 100644 index 00000000..f248ce09 Binary files /dev/null and b/3rdparty/icons/oxygen/16x16/actions/format-text-strikethrough.png differ diff --git a/3rdparty/icons/oxygen/22x22/actions/format-text-strikethrough.png b/3rdparty/icons/oxygen/22x22/actions/format-text-strikethrough.png new file mode 100644 index 00000000..3e25ced5 Binary files /dev/null and b/3rdparty/icons/oxygen/22x22/actions/format-text-strikethrough.png differ diff --git a/3rdparty/icons/oxygen/32x32/actions/format-text-strikethrough.png b/3rdparty/icons/oxygen/32x32/actions/format-text-strikethrough.png new file mode 100644 index 00000000..d062ee7b Binary files /dev/null and b/3rdparty/icons/oxygen/32x32/actions/format-text-strikethrough.png differ diff --git a/3rdparty/icons/oxygen/48x48/actions/format-text-strikethrough.png b/3rdparty/icons/oxygen/48x48/actions/format-text-strikethrough.png new file mode 100644 index 00000000..88970f67 Binary files /dev/null and b/3rdparty/icons/oxygen/48x48/actions/format-text-strikethrough.png differ diff --git a/data/stylesheets/m4yer.qss b/data/stylesheets/m4yer.qss index 163eff5d..eb79149b 100644 --- a/data/stylesheets/m4yer.qss +++ b/data/stylesheets/m4yer.qss @@ -84,11 +84,13 @@ ChatLine[bg-color="0f"] { background: #c0c0c0; } ChatLine[format="bold"] { font-weight: bold;} ChatLine[format="italic"] { font-style: italic; } ChatLine[format="underline"] { font-style: underline; } +ChatLine[format="strikethrough"] { font-style: strikethrough; } // for sender ChatLine[format="bold", sender="self"] { foreground: #323232; font-weight: bold; } ChatLine[format="italic", sender="self"] { foreground: #323232; font-style: italic; } ChatLine[format="underline", sender="self"] { foreground: #323232; font-style: underline; } + ChatLine[format="strikethrough", sender="self"] { foreground: #323232; font-style: strikethrough; } // ChatView message colors ChatLine#notice { foreground: #916409; } diff --git a/src/qtui/inputwidget.cpp b/src/qtui/inputwidget.cpp index ad837166..69986724 100644 --- a/src/qtui/inputwidget.cpp +++ b/src/qtui/inputwidget.cpp @@ -68,6 +68,7 @@ InputWidget::InputWidget(QWidget* parent) ui.boldButton->setIcon(icon::get("format-text-bold")); ui.italicButton->setIcon(icon::get("format-text-italic")); ui.underlineButton->setIcon(icon::get("format-text-underline")); + ui.strikethroughButton->setIcon(icon::get("format-text-strikethrough")); ui.clearButton->setIcon(icon::get("edit-clear")); ui.encryptionIconLabel->hide(); @@ -374,6 +375,11 @@ void InputWidget::toggleFormatUnderline() setFormatUnderline(!ui.underlineButton->isChecked()); } +void InputWidget::toggleFormatStrikethrough() +{ + setFormatStrikethrough(!ui.strikethroughButton->isChecked()); +} + void InputWidget::clearFormat() { // Clear all formatting for selection (not global) @@ -511,6 +517,7 @@ void InputWidget::setFormatClear(const bool global) QTextCharFormat fmt; fmt.setFontWeight(QFont::Normal); fmt.setFontUnderline(false); + fmt.setFontStrikeOut(false); fmt.setFontItalic(false); fmt.clearForeground(); fmt.clearBackground(); @@ -525,6 +532,7 @@ void InputWidget::setFormatClear(const bool global) ui.boldButton->setChecked(false); ui.italicButton->setChecked(false); ui.underlineButton->setChecked(false); + ui.strikethroughButton->setChecked(false); } void InputWidget::setFormatBold(const bool bold) @@ -557,6 +565,16 @@ void InputWidget::setFormatUnderline(const bool underline) ui.underlineButton->setChecked(underline); } +void InputWidget::setFormatStrikethrough(const bool strike) +{ + // Apply formatting + QTextCharFormat fmt; + fmt.setFontStrikeOut(strike); + mergeFormatOnSelection(fmt); + // Make sure UI state follows + ui.strikethroughButton->setChecked(strike); +} + void InputWidget::mergeFormatOnSelection(const QTextCharFormat& format) { QTextCursor cursor = inputLine()->textCursor(); @@ -605,6 +623,11 @@ void InputWidget::on_underlineButton_clicked(bool checked) setFormatUnderline(checked); } +void InputWidget::on_strikethroughButton_clicked(bool checked) +{ + setFormatStrikethrough(checked); +} + void InputWidget::on_italicButton_clicked(bool checked) { setFormatItalic(checked); @@ -615,6 +638,7 @@ void InputWidget::fontChanged(const QFont& f) ui.boldButton->setChecked(f.bold()); ui.italicButton->setChecked(f.italic()); ui.underlineButton->setChecked(f.underline()); + ui.strikethroughButton->setChecked(f.strikeOut()); } void InputWidget::colorChosen(QAction* action) diff --git a/src/qtui/inputwidget.h b/src/qtui/inputwidget.h index b6afaee0..ad209596 100644 --- a/src/qtui/inputwidget.h +++ b/src/qtui/inputwidget.h @@ -83,6 +83,13 @@ public slots: */ void toggleFormatUnderline(); + /** + * Toggle the striking of the selected or typed text + * + * striking becomes normal, and normal becomes underlined. + */ + void toggleFormatStrikethrough(); + /** * Clear the formatting of the selected or typed text * @@ -132,6 +139,7 @@ private slots: void on_boldButton_clicked(bool checked); void on_italicButton_clicked(bool checked); void on_underlineButton_clicked(bool checked); + void on_strikethroughButton_clicked(bool checked); void colorChosen(QAction* action); void colorHighlightChosen(QAction* action); @@ -166,6 +174,13 @@ private: */ void setFormatUnderline(const bool underline); + /** + * Sets the strikethrough of the selected or typed text + * + * @param strike If true, set text striked, otherwise set text normal + */ + void setFormatStrikethrough(const bool strike); + Ui::InputWidget ui; NetworkId _networkId; diff --git a/src/qtui/inputwidget.ui b/src/qtui/inputwidget.ui index 24a25255..631aa757 100644 --- a/src/qtui/inputwidget.ui +++ b/src/qtui/inputwidget.ui @@ -274,6 +274,49 @@ + + + + true + + + + 0 + 0 + + + + + 26 + 24 + + + + + 16777215 + 16777215 + + + + Strikethrough + + + + + + + 16 + 16 + + + + true + + + false + + + diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index dae50296..019216fd 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -466,7 +466,14 @@ void MainWin::setupActions() coll, this, &MainWin::onFormatUnderlineTriggered, - QKeySequence::Underline)}}); + QKeySequence::Underline)}, + {"FormatStrikethrough", + new Action(icon::get("format-text-strikethrough"), + tr("Toggle strikethrough"), + coll, + this, + &MainWin::onFormatStrikethroughTriggered, + QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S))}}); // Navigation coll = QtUi::actionCollection("Navigation", tr("Navigation")); @@ -1834,6 +1841,15 @@ void MainWin::onFormatUnderlineTriggered() _inputWidget->toggleFormatUnderline(); } +void MainWin::onFormatStrikethroughTriggered() +{ + if (!_inputWidget) + return; + + _inputWidget->toggleFormatStrikethrough(); +} + + void MainWin::onJumpHotBufferTriggered() { if (!_bufferHotList->rowCount()) diff --git a/src/qtui/mainwin.h b/src/qtui/mainwin.h index fbcd553a..0ff2a36f 100644 --- a/src/qtui/mainwin.h +++ b/src/qtui/mainwin.h @@ -189,6 +189,13 @@ private slots: */ void onFormatUnderlineTriggered(); + /** + * Toggle the strikethrough of the input widget selected or typed text + * + * @seealso InputWidget::toggleFormatStrikethrough() + */ + void onFormatStrikethroughTriggered(); + /** * Clear the formatting of the input widget selected or typed text * diff --git a/src/uisupport/multilineedit.cpp b/src/uisupport/multilineedit.cpp index 1ecba103..1712cc6f 100644 --- a/src/uisupport/multilineedit.cpp +++ b/src/uisupport/multilineedit.cpp @@ -463,13 +463,13 @@ void MultiLineEdit::keyPressEvent(QKeyEvent* event) QString MultiLineEdit::convertRichtextToMircCodes() { - bool underline, bold, italic, color; + bool underline, bold, italic, color, strikethrough; QString mircText, mircFgColor, mircBgColor; QTextCursor cursor = textCursor(); QTextCursor peekcursor = textCursor(); cursor.movePosition(QTextCursor::Start); - underline = bold = italic = color = false; + underline = bold = italic = color = strikethrough = false; while (cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor)) { if (cursor.selectedText() == QString(QChar(QChar::LineSeparator)) @@ -490,6 +490,10 @@ QString MultiLineEdit::convertRichtextToMircCodes() bold = false; mircText.append('\x02'); } + if (strikethrough) { + strikethrough = false; + mircText.append('\x1E'); + } mircText.append('\n'); } else { @@ -505,6 +509,10 @@ QString MultiLineEdit::convertRichtextToMircCodes() underline = true; mircText.append('\x1f'); } + if (!strikethrough && cursor.charFormat().fontStrikeOut()) { + strikethrough = true; + mircText.append('\x1E'); + } if (!color && (cursor.charFormat().foreground().isOpaque() || cursor.charFormat().background().isOpaque())) { color = true; mircText.append('\x03'); @@ -542,6 +550,10 @@ QString MultiLineEdit::convertRichtextToMircCodes() bold = false; mircText.append('\x02'); } + if (strikethrough) { + strikethrough = false; + mircText.append('\x1E'); + } } } @@ -560,6 +572,9 @@ QString MultiLineEdit::convertRichtextToMircCodes() if (bold) mircText.append('\x02'); + if (strikethrough) + mircText.append('\x1E'); + return mircText; } @@ -572,6 +587,8 @@ bool MultiLineEdit::mircCodesChanged(QTextCursor& cursor, QTextCursor& peekcurso changed = true; if (cursor.charFormat().fontUnderline() != peekcursor.charFormat().fontUnderline()) changed = true; + if (cursor.charFormat().fontStrikeOut() != peekcursor.charFormat().fontStrikeOut()) + changed = true; if (cursor.charFormat().foreground().color() != peekcursor.charFormat().foreground().color()) changed = true; if (cursor.charFormat().background().color() != peekcursor.charFormat().background().color()) @@ -582,7 +599,7 @@ bool MultiLineEdit::mircCodesChanged(QTextCursor& cursor, QTextCursor& peekcurso QString MultiLineEdit::convertMircCodesToHtml(const QString& text) { QStringList words; - QRegExp mircCode = QRegExp("(|||)", Qt::CaseSensitive); + QRegExp mircCode = QRegExp("(\x02|\x1d|\x1f|\x03|\x1E)", Qt::CaseSensitive); int posLeft = 0; int posRight = 0; @@ -623,6 +640,10 @@ QString MultiLineEdit::convertMircCodesToHtml(const QString& text) style.append(" text-decoration: underline;"); words[i].replace('\x1f', ""); } + if (words[i].contains('\x1E')) { + style.append(" text-decoration: line-through;"); + words[i].replace('\x1E', ""); + } if (words[i].contains('\x03')) { int pos = words[i].indexOf('\x03'); int len = 3;