2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2023-07-25 09:41:20 +08:00
|
|
|
#include "environmentappearancewidget.h"
|
|
|
|
#include "ui_environmentappearancewidget.h"
|
2021-06-18 21:02:38 +08:00
|
|
|
|
|
|
|
#include <QApplication>
|
2024-04-23 14:03:48 +08:00
|
|
|
#include <QMessageBox>
|
2021-06-18 21:02:38 +08:00
|
|
|
#include <QStyleFactory>
|
|
|
|
#include "../settings.h"
|
|
|
|
#include "../mainwindow.h"
|
2021-11-07 22:34:19 +08:00
|
|
|
#include "../thememanager.h"
|
2022-01-30 00:22:49 +08:00
|
|
|
#include "../iconsmanager.h"
|
2021-06-18 21:02:38 +08:00
|
|
|
|
2023-07-25 09:41:20 +08:00
|
|
|
EnvironmentAppearanceWidget::EnvironmentAppearanceWidget(const QString& name, const QString& group, QWidget *parent) :
|
2021-06-18 21:02:38 +08:00
|
|
|
SettingsWidget(name,group,parent),
|
2023-07-25 09:41:20 +08:00
|
|
|
ui(new Ui::EnvironmentAppearanceWidget)
|
2021-06-18 21:02:38 +08:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
}
|
|
|
|
|
2023-07-25 09:41:20 +08:00
|
|
|
EnvironmentAppearanceWidget::~EnvironmentAppearanceWidget()
|
2021-06-18 21:02:38 +08:00
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2023-07-25 09:41:20 +08:00
|
|
|
void EnvironmentAppearanceWidget::doLoad()
|
2021-06-18 21:02:38 +08:00
|
|
|
{
|
2022-01-28 20:05:55 +08:00
|
|
|
for (int i=0; i<ui->cbTheme->count();i++) {
|
|
|
|
if (ui->cbTheme->itemData(i) == pSettings->environment().theme()) {
|
|
|
|
ui->cbTheme->setCurrentIndex(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-06-18 21:02:38 +08:00
|
|
|
ui->cbFont->setCurrentFont(QFont(pSettings->environment().interfaceFont()));
|
|
|
|
ui->spinFontSize->setValue(pSettings->environment().interfaceFontSize());
|
2022-01-30 00:22:49 +08:00
|
|
|
for (int i=0; i<ui->cbIconSet->count();i++) {
|
|
|
|
if (ui->cbIconSet->itemData(i) == pSettings->environment().iconSet()) {
|
|
|
|
ui->cbIconSet->setCurrentIndex(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-12-20 11:01:04 +08:00
|
|
|
ui->spinZoomFactor->setValue(pSettings->environment().iconZoomFactor());
|
2022-01-27 12:08:57 +08:00
|
|
|
ui->chkUseCustomIconSet->setChecked(pSettings->environment().useCustomIconSet());
|
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;
|
|
|
|
}
|
|
|
|
}
|
2021-06-18 21:02:38 +08:00
|
|
|
}
|
|
|
|
|
2023-07-25 09:41:20 +08:00
|
|
|
void EnvironmentAppearanceWidget::doSave()
|
2021-06-18 21:02:38 +08:00
|
|
|
{
|
2022-01-28 20:05:55 +08:00
|
|
|
if (pSettings->environment().theme()!=ui->cbTheme->currentData().toString()) {
|
2021-11-07 22:34:19 +08:00
|
|
|
ThemeManager themeManager;
|
2022-01-28 20:05:55 +08:00
|
|
|
PAppTheme appTheme = themeManager.theme(ui->cbTheme->currentData().toString());
|
2021-11-07 22:34:19 +08:00
|
|
|
if (appTheme && !appTheme->defaultColorScheme().isEmpty()) {
|
|
|
|
pSettings->editor().setColorScheme(appTheme->defaultColorScheme());
|
2022-02-03 07:45:59 +08:00
|
|
|
pSettings->editor().save();
|
2021-11-07 22:34:19 +08:00
|
|
|
pMainWindow->updateEditorColorSchemes();
|
|
|
|
}
|
|
|
|
}
|
2022-01-28 20:05:55 +08:00
|
|
|
pSettings->environment().setTheme(ui->cbTheme->currentData().toString());
|
2021-06-18 21:02:38 +08:00
|
|
|
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());
|
2022-01-30 00:22:49 +08:00
|
|
|
pSettings->environment().setIconSet(ui->cbIconSet->currentData().toString());
|
2022-12-20 11:01:04 +08:00
|
|
|
pSettings->environment().setIconZoomFactor(ui->spinZoomFactor->value());
|
|
|
|
|
2022-01-27 12:08:57 +08:00
|
|
|
pSettings->environment().setUseCustomIconSet(ui->chkUseCustomIconSet->isChecked());
|
|
|
|
|
2021-06-18 21:02:38 +08:00
|
|
|
pSettings->environment().save();
|
|
|
|
pMainWindow->applySettings();
|
|
|
|
}
|
2022-01-28 20:05:55 +08:00
|
|
|
|
2024-04-24 10:26:55 +08:00
|
|
|
void EnvironmentAppearanceWidget::updateIcons(const QSize &size)
|
|
|
|
{
|
|
|
|
pIconsManager->setIcon(ui->btnCustomize, IconsManager::ACTION_EDIT_COPY);
|
|
|
|
pIconsManager->setIcon(ui->btnOpenCustomThemeFolder, IconsManager::ACTION_MISC_FOLDER);
|
|
|
|
pIconsManager->setIcon(ui->btnRemoveCustomTheme, IconsManager::ACTION_MISC_REMOVE);
|
|
|
|
}
|
|
|
|
|
2023-07-25 09:41:20 +08:00
|
|
|
void EnvironmentAppearanceWidget::init()
|
2022-01-28 20:05:55 +08:00
|
|
|
{
|
|
|
|
ThemeManager themeManager;
|
|
|
|
QList<PAppTheme> appThemes = themeManager.getThemes();
|
|
|
|
foreach(const PAppTheme& appTheme, appThemes) {
|
2024-04-17 12:48:47 +08:00
|
|
|
ui->cbTheme->addItem(appTheme->categoryIcon() + " " + appTheme->displayName(), appTheme->name());
|
2022-01-28 20:05:55 +08:00
|
|
|
}
|
|
|
|
ui->cbLanguage->addItem(tr("English"),"en");
|
2022-08-05 20:56:09 +08:00
|
|
|
ui->cbLanguage->addItem(tr("Portuguese"),"pt_BR");
|
2022-01-28 20:05:55 +08:00
|
|
|
ui->cbLanguage->addItem(tr("Simplified Chinese"),"zh_CN");
|
2022-04-18 11:01:42 +08:00
|
|
|
ui->cbLanguage->addItem(tr("Traditional Chinese"),"zh_TW");
|
2022-01-30 00:22:49 +08:00
|
|
|
QList<PIconSet> iconSets = pIconsManager->listIconSets();
|
|
|
|
foreach(const PIconSet& iconSet, iconSets) {
|
|
|
|
ui->cbIconSet->addItem(iconSet->displayName,iconSet->name);
|
|
|
|
}
|
2022-01-28 20:05:55 +08:00
|
|
|
SettingsWidget::init();
|
|
|
|
}
|
2022-02-01 21:39:31 +08:00
|
|
|
|
2023-07-25 09:41:20 +08:00
|
|
|
void EnvironmentAppearanceWidget::on_cbTheme_currentIndexChanged(int /* index */)
|
2022-02-01 21:39:31 +08:00
|
|
|
{
|
|
|
|
ThemeManager themeManager;
|
|
|
|
PAppTheme appTheme = themeManager.theme(ui->cbTheme->currentData().toString());
|
2024-04-23 14:03:48 +08:00
|
|
|
ui->btnCustomize->setVisible(appTheme->category() == AppTheme::ThemeCategory::BuiltIn);
|
2024-04-23 17:21:32 +08:00
|
|
|
ui->btnOpenCustomThemeFolder->setVisible(appTheme->category() == AppTheme::ThemeCategory::Custom);
|
2024-04-24 10:26:55 +08:00
|
|
|
ui->btnRemoveCustomTheme->setVisible(appTheme->category() == AppTheme::ThemeCategory::Custom);
|
2024-04-16 20:46:17 +08:00
|
|
|
if(!appTheme->defaultIconSet().isEmpty()) {
|
2022-02-01 21:39:31 +08:00
|
|
|
for (int i=0; i<ui->cbIconSet->count();i++) {
|
|
|
|
if (ui->cbIconSet->itemData(i) == appTheme->defaultIconSet()) {
|
|
|
|
ui->cbIconSet->setCurrentIndex(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-23 14:03:48 +08:00
|
|
|
|
|
|
|
void EnvironmentAppearanceWidget::on_btnCustomize_clicked()
|
|
|
|
{
|
|
|
|
ThemeManager themeManager;
|
|
|
|
PAppTheme appTheme = themeManager.theme(ui->cbTheme->currentData().toString());
|
|
|
|
QString customThemeFolder = pSettings->dirs().config(Settings::Dirs::DataType::Theme);
|
|
|
|
QDir dir{customThemeFolder};
|
|
|
|
if (!dir.exists()) {
|
|
|
|
dir.mkpath(customThemeFolder);
|
|
|
|
}
|
|
|
|
appTheme->copyTo(customThemeFolder);
|
2024-04-24 10:26:55 +08:00
|
|
|
refreshThemeList(appTheme->name());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EnvironmentAppearanceWidget::on_btnOpenCustomThemeFolder_clicked()
|
|
|
|
{
|
|
|
|
QString customThemeFolder = pSettings->dirs().config(Settings::Dirs::DataType::Theme);
|
|
|
|
openFileFolderInExplorer(customThemeFolder);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnvironmentAppearanceWidget::refreshThemeList(const QString ¤tThemeName)
|
|
|
|
{
|
|
|
|
ThemeManager themeManager;
|
2024-04-23 14:03:48 +08:00
|
|
|
ui->cbTheme->clear();
|
|
|
|
QList<PAppTheme> appThemes = themeManager.getThemes();
|
|
|
|
for (int i=0; i<appThemes.count();i++) {
|
|
|
|
const PAppTheme& appTheme =appThemes[i];
|
|
|
|
ui->cbTheme->addItem(appTheme->categoryIcon() + " " + appTheme->displayName(), appTheme->name());
|
|
|
|
if (appTheme->name() == currentThemeName)
|
|
|
|
ui->cbTheme->setCurrentIndex(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-23 17:21:32 +08:00
|
|
|
|
2024-04-24 10:26:55 +08:00
|
|
|
void EnvironmentAppearanceWidget::on_btnRemoveCustomTheme_clicked()
|
2024-04-23 17:21:32 +08:00
|
|
|
{
|
2024-04-24 10:26:55 +08:00
|
|
|
ThemeManager themeManager;
|
|
|
|
PAppTheme appTheme = themeManager.theme(ui->cbTheme->currentData().toString());
|
|
|
|
if (appTheme->category() != AppTheme::ThemeCategory::Custom)
|
|
|
|
return;
|
|
|
|
QFile::remove(appTheme->filename());
|
|
|
|
refreshThemeList(appTheme->name());
|
2024-04-23 17:21:32 +08:00
|
|
|
}
|
|
|
|
|