Files
qt-creator/src/plugins/coreplugin/coreplugin.cpp

456 lines
19 KiB
C++
Raw Normal View History

/****************************************************************************
2008-12-02 12:01:29 +01:00
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator.
2008-12-02 12:01:29 +01:00
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
2010-12-17 16:01:08 +01:00
**
****************************************************************************/
2008-12-02 14:09:21 +01:00
2008-12-02 12:01:29 +01:00
#include "coreplugin.h"
#include "designmode.h"
2008-12-02 12:01:29 +01:00
#include "editmode.h"
#include "helpmanager.h"
#include "icore.h"
#include "idocument.h"
#include "iwizardfactory.h"
#include "mainwindow.h"
#include "modemanager.h"
#include "reaper_p.h"
#include "themechooser.h"
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/documentmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/find/findplugin.h>
#include <coreplugin/find/searchresultwindow.h>
#include <coreplugin/locator/locator.h>
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
#include <coreplugin/coreconstants.h>
#include <coreplugin/fileutils.h>
2008-12-02 12:01:29 +01:00
#include <app/app_version.h>
#include <extensionsystem/pluginerroroverview.h>
#include <extensionsystem/pluginmanager.h>
#include <extensionsystem/pluginspec.h>
#include <utils/algorithm.h>
#include <utils/checkablemessagebox.h>
#include <utils/commandline.h>
#include <utils/infobar.h>
#include <utils/macroexpander.h>
#include <utils/mimetypes/mimedatabase.h>
#include <utils/pathchooser.h>
#include <utils/savefile.h>
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
#include <utils/stringutils.h>
#include <utils/theme/theme.h>
#include <utils/theme/theme_p.h>
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QJsonObject>
#include <QLabel>
#include <QMenu>
#include <QMessageBox>
#include <QSettings>
#include <QUuid>
2008-12-02 12:01:29 +01:00
#include <cstdlib>
using namespace Core;
2008-12-02 12:01:29 +01:00
using namespace Core::Internal;
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
using namespace Utils;
2008-12-02 12:01:29 +01:00
static CorePlugin *m_instance = nullptr;
const char kWarnCrashReportingSetting[] = "WarnCrashReporting";
const char kEnvironmentChanges[] = "Core/EnvironmentChanges";
void CorePlugin::setupSystemEnvironment()
{
m_instance->m_startupSystemEnvironment = Environment::systemEnvironment();
const EnvironmentItems changes = EnvironmentItem::fromStringList(
ICore::settings()->value(kEnvironmentChanges).toStringList());
setEnvironmentChanges(changes);
}
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
CorePlugin::CorePlugin()
2008-12-02 12:01:29 +01:00
{
qRegisterMetaType<Id>();
qRegisterMetaType<Core::Search::TextPosition>();
qRegisterMetaType<Utils::CommandLine>();
qRegisterMetaType<Utils::FilePath>();
m_instance = this;
Core: Fix crash on shutdown ProcessReapers waits for all the processes to terminate, and in the mean time, it processes events. This is done after Core has already been terminated, but QObject dtor has not been called yet, so not all signal connections are disconnected. Crash trace: 1 QWidget::actions Qt5Widgets 0x7ff93a662fe9 2 Core::Internal::MenuActionContainer::updateInternal actioncontainer.cpp 482 0x7ff93158be03 3 Core::Internal::ActionContainerPrivate::update actioncontainer.cpp 417 0x7ff93158bd72 4 QMetaCallEvent::placeMetaCall Qt5Core 0x7ff939b9ac34 5 QObject::event Qt5Core 0x7ff939b995c1 6 QApplicationPrivate::notify_helper Qt5Widgets 0x7ff93a644990 7 QApplication::notify Qt5Widgets 0x7ff93a643a13 8 QCoreApplication::notifyInternal2 Qt5Core 0x7ff939b72aca 9 QCoreApplicationPrivate::sendPostedEvents Qt5Core 0x7ff939b74845 10 qt_plugin_query_metadata qwindows 0x7ff960422dff 11 QEventDispatcherWin32::processEvents Qt5Core 0x7ff939bbba5a 12 qt_plugin_query_metadata qwindows 0x7ff960422dd9 13 Core::Internal::ProcessReapers::~ProcessReapers reaper.cpp 134 0x7ff9317b54ee 14 Core::Internal::CorePlugin::~CorePlugin coreplugin.cpp 114 0x7ff9315a705c 15 Core::Internal::CorePlugin::`scalar deleting destructor' Core 0x7ff9315a8584 16 ExtensionSystem::Internal::PluginSpecPrivate::kill pluginspec.cpp 1125 0x7ff95299a160 17 ExtensionSystem::Internal::PluginManagerPrivate::loadPlugin pluginmanager.cpp 1608 0x7ff95298e2ad 18 ExtensionSystem::Internal::PluginManagerPrivate::deleteAll pluginmanager.cpp 1061 0x7ff9529885f5 19 ExtensionSystem::Internal::PluginManagerPrivate::shutdown pluginmanager.cpp 1397 0x7ff95299463f 20 QObject::qt_static_metacall Qt5Core 0x7ff939b91d49 21 QCoreApplicationPrivate::execCleanup Qt5Core 0x7ff939b71b25 22 QCoreApplication::exec Qt5Core 0x7ff939b71aaf 23 main main.cpp 762 0x7ff734b31bf7 24 WinMain qtcreator 0x7ff734b38407 25 __scrt_common_main_seh exe_common.inl 288 0x7ff734b3716a 26 BaseThreadInitThunk KERNEL32 0x7ff9a8806fd4 27 RtlUserThreadStart ntdll 0x7ff9a8adcec1 Change-Id: I7cf32f57354ee9e2507a2883078f0818fc5d6116 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2021-08-09 10:33:50 +03:00
m_reaper = new ProcessReapers;
setupSystemEnvironment();
2008-12-02 12:01:29 +01:00
}
CorePlugin::~CorePlugin()
{
Core: Fix crash on shutdown ProcessReapers waits for all the processes to terminate, and in the mean time, it processes events. This is done after Core has already been terminated, but QObject dtor has not been called yet, so not all signal connections are disconnected. Crash trace: 1 QWidget::actions Qt5Widgets 0x7ff93a662fe9 2 Core::Internal::MenuActionContainer::updateInternal actioncontainer.cpp 482 0x7ff93158be03 3 Core::Internal::ActionContainerPrivate::update actioncontainer.cpp 417 0x7ff93158bd72 4 QMetaCallEvent::placeMetaCall Qt5Core 0x7ff939b9ac34 5 QObject::event Qt5Core 0x7ff939b995c1 6 QApplicationPrivate::notify_helper Qt5Widgets 0x7ff93a644990 7 QApplication::notify Qt5Widgets 0x7ff93a643a13 8 QCoreApplication::notifyInternal2 Qt5Core 0x7ff939b72aca 9 QCoreApplicationPrivate::sendPostedEvents Qt5Core 0x7ff939b74845 10 qt_plugin_query_metadata qwindows 0x7ff960422dff 11 QEventDispatcherWin32::processEvents Qt5Core 0x7ff939bbba5a 12 qt_plugin_query_metadata qwindows 0x7ff960422dd9 13 Core::Internal::ProcessReapers::~ProcessReapers reaper.cpp 134 0x7ff9317b54ee 14 Core::Internal::CorePlugin::~CorePlugin coreplugin.cpp 114 0x7ff9315a705c 15 Core::Internal::CorePlugin::`scalar deleting destructor' Core 0x7ff9315a8584 16 ExtensionSystem::Internal::PluginSpecPrivate::kill pluginspec.cpp 1125 0x7ff95299a160 17 ExtensionSystem::Internal::PluginManagerPrivate::loadPlugin pluginmanager.cpp 1608 0x7ff95298e2ad 18 ExtensionSystem::Internal::PluginManagerPrivate::deleteAll pluginmanager.cpp 1061 0x7ff9529885f5 19 ExtensionSystem::Internal::PluginManagerPrivate::shutdown pluginmanager.cpp 1397 0x7ff95299463f 20 QObject::qt_static_metacall Qt5Core 0x7ff939b91d49 21 QCoreApplicationPrivate::execCleanup Qt5Core 0x7ff939b71b25 22 QCoreApplication::exec Qt5Core 0x7ff939b71aaf 23 main main.cpp 762 0x7ff734b31bf7 24 WinMain qtcreator 0x7ff734b38407 25 __scrt_common_main_seh exe_common.inl 288 0x7ff734b3716a 26 BaseThreadInitThunk KERNEL32 0x7ff9a8806fd4 27 RtlUserThreadStart ntdll 0x7ff9a8adcec1 Change-Id: I7cf32f57354ee9e2507a2883078f0818fc5d6116 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2021-08-09 10:33:50 +03:00
delete m_reaper;
IWizardFactory::destroyFeatureProvider();
Find::destroy();
delete m_locator;
delete m_editMode;
2008-12-02 12:01:29 +01:00
DesignMode::destroyModeIfRequired();
2008-12-02 12:01:29 +01:00
delete m_mainWindow;
setCreatorTheme(nullptr);
2008-12-02 12:01:29 +01:00
}
CorePlugin *CorePlugin::instance()
{
return m_instance;
}
struct CoreArguments {
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
QColor overrideColor;
Id themeId;
bool presentationMode = false;
};
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
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));
args.overrideColor = QColor(colorcode);
i++; // skip the argument
}
if (arguments.at(i) == QLatin1String("-presentationMode"))
args.presentationMode = true;
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
if (arguments.at(i) == QLatin1String("-theme")) {
args.themeId = Id::fromString(arguments.at(i + 1));
i++; // skip the argument
Implement theming for QtCreator Adds a 'Theme' tab to the environment settings and a '-theme' command line option. A theme is a combination of colors, gradients, flags and style information. There are two themes: - 'default': preserves the current default look - 'dark': uses a more flat for many widgets, dark color theme for everything This does not use a stylesheet (too limited), but rather sets the palette via C++ and modifies drawing behavior. Overall, the look is more flat (removed some gradients and bevels). Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE Desktop (Oxygen base style). For a screenshot, see https://gist.github.com/thorbenk/5ab06bea726de0aa7473 Changes: - Introduce class Theme, defining the interface how to access theme specific settings. The class reads a .creatortheme file (INI file, via QSettings) - Define named colors in the [Palette] section (see dark.creatortheme for example usage) - Use either named colors of AARRGGBB (hex) in the [Colors] section - A file ending with .creatortheme may be supplied to the '-theme' command line option - A global Theme instance can be accessed via creatorTheme() - Query colors, gradients, icons and flags from the theme were possible (TODO: use this in more places...) - There are very many color roles. It seems better to me to describe the role clearly, and then to consolidate later in the actual theme by assigning the same color. For example, one can set the text color of the output pane button individualy. - Many elements are also drawn differently. For the dark theme, I wanted to have a flatter look. - Introduce Theme::WidgetStyle enum, for now {Original, Flat}. - The theme specifies which kind of widget style it wants. - The drawing code queries the theme's style flag and switches between the original, gradient based look and the new, flat look. - Create some custom icons which look better on dark background (wip, currently folder/file icons) - Let ManhattanStyle draw some elements for non-panelwidgets, too (open/close arrows in QTreeView, custom folder/file icons) - For the welcomescreen, pass the WelcomeTheme class. WelcomeTheme exposes theme colors as Q_PROPERTY accessible from .qml - Themes can be modified via the 'Themes' tab in the environment settings. TODO: * Unify image handling * Avoid style name references * Fix gradients Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
}
}
return args;
}
bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
2008-12-02 12:01:29 +01:00
{
// register all mime types from all plugins
for (ExtensionSystem::PluginSpec *plugin : ExtensionSystem::PluginManager::plugins()) {
if (!plugin->isEffectivelyEnabled())
continue;
const QJsonObject metaData = plugin->metaData();
const QJsonValue mimetypes = metaData.value("Mimetypes");
QString mimetypeString;
if (Utils::readMultiLineString(mimetypes, &mimetypeString))
Utils::addMimeTypes(plugin->name() + ".mimetypes", mimetypeString.trimmed().toUtf8());
}
if (ThemeEntry::availableThemes().isEmpty()) {
*errorMessage = tr("No themes found in installation.");
return false;
}
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()));
InfoBar::initialize(ICore::settings());
new ActionManager(this);
ActionManager::setPresentationModeEnabled(args.presentationMode);
m_mainWindow = new MainWindow;
if (args.overrideColor.isValid())
m_mainWindow->setOverrideColor(args.overrideColor);
m_locator = new Locator;
std::srand(unsigned(QDateTime::currentDateTime().toSecsSinceEpoch()));
m_mainWindow->init();
m_editMode = new EditMode;
ModeManager::activateMode(m_editMode->id());
IWizardFactory::initialize();
// Make sure we respect the process's umask when creating new files
SaveFile::initializeUmask();
Find::initialize();
m_locator->initialize();
MacroExpander *expander = Utils::globalMacroExpander();
expander->registerVariable("CurrentDate:ISO", tr("The current date (ISO)."),
[]() { return QDate::currentDate().toString(Qt::ISODate); });
expander->registerVariable("CurrentTime:ISO", tr("The current time (ISO)."),
[]() { return QTime::currentTime().toString(Qt::ISODate); });
expander->registerVariable("CurrentDate:RFC", tr("The current date (RFC2822)."),
[]() { return QDate::currentDate().toString(Qt::RFC2822Date); });
expander->registerVariable("CurrentTime:RFC", tr("The current time (RFC2822)."),
[]() { return QTime::currentTime().toString(Qt::RFC2822Date); });
expander->registerVariable("CurrentDate:Locale", tr("The current date (Locale)."),
[]() { return QLocale::system()
.toString(QDate::currentDate(), QLocale::ShortFormat); });
expander->registerVariable("CurrentTime:Locale", tr("The current time (Locale)."),
[]() { return QLocale::system()
.toString(QTime::currentTime(), QLocale::ShortFormat); });
expander->registerVariable("Config:DefaultProjectDirectory", tr("The configured default directory for projects."),
[]() { return DocumentManager::projectsDirectory().toString(); });
expander->registerVariable("Config:LastFileDialogDirectory", tr("The directory last visited in a file dialog."),
[]() { return DocumentManager::fileDialogLastVisitedDirectory(); });
expander->registerVariable("HostOs:isWindows",
tr("Is %1 running on Windows?").arg(Constants::IDE_DISPLAY_NAME),
[]() { return QVariant(Utils::HostOsInfo::isWindowsHost()).toString(); });
expander->registerVariable("HostOs:isOSX",
tr("Is %1 running on OS X?").arg(Constants::IDE_DISPLAY_NAME),
[]() { return QVariant(Utils::HostOsInfo::isMacHost()).toString(); });
expander->registerVariable("HostOs:isLinux",
tr("Is %1 running on Linux?").arg(Constants::IDE_DISPLAY_NAME),
[]() { return QVariant(Utils::HostOsInfo::isLinuxHost()).toString(); });
expander->registerVariable("HostOs:isUnix",
tr("Is %1 running on any unix-based platform?")
.arg(Constants::IDE_DISPLAY_NAME),
[]() { return QVariant(Utils::HostOsInfo::isAnyUnixHost()).toString(); });
expander->registerVariable("HostOs:PathListSeparator",
tr("The path list separator for the platform."),
[]() { return QString(Utils::HostOsInfo::pathListSeparator()); });
expander->registerVariable("HostOs:ExecutableSuffix",
tr("The platform executable suffix."),
[]() { return QString(Utils::HostOsInfo::withExecutableSuffix("")); });
expander->registerVariable("IDE:ResourcePath",
tr("The directory where %1 finds its pre-installed resources.")
.arg(Constants::IDE_DISPLAY_NAME),
[]() { return ICore::resourcePath().toString(); });
expander->registerPrefix("CurrentDate:", tr("The current date (QDate formatstring)."),
[](const QString &fmt) { return QDate::currentDate().toString(fmt); });
expander->registerPrefix("CurrentTime:", tr("The current time (QTime formatstring)."),
[](const QString &fmt) { return QTime::currentTime().toString(fmt); });
expander->registerVariable("UUID", tr("Generate a new UUID."),
[]() { return QUuid::createUuid().toString(); });
expander->registerPrefix("#:", tr("A comment."), [](const QString &) { return QString(); });
Utils::PathChooser::setAboutToShowContextMenuHandler(&CorePlugin::addToPathChooserContextMenu);
#ifdef ENABLE_CRASHPAD
connect(ICore::instance(), &ICore::coreOpened, this, &CorePlugin::warnAboutCrashReporing,
Qt::QueuedConnection);
#endif
return true;
2008-12-02 12:01:29 +01:00
}
void CorePlugin::extensionsInitialized()
{
DesignMode::createModeIfRequired();
Find::extensionsInitialized();
m_locator->extensionsInitialized();
m_mainWindow->extensionsInitialized();
if (ExtensionSystem::PluginManager::hasError()) {
auto errorOverview = new ExtensionSystem::PluginErrorOverview(m_mainWindow);
errorOverview->setAttribute(Qt::WA_DeleteOnClose);
errorOverview->setModal(true);
errorOverview->show();
}
checkSettings();
2008-12-02 12:01:29 +01:00
}
bool CorePlugin::delayedInitialize()
{
m_locator->delayedInitialize();
IWizardFactory::allWizardFactories(); // scan for all wizard factories
return true;
}
QObject *CorePlugin::remoteCommand(const QStringList & /* options */,
const QString &workingDirectory,
const QStringList &args)
2008-12-02 12:01:29 +01:00
{
if (!ExtensionSystem::PluginManager::isInitializationDone()) {
connect(ExtensionSystem::PluginManager::instance(), &ExtensionSystem::PluginManager::initializationDone,
this, [this, workingDirectory, args]() {
remoteCommand(QStringList(), workingDirectory, args);
});
return nullptr;
}
const FilePaths filePaths = Utils::transform(args, FilePath::fromString);
IDocument *res = MainWindow::openFiles(
filePaths,
ICore::OpenFilesFlags(ICore::SwitchMode | ICore::CanContainLineAndColumnNumbers | ICore::SwitchSplitIfAlreadyVisible),
workingDirectory);
m_mainWindow->raiseWindow();
return res;
}
Environment CorePlugin::startupSystemEnvironment()
{
return m_instance->m_startupSystemEnvironment;
}
EnvironmentItems CorePlugin::environmentChanges()
{
return m_instance->m_environmentChanges;
}
void CorePlugin::setEnvironmentChanges(const EnvironmentItems &changes)
{
if (m_instance->m_environmentChanges == changes)
return;
m_instance->m_environmentChanges = changes;
Environment systemEnv = m_instance->m_startupSystemEnvironment;
systemEnv.modify(changes);
Environment::setSystemEnvironment(systemEnv);
ICore::settings()->setValueWithDefault(kEnvironmentChanges,
EnvironmentItem::toStringList(changes));
if (ICore::instance())
emit ICore::instance()->systemEnvironmentChanged();
}
void CorePlugin::fileOpenRequest(const QString &f)
{
remoteCommand(QStringList(), QString(), QStringList(f));
2008-12-02 12:01:29 +01:00
}
void CorePlugin::addToPathChooserContextMenu(Utils::PathChooser *pathChooser, QMenu *menu)
{
QList<QAction*> actions = menu->actions();
QAction *firstAction = actions.isEmpty() ? nullptr : actions.first();
if (QDir().exists(pathChooser->filePath().toString())) {
auto *showInGraphicalShell = new QAction(Core::FileUtils::msgGraphicalShellAction(), menu);
connect(showInGraphicalShell, &QAction::triggered, pathChooser, [pathChooser]() {
Core::FileUtils::showInGraphicalShell(pathChooser, pathChooser->filePath());
});
menu->insertAction(firstAction, showInGraphicalShell);
auto *showInTerminal = new QAction(Core::FileUtils::msgTerminalHereAction(), menu);
connect(showInTerminal, &QAction::triggered, pathChooser, [pathChooser]() {
if (pathChooser->openTerminalHandler())
pathChooser->openTerminalHandler()();
else
FileUtils::openTerminal(pathChooser->filePath());
});
menu->insertAction(firstAction, showInTerminal);
} else {
auto *mkPathAct = new QAction(tr("Create Folder"), menu);
connect(mkPathAct, &QAction::triggered, pathChooser, [pathChooser]() {
QDir().mkpath(pathChooser->filePath().toString());
pathChooser->triggerChanged();
});
menu->insertAction(firstAction, mkPathAct);
}
if (firstAction)
menu->insertSeparator(firstAction);
}
void CorePlugin::checkSettings()
{
const auto showMsgBox = [this](const QString &msg, QMessageBox::Icon icon) {
connect(ICore::instance(), &ICore::coreOpened, this, [msg, icon]() {
QMessageBox msgBox(ICore::dialogParent());
msgBox.setWindowTitle(tr("Settings File Error"));
msgBox.setText(msg);
msgBox.setIcon(icon);
msgBox.exec();
}, Qt::QueuedConnection);
};
const QSettings * const userSettings = ICore::settings();
QString errorDetails;
switch (userSettings->status()) {
case QSettings::NoError: {
const QFileInfo fi(userSettings->fileName());
if (fi.exists() && !fi.isWritable()) {
const QString errorMsg = tr("The settings file \"%1\" is not writable.\n"
"You will not be able to store any %2 settings.")
.arg(QDir::toNativeSeparators(userSettings->fileName()),
QLatin1String(Core::Constants::IDE_DISPLAY_NAME));
showMsgBox(errorMsg, QMessageBox::Warning);
}
return;
}
case QSettings::AccessError:
errorDetails = tr("The file is not readable.");
break;
case QSettings::FormatError:
errorDetails = tr("The file is invalid.");
break;
}
const QString errorMsg = tr("Error reading settings file \"%1\": %2\n"
"You will likely experience further problems using this instance of %3.")
.arg(QDir::toNativeSeparators(userSettings->fileName()), errorDetails,
QLatin1String(Core::Constants::IDE_DISPLAY_NAME));
showMsgBox(errorMsg, QMessageBox::Critical);
}
void CorePlugin::warnAboutCrashReporing()
{
if (!ICore::infoBar()->canInfoBeAdded(kWarnCrashReportingSetting))
return;
QString warnStr = ICore::settings()->value("CrashReportingEnabled", false).toBool()
? tr("%1 collects crash reports for the sole purpose of fixing bugs. "
"To disable this feature go to %2.")
: tr("%1 can collect crash reports for the sole purpose of fixing bugs. "
"To enable this feature go to %2.");
if (Utils::HostOsInfo::isMacHost()) {
warnStr = warnStr.arg(Core::Constants::IDE_DISPLAY_NAME)
.arg(Core::Constants::IDE_DISPLAY_NAME + tr(" > Preferences > Environment > System"));
} else {
warnStr = warnStr.arg(Core::Constants::IDE_DISPLAY_NAME)
.arg(tr("Tools > Options > Environment > System"));
}
Utils::InfoBarEntry info(kWarnCrashReportingSetting, warnStr,
Utils::InfoBarEntry::GlobalSuppression::Enabled);
info.setCustomButtonInfo(tr("Configure..."), [] {
ICore::infoBar()->removeInfo(kWarnCrashReportingSetting);
ICore::infoBar()->globallySuppressInfo(kWarnCrashReportingSetting);
ICore::showOptionsDialog(Core::Constants::SETTINGS_ID_SYSTEM);
});
info.setDetailsWidgetCreator([]() -> QWidget * {
auto label = new QLabel;
label->setWordWrap(true);
label->setOpenExternalLinks(true);
label->setText(msgCrashpadInformation());
label->setContentsMargins(0, 0, 0, 8);
return label;
});
ICore::infoBar()->addInfo(info);
}
// static
QString CorePlugin::msgCrashpadInformation()
{
return tr("%1 uses Google Crashpad for collecting crashes and sending them to our backend "
"for processing. Crashpad may capture arbitrary contents from crashed process "
"memory, including user sensitive information, URLs, and whatever other content "
"users have trusted %1 with. The collected crash reports are however only used "
"for the sole purpose of fixing bugs.").arg(Core::Constants::IDE_DISPLAY_NAME)
+ "<br><br>" + tr("More information:")
+ "<br><a href='https://chromium.googlesource.com/crashpad/crashpad/+/master/doc/"
"overview_design.md'>" + tr("Crashpad Overview") + "</a>"
"<br><a href='https://sentry.io/security/'>" + tr("%1 security policy").arg("Sentry.io")
+ "</a>";
}
ExtensionSystem::IPlugin::ShutdownFlag CorePlugin::aboutToShutdown()
{
Find::aboutToShutdown();
ExtensionSystem::IPlugin::ShutdownFlag shutdownFlag = m_locator->aboutToShutdown(
[this] { emit asynchronousShutdownFinished(); });
m_mainWindow->aboutToShutdown();
return shutdownFlag;
}