- enhancement: display localized theme name in the option dialog
This commit is contained in:
parent
e58ca80282
commit
4a06534d39
1
NEWS.md
1
NEWS.md
|
@ -1,6 +1,7 @@
|
|||
Red Panda C++ Version 0.14.1
|
||||
- enhancement: custom theme
|
||||
- fix: failed to show function tip, when there are parameters having '[' and ']'
|
||||
- enhancement: display localized theme name in the option dialog
|
||||
|
||||
Red Panda C++ Version 0.14.0
|
||||
- enhancement: custom icon set ( in the configuration folder)
|
||||
|
|
|
@ -28,17 +28,6 @@ EnvironmentAppearenceWidget::EnvironmentAppearenceWidget(const QString& name, co
|
|||
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");
|
||||
ui->cbLanguage->addItem(tr("Simplified Chinese"),"zh_CN");
|
||||
ui->cbIconSet->addItem("newlook");
|
||||
}
|
||||
|
||||
EnvironmentAppearenceWidget::~EnvironmentAppearenceWidget()
|
||||
|
@ -48,7 +37,12 @@ EnvironmentAppearenceWidget::~EnvironmentAppearenceWidget()
|
|||
|
||||
void EnvironmentAppearenceWidget::doLoad()
|
||||
{
|
||||
ui->cbTheme->setCurrentText(pSettings->environment().theme());
|
||||
for (int i=0; i<ui->cbTheme->count();i++) {
|
||||
if (ui->cbTheme->itemData(i) == pSettings->environment().theme()) {
|
||||
ui->cbTheme->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ui->cbFont->setCurrentFont(QFont(pSettings->environment().interfaceFont()));
|
||||
ui->spinFontSize->setValue(pSettings->environment().interfaceFontSize());
|
||||
ui->cbIconSet->setCurrentText(pSettings->environment().iconSet());
|
||||
|
@ -65,15 +59,15 @@ void EnvironmentAppearenceWidget::doLoad()
|
|||
|
||||
void EnvironmentAppearenceWidget::doSave()
|
||||
{
|
||||
if (pSettings->environment().theme()!=ui->cbTheme->currentText()) {
|
||||
if (pSettings->environment().theme()!=ui->cbTheme->currentData().toString()) {
|
||||
ThemeManager themeManager;
|
||||
PAppTheme appTheme = themeManager.theme(ui->cbTheme->currentText());
|
||||
PAppTheme appTheme = themeManager.theme(ui->cbTheme->currentData().toString());
|
||||
if (appTheme && !appTheme->defaultColorScheme().isEmpty()) {
|
||||
pSettings->editor().setColorScheme(appTheme->defaultColorScheme());
|
||||
pMainWindow->updateEditorColorSchemes();
|
||||
}
|
||||
}
|
||||
pSettings->environment().setTheme(ui->cbTheme->currentText());
|
||||
pSettings->environment().setTheme(ui->cbTheme->currentData().toString());
|
||||
pSettings->environment().setInterfaceFont(ui->cbFont->currentFont().family());
|
||||
pSettings->environment().setInterfaceFontSize(ui->spinFontSize->value());
|
||||
pSettings->environment().setLanguage(ui->cbLanguage->currentData().toString());
|
||||
|
@ -85,3 +79,16 @@ void EnvironmentAppearenceWidget::doSave()
|
|||
pSettings->environment().save();
|
||||
pMainWindow->applySettings();
|
||||
}
|
||||
|
||||
void EnvironmentAppearenceWidget::init()
|
||||
{
|
||||
ThemeManager themeManager;
|
||||
QList<PAppTheme> appThemes = themeManager.getThemes();
|
||||
foreach(const PAppTheme& appTheme, appThemes) {
|
||||
ui->cbTheme->addItem(appTheme->displayName(),appTheme->name());
|
||||
}
|
||||
ui->cbLanguage->addItem(tr("English"),"en");
|
||||
ui->cbLanguage->addItem(tr("Simplified Chinese"),"zh_CN");
|
||||
ui->cbIconSet->addItem("newlook");
|
||||
SettingsWidget::init();
|
||||
}
|
||||
|
|
|
@ -39,6 +39,10 @@ private:
|
|||
protected:
|
||||
void doLoad() override;
|
||||
void doSave() override;
|
||||
|
||||
// SettingsWidget interface
|
||||
public:
|
||||
void init() override;
|
||||
};
|
||||
|
||||
#endif // ENVIRONMENTAPPEARENCEWIDGET_H
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
#include "thememanager.h"
|
||||
#include <QApplication>
|
||||
#include <QDirIterator>
|
||||
#include <QFile>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
|
@ -24,6 +25,7 @@
|
|||
#include <QMetaObject>
|
||||
#include "utils.h"
|
||||
#include "settings.h"
|
||||
#include "systemconsts.h"
|
||||
|
||||
ThemeManager::ThemeManager(QObject *parent) : QObject(parent),
|
||||
mUseCustomTheme(false)
|
||||
|
@ -33,6 +35,8 @@ ThemeManager::ThemeManager(QObject *parent) : QObject(parent),
|
|||
|
||||
PAppTheme ThemeManager::theme(const QString &themeName)
|
||||
{
|
||||
if (mUseCustomTheme)
|
||||
prepareCustomeTheme();
|
||||
PAppTheme appTheme = std::make_shared<AppTheme>();
|
||||
QString themeDir;
|
||||
if (mUseCustomTheme)
|
||||
|
@ -61,6 +65,34 @@ void ThemeManager::prepareCustomeTheme()
|
|||
copyFolder(pSettings->dirs().data(Settings::Dirs::DataType::Theme),pSettings->dirs().config(Settings::Dirs::DataType::Theme));
|
||||
}
|
||||
|
||||
QList<PAppTheme> ThemeManager::getThemes()
|
||||
{
|
||||
if (mUseCustomTheme)
|
||||
prepareCustomeTheme();
|
||||
|
||||
QList<PAppTheme> result;
|
||||
QString themeDir;
|
||||
if (mUseCustomTheme)
|
||||
themeDir = pSettings->dirs().config(Settings::Dirs::DataType::Theme);
|
||||
else
|
||||
themeDir = pSettings->dirs().data(Settings::Dirs::DataType::Theme);
|
||||
QDirIterator it(themeDir);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
QFileInfo fileInfo = it.fileInfo();
|
||||
if (fileInfo.suffix().compare("json", PATH_SENSITIVITY)==0) {
|
||||
try {
|
||||
PAppTheme appTheme = std::make_shared<AppTheme>();
|
||||
appTheme->load(fileInfo.absoluteFilePath());
|
||||
result.append(appTheme);
|
||||
} catch(FileError e) {
|
||||
//just skip it
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
AppTheme::AppTheme(QObject *parent):QObject(parent)
|
||||
{
|
||||
|
||||
|
@ -156,7 +188,12 @@ void AppTheme::load(const QString &filename)
|
|||
.arg(error.errorString()));
|
||||
}
|
||||
QJsonObject obj=doc.object();
|
||||
mName = obj["name"].toString();
|
||||
QFileInfo fileInfo(filename);
|
||||
mName = fileInfo.baseName();
|
||||
mDisplayName = obj["name"].toString();
|
||||
QString localeName = obj["name_"+pSettings->environment().language()].toString();
|
||||
if (!localeName.isEmpty())
|
||||
mDisplayName = localeName;
|
||||
mIsDark = obj["isDark"].toBool(false);
|
||||
mDefaultColorScheme = obj["default scheme"].toString();
|
||||
QJsonObject colors = obj["palette"].toObject();
|
||||
|
@ -200,6 +237,16 @@ QPalette AppTheme::initialPalette()
|
|||
return palette;
|
||||
}
|
||||
|
||||
const QString &AppTheme::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
const QString &AppTheme::displayName() const
|
||||
{
|
||||
return mDisplayName;
|
||||
}
|
||||
|
||||
const QString &AppTheme::defaultColorScheme() const
|
||||
{
|
||||
return mDefaultColorScheme;
|
||||
|
|
|
@ -85,11 +85,16 @@ public:
|
|||
const QString &defaultColorScheme() const;
|
||||
void setDefaultColorScheme(const QString &newDefaultColorScheme);
|
||||
|
||||
const QString &displayName() const;
|
||||
|
||||
const QString &name() const;
|
||||
|
||||
private:
|
||||
static QPalette initialPalette();
|
||||
private:
|
||||
QHash<int,QColor> mColors;
|
||||
QString mName;
|
||||
QString mDisplayName;
|
||||
bool mIsDark;
|
||||
QString mDefaultColorScheme;
|
||||
};
|
||||
|
@ -105,6 +110,7 @@ public:
|
|||
bool useCustomTheme() const;
|
||||
void setUseCustomTheme(bool newUseCustomTheme);
|
||||
void prepareCustomeTheme();
|
||||
QList<PAppTheme> getThemes();
|
||||
|
||||
private:
|
||||
bool mUseCustomTheme;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"name":"dark",
|
||||
"name_zh_CN": "深色主题",
|
||||
"isDark": true,
|
||||
"default scheme": "VS Code",
|
||||
"palette": {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"name":"default",
|
||||
"name":"light",
|
||||
"name_zh_CN":"浅色主题",
|
||||
"isDark":false,
|
||||
"default scheme": "Intellij Classic",
|
||||
"palette": {
|
||||
|
|
|
@ -1113,7 +1113,6 @@ void copyFolder(const QString &fromDir, const QString &toDir)
|
|||
return;
|
||||
targetDir.mkpath(targetDir.absolutePath());
|
||||
|
||||
qDebug()<<"copy folder";
|
||||
while (it.hasNext()){
|
||||
it.next();
|
||||
const auto fileInfo = it.fileInfo();
|
||||
|
|
Loading…
Reference in New Issue