1/*
2 * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#include "editorfontwidget.h"
18#include "ui_editorfontwidget.h"
19#include "../settings.h"
20#include "../mainwindow.h"
21
22EditorFontWidget::EditorFontWidget(const QString& name, const QString& group, QWidget *parent) :
23 SettingsWidget(name,group,parent),
24 ui(new Ui::EditorFontWidget)
25{
26 ui->setupUi(this);
27}
28
29EditorFontWidget::~EditorFontWidget()
30{
31 delete ui;
32}
33
34
35void EditorFontWidget::on_chkOnlyMonospacedFonts_stateChanged(int)
36{
37 if (ui->chkOnlyMonospacedFonts->isChecked()) {
38 ui->cbFont->setFontFilters(QFontComboBox::FontFilter::MonospacedFonts);
39 } else {
40 ui->cbFont->setFontFilters(QFontComboBox::FontFilter::AllFonts);
41 }
42}
43
44void EditorFontWidget::on_chkGutterOnlyMonospacedFonts_stateChanged(int)
45{
46 if (ui->chkGutterOnlyMonospacedFonts->isChecked()) {
47 ui->cbGutterFont->setFontFilters(QFontComboBox::FontFilter::MonospacedFonts);
48 } else {
49 ui->cbGutterFont->setFontFilters(QFontComboBox::FontFilter::AllFonts);
50 }
51}
52
53void EditorFontWidget::doLoad()
54{
55 //pSettings->editor().load();
56 //font
57 ui->chkOnlyMonospacedFonts->setChecked(pSettings->editor().fontOnlyMonospaced());
58 ui->cbFont->setCurrentFont(QFont(pSettings->editor().fontName()));
59 ui->cbNonAsciiFont->setCurrentFont(QFont(pSettings->editor().nonAsciiFontName()));
60 ui->spinFontSize->setValue(pSettings->editor().fontSize());
61 ui->chkLigature->setChecked(pSettings->editor().enableLigaturesSupport());
62
63 //gutter
64 ui->chkGutterVisible->setChecked(pSettings->editor().gutterVisible());
65 ui->chkAutoSizeGutter->setChecked(pSettings->editor().gutterAutoSize());
66 ui->spinGutterLeftOffset->setValue(pSettings->editor().gutterLeftOffset());
67 ui->spinGutterRightOffset->setValue(pSettings->editor().gutterRightOffset());
68 ui->spinGutterDigitsCount->setValue(pSettings->editor().gutterDigitsCount());
69 ui->grpGutterShowLineNumbers->setChecked(pSettings->editor().gutterShowLineNumbers());
70 ui->chkAddLeadingZeros->setChecked(pSettings->editor().gutterAddLeadingZero());
71 ui->chkLineNumbersStartsZero->setChecked(pSettings->editor().gutterLineNumbersStartZero());
72 ui->grpUseCustomFont->setChecked(pSettings->editor().gutterUseCustomFont());
73 ui->chkGutterOnlyMonospacedFonts->setChecked(pSettings->editor().gutterFontOnlyMonospaced());
74 ui->cbGutterFont->setCurrentFont(QFont(pSettings->editor().gutterFontName()));
75 ui->spinGutterFontSize->setValue(pSettings->editor().gutterFontSize());
76}
77
78void EditorFontWidget::doSave()
79{
80 //font
81 pSettings->editor().setFontOnlyMonospaced(ui->chkOnlyMonospacedFonts->isChecked());
82 pSettings->editor().setFontName(ui->cbFont->currentFont().family());
83 pSettings->editor().setNonAsciiFontName(ui->cbNonAsciiFont->currentFont().family());
84 pSettings->editor().setFontSize(ui->spinFontSize->value());
85 pSettings->editor().setEnableLigaturesSupport(ui->chkLigature->isChecked());
86
87 //gutter
88 pSettings->editor().setGutterVisible(ui->chkGutterVisible->isChecked());
89 pSettings->editor().setGutterAutoSize(ui->chkAutoSizeGutter->isChecked());
90 pSettings->editor().setGutterLeftOffset(ui->spinGutterLeftOffset->value());
91 pSettings->editor().setGutterRightOffset(ui->spinGutterRightOffset->value());
92 pSettings->editor().setGutterDigitsCount(ui->spinGutterDigitsCount->value());
93 pSettings->editor().setGutterShowLineNumbers(ui->grpGutterShowLineNumbers->isChecked());
94 pSettings->editor().setGutterAddLeadingZero(ui->chkAddLeadingZeros->isChecked());
95 pSettings->editor().setGutterLineNumbersStartZero(ui->chkLineNumbersStartsZero->isChecked());
96 pSettings->editor().setGutterUseCustomFont(ui->grpUseCustomFont->isChecked());
97 pSettings->editor().setGutterFontOnlyMonospaced(ui->chkGutterOnlyMonospacedFonts->isChecked());
98 pSettings->editor().setGutterFontName(ui->cbGutterFont->currentFont().family());
99 pSettings->editor().setGutterFontSize(ui->spinGutterFontSize->value());
100
101 pSettings->editor().save();
102 pMainWindow->updateEditorSettings();
103}
104