Generate a customized copy for theme

This commit is contained in:
Roy Qu 2024-04-23 14:03:48 +08:00
parent 96c4e95172
commit d3db8e2b4d
9 changed files with 1154 additions and 1274 deletions

View File

@ -18,6 +18,7 @@
#include "ui_environmentappearancewidget.h"
#include <QApplication>
#include <QMessageBox>
#include <QStyleFactory>
#include "../settings.h"
#include "../mainwindow.h"
@ -109,6 +110,7 @@ void EnvironmentAppearanceWidget::on_cbTheme_currentIndexChanged(int /* index */
{
ThemeManager themeManager;
PAppTheme appTheme = themeManager.theme(ui->cbTheme->currentData().toString());
ui->btnCustomize->setVisible(appTheme->category() == AppTheme::ThemeCategory::BuiltIn);
if(!appTheme->defaultIconSet().isEmpty()) {
for (int i=0; i<ui->cbIconSet->count();i++) {
if (ui->cbIconSet->itemData(i) == appTheme->defaultIconSet()) {
@ -119,3 +121,25 @@ void EnvironmentAppearanceWidget::on_cbTheme_currentIndexChanged(int /* index */
}
}
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);
ui->cbTheme->clear();
QString currentThemeName = appTheme->name();
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);
}
}

View File

@ -45,6 +45,7 @@ public:
void init() override;
private slots:
void on_cbTheme_currentIndexChanged(int index);
void on_btnCustomize_clicked();
};
#endif // ENVIRONMENTAPPEARANCEWIDGET_H

View File

@ -135,6 +135,13 @@
<item>
<widget class="QComboBox" name="cbTheme"/>
</item>
<item>
<widget class="QPushButton" name="btnCustomize">
<property name="text">
<string>Create a customized copy</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@ -315,6 +322,7 @@
</widget>
<tabstops>
<tabstop>cbTheme</tabstop>
<tabstop>btnCustomize</tabstop>
<tabstop>cbFont</tabstop>
<tabstop>spinFontSize</tabstop>
<tabstop>cbIconSet</tabstop>

View File

@ -302,6 +302,11 @@ QPalette AppTheme::initialPalette()
return palette;
}
AppTheme::ThemeCategory AppTheme::category() const
{
return mCategory;
}
QString AppTheme::initialStyle()
{
static QString style = QApplication::style()->objectName();
@ -329,6 +334,13 @@ const QString AppTheme::categoryIcon() const
}
}
bool AppTheme::copyTo(const QString &targetFolder)
{
QFileInfo fileInfo{mFilename};
return QFile::copy(fileInfo.absoluteFilePath(),
QDir(targetFolder).absoluteFilePath(fileInfo.fileName()));
}
const QString &AppTheme::defaultIconSet() const
{
return mDefaultIconSet;

View File

@ -116,9 +116,13 @@ public:
const QString categoryIcon() const;
bool copyTo(const QString& targetFolder);
public:
static PAppTheme fallbackTheme();
ThemeCategory category() const;
private:
AppTheme();

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
<context>
<name>QObject</name>
<message>
<location filename="qsynedit/exporter/exporter.cpp" line="+127"/>
<location filename="qsynedit/exporter/exporter.cpp" line="+128"/>
<source>Can&apos;t open file &apos;%1&apos; to write!</source>
<translation>&quot;%1&quot;!</translation>
</message>
@ -4288,7 +4288,7 @@
<context>
<name>QSynedit::Document</name>
<message>
<location filename="qsynedit/document.cpp" line="+618"/>
<location filename="qsynedit/document.cpp" line="+617"/>
<source>Can&apos;t open file &apos;%1&apos; for read!</source>
<translation>&quot;%1&quot;.</translation>
</message>