Theming: Do not use absolute path for built-in themes

+ always set the global palette and base style on apply

This is required for correctly using the selected theme
with multiple installations of Qt Creator.

Task-number: QTCREATORBUG-13203
Task-number: QTCREATORBUG-13396
Change-Id: I036b96721b6d184dae43d08c5e8bc9e6d1328a7b
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2014-11-14 09:53:44 +02:00
committed by Orgad Shaneh
parent 3ec16fe4d8
commit 3441594636
10 changed files with 119 additions and 91 deletions

View File

@@ -48,6 +48,7 @@
#include <utils/savefile.h>
#include <utils/stringutils.h>
#include <utils/theme/theme.h>
#include <utils/theme/theme_p.h>
#include <QtPlugin>
#include <QDebug>
@@ -90,11 +91,36 @@ CorePlugin::~CorePlugin()
setCreatorTheme(0);
}
static QString absoluteThemePath(const QString &themeName)
{
if (themeName.isEmpty())
return themeName;
QString res = QDir::fromNativeSeparators(themeName);
QFileInfo fi(res);
// Try the given name
if (fi.exists())
return fi.absoluteFilePath();
const QString suffix = QLatin1String("creatortheme");
// Try name.creatortheme
if (fi.suffix() != suffix) {
res = themeName + QLatin1Char('.') + suffix;
fi.setFile(res);
if (fi.exists())
return fi.absoluteFilePath();
}
if (fi.path().isEmpty())
return QString(); // absolute/relative path, but not found
// If only name was given, look it up in qtcreator/themes
res.prepend(ICore::resourcePath() + QLatin1String("/themes/"));
return QFileInfo::exists(res) ? res : QString();
}
void CorePlugin::parseArguments(const QStringList &arguments)
{
QString themeName = QLatin1String("default");
const QString defaultTheme = QLatin1String("default");
QString themeName = ICore::settings()->value(
QLatin1String(Constants::SETTINGS_THEME), defaultTheme).toString();
QColor overrideColor;
bool overrideTheme = false;
bool presentationMode = false;
for (int i = 0; i < arguments.size(); ++i) {
@@ -106,34 +132,27 @@ void CorePlugin::parseArguments(const QStringList &arguments)
if (arguments.at(i) == QLatin1String("-presentationMode"))
presentationMode = true;
if (arguments.at(i) == QLatin1String("-theme")) {
overrideTheme = true;
themeName = arguments.at(i + 1);
i++;
}
}
QSettings *settings = Core::ICore::settings();
QString themeURI = settings->value(QLatin1String(Core::Constants::SETTINGS_THEME)).toString();
if (!QFileInfo::exists(themeURI) || overrideTheme) {
const QString builtInTheme = QStringLiteral("%1/themes/%2.creatortheme")
.arg(ICore::resourcePath()).arg(themeName);
if (QFile::exists(builtInTheme)) {
themeURI = builtInTheme;
} else if (themeName.endsWith(QLatin1String(".creatortheme"))) {
themeURI = themeName;
} else { // TODO: Fallback to default theme
QString themeURI = absoluteThemePath(themeName);
if (themeURI.isEmpty()) {
themeName = defaultTheme;
themeURI = QStringLiteral("%1/themes/%2.creatortheme").arg(ICore::resourcePath()).arg(themeName);
if (themeURI.isEmpty()) {
qCritical("%s", qPrintable(QCoreApplication::translate("Application", "No valid theme '%1'")
.arg(themeName)));
}
}
QSettings themeSettings(themeURI, QSettings::IniFormat);
Theme *theme = new Theme(qApp);
Theme *theme = new Theme(themeName, qApp);
theme->readSettings(themeSettings);
setCreatorTheme(theme);
if (theme->flag(Theme::ApplyThemePaletteGlobally))
QApplication::setPalette(creatorTheme()->palette());
QApplication::setPalette(theme->palette());
setCreatorTheme(theme);
// defer creation of these widgets until here,
// because they need a valid theme set