enhancement: enable/disable fallback fonts

This commit is contained in:
Roy Qu 2024-02-27 13:05:38 +08:00
parent 45118f5251
commit 451e201881
7 changed files with 88 additions and 35 deletions

View File

@ -5285,15 +5285,8 @@ void Editor::applySettings()
codeFolding().indentGuidesColor = pSettings->editor().indentLineColor();
codeFolding().fillIndents = pSettings->editor().fillIndents();
QStringList fontFamilies{
pSettings->editor().fontName(),
pSettings->editor().fallbackFontName(),
pSettings->editor().fallbackFontName2(),
pSettings->editor().fallbackFontName3(),
};
QFont f=QFont();
f.setFamilies(fontFamilies);
f.setFamilies(pSettings->editor().fontFamilies());
f.setPixelSize(pointToPixel(pSettings->editor().fontSize()));
f.setStyleStrategy(QFont::PreferAntialias);
setFont(f);

View File

@ -697,7 +697,34 @@ void Settings::Editor::setFallbackFontName3(const QString &newFontName)
mFallbackFontName3 = newFontName;
}
bool Settings::Editor::useFallbackFont2() const {
return mUseFallbackFont2;
}
void Settings::Editor::setUseFallbackFont2(bool useFont) {
mUseFallbackFont2 = useFont;
}
bool Settings::Editor::useFallbackFont3() const {
return mUseFallbackFont3;
}
void Settings::Editor::setUseFallbackFont3(bool useFont) {
mUseFallbackFont3 = useFont;
}
QStringList Settings::Editor::fontFamilies() const
{
QStringList result {
mFontName,
mFallbackFontName,
};
if (mUseFallbackFont2)
result.append(mFallbackFontName2);
if (mUseFallbackFont3)
result.append(mFallbackFontName3);
return result;
}
int Settings::Editor::mouseSelectionScrollSpeed() const
{
@ -1373,6 +1400,9 @@ void Settings::Editor::doSave()
saveValue("fallback_font_name", mFallbackFontName);
saveValue("fallback_font_name2", mFallbackFontName2);
saveValue("fallback_font_name3", mFallbackFontName3);
saveValue("use_fallback_font2", mUseFallbackFont2);
saveValue("use_fallback_font3", mUseFallbackFont3);
saveValue("font_size", mFontSize);
saveValue("font_only_monospaced", mFontOnlyMonospaced);
saveValue("line_spacing",mLineSpacing);
@ -1518,6 +1548,8 @@ void Settings::Editor::doLoad()
mFallbackFontName = stringValue("fallback_font_name",defaultCjkFontName);
mFallbackFontName2 = stringValue("fallback_font_name2",DEFAULT_MONO_FONT);
mFallbackFontName3 = stringValue("fallback_font_name3",DEFAULT_MONO_FONT);
mUseFallbackFont2 = boolValue("use_fallback_font2", false);
mUseFallbackFont3 = boolValue("use_fallback_font3", false);
mFontSize = intValue("font_size",12);
mFontOnlyMonospaced = boolValue("font_only_monospaced",true);
mLineSpacing = doubleValue("line_spacing",1.1);

View File

@ -364,6 +364,14 @@ public:
const QString &fallbackFontName3() const;
void setFallbackFontName3(const QString &newFontName);
bool useFallbackFont2() const;
void setUseFallbackFont2(bool useFont);
bool useFallbackFont3() const;
void setUseFallbackFont3(bool useFont);
QStringList fontFamilies() const;
int mouseSelectionScrollSpeed() const;
void setMouseSelectionScrollSpeed(int newMouseSelectionScrollSpeed);
@ -456,6 +464,8 @@ public:
QString mFallbackFontName;
QString mFallbackFontName2;
QString mFallbackFontName3;
bool mUseFallbackFont2;
bool mUseFallbackFont3;
int mFontSize;
bool mFontOnlyMonospaced;
double mLineSpacing;

View File

@ -24,6 +24,10 @@ EditorFontWidget::EditorFontWidget(const QString& name, const QString& group, QW
ui(new Ui::EditorFontWidget)
{
ui->setupUi(this);
connect(ui->chkFallbackFont2, &QCheckBox::stateChanged,
this, &EditorFontWidget::onFallbackFontsCheckStateChanged);
connect(ui->chkFallbackFont3, &QCheckBox::stateChanged,
this, &EditorFontWidget::onFallbackFontsCheckStateChanged);
}
EditorFontWidget::~EditorFontWidget()
@ -59,6 +63,9 @@ void EditorFontWidget::doLoad()
ui->cbFallbackFont->setCurrentFont(QFont(pSettings->editor().fallbackFontName()));
ui->cbFallbackFont2->setCurrentFont(QFont(pSettings->editor().fallbackFontName2()));
ui->cbFallbackFont3->setCurrentFont(QFont(pSettings->editor().fallbackFontName3()));
ui->chkFallbackFont2->setChecked(pSettings->editor().useFallbackFont2());
ui->chkFallbackFont3->setChecked(pSettings->editor().useFallbackFont3());
ui->spinFontSize->setValue(pSettings->editor().fontSize());
ui->spinLineSpacing->setValue(pSettings->editor().lineSpacing());
ui->chkLigature->setChecked(pSettings->editor().enableLigaturesSupport());
@ -89,6 +96,8 @@ void EditorFontWidget::doSave()
pSettings->editor().setFallbackFontName(ui->cbFallbackFont->currentFont().family());
pSettings->editor().setFallbackFontName2(ui->cbFallbackFont2->currentFont().family());
pSettings->editor().setFallbackFontName3(ui->cbFallbackFont3->currentFont().family());
pSettings->editor().setUseFallbackFont2(ui->chkFallbackFont2->isChecked());
pSettings->editor().setUseFallbackFont3(ui->chkFallbackFont3->isChecked());
pSettings->editor().setFontSize(ui->spinFontSize->value());
pSettings->editor().setLineSpacing(ui->spinLineSpacing->value());
@ -114,3 +123,10 @@ void EditorFontWidget::doSave()
pSettings->editor().save();
pMainWindow->updateEditorSettings();
}
void EditorFontWidget::onFallbackFontsCheckStateChanged()
{
ui->cbFallbackFont2->setEnabled(ui->chkFallbackFont2->isChecked());
ui->cbFallbackFont3->setEnabled(ui->chkFallbackFont3->isChecked());
}

View File

@ -27,13 +27,13 @@ class EditorFontWidget;
class EditorFontWidget : public SettingsWidget
{
Q_OBJECT
public:
explicit EditorFontWidget(const QString& name, const QString& group, QWidget *parent = nullptr);
~EditorFontWidget();
private slots:
void onFallbackFontsCheckStateChanged();
void on_chkOnlyMonospacedFonts_stateChanged(int arg1);
void on_chkGutterOnlyMonospacedFonts_stateChanged(int arg1);

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>876</width>
<height>713</height>
<height>781</height>
</rect>
</property>
<property name="windowTitle">
@ -156,13 +156,6 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Fallback Font 2:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QWidget" name="widget_9" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_7">
@ -249,15 +242,8 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Fallback Font 3:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QWidget" name="widget_11" native="true">
<widget class="QWidget" name="panelFallbackFont2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<property name="leftMargin">
<number>0</number>
@ -272,7 +258,11 @@
<number>0</number>
</property>
<item>
<widget class="QFontComboBox" name="cbFallbackFont2"/>
<widget class="QFontComboBox" name="cbFallbackFont2">
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_13">
@ -298,7 +288,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QWidget" name="widget_12" native="true">
<widget class="QWidget" name="panelFallbackFont3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="leftMargin">
<number>0</number>
@ -313,7 +303,11 @@
<number>0</number>
</property>
<item>
<widget class="QFontComboBox" name="cbFallbackFont3"/>
<widget class="QFontComboBox" name="cbFallbackFont3">
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_14">
@ -338,6 +332,20 @@
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="chkFallbackFont2">
<property name="text">
<string>Fallback Font 2:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="chkFallbackFont3">
<property name="text">
<string>Fallback Font 3:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -144,13 +144,7 @@ void CPUDialog::resetEditorFont(float dpi)
{
QFont f=QFont();
f.setFamilies(
QStringList{
pSettings->editor().fontName(),
pSettings->editor().fallbackFontName(),
pSettings->editor().fallbackFontName2(),
pSettings->editor().fallbackFontName3(),
});
f.setFamilies(pSettings->editor().fontFamilies());
f.setPixelSize(pointToPixel(pSettings->editor().fontSize(),dpi));
f.setStyleStrategy(QFont::PreferAntialias);
ui->txtCode->setFont(f);