From cf5a03aa6f2fbe9d01dfebe0340974a28386c190 Mon Sep 17 00:00:00 2001 From: ctrlaltca Date: Fri, 2 Aug 2024 11:09:07 +0200 Subject: [PATCH] Add support for "Monospace" control code (ASCII 0x11). By now just ignore it. (#2672) --- src/kvilib/irc/KviControlCodes.cpp | 1 + src/kvilib/irc/KviControlCodes.h | 5 +++-- src/kvirc/kernel/KviHtmlGenerator.cpp | 22 +++++++++++++++++++++- src/kvirc/ui/KviInputEditor.cpp | 14 ++++++++++++-- src/kvirc/ui/KviIrcView.cpp | 6 ++++++ src/kvirc/ui/KviIrcView_events.cpp | 1 + src/kvirc/ui/KviIrcView_getTextLine.cpp | 3 ++- src/kvirc/ui/KviTopicWidget.cpp | 9 +++++++++ 8 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/kvilib/irc/KviControlCodes.cpp b/src/kvilib/irc/KviControlCodes.cpp index 30d20963dd..f99fad0e85 100644 --- a/src/kvilib/irc/KviControlCodes.cpp +++ b/src/kvilib/irc/KviControlCodes.cpp @@ -45,6 +45,7 @@ namespace KviControlCodes case KviControlCodes::Underline: case KviControlCodes::Bold: case KviControlCodes::Italic: + case KviControlCodes::Monospace: case KviControlCodes::Reset: case KviControlCodes::Reverse: case KviControlCodes::CryptEscape: diff --git a/src/kvilib/irc/KviControlCodes.h b/src/kvilib/irc/KviControlCodes.h index fa03054715..137c7609d9 100644 --- a/src/kvilib/irc/KviControlCodes.h +++ b/src/kvilib/irc/KviControlCodes.h @@ -66,11 +66,11 @@ // 008 BS Backspace (Should not be assigned: terminal control) // 009 HT Horizontal tabulation (Should not be assigned: terminal control) // 010 LF Line feed (Should not be assigned: terminal control) -// 011 VT Vertical tabulation (Should not be assigned: terminal control) +// 011 VT Vertical tabulation ( Monospace text ) // 012 FF Form feed (Should not be assigned: terminal control) // 013 CR Carriage return (Should not be assigned: terminal control) // 014 SO Shift out (Should not be assigned: terminal control) -// 015 SI Shift in ( Resets Bold,Color,Underline and Reverse ) (Conflicting with terminal control) +// 015 SI Shift in ( Resets Bold,Color,Underline,Monospace and Reverse ) (Conflicting with terminal control) // 016 DLE Data link escape (Decent, can be assigned) // 017 DC1 Device control 1 (Good to be assigned) // 018 DC2 Device control 2 (Good to be assigned) @@ -157,6 +157,7 @@ namespace KviControlCodes UnIcon = 0x06, /**< Unicon, totally artificial and internal to KviIrcView */ ArbitraryBreak = UnIcon, /**< Arbitrary block break, totally artificial and internal to KviIrcView */ Reset = 0x0f, /**< Reset */ + Monospace = 0x11, /**< Monospace */ Reverse = 0x16, /**< Reverse */ Icon = 0x1c, /**< Icon, KVIrc control code */ Italic = 0x1d, /**< Italic */ diff --git a/src/kvirc/kernel/KviHtmlGenerator.cpp b/src/kvirc/kernel/KviHtmlGenerator.cpp index 0dd94895ab..d88d064c57 100644 --- a/src/kvirc/kernel/KviHtmlGenerator.cpp +++ b/src/kvirc/kernel/KviHtmlGenerator.cpp @@ -37,6 +37,7 @@ namespace KviHtmlGenerator bool bCurBold = false; bool bCurItalic = false; bool bCurUnderline = false; + bool bCurMonospace = false; bool bIgnoreIcons = false; bool bShowIcons = KVI_OPTION_BOOL(KviOption_boolDrawEmoticons); unsigned char uCurFore = Foreground; @@ -51,7 +52,7 @@ namespace KviHtmlGenerator unsigned int uStart = uIdx; while( - (c != KviControlCodes::Color) && (c != KviControlCodes::Bold) && (c != KviControlCodes::Italic) && (c != KviControlCodes::Underline) && (c != KviControlCodes::Reverse) && (c != KviControlCodes::Reset) && (c != KviControlCodes::Icon) && ((c != ':') || bIgnoreIcons) && ((c != ';') || bIgnoreIcons) && ((c != '=') || bIgnoreIcons)) + (c != KviControlCodes::Color) && (c != KviControlCodes::Bold) && (c != KviControlCodes::Italic) && (c != KviControlCodes::Underline) && (c != KviControlCodes::Reverse) && (c != KviControlCodes::Reset) && (c != KviControlCodes::Icon) && (c != KviControlCodes::Monospace) && ((c != ':') || bIgnoreIcons) && ((c != ';') || bIgnoreIcons) && ((c != '=') || bIgnoreIcons)) { bIgnoreIcons = false; if(c == '&') @@ -158,6 +159,19 @@ namespace KviHtmlGenerator } } + if(bCurMonospace) + { + if(!bOpened) + { + szResult.append(""); @@ -193,6 +207,12 @@ namespace KviHtmlGenerator ++uIdx; break; } + case KviControlCodes::Monospace: + { + bCurMonospace = !bCurMonospace; + ++uIdx; + break; + } case KviControlCodes::Reset: { uCurFore = Foreground; diff --git a/src/kvirc/ui/KviInputEditor.cpp b/src/kvirc/ui/KviInputEditor.cpp index 93dcdecfb8..3bd6925b0f 100644 --- a/src/kvirc/ui/KviInputEditor.cpp +++ b/src/kvirc/ui/KviInputEditor.cpp @@ -109,7 +109,8 @@ class KviInputEditorTextBlock IsItalic = 4, IsUnderline = 8, IsSpellingMistake = 16, - IsSelected = 32 + IsSelected = 32, + IsMonospace = 64 }; public: @@ -536,7 +537,7 @@ void KviInputEditor::rebuildTextBlocks() #define NOT_CONTROL_CHAR() \ ( \ - (c > 32) || ((c != KviControlCodes::Color) && (c != KviControlCodes::Bold) && (c != KviControlCodes::Italic) && (c != KviControlCodes::Underline) && (c != KviControlCodes::Reset) && (c != KviControlCodes::Reverse) && (c != KviControlCodes::CryptEscape) && (c != KviControlCodes::Icon))) + (c > 32) || ((c != KviControlCodes::Color) && (c != KviControlCodes::Bold) && (c != KviControlCodes::Italic) && (c != KviControlCodes::Underline) && (c != KviControlCodes::Monospace) && (c != KviControlCodes::Reset) && (c != KviControlCodes::Reverse) && (c != KviControlCodes::CryptEscape) && (c != KviControlCodes::Icon))) // FIXME: get rid of getLastFontMetrics() ? QFontMetrics * fm = getLastFontMetrics(font()); @@ -605,6 +606,12 @@ void KviInputEditor::rebuildTextBlocks() else uFlags |= KviInputEditorTextBlock::IsUnderline; break; + case KviControlCodes::Monospace: + if(uFlags & KviInputEditorTextBlock::IsMonospace) + uFlags &= ~KviInputEditorTextBlock::IsMonospace; + else + uFlags |= KviInputEditorTextBlock::IsMonospace; + break; case KviControlCodes::Reset: uCurFore = KVI_INPUT_DEF_FORE; uCurBack = KVI_INPUT_DEF_BACK; @@ -976,6 +983,9 @@ QChar KviInputEditor::getSubstituteChar(unsigned short uControlCode) case KviControlCodes::Italic: return QChar('I'); break; + case KviControlCodes::Monospace: + return QChar('M'); + break; case KviControlCodes::Reset: return QChar('O'); break; diff --git a/src/kvirc/ui/KviIrcView.cpp b/src/kvirc/ui/KviIrcView.cpp index 4fa30321d4..8ca9eec9a5 100644 --- a/src/kvirc/ui/KviIrcView.cpp +++ b/src/kvirc/ui/KviIrcView.cpp @@ -1196,6 +1196,7 @@ void KviIrcView::paintEvent(QPaintEvent * p) bool curBold = false; bool curItalic = false; bool curUnderline = false; + bool curMonospace = false; char foreBeforeEscape = KviControlCodes::Black; bool curLink = false; bool bacWasTransp = false; @@ -1256,10 +1257,14 @@ void KviIrcView::paintEvent(QPaintEvent * p) case KviControlCodes::Underline: curUnderline = !curUnderline; break; + case KviControlCodes::Monospace: + curMonospace = !curMonospace; + break; case KviControlCodes::Reset: curBold = false; curItalic = false; curUnderline = false; + curMonospace = false; bacWasTransp = false; curFore = defaultFore; curBack = defaultBack; @@ -3004,6 +3009,7 @@ KviIrcViewWrappedBlock * KviIrcView::getLinkUnderMouse(int xPos, int yPos, QRect case KviControlCodes::Bold: case KviControlCodes::Italic: case KviControlCodes::Underline: + case KviControlCodes::Monospace: case KviControlCodes::Reverse: case KviControlCodes::Reset: szLink.append(QChar(l->pBlocks[iEndOfLInk].pChunk->type)); diff --git a/src/kvirc/ui/KviIrcView_events.cpp b/src/kvirc/ui/KviIrcView_events.cpp index d9730ac0fd..dcac81c3fb 100644 --- a/src/kvirc/ui/KviIrcView_events.cpp +++ b/src/kvirc/ui/KviIrcView_events.cpp @@ -447,6 +447,7 @@ void KviIrcView::addControlCharacter(KviIrcViewLineChunk * pC, QString & szSelec case KviControlCodes::Bold: case KviControlCodes::Italic: case KviControlCodes::Underline: + case KviControlCodes::Monospace: case KviControlCodes::Reverse: case KviControlCodes::Reset: szSelectionText.append(QChar(pC->type)); diff --git a/src/kvirc/ui/KviIrcView_getTextLine.cpp b/src/kvirc/ui/KviIrcView_getTextLine.cpp index 18010bd106..54257fc2f3 100644 --- a/src/kvirc/ui/KviIrcView_getTextLine.cpp +++ b/src/kvirc/ui/KviIrcView_getTextLine.cpp @@ -363,7 +363,7 @@ const kvi_wchar_t * KviIrcView::getTextLine( nullptr ,nullptr ,nullptr ,nullptr , nullptr ,&&found_tab ,&&found_end_of_line ,nullptr , nullptr ,&&found_command_escape ,nullptr ,&&found_mirc_escape , - nullptr ,nullptr ,nullptr ,nullptr , + nullptr ,&&found_mirc_escape ,nullptr ,nullptr , nullptr ,nullptr ,&&found_mirc_escape ,nullptr , nullptr ,nullptr ,nullptr ,nullptr , &&found_icon_escape ,&&found_mirc_escape ,nullptr ,&&found_mirc_escape , // 000-031 @@ -749,6 +749,7 @@ const kvi_wchar_t * KviIrcView::getTextLine( case KviControlCodes::Bold: case KviControlCodes::Italic: case KviControlCodes::Underline: + case KviControlCodes::Monospace: case KviControlCodes::Reverse: case KviControlCodes::Reset: #ifdef COMPILE_USE_DYNAMIC_LABELS diff --git a/src/kvirc/ui/KviTopicWidget.cpp b/src/kvirc/ui/KviTopicWidget.cpp index d4115ae749..5f41bd5ef9 100644 --- a/src/kvirc/ui/KviTopicWidget.cpp +++ b/src/kvirc/ui/KviTopicWidget.cpp @@ -234,6 +234,7 @@ static bool isKviControlCode(unsigned short c) case KviControlCodes::Bold: case KviControlCodes::Italic: case KviControlCodes::Underline: + case KviControlCodes::Monospace: case KviControlCodes::Reverse: case KviControlCodes::Reset: case KviControlCodes::Icon: @@ -249,6 +250,7 @@ void KviTopicWidget::paintColoredText(QPainter * p, QString text, const QPalette bool curBold = false; bool curItalic = false; bool curUnderline = false; + bool curMonospace = false; unsigned char curFore = KVI_LABEL_DEF_FORE; //default fore unsigned char curBack = KVI_LABEL_DEF_BACK; //default back int baseline = rect.top() + rect.height() - fm.descent() - 1; @@ -342,6 +344,10 @@ void KviTopicWidget::paintColoredText(QPainter * p, QString text, const QPalette curUnderline = !curUnderline; ++idx; break; + case KviControlCodes::Monospace: + curMonospace = !curMonospace; + ++idx; + break; case KviControlCodes::Reverse: { char auxBack = curBack; @@ -744,6 +750,9 @@ QChar KviTopicWidget::getSubstituteChar(unsigned short control_code) case KviControlCodes::Italic: return QChar('I'); break; + case KviControlCodes::Monospace: + return QChar('M'); + break; case KviControlCodes::Reset: return QChar('O'); break;