X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fmultilineedit.cpp;h=a9a2ae248a75532ed3594a25d225d628cef30bbf;hp=166e12cc460e82210c4bdc77ab2b37d517056503;hb=HEAD;hpb=3e800ec6553158aa0da3b08da78083d587389914 diff --git a/src/uisupport/multilineedit.cpp b/src/uisupport/multilineedit.cpp index 166e12cc..37118315 100644 --- a/src/uisupport/multilineedit.cpp +++ b/src/uisupport/multilineedit.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2019 by the Quassel Project * + * Copyright (C) 2005-2022 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;