From 8c889a3a1bdc612f04665f2c5e9f32f757e4bc30 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 15 Apr 2024 21:25:07 +0800 Subject: [PATCH] refactor: painter for qsyneditor : member Namespace Spaces in disabled lines use the same color as in other places. --- RedPandaIDE/editor.cpp | 3 +- libs/qsynedit/qsynedit/painter.cpp | 60 +++++++++++++++--------------- libs/qsynedit/qsynedit/painter.h | 6 +-- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 8ecd0526..d2be6b7f 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -1318,8 +1318,9 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to if (mParser) { // ifdef lines if (!mParser->isLineVisible(mFilename, line)) { - foreground = syntaxer()->commentAttribute()->foreground(); background = syntaxer()->commentAttribute()->background(); + if (attr->tokenType() != QSynedit::TokenType::Space) + foreground = syntaxer()->commentAttribute()->foreground(); return; } QString sLine = lineText(line); diff --git a/libs/qsynedit/qsynedit/painter.cpp b/libs/qsynedit/qsynedit/painter.cpp index 94ea053a..d47bb3c0 100644 --- a/libs/qsynedit/qsynedit/painter.cpp +++ b/libs/qsynedit/qsynedit/painter.cpp @@ -313,17 +313,17 @@ void QSynEditPainter::computeSelectionInfo() void QSynEditPainter::getDrawingColors(bool selected, QColor &foreground, QColor &background) { if (selected) { - if (colSelFG.isValid()) - foreground = colSelFG; + if (mSelectionForeground.isValid()) + foreground = mSelectionForeground; else - foreground = colFG; - if (colSelBG.isValid()) - background = colSelBG; + foreground = mForeground; + if (mSelectionBackground.isValid()) + background = mSelectionBackground; else - background = colBG; + background = mBackground; } else { - foreground = colFG; - background = colBG; + foreground = mForeground; + background = mBackground; } } @@ -596,14 +596,8 @@ void QSynEditPainter::paintHighlightToken(const QString& lineText, // Any token chars accumulated? if (mTokenAccu.width > 0) { // Initialize the colors and the font style. - colBG = mTokenAccu.background; - colFG = mTokenAccu.foreground; - if (mIsSpecialLine) { - if (colSpFG.isValid()) - colFG = colSpFG; - if (colSpBG.isValid()) - colBG = colSpBG; - } + mBackground = mTokenAccu.background; + mForeground = mTokenAccu.foreground; // if (bSpecialLine && mEdit->mOptions.testFlag(eoSpecialLineDefaultFg)) // colFG = TokenAccu.FG; @@ -674,10 +668,10 @@ void QSynEditPainter::paintHighlightToken(const QString& lineText, // Fill the background to the end of this line if necessary. if (bFillToEOL && mRcToken.left() < mRcLine.right()) { - if (mIsSpecialLine && colSpBG.isValid()) - colBG = colSpBG; + if (mIsSpecialLine && mSpecialLineBackground.isValid()) + mBackground = mSpecialLineBackground; else - colBG = colEditorBG(); + mBackground = colEditorBG(); QColor foreground,background; if (mHasSelectionInLine) { getDrawingColors(mIsLineEndSelected,foreground,background); @@ -736,8 +730,8 @@ void QSynEditPainter::addHighlightToken( background = attri->background(); style = attri->styles(); } else { - foreground = colFG; - background = colBG; + foreground = mForeground; + background = mBackground; style = getFontStyles(mEdit->font()); } @@ -755,6 +749,14 @@ void QSynEditPainter::addHighlightToken( foreground = mEdit->mForegroundColor; } + if (mIsSpecialLine) { + QColor oldForeground = foreground; + if (mSpecialLineForeground.isValid()) + foreground = mSpecialLineForeground; + if (mSpecialLineBackground.isValid()) + background = mSpecialLineBackground; + } + // Do we have to paint the old chars first, or can we just append? bool bCanAppend = false; bool bInitFont = (mTokenAccu.width==0); @@ -989,14 +991,14 @@ void QSynEditPainter::paintLines() } // Initialize the text and background colors, maybe the line should // use special values for them. - colFG = mEdit->mForegroundColor; - colBG = colEditorBG(); - colSpFG = QColor(); - colSpBG = QColor(); - mIsSpecialLine = mEdit->onGetSpecialLineColors(vLine, colSpFG, colSpBG); + mForeground = mEdit->mForegroundColor; + mBackground = colEditorBG(); + mSpecialLineForeground = QColor(); + mSpecialLineBackground = QColor(); + mIsSpecialLine = mEdit->onGetSpecialLineColors(vLine, mSpecialLineForeground, mSpecialLineBackground); - colSelFG = mEdit->mSelectedForeground; - colSelBG = mEdit->mSelectedBackground; + mSelectionForeground = mEdit->mSelectedForeground; + mSelectionBackground = mEdit->mSelectedBackground; mEdit->onGetEditingAreas(vLine, areaList); // Get the information about the line selection. Three different parts // are possible (unselected before, selected, unselected after), only @@ -1237,7 +1239,7 @@ void QSynEditPainter::paintLines() if (preeditAttr) { area->color = preeditAttr->foreground(); } else { - area->color = colFG; + area->color = mForeground; } areaList.append(area); diff --git a/libs/qsynedit/qsynedit/painter.h b/libs/qsynedit/qsynedit/painter.h index 919d55a5..c3531fca 100644 --- a/libs/qsynedit/qsynedit/painter.h +++ b/libs/qsynedit/qsynedit/painter.h @@ -118,9 +118,9 @@ private: DisplayCoord mSelEnd; // end of selected area // info about normal and selected text and background colors bool mIsSpecialLine, mIsCurrentLine, mIsLineEndSelected; - QColor colFG, colBG; - QColor colSelFG, colSelBG; - QColor colSpFG, colSpBG; + QColor mForeground, mBackground; + QColor mSelectionForeground, mSelectionBackground; + QColor mSpecialLineForeground, mSpecialLineBackground; // info about selection of the current line int mLineSelStart, mLineSelEnd; bool mHasSelectionInLine;