relevant themes(#816) and delete improvement (#846)

* change constants to enum

* code improvements

* remove redundant lambda usage

* add themes

* bug fix

* bug fix 2

* first start bug fix

* big refactoring

* merge conflict fixes

* removes debug information
This commit is contained in:
optizone8 2018-11-11 12:11:50 +00:00 committed by Itay Cohen
parent bd82f2cf45
commit 5a62bd6dc7
6 changed files with 113 additions and 39 deletions

@ -1 +1 @@
Subproject commit 35a5c42a52cff8524f065c205e3f1982302c583d
Subproject commit 0c0fee7b48283643a9ba9e855a32e2503f88a63e

View File

@ -8,6 +8,11 @@
#include "common/ColorSchemeFileSaver.h"
const QList<CutterQtTheme> kCutterQtThemesList = {
{ "Default", LightFlag },
{ "Dark", DarkFlag }
};
Configuration *Configuration::mPtr = nullptr;
/*!
@ -226,22 +231,33 @@ void Configuration::setFont(const QFont &font)
emit fontsUpdated();
}
QString Configuration::getLastThemeOf(const CutterQtTheme &currQtTheme) const
{
return s.value("lastThemeOf." + currQtTheme.name,
Config()->getCurrentTheme()).toString();
}
void Configuration::setTheme(int theme)
{
if (theme >= kCutterQtThemesList.size() ||
theme < 0) {
theme = 0;
}
s.setValue("ColorPalette", theme);
switch (theme) {
case 0:
QString themeName = kCutterQtThemesList[theme].name;
if (themeName == "Default") {
loadDefaultTheme();
break;
case 1:
} else if (themeName == "Dark") {
loadDarkTheme();
break;
default:
} else {
loadDefaultTheme();
}
emit colorsUpdated();
}
QString Configuration::getLogoFile()
{
return logoFile;
@ -257,6 +273,11 @@ void Configuration::setColor(const QString &name, const QColor &color)
s.setValue("colors." + name, color);
}
void Configuration::setLastThemeOf(const CutterQtTheme &currQtTheme, const QString &theme)
{
s.setValue("lastThemeOf." + currQtTheme.name, theme);
}
const QColor Configuration::getColor(const QString &name) const
{
if (s.contains("colors." + name)) {

View File

@ -8,6 +8,18 @@
#define Config() (Configuration::instance())
#define ConfigColor(x) Config()->getColor(x)
enum ColorFlags {
LightFlag = 1,
DarkFlag = 2
};
struct CutterQtTheme {
QString name;
ColorFlags flag;
};
extern const QList<CutterQtTheme> kCutterQtThemesList;
class Configuration : public QObject
{
Q_OBJECT
@ -45,11 +57,13 @@ public:
void setFont(const QFont &font);
// Colors
void setLastThemeOf(const CutterQtTheme &currQtTheme, const QString& theme);
QString getLastThemeOf(const CutterQtTheme &currQtTheme) const;
const QColor getColor(const QString &name) const;
void setTheme(int theme);
int getTheme()
{
return s.value("ColorPalette").toInt();
return s.value("ColorPalette", 0).toInt();
}
QString getDirProjects();

View File

@ -3,6 +3,7 @@
#include <QFontDialog>
#include <QTranslator>
#include <QInputDialog>
#include <QSignalBlocker>
#include <QComboBox>
#include "PreferencesDialog.h"
@ -15,13 +16,26 @@
#include "common/ColorSchemeFileSaver.h"
#include "widgets/ColorSchemePrefWidget.h"
static const QHash<QString, ColorFlags> kRelevantSchemes = {
{ "ayu", DarkFlag },
{ "consonance", DarkFlag },
{ "darkda", DarkFlag },
{ "onedark", DarkFlag },
{ "solarized", DarkFlag },
{ "zenburn", DarkFlag },
{ "cutter", LightFlag },
{ "dark", LightFlag },
{ "matrix", LightFlag },
{ "tango", LightFlag },
{ "white", LightFlag }
};
QStringList findLanguages()
{
QDir dir(QCoreApplication::applicationDirPath() + QDir::separator() +
"translations");
QStringList fileNames = dir.entryList(QStringList("cutter_*.qm"), QDir::Files,
QDir::Name);
QStringList languages;
QString currLanguageName;
auto allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript,
@ -43,6 +57,7 @@ QStringList findLanguages()
return languages << "English";
}
AppearanceOptionsWidget::AppearanceOptionsWidget(PreferencesDialog *dialog, QWidget *parent)
: QDialog(parent),
ui(new Ui::AppearanceOptionsWidget)
@ -69,11 +84,6 @@ AppearanceOptionsWidget::AppearanceOptionsWidget(PreferencesDialog *dialog, QWid
connect(Config(), &Configuration::fontsUpdated, this,
&AppearanceOptionsWidget::updateFontFromConfig);
connect(ui.get()->colorComboBox, &QComboBox::currentTextChanged, [&](const QString & name) {
static_cast<ColorSchemePrefWidget *>(ui.get()->colorSchemePrefWidget)->setNewScheme(name);
});
static_cast<ColorSchemePrefWidget *>
(ui.get()->colorSchemePrefWidget)->setNewScheme(Config()->getCurrentTheme());
}
AppearanceOptionsWidget::~AppearanceOptionsWidget() {}
@ -87,18 +97,38 @@ void AppearanceOptionsWidget::updateFontFromConfig()
void AppearanceOptionsWidget::updateThemeFromConfig()
{
// Disconnect currentIndexChanged because clearing the comboxBox and refiling it causes its index to change.
disconnect(ui->colorComboBox, SIGNAL(currentIndexChanged(int)), this,
SLOT(on_colorComboBox_currentIndexChanged(int)));
ui->themeComboBox->setCurrentIndex(Config()->getTheme());
QSignalBlocker signalBlockerColorBox(ui->colorComboBox);
QSignalBlocker signalBlockerThemeBox(ui->themeComboBox);
ui->themeComboBox->clear();
for (auto &it : kCutterQtThemesList) {
ui->themeComboBox->addItem(it.name);
}
uint curQtThemeIndex = Config()->getTheme();
if (curQtThemeIndex >= kCutterQtThemesList.size()) {
curQtThemeIndex = 0;
Config()->setTheme(curQtThemeIndex);
}
ui->themeComboBox->setCurrentIndex(curQtThemeIndex);
QList<QString> themes = Core()->getColorThemes();
ui->colorComboBox->clear();
ui->colorComboBox->addItem("default");
for (QString str : themes)
ui->colorComboBox->addItem(str);
QString curTheme = Config()->getCurrentTheme();
int index = themes.indexOf(curTheme) + 1;
for (QString theme : themes) {
if (ColorSchemeFileWorker().isCustomScheme(theme) ||
(kCutterQtThemesList[curQtThemeIndex].flag & kRelevantSchemes[theme])) {
ui->colorComboBox->addItem(theme);
}
}
QString curTheme = Config()->getLastThemeOf(kCutterQtThemesList[curQtThemeIndex]);
int index = ui->colorComboBox->findText(curTheme);
if (index == -1) {
index = 0;
}
ui->colorComboBox->setCurrentIndex(index);
curTheme = ui->colorComboBox->currentText();
Config()->setColorTheme(curTheme);
ui->colorSchemePrefWidget->updateSchemeFromConfig();
int maxThemeLen = 0;
for (QString str : themes) {
int strLen = str.length();
@ -108,8 +138,6 @@ void AppearanceOptionsWidget::updateThemeFromConfig()
}
ui->colorComboBox->setMinimumContentsLength(maxThemeLen);
ui->colorComboBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
connect(ui->colorComboBox, SIGNAL(currentIndexChanged(int)), this,
SLOT(on_colorComboBox_currentIndexChanged(int)));
}
void AppearanceOptionsWidget::on_fontSelectionButton_clicked()
@ -125,15 +153,23 @@ void AppearanceOptionsWidget::on_fontSelectionButton_clicked()
void AppearanceOptionsWidget::on_themeComboBox_currentIndexChanged(int index)
{
//disconnect(Config(), SIGNAL(colorsUpdated()), this, SLOT(updateThemeFromConfig()));
Config()->setTheme(index);
//connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(updateThemeFromConfig()));
updateThemeFromConfig();
}
void AppearanceOptionsWidget::on_colorComboBox_currentIndexChanged(int index)
{
QString theme = ui->colorComboBox->itemText(index);
uint curQtThemeIndex = Config()->getTheme();
if (curQtThemeIndex >= kCutterQtThemesList.size()) {
curQtThemeIndex = 0;
Config()->setTheme(curQtThemeIndex);
}
Config()->setLastThemeOf(kCutterQtThemesList[curQtThemeIndex], theme);
Config()->setColorTheme(theme);
ui->colorSchemePrefWidget->updateSchemeFromConfig();
}
void AppearanceOptionsWidget::on_copyButton_clicked()
@ -149,14 +185,23 @@ void AppearanceOptionsWidget::on_copyButton_clicked()
return;
ColorSchemeFileWorker().copy(Config()->getCurrentTheme(), newSchemeName);
Config()->setColorTheme(newSchemeName);
ui.get()->colorSchemePrefWidget->setNewScheme(newSchemeName);
ui->colorSchemePrefWidget->updateSchemeFromConfig();
updateThemeFromConfig();
ui.get()->colorComboBox->setCurrentIndex(ui.get()->colorComboBox->findText(newSchemeName));
}
void AppearanceOptionsWidget::on_deleteButton_clicked()
{
ColorSchemeFileWorker().deleteScheme(Config()->getCurrentTheme());
if (ColorSchemeFileWorker().isCustomScheme(Config()->getCurrentTheme())) {
QMessageBox mb;
mb.setWindowTitle(tr("Delete"));
mb.setText(tr("Are you sure you want to delete theme ") + Config()->getCurrentTheme());
mb.setIcon(QMessageBox::Question);
mb.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
if (mb.exec() == QMessageBox::Yes) {
ColorSchemeFileWorker().deleteScheme(Config()->getCurrentTheme());
updateThemeFromConfig();
}
}
}
void AppearanceOptionsWidget::onLanguageComboBoxCurrentIndexChanged(int index)

View File

@ -442,13 +442,7 @@ void ColorSchemePrefWidget::newColor()
static_cast<ColorSettingsModel *>(ui->preferencesListView->model())->setColor(currCO.optionName,
d.selectedColor());
static_cast<ColorViewButton *>(QObject::sender())->setColor(d.selectedColor());
if (currCO.optionName == standardBackgroundOptionName) {
static_cast<PreferencesListView *>(ui->preferencesListView)->setStandardColors();
} else {
static_cast<PreferencesListView *>(ui->preferencesListView)->setStandardColors();
}
ui->preferencesListView->setStandardColors();
}
void ColorSchemePrefWidget::indexChanged(const QModelIndex &ni)
@ -456,9 +450,9 @@ void ColorSchemePrefWidget::indexChanged(const QModelIndex &ni)
ui->colorViewFore->setColor(ni.data(Qt::UserRole).value<ColorOption>().color);
}
void ColorSchemePrefWidget::setNewScheme(const QString &schemeName)
void ColorSchemePrefWidget::updateSchemeFromConfig()
{
isEditable = ColorSchemeFileWorker().isCustomScheme(schemeName);
isEditable = ColorSchemeFileWorker().isCustomScheme(Config()->getCurrentTheme());
static_cast<ColorSettingsModel *>(ui->preferencesListView->model())->updateScheme();
}

View File

@ -21,7 +21,7 @@ public:
public slots:
void apply();
void setNewScheme(const QString &schemeName);
void updateSchemeFromConfig();
private slots:
void newColor();