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

View File

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

View File

@ -302,6 +302,11 @@ QPalette AppTheme::initialPalette()
return palette; return palette;
} }
AppTheme::ThemeCategory AppTheme::category() const
{
return mCategory;
}
QString AppTheme::initialStyle() QString AppTheme::initialStyle()
{ {
static QString style = QApplication::style()->objectName(); 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 const QString &AppTheme::defaultIconSet() const
{ {
return mDefaultIconSet; return mDefaultIconSet;

View File

@ -116,9 +116,13 @@ public:
const QString categoryIcon() const; const QString categoryIcon() const;
bool copyTo(const QString& targetFolder);
public: public:
static PAppTheme fallbackTheme(); static PAppTheme fallbackTheme();
ThemeCategory category() const;
private: private:
AppTheme(); 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> <context>
<name>QObject</name> <name>QObject</name>
<message> <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> <source>Can&apos;t open file &apos;%1&apos; to write!</source>
<translation>&quot;%1&quot;!</translation> <translation>&quot;%1&quot;!</translation>
</message> </message>
@ -4288,7 +4288,7 @@
<context> <context>
<name>QSynedit::Document</name> <name>QSynedit::Document</name>
<message> <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> <source>Can&apos;t open file &apos;%1&apos; for read!</source>
<translation>&quot;%1&quot;.</translation> <translation>&quot;%1&quot;.</translation>
</message> </message>