/***************************************************************************
- * Copyright (C) 2005-2019 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 *
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))
bold = false;
mircText.append('\x02');
}
+ if (strikethrough) {
+ strikethrough = false;
+ mircText.append('\x1E');
+ }
mircText.append('\n');
}
else {
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');
bold = false;
mircText.append('\x02');
}
+ if (strikethrough) {
+ strikethrough = false;
+ mircText.append('\x1E');
+ }
}
}
if (bold)
mircText.append('\x02');
+ if (strikethrough)
+ mircText.append('\x1E');
+
return mircText;
}
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())
QString MultiLineEdit::convertMircCodesToHtml(const QString& text)
{
QStringList words;
- QRegExp mircCode = QRegExp("(\ 2|\1d|\1f|\ 3)", Qt::CaseSensitive);
+ QRegExp mircCode = QRegExp("(\x02|\x1d|\x1f|\x03|\x1E)", Qt::CaseSensitive);
int posLeft = 0;
int posRight = 0;
}
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;
}
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;