use point as the unit for font size in configuration

This commit is contained in:
Roy Qu 2021-12-17 09:05:01 +08:00
parent b2caf38e89
commit 959cdab6cb
5 changed files with 25 additions and 11 deletions

View File

@ -4078,7 +4078,7 @@ void Editor::applySettings()
codeFolding().fillIndents = pSettings->editor().fillIndents(); codeFolding().fillIndents = pSettings->editor().fillIndents();
QFont f=QFont(pSettings->editor().fontName()); QFont f=QFont(pSettings->editor().fontName());
f.setPixelSize(pSettings->editor().fontSize()); f.setPixelSize(pointToPixel(pSettings->editor().fontSize()));
f.setStyleStrategy(QFont::PreferAntialias); f.setStyleStrategy(QFont::PreferAntialias);
setFont(f); setFont(f);
@ -4089,10 +4089,10 @@ void Editor::applySettings()
gutter().setUseFontStyle(pSettings->editor().gutterUseCustomFont()); gutter().setUseFontStyle(pSettings->editor().gutterUseCustomFont());
if (pSettings->editor().gutterUseCustomFont()) { if (pSettings->editor().gutterUseCustomFont()) {
f=QFont(pSettings->editor().gutterFontName()); f=QFont(pSettings->editor().gutterFontName());
f.setPixelSize(pSettings->editor().gutterFontSize()); f.setPixelSize(pointToPixel(pSettings->editor().gutterFontSize()));
} else { } else {
f=QFont(pSettings->editor().fontName()); f=QFont(pSettings->editor().fontName());
f.setPixelSize(pSettings->editor().fontSize()); f.setPixelSize(pointToPixel(pSettings->editor().fontSize()));
} }
f.setStyleStrategy(QFont::PreferAntialias); f.setStyleStrategy(QFont::PreferAntialias);
gutter().setFont(f); gutter().setFont(f);

View File

