From 74fdf1ebef1995176df9d451111f419486464949 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 20 Dec 2021 09:36:18 +0800 Subject: [PATCH] - fix: left and right gutter offset settings not correctly saved - enhancement: use svg icons for editor gutter, and they can zoom with font now --- NEWS.md | 2 + RedPandaIDE/editor.cpp | 24 ++++++----- RedPandaIDE/icons.qrc | 1 + RedPandaIDE/iconsmanager.cpp | 16 ++++++- RedPandaIDE/iconsmanager.h | 2 + RedPandaIDE/images/editor/breakpoint.svg | 54 ++++++++++++++++++++++++ RedPandaIDE/mainwindow.cpp | 2 + RedPandaIDE/settings.cpp | 4 +- 8 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 RedPandaIDE/images/editor/breakpoint.svg diff --git a/NEWS.md b/NEWS.md index e50341cf..e77c198d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ Version 0.11.4 For Dev-C++ 7 Beta - fix: compiler set's custom link parameters not used when compiling - fix: code completion doesn't work when input inside () or [] - fix: auto indent processing error when input '{' in the middle of if statement + - fix: left and right gutter offset settings not correctly saved + - enhancement: use svg icons for editor gutter, and they can zoom with font now Version 0.11.3 For Dev-C++ 7 Beta - fix: use pixel size for fonts, to fit different dpi in multiple displays diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 271eec69..5e9c248b 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -787,13 +787,12 @@ void Editor::onGutterPaint(QPainter &painter, int aLine, int X, int Y) { // Get point where to draw marks //X := (fText.Gutter.RealGutterWidth(fText.CharWidth) - fText.Gutter.RightOffset) div 2 - 3; - X = 5; - Y += (this->textHeight() - 16) / 2; + PIcon icon; if (mActiveBreakpointLine == aLine) { - painter.drawPixmap(X,Y,*(pIconsManager->activeBreakpoint())); + icon = pIconsManager->activeBreakpoint(); } else if (hasBreakpoint(aLine)) { - painter.drawPixmap(X,Y,*(pIconsManager->breakpoint())); + icon = pIconsManager->breakpoint(); } else { PSyntaxIssueList lst = getSyntaxIssuesAtLine(aLine); if (lst) { @@ -805,16 +804,19 @@ void Editor::onGutterPaint(QPainter &painter, int aLine, int X, int Y) } } if (hasError) { - painter.drawPixmap(X,Y,*(pIconsManager->syntaxError())); + icon = pIconsManager->syntaxError(); } else { - painter.drawPixmap(X,Y,*(pIconsManager->syntaxWarning())); + icon = pIconsManager->syntaxWarning(); } - return; - } - if (hasBookmark(aLine)) { - painter.drawPixmap(X,Y,*(pIconsManager->bookmark())); + } else if (hasBookmark(aLine)) { + icon = pIconsManager->bookmark(); } } + if (icon) { + X = 5; + Y += (this->textHeight() - icon->height()) / 2; + painter.drawPixmap(X,Y,*icon); + } } void Editor::onGetEditingAreas(int Line, SynEditingAreaList &areaList) @@ -4049,7 +4051,7 @@ void Editor::applySettings() setFont(f); // Set gutter properties - gutter().setLeftOffset(pSettings->editor().gutterLeftOffset()); + gutter().setLeftOffset(pointToPixel(pSettings->editor().fontSize()) + pSettings->editor().gutterLeftOffset()); gutter().setRightOffset(pSettings->editor().gutterRightOffset()); gutter().setBorderStyle(SynGutterBorderStyle::None); gutter().setUseFontStyle(pSettings->editor().gutterUseCustomFont()); diff --git a/RedPandaIDE/icons.qrc b/RedPandaIDE/icons.qrc index 4727b69d..e686bf63 100644 --- a/RedPandaIDE/icons.qrc +++ b/RedPandaIDE/icons.qrc @@ -490,5 +490,6 @@ images/newlook24/091-openproblemanswer.png images/newlook24/092-runallproblemcases.png images/newlook24/093-pause.png + images/editor/breakpoint.svg diff --git a/RedPandaIDE/iconsmanager.cpp b/RedPandaIDE/iconsmanager.cpp index 000c1a18..374f5457 100644 --- a/RedPandaIDE/iconsmanager.cpp +++ b/RedPandaIDE/iconsmanager.cpp @@ -1,12 +1,26 @@ #include "iconsmanager.h" +#include +#include + IconsManager* pIconsManager; IconsManager::IconsManager(QObject *parent) : QObject(parent) { + updateIcons(24); + +} + +void IconsManager::updateIcons(int size) +{ + QSvgRenderer renderer(QString(":/icons/images/editor/breakpoint.svg")); + mBreakpoint = std::make_shared(size,size); + mBreakpoint->fill(Qt::transparent); + QPainter painter(mBreakpoint.get()); + renderer.render(&painter,mBreakpoint->rect()); + mSyntaxError = std::make_shared(":/icons/images/editor/syntaxerror.png"); mSyntaxWarning = std::make_shared(":/icons/images/editor/syntaxwarning.png"); - mBreakpoint = std::make_shared(":/icons/images/editor/breakpoint.png"); mActiveBreakpoint = std::make_shared(":/icons/images/editor/currentline.png"); mBookmark = std::make_shared(":/icons/images/editor/bookmark.png"); mFolder = std::make_shared(":/icons/images/newlook24/090-explorer.png"); diff --git a/RedPandaIDE/iconsmanager.h b/RedPandaIDE/iconsmanager.h index 5cf72a8b..5f3d87ab 100644 --- a/RedPandaIDE/iconsmanager.h +++ b/RedPandaIDE/iconsmanager.h @@ -12,6 +12,8 @@ class IconsManager : public QObject public: explicit IconsManager(QObject *parent = nullptr); + void updateIcons(int size); + const PIcon &syntaxError() const; const PIcon &syntaxWarning() const; diff --git a/RedPandaIDE/images/editor/breakpoint.svg b/RedPandaIDE/images/editor/breakpoint.svg new file mode 100644 index 00000000..199039b8 --- /dev/null +++ b/RedPandaIDE/images/editor/breakpoint.svg @@ -0,0 +1,54 @@ + + + + + + + + + + + diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index b0b6f6a0..91c75497 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -21,6 +21,7 @@ #include "problems/problemcasevalidator.h" #include "widgets/ojproblempropertywidget.h" #include "version.h" +#include "iconsmanager.h" #include #include @@ -320,6 +321,7 @@ void MainWindow::updateForEncodingInfo() { void MainWindow::updateEditorSettings() { + pIconsManager->updateIcons(pointToPixel(pSettings->editor().fontSize())); mEditorList->applySettings(); } diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 1ae656b9..69d7c533 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -1059,6 +1059,8 @@ void Settings::Editor::doSave() //gutter saveValue("gutter_visible", mGutterVisible); saveValue("gutter_auto_size", mGutterAutoSize); + saveValue("gutter_left_offset",mGutterLeftOffset); + saveValue("gutter_right_offset",mGutterRightOffset); saveValue("gutter_digits_count", mGutterDigitsCount); saveValue("gutter_show_line_numbers",mGutterShowLineNumbers); saveValue("gutter_add_leading_zero",mGutterAddLeadingZero); @@ -1173,7 +1175,7 @@ void Settings::Editor::doLoad() //gutter mGutterVisible = boolValue("gutter_visible",true); mGutterAutoSize = boolValue("gutter_auto_size",true); - mGutterLeftOffset = intValue("gutter_left_offset",28); + mGutterLeftOffset = intValue("gutter_left_offset",6); mGutterRightOffset = intValue("gutter_right_offset",24); mGutterDigitsCount = intValue("gutter_digits_count",1); mGutterShowLineNumbers = boolValue("gutter_show_line_numbers",true);