X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fuisupport%2Fmultilineedit.cpp;h=1712cc6f08c9b3f74414a42c5772723eb294ec22;hb=082cb8c8eb6db90cbb2166a0098874e76d5c6ad9;hp=6bc549e18ee4a2493c16dab2cc1793378e5cbbd5;hpb=c1cf157116de7fc3da96203aa6f03c38c7ebb650;p=quassel.git diff --git a/src/uisupport/multilineedit.cpp b/src/uisupport/multilineedit.cpp index 6bc549e1..1712cc6f 100644 --- a/src/uisupport/multilineedit.cpp +++ b/src/uisupport/multilineedit.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2020 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -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; @@ -601,6 +618,10 @@ QString MultiLineEdit::convertMircCodesToHtml(const QString& text) } posRight = text.indexOf(mircCode.cap(), posRight + 1); + if (posRight == -1) { + words << text.mid(posLeft); + break; // unclosed color code; can't process + } words << text.mid(posLeft, posRight + 1 - posLeft); posLeft = posRight + 1; } @@ -619,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;