@ -540,13 +540,13 @@ void MainWindow::applySettings()
updateEditorColorSchemes(); updateEditorColorSchemes();
QFont font(pSettings->environment().interfaceFont()); QFont font(pSettings->environment().interfaceFont());
font.setPixelSize(pSettings->environment().interfaceFontSize()); font.setPixelSize(pointToPixel(pSettings->environment().interfaceFontSize()));
font.setStyleStrategy(QFont::PreferAntialias); font.setStyleStrategy(QFont::PreferAntialias);
qApp->setFont(font); qApp->setFont(font);
this->setFont(font); this->setFont(font);
QFont caseEditorFont(pSettings->executor().caseEditorFontName()); QFont caseEditorFont(pSettings->executor().caseEditorFontName());
caseEditorFont.setPixelSize(pSettings->executor().caseEditorFontSize()); caseEditorFont.setPixelSize(pointToPixel(pSettings->executor().caseEditorFontSize()));
font.setStyleStrategy(QFont::PreferAntialias); font.setStyleStrategy(QFont::PreferAntialias);
ui->txtProblemCaseInput->setFont(caseEditorFont); ui->txtProblemCaseInput->setFont(caseEditorFont);
ui->txtProblemCaseOutput->setFont(caseEditorFont); ui->txtProblemCaseOutput->setFont(caseEditorFont);
@ -1071,7 +1071,7 @@ void MainWindow::updateCompilerSet()
void MainWindow::updateDebuggerSettings() void MainWindow::updateDebuggerSettings()
{ {
QFont font(pSettings->debugger().fontName()); QFont font(pSettings->debugger().fontName());
font.setPixelSize(pSettings->debugger().fontSize()); font.setPixelSize(pointToPixel(pSettings->debugger().fontSize()));
ui->debugConsole->setFont(font); ui->debugConsole->setFont(font);
ui->txtMemoryView->setFont(font); ui->txtMemoryView->setFont(font);
ui->txtLocals->setFont(font); ui->txtLocals->setFont(font);

View File

@ -1167,7 +1167,7 @@ void Settings::Editor::doLoad()
//Font //Font
//font //font
mFontName = stringValue("font_name","consolas"); mFontName = stringValue("font_name","consolas");
mFontSize = intValue("font_size",16*qApp->desktop()->logicalDpiY()/96); mFontSize = intValue("font_size",14);
mFontOnlyMonospaced = boolValue("font_only_monospaced",true); mFontOnlyMonospaced = boolValue("font_only_monospaced",true);
//gutter //gutter
@ -1181,7 +1181,7 @@ void Settings::Editor::doLoad()
mGutterLineNumbersStartZero = boolValue("gutter_line_numbers_start_zero",false); mGutterLineNumbersStartZero = boolValue("gutter_line_numbers_start_zero",false);
mGutterUseCustomFont = boolValue("gutter_use_custom_font",false); mGutterUseCustomFont = boolValue("gutter_use_custom_font",false);
mGutterFontName = stringValue("gutter_font_name","consolas"); mGutterFontName = stringValue("gutter_font_name","consolas");
mGutterFontSize = intValue("gutter_font_size",16*qApp->desktop()->logicalDpiY()/96); mGutterFontSize = intValue("gutter_font_size",14);
mGutterFontOnlyMonospaced = boolValue("gutter_font_only_monospaced",true); mGutterFontOnlyMonospaced = boolValue("gutter_font_only_monospaced",true);
//copy //copy
@ -2755,7 +2755,7 @@ void Settings::Environment::doLoad()
} }
} }
mInterfaceFont = stringValue("interface_font",defaultFontName); mInterfaceFont = stringValue("interface_font",defaultFontName);
mInterfaceFontSize = intValue("interface_font_size",12*qApp->desktop()->logicalDpiY()/96); mInterfaceFontSize = intValue("interface_font_size",10);
mLanguage = stringValue("language", QLocale::system().name()); mLanguage = stringValue("language", QLocale::system().name());
mCurrentFolder = stringValue("current_folder",QDir::currentPath()); mCurrentFolder = stringValue("current_folder",QDir::currentPath());
@ -3007,7 +3007,7 @@ void Settings::Executor::doLoad()
mCompetivieCompanionPort = intValue("competitive_companion_port",10045); mCompetivieCompanionPort = intValue("competitive_companion_port",10045);
mIgnoreSpacesWhenValidatingCases = boolValue("ignore_spaces_when_validating_cases",false); mIgnoreSpacesWhenValidatingCases = boolValue("ignore_spaces_when_validating_cases",false);
mCaseEditorFontName = stringValue("case_editor_font_name","consolas"); mCaseEditorFontName = stringValue("case_editor_font_name","consolas");
mCaseEditorFontSize = intValue("case_editor_font_size",14*qApp->desktop()->logicalDpiY()/96); mCaseEditorFontSize = intValue("case_editor_font_size",10);
mCaseEditorFontOnlyMonospaced = boolValue("case_editor_font_only_monospaced",true); mCaseEditorFontOnlyMonospaced = boolValue("case_editor_font_only_monospaced",true);
} }
@ -3171,7 +3171,7 @@ void Settings::Debugger::doLoad()
mShowDetailLog = boolValue("show_detail_log",false); mShowDetailLog = boolValue("show_detail_log",false);
mFontName = stringValue("font_name","Consolas"); mFontName = stringValue("font_name","Consolas");
mOnlyShowMono = boolValue("only_show_mono",true); mOnlyShowMono = boolValue("only_show_mono",true);
mFontSize = intValue("font_size",12*qApp->desktop()->logicalDpiY()/96); mFontSize = intValue("font_size",12);
mUseIntelStyle = boolValue("use_intel_style",true); mUseIntelStyle = boolValue("use_intel_style",true);
mBlendMode = boolValue("blend_mode",true); mBlendMode = boolValue("blend_mode",true);
mSkipSystemLibraries = boolValue("skip_system_lib",true); mSkipSystemLibraries = boolValue("skip_system_lib",true);

View File

@ -15,6 +15,7 @@
#include <QStyleFactory> #include <QStyleFactory>
#include <QDateTime> #include <QDateTime>
#include <QColor> #include <QColor>
#include <QDesktopWidget>
#include "parser/cppparser.h" #include "parser/cppparser.h"
#include "settings.h" #include "settings.h"
#include "mainwindow.h" #include "mainwindow.h"
@ -957,3 +958,13 @@ QString localizePath(const QString &path)
result.replace("/",QDir::separator()); result.replace("/",QDir::separator());
return result; return result;
} }
float pointToPixel(float point)
{
return point * qApp->desktop()->logicalDpiY() / 72;
}
float pixelToPoint(float pixel)
{
return pixel * 72 / qApp->desktop()->logicalDpiY();
}

View File

@ -204,6 +204,9 @@ bool readRegistry(HKEY key,const QByteArray& subKey, const QByteArray& name, QSt
class CppParser; class CppParser;
void resetCppParser(std::shared_ptr<CppParser> parser); void resetCppParser(std::shared_ptr<CppParser> parser);
float pointToPixel(float point);
float pixelToPoint(float pixel);
/** /**
* from https://github.com/Microsoft/GSL * from https://github.com/Microsoft/GSL