RedPanda-CPP/RedPandaIDE/settingsdialog/environmentappearencewidget...

67 lines
2.4 KiB
C++
Raw Normal View History

#include "environmentappearencewidget.h"
#include "ui_environmentappearencewidget.h"
#include <QApplication>
#include <QStyleFactory>
#include "../settings.h"
#include "../mainwindow.h"
#include "../thememanager.h"
EnvironmentAppearenceWidget::EnvironmentAppearenceWidget(const QString& name, const QString& group, QWidget *parent) :
SettingsWidget(name,group,parent),
ui(new Ui::EnvironmentAppearenceWidget)
{
ui->setupUi(this);
ui->cbTheme->addItem("default");
ui->cbTheme->addItem("dark");
// ui->cbTheme->addItem("dracula");
// ui->cbTheme->addItem("light");
// QStyleFactory factory;
// for (QString name:factory.keys()) {
// ui->cbTheme->addItem(name);
// }
ui->cbLanguage->addItem(tr("English"),"en");
2021-08-16 23:17:48 +08:00
ui->cbLanguage->addItem(tr("Simplified Chinese"),"zh_CN");
ui->cbIconSet->addItem("newlook");
}
EnvironmentAppearenceWidget::~EnvironmentAppearenceWidget()
{
delete ui;
}
void EnvironmentAppearenceWidget::doLoad()
{
ui->cbTheme->setCurrentText(pSettings->environment().theme());
ui->cbFont->setCurrentFont(QFont(pSettings->environment().interfaceFont()));
ui->spinFontSize->setValue(pSettings->environment().interfaceFontSize());
ui->cbIconSet->setCurrentText(pSettings->environment().iconSet());
2021-06-20 09:27:37 +08:00
for (int i=0;i<ui->cbLanguage->count();i++) {
if (ui->cbLanguage->itemData(i) == pSettings->environment().language()) {
ui->cbLanguage->setCurrentIndex(i);
break;
}
}
}
void EnvironmentAppearenceWidget::doSave()
{
if (pSettings->environment().theme()!=ui->cbTheme->currentText()) {
ThemeManager themeManager;
PAppTheme appTheme = themeManager.theme(ui->cbTheme->currentText());
if (appTheme && !appTheme->defaultColorScheme().isEmpty()) {
pSettings->editor().setColorScheme(appTheme->defaultColorScheme());
pMainWindow->updateEditorColorSchemes();
}
}
pSettings->environment().setTheme(ui->cbTheme->currentText());
pSettings->environment().setInterfaceFont(ui->cbFont->currentFont().family());
pSettings->environment().setInterfaceFontSize(ui->spinFontSize->value());
2021-06-20 09:27:37 +08:00
pSettings->environment().setLanguage(ui->cbLanguage->currentData().toString());
pSettings->environment().setIconSet(ui->cbIconSet->currentText());
pSettings->editor().save();
pSettings->environment().save();
pMainWindow->applySettings();
}