From b2caf38e891cd60bfbaef48b33d80b2c633d840f Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 16 Dec 2021 19:14:14 +0800 Subject: [PATCH] - fix: use pixel size for fonts, to fit different dpi in multiple displays --- NEWS.md | 3 +++ RedPandaIDE/editor.cpp | 9 +++++--- RedPandaIDE/mainwindow.cpp | 12 +++++------ RedPandaIDE/qsynedit/SynEdit.cpp | 21 ++++++------------- RedPandaIDE/settings.cpp | 17 ++++++++------- .../widgets/ojproblempropertywidget.cpp | 2 +- 6 files changed, 31 insertions(+), 33 deletions(-) diff --git a/NEWS.md b/NEWS.md index 861cb0b1..01f75e26 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +Version 0.11.3 For Dev-C++ 7 Beta + - fix: use pixel size for fonts, to fit different dpi in multiple displays + Version 0.11.2 For Dev-C++ 7 Beta - fix: button "run all problem cases" not disabled when compiling or debugging - enhancement: set font for problem case input/output textedits diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 72a416ed..bdbda6c2 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -4077,7 +4077,8 @@ void Editor::applySettings() codeFolding().indentGuidesColor = pSettings->editor().indentLineColor(); codeFolding().fillIndents = pSettings->editor().fillIndents(); - QFont f=QFont(pSettings->editor().fontName(),pSettings->editor().fontSize()); + QFont f=QFont(pSettings->editor().fontName()); + f.setPixelSize(pSettings->editor().fontSize()); f.setStyleStrategy(QFont::PreferAntialias); setFont(f); @@ -4087,9 +4088,11 @@ void Editor::applySettings() gutter().setBorderStyle(SynGutterBorderStyle::None); gutter().setUseFontStyle(pSettings->editor().gutterUseCustomFont()); if (pSettings->editor().gutterUseCustomFont()) { - f=QFont(pSettings->editor().gutterFontName(),pSettings->editor().gutterFontSize()); + f=QFont(pSettings->editor().gutterFontName()); + f.setPixelSize(pSettings->editor().gutterFontSize()); } else { - f=QFont(pSettings->editor().fontName(),pSettings->editor().fontSize()); + f=QFont(pSettings->editor().fontName()); + f.setPixelSize(pSettings->editor().fontSize()); } f.setStyleStrategy(QFont::PreferAntialias); gutter().setFont(f); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 51a5a280..70752553 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -539,14 +539,14 @@ void MainWindow::applySettings() mFileInfoStatus->setPalette(appTheme->palette()); updateEditorColorSchemes(); - QFont font(pSettings->environment().interfaceFont(), - pSettings->environment().interfaceFontSize()); + QFont font(pSettings->environment().interfaceFont()); + font.setPixelSize(pSettings->environment().interfaceFontSize()); font.setStyleStrategy(QFont::PreferAntialias); qApp->setFont(font); this->setFont(font); - QFont caseEditorFont(pSettings->executor().caseEditorFontName(), - pSettings->executor().caseEditorFontSize()); + QFont caseEditorFont(pSettings->executor().caseEditorFontName()); + caseEditorFont.setPixelSize(pSettings->executor().caseEditorFontSize()); font.setStyleStrategy(QFont::PreferAntialias); ui->txtProblemCaseInput->setFont(caseEditorFont); ui->txtProblemCaseOutput->setFont(caseEditorFont); @@ -1070,8 +1070,8 @@ void MainWindow::updateCompilerSet() void MainWindow::updateDebuggerSettings() { - QFont font(pSettings->debugger().fontName(), - pSettings->debugger().fontSize()); + QFont font(pSettings->debugger().fontName()); + font.setPixelSize(pSettings->debugger().fontSize()); ui->debugConsole->setFont(font); ui->txtMemoryView->setFont(font); ui->txtLocals->setFont(font); diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index a7924814..f612624f 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -21,6 +21,7 @@ #include #include #include +#include SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) { @@ -148,6 +149,7 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) //setMouseTracking(true); setAcceptDrops(true); + } int SynEdit::displayLineCount() const @@ -4442,20 +4444,20 @@ void SynEdit::doRedoItem() void SynEdit::doZoomIn() { QFont newFont = font(); - int size = newFont.pointSize(); + int size = newFont.pixelSize(); size++; - newFont.setPointSize(size); + newFont.setPixelSize(size); setFont(newFont); } void SynEdit::doZoomOut() { QFont newFont = font(); - int size = newFont.pointSize(); + int size = newFont.pixelSize(); size--; if (size<2) size = 2; - newFont.setPointSize(size); + newFont.setPixelSize(size); setFont(newFont); } @@ -5818,17 +5820,6 @@ void SynEdit::paintEvent(QPaintEvent *event) // Now paint everything while the caret is hidden. QPainter painter(viewport()); - if (fontMetrics().fontDpi()!=painter.device()->logicalDpiX()) { - QFont f; - f.setFamily(font().family()); - f.setPointSize(font().pointSize()); - f.setBold(font().bold()); - f.setItalic(font().bold()); - f.setUnderline(font().underline()); - f.setStrikeOut(font().strikeOut()); - setFont(f); - return; - } //Get the invalidated rect. QRect rcClip = event->rect(); QRect rcCaret = calculateCaretRect(); diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 9c5d5bb5..3e599fbd 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -9,6 +9,7 @@ #include #include #include +#include const char ValueToChar[28] = {'0', '1', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', @@ -1166,7 +1167,7 @@ void Settings::Editor::doLoad() //Font //font mFontName = stringValue("font_name","consolas"); - mFontSize = intValue("font_size",14); + mFontSize = intValue("font_size",16*qApp->desktop()->logicalDpiY()/96); mFontOnlyMonospaced = boolValue("font_only_monospaced",true); //gutter @@ -1180,7 +1181,7 @@ void Settings::Editor::doLoad() mGutterLineNumbersStartZero = boolValue("gutter_line_numbers_start_zero",false); mGutterUseCustomFont = boolValue("gutter_use_custom_font",false); mGutterFontName = stringValue("gutter_font_name","consolas"); - mGutterFontSize = intValue("gutter_font_size",14); + mGutterFontSize = intValue("gutter_font_size",16*qApp->desktop()->logicalDpiY()/96); mGutterFontOnlyMonospaced = boolValue("gutter_font_only_monospaced",true); //copy @@ -2753,8 +2754,8 @@ void Settings::Environment::doLoad() defaultFontName = fontName; } } - mInterfaceFont = stringValue("interface font",defaultFontName); - mInterfaceFontSize = intValue("interface font size",10); + mInterfaceFont = stringValue("interface_font",defaultFontName); + mInterfaceFontSize = intValue("interface_font_size",12*qApp->desktop()->logicalDpiY()/96); mLanguage = stringValue("language", QLocale::system().name()); mCurrentFolder = stringValue("current_folder",QDir::currentPath()); @@ -2811,8 +2812,8 @@ void Settings::Environment::doSave() { //Appearence saveValue("theme", mTheme); - saveValue("interface font", mInterfaceFont); - saveValue("interface font size", mInterfaceFontSize); + saveValue("interface_font", mInterfaceFont); + saveValue("interface_font_size", mInterfaceFontSize); saveValue("language", mLanguage); saveValue("current_folder",mCurrentFolder); @@ -3006,7 +3007,7 @@ void Settings::Executor::doLoad() mCompetivieCompanionPort = intValue("competitive_companion_port",10045); mIgnoreSpacesWhenValidatingCases = boolValue("ignore_spaces_when_validating_cases",false); mCaseEditorFontName = stringValue("case_editor_font_name","consolas"); - mCaseEditorFontSize = intValue("case_editor_font_size",14); + mCaseEditorFontSize = intValue("case_editor_font_size",14*qApp->desktop()->logicalDpiY()/96); mCaseEditorFontOnlyMonospaced = boolValue("case_editor_font_only_monospaced",true); } @@ -3170,7 +3171,7 @@ void Settings::Debugger::doLoad() mShowDetailLog = boolValue("show_detail_log",false); mFontName = stringValue("font_name","Consolas"); mOnlyShowMono = boolValue("only_show_mono",true); - mFontSize = intValue("font_size",12); + mFontSize = intValue("font_size",12*qApp->desktop()->logicalDpiY()/96); mUseIntelStyle = boolValue("use_intel_style",true); mBlendMode = boolValue("blend_mode",true); mSkipSystemLibraries = boolValue("skip_system_lib",true); diff --git a/RedPandaIDE/widgets/ojproblempropertywidget.cpp b/RedPandaIDE/widgets/ojproblempropertywidget.cpp index 597444af..dc6b8840 100644 --- a/RedPandaIDE/widgets/ojproblempropertywidget.cpp +++ b/RedPandaIDE/widgets/ojproblempropertywidget.cpp @@ -16,7 +16,7 @@ OJProblemPropertyWidget::~OJProblemPropertyWidget() void OJProblemPropertyWidget::setName(const QString &name) { QFont f = ui->lbName->font(); - f.setPointSize(f.pointSize()+2); + f.setPixelSize(f.pixelSize()+2); f.setBold(true); ui->lbName->setFont(f); ui->lbName->setText(name);