summaryrefslogtreecommitdiff
path: root/src/plugins/coreplugin/coreplugin.cpp
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2016-10-31 17:27:24 +0100
committerEike Ziller <eike.ziller@qt.io>2016-11-02 11:10:18 +0000
commit05bf915c031a1b1d0331fe6209e1eddaee5f7f07 (patch)
tree111fadbb4bdc90864a63799c00c5c23c71ffca72 /src/plugins/coreplugin/coreplugin.cpp
parentd93963296a91969321d20e3526b14fc05e83dd90 (diff)
downloadqt-creator-05bf915c031a1b1d0331fe6209e1eddaee5f7f07.tar.gz
Core: Refactor argument handling
Split up getting the data from the arguments list and actually applying the values, and move the details of theme creation and application to better places. This gets rid of ugly control flow details like that CorePlugin::initialize created the action manager before calling parseArguments, because that is needed to apply the presentation mode argument setting, and parseArguments created the main window because that needs to be created _after_ setting the theme (which can be overridden by command line argument), but _before_ applying the override color argument setting. Change-Id: I9c99305b6efbfcc4b37cea9e5c70d816a621963b Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/coreplugin/coreplugin.cpp')
-rw-r--r--src/plugins/coreplugin/coreplugin.cpp58
1 files changed, 21 insertions, 37 deletions
diff --git a/src/plugins/coreplugin/coreplugin.cpp b/src/plugins/coreplugin/coreplugin.cpp
index 75df422801..888abfbb5c 100644
--- a/src/plugins/coreplugin/coreplugin.cpp
+++ b/src/plugins/coreplugin/coreplugin.cpp
@@ -93,53 +93,29 @@ CorePlugin::~CorePlugin()
setCreatorTheme(0);
}
-void CorePlugin::parseArguments(const QStringList &arguments)
-{
- const Id settingsThemeId = Id::fromSetting(ICore::settings()->value(
- QLatin1String(Constants::SETTINGS_THEME), QLatin1String(Constants::DEFAULT_THEME)));
- Id themeId = settingsThemeId;
+struct CoreArguments {
QColor overrideColor;
+ Id themeId;
bool presentationMode = false;
+};
+CoreArguments parseArguments(const QStringList &arguments)
+{
+ CoreArguments args;
for (int i = 0; i < arguments.size(); ++i) {
if (arguments.at(i) == QLatin1String("-color")) {
const QString colorcode(arguments.at(i + 1));
- overrideColor = QColor(colorcode);
+ args.overrideColor = QColor(colorcode);
i++; // skip the argument
}
if (arguments.at(i) == QLatin1String("-presentationMode"))
- presentationMode = true;
+ args.presentationMode = true;
if (arguments.at(i) == QLatin1String("-theme")) {
- themeId = Id::fromString(arguments.at(i + 1));
- i++;
+ args.themeId = Id::fromString(arguments.at(i + 1));
+ i++; // skip the argument
}
}
- const QList<ThemeEntry> availableThemes = ThemeEntry::availableThemes();
- int themeIndex = Utils::indexOf(availableThemes, Utils::equal(&ThemeEntry::id, themeId));
- if (themeIndex < 0) {
- themeIndex = Utils::indexOf(availableThemes,
- Utils::equal(&ThemeEntry::id, settingsThemeId));
- }
- if (themeIndex < 0)
- themeIndex = 0;
- if (themeIndex < availableThemes.size()) {
- const ThemeEntry themeEntry = availableThemes.at(themeIndex);
- QSettings themeSettings(themeEntry.filePath(), QSettings::IniFormat);
- Theme *theme = new Theme(themeEntry.id().toString(), qApp);
- theme->readSettings(themeSettings);
- if (theme->flag(Theme::ApplyThemePaletteGlobally))
- QApplication::setPalette(theme->palette());
- setCreatorTheme(theme);
- }
-
- // defer creation of these widgets until here,
- // because they need a valid theme set
- m_mainWindow = new MainWindow;
- ActionManager::setPresentationModeEnabled(presentationMode);
- m_locator = new Locator;
-
- if (overrideColor.isValid())
- m_mainWindow->setOverrideColor(overrideColor);
+ return args;
}
bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
@@ -148,10 +124,18 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
*errorMessage = tr("No themes found in installation.");
return false;
}
- new ActionManager(this);
+ const CoreArguments args = parseArguments(arguments);
Theme::initialPalette(); // Initialize palette before setting it
+ Theme *themeFromArg = ThemeEntry::createTheme(args.themeId);
+ setCreatorTheme(themeFromArg ? themeFromArg
+ : ThemeEntry::createTheme(ThemeEntry::themeSetting()));
+ new ActionManager(this);
+ ActionManager::setPresentationModeEnabled(args.presentationMode);
+ m_mainWindow = new MainWindow;
+ if (args.overrideColor.isValid())
+ m_mainWindow->setOverrideColor(args.overrideColor);
+ m_locator = new Locator;
qsrand(QDateTime::currentDateTime().toTime_t());
- parseArguments(arguments);
const bool success = m_mainWindow->init(errorMessage);
if (success) {
m_editMode = new EditMode;