2019-05-01 16:15:33 +00:00
|
|
|
#include "ColorThemeComboBox.h"
|
|
|
|
|
|
|
|
#include "core/Cutter.h"
|
|
|
|
|
|
|
|
#include "common/ColorThemeWorker.h"
|
|
|
|
#include "common/Configuration.h"
|
|
|
|
|
|
|
|
ColorThemeComboBox::ColorThemeComboBox(QWidget *parent) : QComboBox(parent), showOnlyCustom(false)
|
|
|
|
{
|
|
|
|
connect(this, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
|
|
|
this, &ColorThemeComboBox::onCurrentIndexChanged);
|
|
|
|
updateFromConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColorThemeComboBox::updateFromConfig(bool interfaceThemeChanged)
|
|
|
|
{
|
|
|
|
QSignalBlocker signalBlockerColorBox(this);
|
|
|
|
|
|
|
|
const int curInterfaceThemeIndex = Config()->getInterfaceTheme();
|
|
|
|
const QList<QString> themes(showOnlyCustom
|
|
|
|
? ThemeWorker().customThemes()
|
|
|
|
: Core()->getColorThemes());
|
|
|
|
|
|
|
|
clear();
|
|
|
|
for (const QString &theme : themes) {
|
|
|
|
if (ThemeWorker().isCustomTheme(theme) ||
|
2019-06-12 17:46:07 +00:00
|
|
|
(Configuration::cutterInterfaceThemesList()[curInterfaceThemeIndex].flag &
|
|
|
|
Configuration::relevantThemes[theme])) {
|
2019-05-01 16:15:33 +00:00
|
|
|
addItem(theme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString curTheme = interfaceThemeChanged
|
2019-06-12 17:46:07 +00:00
|
|
|
? Config()->getLastThemeOf(Configuration::cutterInterfaceThemesList()[curInterfaceThemeIndex])
|
2019-05-01 16:15:33 +00:00
|
|
|
: Config()->getColorTheme();
|
|
|
|
const int index = findText(curTheme);
|
|
|
|
|
|
|
|
setCurrentIndex(index == -1 ? 0 : index);
|
|
|
|
if (interfaceThemeChanged || index == -1) {
|
|
|
|
curTheme = currentText();
|
|
|
|
Config()->setColorTheme(curTheme);
|
|
|
|
}
|
|
|
|
int maxThemeLen = 0;
|
|
|
|
for (const QString &str : themes) {
|
|
|
|
int strLen = str.length();
|
|
|
|
if (strLen > maxThemeLen) {
|
|
|
|
maxThemeLen = strLen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setMinimumContentsLength(maxThemeLen);
|
|
|
|
setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColorThemeComboBox::onCurrentIndexChanged(int index)
|
|
|
|
{
|
|
|
|
QString theme = itemText(index);
|
|
|
|
|
|
|
|
int curQtThemeIndex = Config()->getInterfaceTheme();
|
2019-06-12 17:46:07 +00:00
|
|
|
if (curQtThemeIndex >= Configuration::cutterInterfaceThemesList().size()) {
|
2019-05-01 16:15:33 +00:00
|
|
|
curQtThemeIndex = 0;
|
|
|
|
Config()->setInterfaceTheme(curQtThemeIndex);
|
|
|
|
}
|
|
|
|
|
2019-06-12 17:46:07 +00:00
|
|
|
Config()->setLastThemeOf(Configuration::cutterInterfaceThemesList()[curQtThemeIndex], theme);
|
2019-05-01 16:15:33 +00:00
|
|
|
Config()->setColorTheme(theme);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColorThemeComboBox::setShowOnlyCustom(bool value)
|
|
|
|
{
|
|
|
|
showOnlyCustom = value;
|
|
|
|
updateFromConfig();
|
|
|
|
}
|