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