From 46b273a88d9b512f71754194431dbe7e06ad0110 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 14 Mar 2024 20:06:45 +0800 Subject: [PATCH] - enhancement: Folding button scales with editor font. --- NEWS.md | 1 + RedPandaIDE/editor.cpp | 2 +- RedPandaIDE/settings.cpp | 8 ++++++-- libs/qsynedit/qsynedit/painter.cpp | 25 +++++++++++++++---------- libs/qsynedit/qsynedit/qsynedit.cpp | 3 +-- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/NEWS.md b/NEWS.md index b9017c3c..df99ec75 100644 --- a/NEWS.md +++ b/NEWS.md @@ -55,6 +55,7 @@ Red Panda C++ Version 2.27 - enhancement: Make output in the debug console cleaner. - enhancement: Execute the last debug command in the debug console if ENTER pressed. - change: When debugging, don't auto set focus to the editor. + - enhancement: Folding button scales with editor font. Red Panda C++ Version 2.26 - enhancement: Code suggestion for embedded std::vectors. diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 2cf04d5f..bfc16fbc 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -5275,7 +5275,7 @@ void Editor::applySettings() // Set gutter properties gutter().setLeftOffset(pointToPixel(pSettings->editor().fontSize()) + pSettings->editor().gutterLeftOffset()); - gutter().setRightOffset(pSettings->editor().gutterRightOffset()); + gutter().setRightOffset(pointToPixel(pSettings->editor().fontSize()) + pSettings->editor().gutterRightOffset()); gutter().setBorderStyle(QSynedit::GutterBorderStyle::None); gutter().setUseFontStyle(pSettings->editor().gutterUseCustomFont()); if (pSettings->editor().gutterUseCustomFont()) { diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index afbad3d9..2d54cdf0 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -1365,7 +1365,7 @@ void Settings::Editor::doSave() saveValue("gutter_visible", mGutterVisible); saveValue("gutter_auto_size", mGutterAutoSize); saveValue("gutter_left_offset",mGutterLeftOffset); - saveValue("gutter_right_offset",mGutterRightOffset); + saveValue("gutter_right_offset2",mGutterRightOffset); saveValue("gutter_digits_count", mGutterDigitsCount); saveValue("gutter_show_line_numbers",mGutterShowLineNumbers); saveValue("gutter_add_leading_zero",mGutterAddLeadingZero); @@ -1514,7 +1514,11 @@ void Settings::Editor::doLoad() mGutterVisible = boolValue("gutter_visible",true); mGutterAutoSize = boolValue("gutter_auto_size",true); mGutterLeftOffset = intValue("gutter_left_offset",6); - mGutterRightOffset = intValue("gutter_right_offset",24); + mGutterRightOffset = intValue("gutter_right_offset",-1); + if (mGutterRightOffset>0) + mGutterRightOffset = std::max(0, mGutterRightOffset-20); + else + mGutterRightOffset = intValue("gutter_right_offset2",4); mGutterDigitsCount = intValue("gutter_digits_count",1); mGutterShowLineNumbers = boolValue("gutter_show_line_numbers",true); mGutterAddLeadingZero = boolValue("gutter_add_leading_zero",false); diff --git a/libs/qsynedit/qsynedit/painter.cpp b/libs/qsynedit/qsynedit/painter.cpp index 34475d43..0684a2b4 100644 --- a/libs/qsynedit/qsynedit/painter.cpp +++ b/libs/qsynedit/qsynedit/painter.cpp @@ -160,6 +160,7 @@ void QSynEditPainter::paintGutter(const QRect& clip) // Draw the folding lines and squares if (mEdit->useCodeFolding()) { + int lineWidth = std::max(0.0,std::ceil(mEdit->font().pixelSize() / 15)); for (int row = mLastRow; row>= mFirstRow; row--) { int line = mEdit->rowToLine(row); if ((line > mEdit->mDocument->count()) && (mEdit->mDocument->count() != 0)) @@ -171,7 +172,7 @@ void QSynEditPainter::paintGutter(const QRect& clip) rcFold.setRight(rcFold.left() + mEdit->mGutter.rightOffset() - 4); rcFold.setBottom(rcFold.top() + mEdit->mTextHeight); - mPainter->setPen(mEdit->mCodeFolding.folderBarLinesColor); + mPainter->setPen(QPen(mEdit->mCodeFolding.folderBarLinesColor,lineWidth)); // Need to paint a line? if (mEdit->foldAroundLine(line)) { @@ -200,24 +201,28 @@ void QSynEditPainter::paintGutter(const QRect& clip) // make a square rect inflateRect(rcFold,-2, 0); - rcFold.setTop( - rcFold.top() + ((mEdit->mTextHeight - rcFold.width()) / 2)); - rcFold.setBottom(rcFold.top() + rcFold.width()); + int size = std::min(mEdit->font().pixelSize() * 4 / 5, mEdit->mGutter.rightOffset()) - lineWidth; + float centerX = rcFold.left() + rcFold.width() / 2.0; + float centerY = rcFold.top() + rcFold.height() / 2.0; + float halfSize = size / 2.0; + rcFold.setLeft(centerX - halfSize); + rcFold.setRight(centerX + halfSize); + rcFold.setTop(centerY - halfSize); + rcFold.setBottom(centerY + halfSize); // Paint the square the user can click on mPainter->setBrush(mEdit->mGutter.color()); - mPainter->setPen(mEdit->mCodeFolding.folderBarLinesColor); + //mPainter->setPen(mEdit->mCodeFolding.folderBarLinesColor); mPainter->drawRect(rcFold); // Paint minus sign mPainter->drawLine( - rcFold.left() + 2, rcFold.top() + (rcFold.height() / 2 ), - rcFold.right() - 2, rcFold.top() + (rcFold.height() / 2 )); + rcFold.left() + lineWidth * 2 , centerY, + rcFold.right() - lineWidth * 2 , centerY ); // Paint vertical line of plus sign if (foldRange->collapsed) { - x = rcFold.left() + (rcFold.width() / 2); - mPainter->drawLine(x, rcFold.top() + 2, - x, rcFold.bottom() - 2); + mPainter->drawLine(centerX, rcFold.top() + lineWidth * 2, + centerX, rcFold.bottom() - lineWidth * 2 ); } } } diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index c59b6629..b5e9bbec 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -3220,8 +3220,7 @@ void QSynEdit::recalcCharExtent() mTextHeight = 0; mCharWidth = 0; QFontMetrics fm(font()); - QFontMetrics fm2(font()); - mTextHeight = std::max(fm.lineSpacing(),fm2.lineSpacing()); + mTextHeight = fm.lineSpacing(); mCharWidth = fm.horizontalAdvance("M"); if (hasStyles[0]) { // has bold font