cmake: avoid de-duplication of user's CXXFLAGS
[quassel.git] / src / uisupport / multilineedit.cpp
index 166e12c..3711831 100644 (file)
@@ -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("(\ 2|\1d|\1f|\ 3)", 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;