forked from qt-creator/qt-creator
Utils: Let Themes define their default ToolbarStyle
The upcoming themes were designed with the relaxed ToolbarStyle in mind. The default style is however ToolbarStyleCompact. This change allows themes to define their individual default toolbar style, analogous to the default text editor scheme. Change-Id: I31383e37134c5591c18be536f9133f97323f8456 Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io> Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -38,7 +38,7 @@ static int range(float x, int min, int max)
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
static StyleHelper::ToolbarStyle s_toolbarStyle = StyleHelper::defaultToolbarStyle;
|
static StyleHelper::ToolbarStyle s_toolbarStyle = StyleHelper::ToolbarStyle::Compact;
|
||||||
// Invalid by default, setBaseColor needs to be called at least once
|
// Invalid by default, setBaseColor needs to be called at least once
|
||||||
static QColor s_baseColor;
|
static QColor s_baseColor;
|
||||||
static QColor s_requestedBaseColor;
|
static QColor s_requestedBaseColor;
|
||||||
@@ -95,6 +95,11 @@ StyleHelper::ToolbarStyle StyleHelper::toolbarStyle()
|
|||||||
return s_toolbarStyle;
|
return s_toolbarStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StyleHelper::ToolbarStyle StyleHelper::defaultToolbarStyle()
|
||||||
|
{
|
||||||
|
return creatorTheme() ? creatorTheme()->defaultToolbarStyle() : ToolbarStyle::Compact;
|
||||||
|
}
|
||||||
|
|
||||||
QColor StyleHelper::notTooBrightHighlightColor()
|
QColor StyleHelper::notTooBrightHighlightColor()
|
||||||
{
|
{
|
||||||
QColor highlightColor = QApplication::palette().highlight().color();
|
QColor highlightColor = QApplication::palette().highlight().color();
|
||||||
|
@@ -77,7 +77,6 @@ enum class ToolbarStyle {
|
|||||||
Compact,
|
Compact,
|
||||||
Relaxed,
|
Relaxed,
|
||||||
};
|
};
|
||||||
constexpr ToolbarStyle defaultToolbarStyle = ToolbarStyle::Compact;
|
|
||||||
|
|
||||||
// Keep in sync with:
|
// Keep in sync with:
|
||||||
// SyleHelper::uiFontMetrics, ICore::uiConfigInformation, tst_manual_widgets_uifonts::main
|
// SyleHelper::uiFontMetrics, ICore::uiConfigInformation, tst_manual_widgets_uifonts::main
|
||||||
@@ -105,6 +104,7 @@ enum UiElement {
|
|||||||
QTCREATOR_UTILS_EXPORT int navigationWidgetHeight();
|
QTCREATOR_UTILS_EXPORT int navigationWidgetHeight();
|
||||||
QTCREATOR_UTILS_EXPORT void setToolbarStyle(ToolbarStyle style);
|
QTCREATOR_UTILS_EXPORT void setToolbarStyle(ToolbarStyle style);
|
||||||
QTCREATOR_UTILS_EXPORT ToolbarStyle toolbarStyle();
|
QTCREATOR_UTILS_EXPORT ToolbarStyle toolbarStyle();
|
||||||
|
QTCREATOR_UTILS_EXPORT ToolbarStyle defaultToolbarStyle();
|
||||||
QTCREATOR_UTILS_EXPORT QPalette sidebarFontPalette(const QPalette &original);
|
QTCREATOR_UTILS_EXPORT QPalette sidebarFontPalette(const QPalette &original);
|
||||||
|
|
||||||
// This is our color table, all colors derive from baseColor
|
// This is our color table, all colors derive from baseColor
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
#include "../hostosinfo.h"
|
#include "../hostosinfo.h"
|
||||||
#include "../qtcassert.h"
|
#include "../qtcassert.h"
|
||||||
#include "filepath.h"
|
#include "filepath.h"
|
||||||
|
#include "stylehelper.h"
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
#import "theme_mac.h"
|
#import "theme_mac.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -21,6 +22,7 @@ static Theme *m_creatorTheme = nullptr;
|
|||||||
static std::optional<QPalette> m_initialPalette;
|
static std::optional<QPalette> m_initialPalette;
|
||||||
|
|
||||||
ThemePrivate::ThemePrivate()
|
ThemePrivate::ThemePrivate()
|
||||||
|
: defaultToolbarStyle(StyleHelper::ToolbarStyle::Compact)
|
||||||
{
|
{
|
||||||
const QMetaObject &m = Theme::staticMetaObject;
|
const QMetaObject &m = Theme::staticMetaObject;
|
||||||
colors.resize (m.enumerator(m.indexOfEnumerator("Color")).keyCount());
|
colors.resize (m.enumerator(m.indexOfEnumerator("Color")).keyCount());
|
||||||
@@ -130,6 +132,11 @@ QString Theme::defaultTextEditorColorScheme() const
|
|||||||
return d->defaultTextEditorColorScheme;
|
return d->defaultTextEditorColorScheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StyleHelper::ToolbarStyle Theme::defaultToolbarStyle() const
|
||||||
|
{
|
||||||
|
return d->defaultToolbarStyle;
|
||||||
|
}
|
||||||
|
|
||||||
QString Theme::id() const
|
QString Theme::id() const
|
||||||
{
|
{
|
||||||
return d->id;
|
return d->id;
|
||||||
@@ -228,6 +235,9 @@ void Theme::readSettingsInternal(QSettings &settings)
|
|||||||
d->preferredStyles.removeAll(QString());
|
d->preferredStyles.removeAll(QString());
|
||||||
d->defaultTextEditorColorScheme
|
d->defaultTextEditorColorScheme
|
||||||
= settings.value(QLatin1String("DefaultTextEditorColorScheme")).toString();
|
= settings.value(QLatin1String("DefaultTextEditorColorScheme")).toString();
|
||||||
|
d->defaultToolbarStyle =
|
||||||
|
settings.value(QLatin1String("DefaultToolbarStyle")).toString() == "Relaxed"
|
||||||
|
? StyleHelper::ToolbarStyle::Relaxed : StyleHelper::ToolbarStyle::Compact;
|
||||||
d->enforceAccentColorOnMacOS = settings.value("EnforceAccentColorOnMacOS").toString();
|
d->enforceAccentColorOnMacOS = settings.value("EnforceAccentColorOnMacOS").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,6 +18,10 @@ QT_END_NAMESPACE
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
|
namespace StyleHelper {
|
||||||
|
enum class ToolbarStyle;
|
||||||
|
}
|
||||||
|
|
||||||
class ThemePrivate;
|
class ThemePrivate;
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT Theme : public QObject
|
class QTCREATOR_UTILS_EXPORT Theme : public QObject
|
||||||
@@ -530,6 +534,7 @@ public:
|
|||||||
QPalette palette() const;
|
QPalette palette() const;
|
||||||
QStringList preferredStyles() const;
|
QStringList preferredStyles() const;
|
||||||
QString defaultTextEditorColorScheme() const;
|
QString defaultTextEditorColorScheme() const;
|
||||||
|
StyleHelper::ToolbarStyle defaultToolbarStyle() const;
|
||||||
|
|
||||||
QString id() const;
|
QString id() const;
|
||||||
QString filePath() const;
|
QString filePath() const;
|
||||||
|
@@ -12,6 +12,10 @@
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
|
namespace StyleHelper {
|
||||||
|
enum class ToolbarStyle;
|
||||||
|
}
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT ThemePrivate
|
class QTCREATOR_UTILS_EXPORT ThemePrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -22,6 +26,7 @@ public:
|
|||||||
QString displayName;
|
QString displayName;
|
||||||
QStringList preferredStyles;
|
QStringList preferredStyles;
|
||||||
QString defaultTextEditorColorScheme;
|
QString defaultTextEditorColorScheme;
|
||||||
|
StyleHelper::ToolbarStyle defaultToolbarStyle;
|
||||||
QString enforceAccentColorOnMacOS;
|
QString enforceAccentColorOnMacOS;
|
||||||
QList<QPair<QColor, QString> > colors;
|
QList<QPair<QColor, QString> > colors;
|
||||||
QList<QString> imageFiles;
|
QList<QString> imageFiles;
|
||||||
|
@@ -306,7 +306,7 @@ void GeneralSettingsWidget::apply()
|
|||||||
if (const auto newStyle = m_toolbarStyleBox->currentData().value<StyleHelper::ToolbarStyle>();
|
if (const auto newStyle = m_toolbarStyleBox->currentData().value<StyleHelper::ToolbarStyle>();
|
||||||
newStyle != StyleHelper::toolbarStyle()) {
|
newStyle != StyleHelper::toolbarStyle()) {
|
||||||
ICore::settings()->setValueWithDefault(settingsKeyToolbarStyle, int(newStyle),
|
ICore::settings()->setValueWithDefault(settingsKeyToolbarStyle, int(newStyle),
|
||||||
int(StyleHelper::defaultToolbarStyle));
|
int(StyleHelper::defaultToolbarStyle()));
|
||||||
StyleHelper::setToolbarStyle(newStyle);
|
StyleHelper::setToolbarStyle(newStyle);
|
||||||
QStyle *applicationStyle = QApplication::style();
|
QStyle *applicationStyle = QApplication::style();
|
||||||
for (QWidget *widget : QApplication::allWidgets())
|
for (QWidget *widget : QApplication::allWidgets())
|
||||||
@@ -383,11 +383,11 @@ void GeneralSettingsWidget::setCodecForLocale(const QByteArray &codec)
|
|||||||
StyleHelper::ToolbarStyle toolbarStylefromSettings()
|
StyleHelper::ToolbarStyle toolbarStylefromSettings()
|
||||||
{
|
{
|
||||||
if (!ExtensionSystem::PluginManager::instance()) // May happen in tests
|
if (!ExtensionSystem::PluginManager::instance()) // May happen in tests
|
||||||
return StyleHelper::defaultToolbarStyle;
|
return StyleHelper::defaultToolbarStyle();
|
||||||
|
|
||||||
return StyleHelper::ToolbarStyle(
|
return StyleHelper::ToolbarStyle(
|
||||||
ICore::settings()->value(settingsKeyToolbarStyle,
|
ICore::settings()->value(settingsKeyToolbarStyle,
|
||||||
int(StyleHelper::defaultToolbarStyle)).toInt());
|
int(StyleHelper::defaultToolbarStyle())).toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeneralSettingsWidget::fillToolbarStyleBox() const
|
void GeneralSettingsWidget::fillToolbarStyleBox() const
|
||||||
|
Reference in New Issue
Block a user