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 "environmentappearencewidget.h" |
18 | #include "ui_environmentappearencewidget.h" |
19 | |
20 | #include <QApplication> |
21 | #include <QStyleFactory> |
22 | #include "../settings.h" |
23 | #include "../mainwindow.h" |
24 | #include "../thememanager.h" |
25 | #include "../iconsmanager.h" |
26 | |
27 | EnvironmentAppearenceWidget::EnvironmentAppearenceWidget(const QString& name, const QString& group, QWidget *parent) : |
28 | SettingsWidget(name,group,parent), |
29 | ui(new Ui::EnvironmentAppearenceWidget) |
30 | { |
31 | ui->setupUi(this); |
32 | } |
33 | |
34 | EnvironmentAppearenceWidget::~EnvironmentAppearenceWidget() |
35 | { |
36 | delete ui; |
37 | } |
38 | |
39 | void EnvironmentAppearenceWidget::doLoad() |
40 | { |
41 | for (int i=0; i<ui->cbTheme->count();i++) { |
42 | if (ui->cbTheme->itemData(i) == pSettings->environment().theme()) { |
43 | ui->cbTheme->setCurrentIndex(i); |
44 | break; |
45 | } |
46 | } |
47 | ui->cbFont->setCurrentFont(QFont(pSettings->environment().interfaceFont())); |
48 | ui->spinFontSize->setValue(pSettings->environment().interfaceFontSize()); |
49 | for (int i=0; i<ui->cbIconSet->count();i++) { |
50 | if (ui->cbIconSet->itemData(i) == pSettings->environment().iconSet()) { |
51 | ui->cbIconSet->setCurrentIndex(i); |
52 | break; |
53 | } |
54 | } |
55 | ui->chkUseCustomIconSet->setChecked(pSettings->environment().useCustomIconSet()); |
56 | ui->chkUseCustomTheme->setChecked(pSettings->environment().useCustomTheme()); |
57 | |
58 | for (int i=0;i<ui->cbLanguage->count();i++) { |
59 | if (ui->cbLanguage->itemData(i) == pSettings->environment().language()) { |
60 | ui->cbLanguage->setCurrentIndex(i); |
61 | break; |
62 | } |
63 | } |
64 | } |
65 | |
66 | void EnvironmentAppearenceWidget::doSave() |
67 | { |
68 | if (pSettings->environment().theme()!=ui->cbTheme->currentData().toString()) { |
69 | ThemeManager themeManager; |
70 | PAppTheme appTheme = themeManager.theme(ui->cbTheme->currentData().toString()); |
71 | if (appTheme && !appTheme->defaultColorScheme().isEmpty()) { |
72 | pSettings->editor().setColorScheme(appTheme->defaultColorScheme()); |
73 | pSettings->editor().save(); |
74 | pMainWindow->updateEditorColorSchemes(); |
75 | } |
76 | } |
77 | pSettings->environment().setTheme(ui->cbTheme->currentData().toString()); |
78 | pSettings->environment().setInterfaceFont(ui->cbFont->currentFont().family()); |
79 | pSettings->environment().setInterfaceFontSize(ui->spinFontSize->value()); |
80 | pSettings->environment().setLanguage(ui->cbLanguage->currentData().toString()); |
81 | pSettings->environment().setIconSet(ui->cbIconSet->currentData().toString()); |
82 | pSettings->environment().setUseCustomIconSet(ui->chkUseCustomIconSet->isChecked()); |
83 | pSettings->environment().setUseCustomTheme(ui->chkUseCustomTheme->isChecked()); |
84 | |
85 | |
86 | pSettings->environment().save(); |
87 | pMainWindow->applySettings(); |
88 | } |
89 | |
90 | void EnvironmentAppearenceWidget::init() |
91 | { |
92 | ThemeManager themeManager; |
93 | QList<PAppTheme> appThemes = themeManager.getThemes(); |
94 | foreach(const PAppTheme& appTheme, appThemes) { |
95 | ui->cbTheme->addItem(appTheme->displayName(),appTheme->name()); |
96 | } |
97 | ui->cbLanguage->addItem(tr("English" ),"en" ); |
98 | ui->cbLanguage->addItem(tr("Portuguese" ),"pt_BR" ); |
99 | ui->cbLanguage->addItem(tr("Simplified Chinese" ),"zh_CN" ); |
100 | ui->cbLanguage->addItem(tr("Traditional Chinese" ),"zh_TW" ); |
101 | QList<PIconSet> iconSets = pIconsManager->listIconSets(); |
102 | foreach(const PIconSet& iconSet, iconSets) { |
103 | ui->cbIconSet->addItem(iconSet->displayName,iconSet->name); |
104 | } |
105 | SettingsWidget::init(); |
106 | } |
107 | |
108 | void EnvironmentAppearenceWidget::on_cbTheme_currentIndexChanged(int /* index */) |
109 | { |
110 | ThemeManager themeManager; |
111 | PAppTheme appTheme = themeManager.theme(ui->cbTheme->currentData().toString()); |
112 | if (appTheme && !appTheme->defaultIconSet().isEmpty()) { |
113 | for (int i=0; i<ui->cbIconSet->count();i++) { |
114 | if (ui->cbIconSet->itemData(i) == appTheme->defaultIconSet()) { |
115 | ui->cbIconSet->setCurrentIndex(i); |
116 | break; |
117 | } |
118 | } |
119 | } |
120 | } |
121 | |
122 | |