Commit 2ff75813 authored by Alessandro Portale's avatar Alessandro Portale

TextEditor: Define Color Scheme entry per Theme

The TextEditor settings do not remember a global Color Scheme setting,
anymore, but rather a Color Scheme ber Theme. A .creatortheme can define
a default TextEditor Color Scheme (overridable in the settings). This
makes switching of schemes more pleasant.

Taks-number: QTCREATORBUG-15229
Change-Id: I3bd36a4dfa23feea2254be2df50fce064e8fe2af
Reviewed-by: default avatarLeena Miettinen <riitta-leena.miettinen@theqtcompany.com>
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent ff7b8ffc
[General]
ThemeName=dark
PreferredStyles=Fusion
DefaultTextEditorColorScheme=dark.xml
[Palette]
shadowBackground=ff232323
......
......@@ -83,6 +83,11 @@ QStringList Theme::preferredStyles() const
return d->preferredStyles;
}
QString Theme::defaultTextEditorColorScheme() const
{
return d->defaultTextEditorColorScheme;
}
QString Theme::id() const
{
return d->id;
......@@ -182,6 +187,8 @@ void Theme::readSettings(QSettings &settings)
d->displayName = settings.value(QLatin1String("ThemeName"), QLatin1String("unnamed")).toString();
d->preferredStyles = settings.value(QLatin1String("PreferredStyles")).toStringList();
d->preferredStyles.removeAll(QLatin1String(""));
d->defaultTextEditorColorScheme =
settings.value(QLatin1String("DefaultTextEditorColorScheme")).toString();
}
{
settings.beginGroup(QLatin1String("Palette"));
......
......@@ -274,6 +274,7 @@ public:
QGradientStops gradient(Gradient role) const;
QPalette palette() const;
QStringList preferredStyles() const;
QString defaultTextEditorColorScheme() const;
QString id() const;
QString filePath() const;
......
......@@ -43,6 +43,7 @@ public:
QString fileName;
QString displayName;
QStringList preferredStyles;
QString defaultTextEditorColorScheme;
QVector<QPair<QColor, QString> > colors;
QVector<QString> imageFiles;
QVector<QGradientStops> gradients;
......
......@@ -28,6 +28,7 @@
#include <utils/fileutils.h>
#include <utils/hostosinfo.h>
#include <utils/theme/theme.h>
#include <coreplugin/icore.h>
#include <QCoreApplication>
......@@ -41,7 +42,7 @@ static const char fontFamilyKey[] = "FontFamily";
static const char fontSizeKey[] = "FontSize";
static const char fontZoomKey[] = "FontZoom";
static const char antialiasKey[] = "FontAntialias";
static const char schemeFileNameKey[] = "ColorScheme";
static const char schemeFileNamesKey[] = "ColorSchemes";
namespace {
static const bool DEFAULT_ANTIALIAS = true;
......@@ -85,8 +86,11 @@ void FontSettings::toSettings(const QString &category,
if (m_antialias != DEFAULT_ANTIALIAS || s->contains(QLatin1String(antialiasKey)))
s->setValue(QLatin1String(antialiasKey), m_antialias);
if (m_schemeFileName != defaultSchemeFileName() || s->contains(QLatin1String(schemeFileNameKey)))
s->setValue(QLatin1String(schemeFileNameKey), m_schemeFileName);
auto schemeFileNames = s->value(QLatin1String(schemeFileNamesKey)).toMap();
if (m_schemeFileName != defaultSchemeFileName() || schemeFileNames.contains(Utils::creatorTheme()->id())) {
schemeFileNames.insert(Utils::creatorTheme()->id(), m_schemeFileName);
s->setValue(QLatin1String(schemeFileNamesKey), schemeFileNames);
}
s->endGroup();
}
......@@ -108,12 +112,13 @@ bool FontSettings::fromSettings(const QString &category,
m_fontZoom= s->value(group + QLatin1String(fontZoomKey), m_fontZoom).toInt();
m_antialias = s->value(group + QLatin1String(antialiasKey), DEFAULT_ANTIALIAS).toBool();
if (s->contains(group + QLatin1String(schemeFileNameKey))) {
// Load the selected color scheme
QString scheme = s->value(group + QLatin1String(schemeFileNameKey)).toString();
if (scheme.isEmpty() || !QFile::exists(scheme))
scheme = defaultSchemeFileName(Utils::FileName::fromString(scheme).fileName());
loadColorScheme(scheme, descriptions);
if (s->contains(group + QLatin1String(schemeFileNamesKey))) {
// Load the selected color scheme for the current theme
auto schemeFileNames = s->value(group + QLatin1String(schemeFileNamesKey)).toMap();
if (schemeFileNames.contains(Utils::creatorTheme()->id())) {
const QString scheme = schemeFileNames.value(Utils::creatorTheme()->id()).toString();
loadColorScheme(scheme, descriptions);
}
}
return true;
......@@ -368,10 +373,15 @@ QString FontSettings::defaultSchemeFileName(const QString &fileName)
QString defaultScheme = Core::ICore::resourcePath();
defaultScheme += QLatin1String("/styles/");
if (!fileName.isEmpty() && QFile::exists(defaultScheme + fileName))
if (!fileName.isEmpty() && QFile::exists(defaultScheme + fileName)) {
defaultScheme += fileName;
else
defaultScheme += QLatin1String("default.xml");
} else {
const QString themeScheme = Utils::creatorTheme()->defaultTextEditorColorScheme();
if (!themeScheme.isEmpty() && QFile::exists(defaultScheme + themeScheme))
defaultScheme += themeScheme;
else
defaultScheme += QLatin1String("default.xml");
}
return defaultScheme;
}
......
......@@ -32,6 +32,7 @@
#include <utils/fileutils.h>
#include <utils/stringutils.h>
#include <utils/qtcassert.h>
#include <utils/theme/theme.h>
#include <QFileDialog>
#include <QFontDatabase>
......@@ -346,6 +347,9 @@ QWidget *FontSettingsPage::widget()
d_ptr->m_widget = new QWidget;
d_ptr->m_ui = new Ui::FontSettingsPage;
d_ptr->m_ui->setupUi(d_ptr->m_widget);
d_ptr->m_ui->colorSchemeGroupBox->setTitle(
tr("Color Scheme for Qt Creator Theme \"%1\"")
.arg(Utils::creatorTheme()->displayName()));
d_ptr->m_ui->schemeComboBox->setModel(d_ptr->m_schemeListModel);
d_ptr->m_ui->fontComboBox->setCurrentFont(d_ptr->m_value.family());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment