diff --git a/NEWS.md b/NEWS.md index 420bb23a..86b5ef58 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,6 +20,8 @@ Red Panda C++ Version 2.7 - fix: Project's "static link" option is overwrited by global compiler set settings, when project options dialog is opened. - fix: Icon size not correct under macOS high DPI / zoom factor settings. - enhancement: "Icon zoom" in options / environment / appearance + - enhancement: "Line Spacing" in options / editor / font + - enhancement: "Show whitespaces" in options / editor / font Red Panda C++ Version 2.6 diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index c991378d..f65d5ee6 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -4705,7 +4705,10 @@ void Editor::applySettings() QSynedit::eoRightMouseMovesCursor | QSynedit::eoScrollByOneLess | QSynedit::eoTabIndent | QSynedit::eoHideShowScrollbars | QSynedit::eoGroupUndo | QSynedit::eoSelectWordByDblClick; - options.setFlag(QSynedit::eoShowSpecialChars, pSettings->editor().showSpecialChars()); + options.setFlag(QSynedit::eoShowLeadingSpaces, pSettings->editor().showLeadingSpaces()); + options.setFlag(QSynedit::eoShowTrailingSpaces, pSettings->editor().showTrailingSpaces()); + options.setFlag(QSynedit::eoShowInnerSpaces, pSettings->editor().showInnerSpaces()); + options.setFlag(QSynedit::eoShowLineBreaks, pSettings->editor().showLineBreaks()); //options options.setFlag(QSynedit::eoAutoIndent,pSettings->editor().autoIndent()); @@ -4746,6 +4749,7 @@ void Editor::applySettings() f2.setPixelSize(pointToPixel(pSettings->editor().fontSize())); f2.setStyleStrategy(QFont::PreferAntialias); setFontForNonAscii(f2); + setLineSpacingFactor(pSettings->editor().lineSpacing()); // Set gutter properties gutter().setLeftOffset(pointToPixel(pSettings->editor().fontSize()) + pSettings->editor().gutterLeftOffset()); diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 14227c9b..9ce86718 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -735,14 +735,54 @@ void Settings::Editor::setRemoveTrailingSpacesWhenSaved(bool newRemoveTrailingSp mRemoveTrailingSpacesWhenSaved = newRemoveTrailingSpacesWhenSaved; } -bool Settings::Editor::showSpecialChars() const +double Settings::Editor::lineSpacing() const { - return mShowSpecialChars; + return mLineSpacing; } -void Settings::Editor::setShowSpecialChars(bool newShowSpecialChars) +void Settings::Editor::setLineSpacing(double newLineSpacing) { - mShowSpecialChars = newShowSpecialChars; + mLineSpacing = newLineSpacing; +} + +bool Settings::Editor::showLeadingSpaces() const +{ + return mShowLeadingSpaces; +} + +void Settings::Editor::setShowLeadingSpaces(bool newShowStartSpaces) +{ + mShowLeadingSpaces = newShowStartSpaces; +} + +bool Settings::Editor::showTrailingSpaces() const +{ + return mShowTrailingSpaces; +} + +void Settings::Editor::setShowTrailingSpaces(bool newShowEndSpaces) +{ + mShowTrailingSpaces = newShowEndSpaces; +} + +bool Settings::Editor::showInnerSpaces() const +{ + return mShowInnerSpaces; +} + +void Settings::Editor::setShowInnerSpaces(bool newShowMiddleSpaces) +{ + mShowInnerSpaces = newShowMiddleSpaces; +} + +bool Settings::Editor::showLineBreaks() const +{ + return mShowLineBreaks; +} + +void Settings::Editor::setShowLineBreaks(bool newShowLineBreaks) +{ + mShowLineBreaks = newShowLineBreaks; } bool Settings::Editor::highlightCurrentWord() const @@ -1235,8 +1275,6 @@ void Settings::Editor::doSave() saveValue("caret_use_text_color",mCaretUseTextColor); saveValue("caret_color",mCaretColor); - saveValue("show_special_chars",mShowSpecialChars); - //highlight saveValue("highlight_matching_braces",mHighlightMathingBraces); saveValue("highlight_current_word",mHighlightCurrentWord); @@ -1261,8 +1299,14 @@ void Settings::Editor::doSave() saveValue("non_ascii_font_name", mNonAsciiFontName); saveValue("font_size", mFontSize); saveValue("font_only_monospaced", mFontOnlyMonospaced); + saveValue("line_spacing",mLineSpacing); saveValue("enable_ligatures_support", mEnableLigaturesSupport); + saveValue("show_leading_spaces", mShowLeadingSpaces); + saveValue("show_trailing_spaces", mShowTrailingSpaces); + saveValue("show_inner_spaces", mShowInnerSpaces); + saveValue("show_line_breaks", mShowLineBreaks); + //gutter saveValue("gutter_visible", mGutterVisible); saveValue("gutter_auto_size", mGutterAutoSize); @@ -1362,9 +1406,6 @@ void Settings::Editor::doLoad() mCaretUseTextColor = boolValue("caret_use_text_color",true); mCaretColor = colorValue("caret_color",Qt::yellow); - mShowSpecialChars = boolValue("show_special_chars",false); - - //highlight mHighlightMathingBraces = boolValue("highlight_matching_braces",true); mHighlightCurrentWord = boolValue("highlight_current_word",true); @@ -1397,8 +1438,14 @@ void Settings::Editor::doLoad() #endif mFontSize = intValue("font_size",12); mFontOnlyMonospaced = boolValue("font_only_monospaced",true); + mLineSpacing = doubleValue("line_spacing",1.0); mEnableLigaturesSupport = boolValue("enable_ligatures_support", false); + mShowLeadingSpaces = boolValue("show_leading_spaces", false); + mShowTrailingSpaces = boolValue("show_trailing_spaces", false); + mShowInnerSpaces = boolValue("show_inner_spaces", false); + mShowLineBreaks = boolValue("show_line_breaks", false); + //gutter mGutterVisible = boolValue("gutter_visible",true); mGutterAutoSize = boolValue("gutter_auto_size",true); @@ -1716,27 +1763,27 @@ QString Settings::CompilerSet::getCompileOptionValue(const QString &key) return mCompileOptions.value(key,QString()); } -static void checkDirs(const QStringList& dirlist, QString& gooddirs, QString& baddirs) { - gooddirs = ""; - baddirs = ""; +//static void checkDirs(const QStringList& dirlist, QString& gooddirs, QString& baddirs) { +// gooddirs = ""; +// baddirs = ""; - for (int i=0; icbFont->setCurrentFont(QFont(pSettings->editor().fontName())); ui->cbNonAsciiFont->setCurrentFont(QFont(pSettings->editor().nonAsciiFontName())); ui->spinFontSize->setValue(pSettings->editor().fontSize()); + ui->spinLineSpacing->setValue(pSettings->editor().lineSpacing()); ui->chkLigature->setChecked(pSettings->editor().enableLigaturesSupport()); - ui->chkShowSpecialChars->setChecked(pSettings->editor().showSpecialChars()); + ui->chkLeadingSpaces->setChecked(pSettings->editor().showLeadingSpaces()); + ui->chkInnerSpaces->setChecked(pSettings->editor().showInnerSpaces()); + ui->chkTrailingSpaces->setChecked(pSettings->editor().showTrailingSpaces()); + ui->chkLineBreaks->setChecked(pSettings->editor().showLineBreaks()); //gutter ui->chkGutterVisible->setChecked(pSettings->editor().gutterVisible()); ui->chkAutoSizeGutter->setChecked(pSettings->editor().gutterAutoSize()); @@ -82,8 +86,13 @@ void EditorFontWidget::doSave() pSettings->editor().setFontName(ui->cbFont->currentFont().family()); pSettings->editor().setNonAsciiFontName(ui->cbNonAsciiFont->currentFont().family()); pSettings->editor().setFontSize(ui->spinFontSize->value()); + pSettings->editor().setLineSpacing(ui->spinLineSpacing->value()); + pSettings->editor().setEnableLigaturesSupport(ui->chkLigature->isChecked()); - pSettings->editor().setShowSpecialChars(ui->chkShowSpecialChars->isChecked()); + pSettings->editor().setShowLeadingSpaces(ui->chkLeadingSpaces->isChecked()); + pSettings->editor().setShowInnerSpaces(ui->chkInnerSpaces->isChecked()); + pSettings->editor().setShowTrailingSpaces(ui->chkTrailingSpaces->isChecked()); + pSettings->editor().setShowLineBreaks(ui->chkLineBreaks->isChecked()); //gutter pSettings->editor().setGutterVisible(ui->chkGutterVisible->isChecked()); pSettings->editor().setGutterAutoSize(ui->chkAutoSizeGutter->isChecked()); diff --git a/RedPandaIDE/settingsdialog/editorfontwidget.ui b/RedPandaIDE/settingsdialog/editorfontwidget.ui index 1bf442ac..db31a89d 100644 --- a/RedPandaIDE/settingsdialog/editorfontwidget.ui +++ b/RedPandaIDE/settingsdialog/editorfontwidget.ui @@ -23,13 +23,146 @@ 11 - - + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 1 + + + 1.000000000000000 + + + 3.000000000000000 + + + 0.100000000000000 + + + + + + + Qt::Horizontal + + + + 563 + 20 + + + + + + + + + - Font: + Size: + + + + Enable ligatures support + + + + + + + Line Spacing: + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 2 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + @@ -81,51 +214,6 @@ - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 2 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - Size: - - - @@ -133,51 +221,47 @@ - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - + + - Show special chars + Font: - - + + + + + + + Show whitespaces + + + + - Enable ligatures support + Leading + + + + + + + Inner + + + + + + + Trailing + + + + + + + Line break diff --git a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts index 5f5961a4..0d7062d1 100644 --- a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts +++ b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts @@ -1402,11 +1402,31 @@ Usar fonte personalizada - Show special chars + Enable ligatures support - Enable ligatures support + Line Spacing: + + + + Show whitespaces + + + + Leading + + + + Inner + + + + Trailing + + + + Line break diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts index 8b9b358d..af6f5c0a 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts @@ -1458,7 +1458,7 @@ Are you really want to continue? 输入当前断点的生效条件: - + Readonly 只读 @@ -1568,7 +1568,7 @@ Are you really want to continue? Copy with format as - 同时带格式复制为 + 带格式复制为 @@ -1859,20 +1859,20 @@ Are you really want to continue? 表单 - - + + Size: 大小: - - + + Font: 英文字体: - - + + Show only monospaced fonts 只显示等宽字体 @@ -1881,67 +1881,96 @@ Are you really want to continue? 启用合字显示支持(需要Fira Code等字体) - + Font for non-ascii Text: 非英文字体: - Show special chars - 显示特殊字符 + 显示特殊字符 - + Enable ligatures support 启用连字(ligratures)功能 - + + Line Spacing: + 行高: + + + + Show whitespaces + 显示空白字符 + + + + Leading + 行首 + + + + Inner + 中间 + + + + Trailing + 行尾 + + + + Line break + 换行符 + + + Gutter 装订线 - + Gutter is visible 显示装订线区域 - + Left Offset 左侧留白 - + Right Offset 右侧留白 - + Show Line Numbers 显示行号 - + Add leading zeros to line numbers 在行号前补齐前导0 - + Line numbers starts at zero 第一行从0开始编号 - + Auto calculate the digit count of line number 自动计算行号位数 - + Digit count 行号位数 - + Use Custom Font 使用自定义字体 @@ -8030,7 +8059,7 @@ Are you really want to continue? 生成调试信息(-g3) - + Would you like Red Panda C++ to search for compilers in PATH? 您同意小熊猫C++在PATH路径中寻找gcc编译器吗? @@ -8143,7 +8172,7 @@ Are you really want to continue? 只生成汇编代码(-S) - + Confirm 确认 @@ -8164,13 +8193,13 @@ Are you really want to continue? 如果仍然保留这些设置,可能会导致编译错误。<br /><br />请选择“是”,除非您清楚的知道选择“否”的后果, - - + + Compiler set not configuared. 未配置编译器设置。 - + Would you like Red Panda C++ to search for compilers in the following locations: <BR />'%1'<BR />'%2'? 您需要小熊猫C++在下列位置搜索编译器吗:<br />%1<br />%2 diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts index ad006a6c..0a771efd 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts @@ -1287,11 +1287,31 @@ - Show special chars + Enable ligatures support - Enable ligatures support + Line Spacing: + + + + Show whitespaces + + + + Leading + + + + Inner + + + + Trailing + + + + Line break diff --git a/libs/qsynedit/qsynedit/SynEdit.cpp b/libs/qsynedit/qsynedit/SynEdit.cpp index be08b73e..5166bb7a 100644 --- a/libs/qsynedit/qsynedit/SynEdit.cpp +++ b/libs/qsynedit/qsynedit/SynEdit.cpp @@ -105,7 +105,7 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent), this->setCursor(Qt::CursorShape::IBeamCursor); //TabStop := True; mInserting = true; - mExtraLineSpacing = 0; + mLineSpacingFactor = 1.0; this->setFrameShape(QFrame::Panel); this->setFrameShadow(QFrame::Sunken); @@ -3405,7 +3405,7 @@ void SynEdit::recalcCharExtent() if (fm.horizontalAdvance("M")>mCharWidth) mCharWidth = fm.horizontalAdvance("M"); } - mTextHeight += mExtraLineSpacing; + mTextHeight *= mLineSpacingFactor; } QString SynEdit::expandAtWideGlyphs(const QString &S) @@ -3968,6 +3968,19 @@ void SynEdit::onScrolled(int) invalidate(); } +double SynEdit::lineSpacingFactor() const +{ + return mLineSpacingFactor; +} + +void SynEdit::setLineSpacingFactor(double newLineSpacingFactor) +{ + if (newLineSpacingFactor<1.0) + newLineSpacingFactor = 1.0; + mLineSpacingFactor = newLineSpacingFactor; + recalcCharExtent(); +} + ScrollStyle SynEdit::scrollBars() const { return mScrollBars; @@ -4185,6 +4198,10 @@ EditorOptions SynEdit::getOptions() const return mOptions; } + +static bool sameEditorOption(const EditorOptions& value1, const EditorOptions& value2, EditorOption flag) { + return value1.testFlag(flag)==value2.testFlag(flag); +} void SynEdit::setOptions(const EditorOptions &Value) { if (Value != mOptions) { @@ -4195,8 +4212,11 @@ void SynEdit::setOptions(const EditorOptions &Value) setTopLine(mTopLine); bool bUpdateAll = - (Value.testFlag(eoShowSpecialChars) != mOptions.testFlag(eoShowSpecialChars)) - || (Value.testFlag(eoShowRainbowColor) != mOptions.testFlag(eoShowRainbowColor)); + !sameEditorOption(Value,mOptions,eoShowLeadingSpaces) + || !sameEditorOption(Value,mOptions,eoShowInnerSpaces) + || !sameEditorOption(Value,mOptions,eoShowTrailingSpaces) + || !sameEditorOption(Value,mOptions,eoShowLineBreaks) + || !sameEditorOption(Value,mOptions,eoShowRainbowColor); //bool bUpdateScroll = (Options * ScrollOptions)<>(Value * ScrollOptions); bool bUpdateScroll = true; mOptions = Value; diff --git a/libs/qsynedit/qsynedit/SynEdit.h b/libs/qsynedit/qsynedit/SynEdit.h index 92a21059..4d202e9a 100644 --- a/libs/qsynedit/qsynedit/SynEdit.h +++ b/libs/qsynedit/qsynedit/SynEdit.h @@ -89,12 +89,16 @@ enum EditorOption { eoScrollByOneLess = 0x00001000, //Forces scrolling to be one less eoScrollPastEof = 0x00002000, //Allows the cursor to go past the end of file marker eoScrollPastEol = 0x00004000, //Allows the cursor to go past the last character into the white space at the end of a line - eoShowSpecialChars = 0x00008000, //Shows the special Characters +// eoShowSpecialChars = 0x00008000, //Shows the special Characters // eoSpecialLineDefaultFg = 0x00010000, //disables the foreground text color override when using the OnSpecialLineColor event eoTabIndent = 0x00020000, //When active and act as block indent, unindent when text is selected eoTabsToSpaces = 0x00040000, //Converts a tab character to a specified number of space characters eoShowRainbowColor = 0x00080000, eoSelectWordByDblClick= 0x00100000, + eoShowLeadingSpaces = 0x00200000, + eoShowTrailingSpaces = 0x00400000, + eoShowInnerSpaces= 0x00800000, + eoShowLineBreaks = 0x01000000, }; Q_DECLARE_FLAGS(EditorOptions, EditorOption) @@ -682,7 +686,7 @@ private: EditKeyStrokes mKeyStrokes; bool mModified; QDateTime mLastModifyTime; - int mExtraLineSpacing; + double mLineSpacingFactor; SelectionMode mSelectionMode; SelectionMode mActiveSelectionMode; //mode of the active selection bool mWantReturns; @@ -776,6 +780,9 @@ protected: ScrollStyle scrollBars() const; void setScrollBars(ScrollStyle newScrollBars); + double lineSpacingFactor() const; + void setLineSpacingFactor(double newLineSpacingFactor); + protected: void dragEnterEvent(QDragEnterEvent *event) override; void dropEvent(QDropEvent *event) override; diff --git a/libs/qsynedit/qsynedit/TextPainter.cpp b/libs/qsynedit/qsynedit/TextPainter.cpp index 24086c27..a021d2c6 100644 --- a/libs/qsynedit/qsynedit/TextPainter.cpp +++ b/libs/qsynedit/qsynedit/TextPainter.cpp @@ -485,8 +485,8 @@ void SynEditTextPainter::paintHighlightToken(bool bFillToEOL) bool bU1, bSel, bU2; int nX1, nX2; // Compute some helper variables. - nC1 = std::max(FirstCol, TokenAccu.ColumnsBefore + 1); - nC2 = std::min(LastCol, TokenAccu.ColumnsBefore + TokenAccu.Columns + 1); + nC1 = std::max(FirstCol, mTokenAccu.columnsBefore + 1); + nC2 = std::min(LastCol, mTokenAccu.columnsBefore + mTokenAccu.columns + 1); if (bComplexLine) { bU1 = (nC1 < nLineSelStart); bSel = (nC1 < nLineSelEnd) && (nC2 >= nLineSelStart); @@ -499,10 +499,10 @@ void SynEditTextPainter::paintHighlightToken(bool bFillToEOL) bU2 = false; // to shut up compiler warning. } // Any token chars accumulated? - if (TokenAccu.Columns > 0) { + if (mTokenAccu.columns > 0) { // Initialize the colors and the font style. - colBG = TokenAccu.BG; - colFG = TokenAccu.FG; + colBG = mTokenAccu.background; + colFG = mTokenAccu.foreground; if (bSpecialLine) { if (colSpFG.isValid()) colFG = colSpFG; @@ -513,16 +513,16 @@ void SynEditTextPainter::paintHighlightToken(bool bFillToEOL) // if (bSpecialLine && edit->mOptions.testFlag(eoSpecialLineDefaultFg)) // colFG = TokenAccu.FG; QFont font = edit->font(); - font.setBold(TokenAccu.Style & FontStyle::fsBold); - font.setItalic(TokenAccu.Style & FontStyle::fsItalic); - font.setStrikeOut(TokenAccu.Style & FontStyle::fsStrikeOut); - font.setUnderline(TokenAccu.Style & FontStyle::fsUnderline); + font.setBold(mTokenAccu.style & FontStyle::fsBold); + font.setItalic(mTokenAccu.style & FontStyle::fsItalic); + font.setStrikeOut(mTokenAccu.style & FontStyle::fsStrikeOut); + font.setUnderline(mTokenAccu.style & FontStyle::fsUnderline); painter->setFont(font); QFont nonAsciiFont = edit->fontForNonAscii(); - nonAsciiFont.setBold(TokenAccu.Style & FontStyle::fsBold); - nonAsciiFont.setItalic(TokenAccu.Style & FontStyle::fsItalic); - nonAsciiFont.setStrikeOut(TokenAccu.Style & FontStyle::fsStrikeOut); - nonAsciiFont.setUnderline(TokenAccu.Style & FontStyle::fsUnderline); + nonAsciiFont.setBold(mTokenAccu.style & FontStyle::fsBold); + nonAsciiFont.setItalic(mTokenAccu.style & FontStyle::fsItalic); + nonAsciiFont.setStrikeOut(mTokenAccu.style & FontStyle::fsStrikeOut); + nonAsciiFont.setUnderline(mTokenAccu.style & FontStyle::fsUnderline); // Paint the chars if (bComplexToken) { @@ -531,24 +531,24 @@ void SynEditTextPainter::paintHighlightToken(bool bFillToEOL) setDrawingColors(false); rcToken.setRight(columnToXValue(nLineSelStart)); paintToken( - TokenAccu.s,TokenAccu.Columns,TokenAccu.ColumnsBefore,nC1,nLineSelStart,false,font,nonAsciiFont, TokenAccu.showSpecialGlyphs); + mTokenAccu.s,mTokenAccu.columns,mTokenAccu.columnsBefore,nC1,nLineSelStart,false,font,nonAsciiFont, mTokenAccu.showSpecialGlyphs); } // selected part of the token setDrawingColors(true); nC1Sel = std::max(nLineSelStart, nC1); nC2Sel = std::min(nLineSelEnd, nC2); rcToken.setRight(columnToXValue(nC2Sel)); - paintToken(TokenAccu.s, TokenAccu.Columns, TokenAccu.ColumnsBefore, nC1Sel, nC2Sel,true,font,nonAsciiFont, TokenAccu.showSpecialGlyphs); + paintToken(mTokenAccu.s, mTokenAccu.columns, mTokenAccu.columnsBefore, nC1Sel, nC2Sel,true,font,nonAsciiFont, mTokenAccu.showSpecialGlyphs); // second unselected part of the token if (bU2) { setDrawingColors(false); rcToken.setRight(columnToXValue(nC2)); - paintToken(TokenAccu.s, TokenAccu.Columns, TokenAccu.ColumnsBefore,nLineSelEnd, nC2,false,font,nonAsciiFont, TokenAccu.showSpecialGlyphs); + paintToken(mTokenAccu.s, mTokenAccu.columns, mTokenAccu.columnsBefore,nLineSelEnd, nC2,false,font,nonAsciiFont, mTokenAccu.showSpecialGlyphs); } } else { setDrawingColors(bSel); rcToken.setRight(columnToXValue(nC2)); - paintToken(TokenAccu.s, TokenAccu.Columns, TokenAccu.ColumnsBefore, nC1, nC2,bSel,font,nonAsciiFont, TokenAccu.showSpecialGlyphs); + paintToken(mTokenAccu.s, mTokenAccu.columns, mTokenAccu.columnsBefore, nC1, nC2,bSel,font,nonAsciiFont, mTokenAccu.showSpecialGlyphs); } } @@ -593,21 +593,17 @@ void SynEditTextPainter::paintHighlightToken(bool bFillToEOL) // Store the token chars with the attributes in the TokenAccu // record. This will paint any chars already stored if there is // a (visible) change in the attributes. -void SynEditTextPainter::addHighlightToken(const QString &Token, int columnsBefore, - int tokenColumns, int cLine, PTokenAttribute p_Attri) +void SynEditTextPainter::addHighlightToken(const QString &token, int columnsBefore, + int tokenColumns, int cLine, PTokenAttribute attri, bool showGlyphs) { bool bCanAppend; QColor foreground, background; FontStyles style; - bool isSpaces=false; - bool showGlyphs=false; - if (p_Attri) { - foreground = p_Attri->foreground(); - background = p_Attri->background(); - style = p_Attri->styles(); - isSpaces = p_Attri->tokenType() == TokenType::Space; - showGlyphs = isSpaces && edit->mOptions.testFlag(eoShowSpecialChars); + if (attri) { + foreground = attri->foreground(); + background = attri->background(); + style = attri->styles(); } else { foreground = colFG; background = colBG; @@ -625,21 +621,20 @@ void SynEditTextPainter::addHighlightToken(const QString &Token, int columnsBefo } edit->onPreparePaintHighlightToken(cLine,edit->mSyntaxer->getTokenPos()+1, - Token,p_Attri,style,foreground,background); + token,attri,style,foreground,background); // Do we have to paint the old chars first, or can we just append? bCanAppend = false; - if (TokenAccu.Columns > 0 ) { - if (showGlyphs == TokenAccu.showSpecialGlyphs) { + if (mTokenAccu.columns > 0 ) { + if (showGlyphs == mTokenAccu.showSpecialGlyphs) { // font style must be the same or token is only spaces - if (TokenAccu.Style == style || ( (style & FontStyle::fsUnderline) == (TokenAccu.Style & fsUnderline) - && isSpaces)) { + if (mTokenAccu.style == style) { if ( // background color must be the same and - (TokenAccu.BG == background) && + (mTokenAccu.background == background) && // foreground color must be the same or token is only spaces - ((TokenAccu.FG == foreground) || isSpaces)) { - bCanAppend = true; + (mTokenAccu.foreground == foreground)) { + bCanAppend = true; } } } @@ -649,16 +644,16 @@ void SynEditTextPainter::addHighlightToken(const QString &Token, int columnsBefo } // Don't use AppendStr because it's more expensive. if (bCanAppend) { - TokenAccu.s.append(Token); - TokenAccu.Columns+=tokenColumns; + mTokenAccu.s.append(token); + mTokenAccu.columns+=tokenColumns; } else { - TokenAccu.Columns = tokenColumns; - TokenAccu.s = Token; - TokenAccu.ColumnsBefore = columnsBefore; - TokenAccu.FG = foreground; - TokenAccu.BG = background; - TokenAccu.Style = style; - TokenAccu.showSpecialGlyphs = showGlyphs; + mTokenAccu.columns = tokenColumns; + mTokenAccu.s = token; + mTokenAccu.columnsBefore = columnsBefore; + mTokenAccu.foreground = foreground; + mTokenAccu.background = background; + mTokenAccu.style = style; + mTokenAccu.showSpecialGlyphs = showGlyphs; } } @@ -814,8 +809,8 @@ void SynEditTextPainter::paintLines() // inside the loop. Get only the starting point for this. rcLine = AClip; rcLine.setBottom((aFirstRow - edit->mTopLine) * edit->mTextHeight); - TokenAccu.Columns = 0; - TokenAccu.ColumnsBefore = 0; + mTokenAccu.columns = 0; + mTokenAccu.columnsBefore = 0; // Now loop through all the lines. The indices are valid for Lines. BufferCoord selectionBegin = edit->blockBegin(); BufferCoord selectionEnd= edit->blockEnd(); @@ -908,7 +903,7 @@ void SynEditTextPainter::paintLines() } else { nTokenColumnLen = edit->mDocument->lineColumns(vLine-1); } - if (edit->mOptions.testFlag(eoShowSpecialChars) && (!bLineSelected) && (!bSpecialLine) && (nTokenColumnLen < vLastChar)) { + if (edit->mOptions.testFlag(eoShowLineBreaks) && (!bLineSelected) && (!bSpecialLine) && (nTokenColumnLen < vLastChar)) { sToken = sToken + LineBreakGlyph; nTokenColumnLen += edit->charColumns(LineBreakGlyph); } @@ -955,7 +950,7 @@ void SynEditTextPainter::paintLines() // of ExtTextOut calls necessary. This depends on the selection state // or the line having special colors. For spaces the foreground color // is ignored as well. - TokenAccu.Columns = 0; + mTokenAccu.columns = 0; nTokenColumnsBefore = 0; // Test first whether anything of this token is visible. while (!edit->mSyntaxer->eol()) { @@ -1014,38 +1009,40 @@ void SynEditTextPainter::paintLines() } } } + bool showGlyph=false; + if (attr && attr->tokenType() == TokenType::Space) { + int pos = edit->mSyntaxer->getTokenPos(); + if (pos==0) { + showGlyph = edit->mOptions.testFlag(eoShowLeadingSpaces); + } else if (pos+sToken.length()==sLine.length()) { + showGlyph = edit->mOptions.testFlag(eoShowTrailingSpaces); + } else { + showGlyph = edit->mOptions.testFlag(eoShowInnerSpaces); + } + } addHighlightToken(sToken, nTokenColumnsBefore - (vFirstChar - FirstCol), - nTokenColumnLen, vLine,attr); + nTokenColumnLen, vLine,attr, showGlyph); } nTokenColumnsBefore+=nTokenColumnLen; // Let the highlighter scan the next token. edit->mSyntaxer->next(); } - // Don't assume HL.GetTokenPos is valid after HL.GetEOL == True. - //nTokenColumnsBefore += edit->stringColumns(sToken,nTokenColumnsBefore); - if (edit->mSyntaxer->eol() && (nTokenColumnsBefore < vLastChar)) { - int lineColumns = edit->mDocument->lineColumns(vLine-1); - // Draw text that couldn't be parsed by the highlighter, if any. - if (nTokenColumnsBefore < lineColumns) { - if (nTokenColumnsBefore + 1 < vFirstChar) - nTokenColumnsBefore = vFirstChar - 1; - nTokenColumnLen = std::min(lineColumns, vLastChar) - (nTokenColumnsBefore + 1); - if (nTokenColumnLen > 0) { - sToken = edit->substringByColumns(sLine,nTokenColumnsBefore+1,nTokenColumnLen); - addHighlightToken(sToken, nTokenColumnsBefore - (vFirstChar - FirstCol), - nTokenColumnLen, vLine, PTokenAttribute()); - } - } - // Draw LineBreak glyph. - if (edit->mOptions.testFlag(eoShowSpecialChars) -// && (!bLineSelected) -// && (!bSpecialLine) - && (edit->mDocument->lineColumns(vLine-1) < vLastChar)) { - addHighlightToken(LineBreakGlyph, - edit->mDocument->lineColumns(vLine-1) - (vFirstChar - FirstCol), - edit->charColumns(LineBreakGlyph),vLine, edit->mSyntaxer->whitespaceAttribute()); - } - } +// // Don't assume HL.GetTokenPos is valid after HL.GetEOL == True. +// //nTokenColumnsBefore += edit->stringColumns(sToken,nTokenColumnsBefore); +// if (edit->mSyntaxer->eol() && (nTokenColumnsBefore < vLastChar)) { +// int lineColumns = edit->mDocument->lineColumns(vLine-1); +// // Draw text that couldn't be parsed by the highlighter, if any. +// if (nTokenColumnsBefore < lineColumns) { +// if (nTokenColumnsBefore + 1 < vFirstChar) +// nTokenColumnsBefore = vFirstChar - 1; +// nTokenColumnLen = std::min(lineColumns, vLastChar) - (nTokenColumnsBefore + 1); +// if (nTokenColumnLen > 0) { +// sToken = edit->substringByColumns(sLine,nTokenColumnsBefore+1,nTokenColumnLen); +// addHighlightToken(sToken, nTokenColumnsBefore - (vFirstChar - FirstCol), +// nTokenColumnLen, vLine, PTokenAttribute(),false); +// } +// } +// } // Paint folding foldRange = edit->foldStartAtLine(vLine); @@ -1055,9 +1052,18 @@ void SynEditTextPainter::paintLines() attr = edit->mSyntaxer->symbolAttribute(); getBraceColorAttr(edit->mSyntaxer->getState().braceLevel,attr); addHighlightToken(sFold,edit->mDocument->lineColumns(vLine-1) - (vFirstChar - FirstCol) - , nFold, vLine, attr); + , nFold, vLine, attr,false); + } else { + // Draw LineBreak glyph. + if (edit->mOptions.testFlag(eoShowLineBreaks) + && (!bLineSelected) + && (!bSpecialLine) + && (edit->mDocument->lineColumns(vLine-1) < vLastChar)) { + addHighlightToken(LineBreakGlyph, + edit->mDocument->lineColumns(vLine-1) - (vFirstChar - FirstCol), + edit->charColumns(LineBreakGlyph),vLine, edit->mSyntaxer->whitespaceAttribute(),false); + } } - // Draw anything that's left in the TokenAccu record. Fill to the end // of the invalid area with the correct colors. paintHighlightToken(true); diff --git a/libs/qsynedit/qsynedit/TextPainter.h b/libs/qsynedit/qsynedit/TextPainter.h index 9cc4d914..b07dc73c 100644 --- a/libs/qsynedit/qsynedit/TextPainter.h +++ b/libs/qsynedit/qsynedit/TextPainter.h @@ -29,12 +29,12 @@ class SynEdit; class SynEditTextPainter { struct SynTokenAccu { - int Columns; - int ColumnsBefore; + int columns; + int columnsBefore; QString s; - QColor FG; - QColor BG; - FontStyles Style; + QColor foreground; + QColor background; + FontStyles style; bool showSpecialGlyphs; }; @@ -55,7 +55,7 @@ private: void paintEditAreas(const EditingAreaList& areaList); void paintHighlightToken(bool bFillToEOL); void addHighlightToken(const QString& token, int columnsBefore, int tokenColumns, - int cLine, PTokenAttribute p_Attri); + int cLine, PTokenAttribute p_Attri, bool showGlyphs); void paintFoldAttributes(); void getBraceColorAttr(int level, PTokenAttribute &attr); @@ -84,7 +84,7 @@ private: QRect AClip; int aFirstRow, aLastRow, FirstCol, LastCol; - SynTokenAccu TokenAccu; + SynTokenAccu mTokenAccu; }; }