forked from qt-creator/qt-creator
Theme: Use QVariantMap for theme properties
QML can directly mirror this into a JavaScript object, so there is no need to manually copy the values into a different container. Also, QQmlPropertyMap is very expensive as it will listen to changes to any value in the map. We never use this. It would be entirely enough to update the whole map at once if we ever want to update the theme at runtime. Change-Id: Ie2b549e9af51d620801808c87d6f659cc7a06c04 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@theqtcompany.com>
This commit is contained in:
@@ -104,12 +104,8 @@ public:
|
|||||||
|
|
||||||
void TimelineTheme::setupTheme(QQmlEngine *engine)
|
void TimelineTheme::setupTheme(QQmlEngine *engine)
|
||||||
{
|
{
|
||||||
QQmlPropertyMap *themePropertyMap = new QQmlPropertyMap(engine);
|
engine->rootContext()->setContextProperty(QLatin1String("creatorTheme"),
|
||||||
const QVariantHash creatorTheme = Utils::creatorTheme()->values();
|
Utils::creatorTheme()->values());
|
||||||
for (auto it = creatorTheme.constBegin(); it != creatorTheme.constEnd(); ++it)
|
|
||||||
themePropertyMap->insert(it.key(), it.value());
|
|
||||||
|
|
||||||
engine->rootContext()->setContextProperty(QLatin1String("creatorTheme"), themePropertyMap);
|
|
||||||
|
|
||||||
engine->addImageProvider(QLatin1String("icons"), new TimelineImageIconProvider);
|
engine->addImageProvider(QLatin1String("icons"), new TimelineImageIconProvider);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,26 +141,27 @@ void Theme::setDisplayName(const QString &name)
|
|||||||
d->displayName = name;
|
d->displayName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantHash Theme::values() const
|
const QVariantMap &Theme::values() const
|
||||||
{
|
{
|
||||||
QVariantHash result;
|
if (d->values.isEmpty()) {
|
||||||
const QMetaObject &m = *metaObject();
|
const QMetaObject &m = *metaObject();
|
||||||
{
|
{
|
||||||
const QMetaEnum e = m.enumerator(m.indexOfEnumerator("Color"));
|
const QMetaEnum e = m.enumerator(m.indexOfEnumerator("Color"));
|
||||||
for (int i = 0, total = e.keyCount(); i < total; ++i) {
|
for (int i = 0, total = e.keyCount(); i < total; ++i) {
|
||||||
const QString key = QLatin1String(e.key(i));
|
const QString key = QLatin1String(e.key(i));
|
||||||
const QPair<QColor, QString> &var = d->colors.at(i);
|
const QPair<QColor, QString> &var = d->colors.at(i);
|
||||||
result.insert(key, var.first);
|
d->values.insert(key, var.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const QMetaEnum e = m.enumerator(m.indexOfEnumerator("Flag"));
|
||||||
|
for (int i = 0, total = e.keyCount(); i < total; ++i) {
|
||||||
|
const QString key = QLatin1String(e.key(i));
|
||||||
|
d->values.insert(key, flag(static_cast<Theme::Flag>(i)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
return d->values;
|
||||||
const QMetaEnum e = m.enumerator(m.indexOfEnumerator("Flag"));
|
|
||||||
for (int i = 0, total = e.keyCount(); i < total; ++i) {
|
|
||||||
const QString key = QLatin1String(e.key(i));
|
|
||||||
result.insert(key, flag(static_cast<Theme::Flag>(i)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static QColor readColor(const QString &color)
|
static QColor readColor(const QString &color)
|
||||||
|
|||||||
@@ -340,7 +340,7 @@ public:
|
|||||||
QString displayName() const;
|
QString displayName() const;
|
||||||
void setDisplayName(const QString &displayName);
|
void setDisplayName(const QString &displayName);
|
||||||
|
|
||||||
QVariantHash values() const;
|
const QVariantMap &values() const;
|
||||||
|
|
||||||
void readSettings(QSettings &settings);
|
void readSettings(QSettings &settings);
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ public:
|
|||||||
QVector<QGradientStops> gradients;
|
QVector<QGradientStops> gradients;
|
||||||
QVector<bool> flags;
|
QVector<bool> flags;
|
||||||
QMap<QString, QColor> palette;
|
QMap<QString, QColor> palette;
|
||||||
|
|
||||||
|
QVariantMap values;
|
||||||
};
|
};
|
||||||
|
|
||||||
QTCREATOR_UTILS_EXPORT void setCreatorTheme(Theme *theme);
|
QTCREATOR_UTILS_EXPORT void setCreatorTheme(Theme *theme);
|
||||||
|
|||||||
@@ -33,11 +33,13 @@
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
void Theming::insertTheme(QQmlPropertyMap *map)
|
const QVariantMap &Theming::theme()
|
||||||
{
|
{
|
||||||
const QVariantHash creatorTheme = Utils::creatorTheme()->values();
|
static QVariantMap map;
|
||||||
for (auto it = creatorTheme.constBegin(); it != creatorTheme.constEnd(); ++it)
|
if (!map.isEmpty())
|
||||||
map->insert(it.key(), it.value());
|
return map;
|
||||||
|
|
||||||
|
map = Utils::creatorTheme()->values();
|
||||||
|
|
||||||
/* Define QmlDesigner colors and remove alpha channels */
|
/* Define QmlDesigner colors and remove alpha channels */
|
||||||
const QColor backgroundColor = Utils::creatorTheme()->color(Utils::Theme::QmlDesigner_BackgroundColor);
|
const QColor backgroundColor = Utils::creatorTheme()->color(Utils::Theme::QmlDesigner_BackgroundColor);
|
||||||
@@ -58,18 +60,18 @@ void Theming::insertTheme(QQmlPropertyMap *map)
|
|||||||
tabDark = tabDark.darker(260);
|
tabDark = tabDark.darker(260);
|
||||||
}
|
}
|
||||||
|
|
||||||
map->insert("QmlDesignerBackgroundColorDarker", darkerBackground);
|
map.insert("QmlDesignerBackgroundColorDarker", darkerBackground);
|
||||||
map->insert("QmlDesignerBackgroundColorDarkAlternate", backgroundColor);
|
map.insert("QmlDesignerBackgroundColorDarkAlternate", backgroundColor);
|
||||||
map->insert("QmlDesignerTabLight", tabLight);
|
map.insert("QmlDesignerTabLight", tabLight);
|
||||||
map->insert("QmlDesignerTabDark", tabDark);
|
map.insert("QmlDesignerTabDark", tabDark);
|
||||||
map->insert("QmlDesignerButtonColor", buttonColor);
|
map.insert("QmlDesignerButtonColor", buttonColor);
|
||||||
map->insert("QmlDesignerBorderColor", Utils::creatorTheme()->color(Utils::Theme::SplitterColor));
|
map.insert("QmlDesignerBorderColor", Utils::creatorTheme()->color(Utils::Theme::SplitterColor));
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Theming::replaceCssColors(const QString &input)
|
QString Theming::replaceCssColors(const QString &input)
|
||||||
{
|
{
|
||||||
QQmlPropertyMap map;
|
const QVariantMap &map = theme();
|
||||||
insertTheme(&map);
|
|
||||||
QRegExp rx("creatorTheme\\.(\\w+);");
|
QRegExp rx("creatorTheme\\.(\\w+);");
|
||||||
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace QmlDesigner {
|
|||||||
class Theming
|
class Theming
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void insertTheme(QQmlPropertyMap *map);
|
static const QVariantMap &theme();
|
||||||
static QString replaceCssColors(const QString &input);
|
static QString replaceCssColors(const QString &input);
|
||||||
static void registerIconProvider(QQmlEngine *engine);
|
static void registerIconProvider(QQmlEngine *engine);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -83,8 +83,7 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
|
|||||||
rootContext->setContextProperty(QStringLiteral("itemLibraryIconWidth"), m_itemIconSize.width());
|
rootContext->setContextProperty(QStringLiteral("itemLibraryIconWidth"), m_itemIconSize.width());
|
||||||
rootContext->setContextProperty(QStringLiteral("itemLibraryIconHeight"), m_itemIconSize.height());
|
rootContext->setContextProperty(QStringLiteral("itemLibraryIconHeight"), m_itemIconSize.height());
|
||||||
rootContext->setContextProperty(QStringLiteral("rootView"), this);
|
rootContext->setContextProperty(QStringLiteral("rootView"), this);
|
||||||
Theming::insertTheme(&m_themeProperties);
|
rootContext->setContextProperty(QLatin1String("creatorTheme"), Theming::theme());
|
||||||
rootContext->setContextProperty(QLatin1String("creatorTheme"), &m_themeProperties);
|
|
||||||
|
|
||||||
m_itemViewQuickWidget->rootContext()->setContextProperty(QStringLiteral("highlightColor"), Utils::StyleHelper::notTooBrightHighlightColor());
|
m_itemViewQuickWidget->rootContext()->setContextProperty(QStringLiteral("highlightColor"), Utils::StyleHelper::notTooBrightHighlightColor());
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,6 @@ private:
|
|||||||
QPointer<Model> m_model;
|
QPointer<Model> m_model;
|
||||||
FilterChangeFlag m_filterFlag;
|
FilterChangeFlag m_filterFlag;
|
||||||
ItemLibraryEntry m_currentitemLibraryEntry;
|
ItemLibraryEntry m_currentitemLibraryEntry;
|
||||||
QQmlPropertyMap m_themeProperties;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,8 +103,7 @@ PropertyEditorQmlBackend::PropertyEditorQmlBackend(PropertyEditorView *propertyE
|
|||||||
m_contextObject->setModel(propertyEditor->model());
|
m_contextObject->setModel(propertyEditor->model());
|
||||||
m_contextObject->insertInQmlContext(context());
|
m_contextObject->insertInQmlContext(context());
|
||||||
|
|
||||||
Theming::insertTheme(&m_themeProperties);
|
context()->setContextProperty(QLatin1String("creatorTheme"), Theming::theme());
|
||||||
context()->setContextProperty(QLatin1String("creatorTheme"), &m_themeProperties);
|
|
||||||
|
|
||||||
QObject::connect(&m_backendValuesPropertyMap, &DesignerPropertyMap::valueChanged, propertyEditor, &PropertyEditorView::changeValue);
|
QObject::connect(&m_backendValuesPropertyMap, &DesignerPropertyMap::valueChanged, propertyEditor, &PropertyEditorView::changeValue);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,6 @@ private:
|
|||||||
QScopedPointer<PropertyEditorTransaction> m_propertyEditorTransaction;
|
QScopedPointer<PropertyEditorTransaction> m_propertyEditorTransaction;
|
||||||
QScopedPointer<PropertyEditorValue> m_dummyPropertyEditorValue;
|
QScopedPointer<PropertyEditorValue> m_dummyPropertyEditorValue;
|
||||||
QScopedPointer<PropertyEditorContextObject> m_contextObject;
|
QScopedPointer<PropertyEditorContextObject> m_contextObject;
|
||||||
QQmlPropertyMap m_themeProperties;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} //QmlDesigner
|
} //QmlDesigner
|
||||||
|
|||||||
@@ -99,8 +99,7 @@ StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, State
|
|||||||
|
|
||||||
rootContext()->setContextProperty(QLatin1String("canAddNewStates"), true);
|
rootContext()->setContextProperty(QLatin1String("canAddNewStates"), true);
|
||||||
|
|
||||||
Theming::insertTheme(&m_themeProperties);
|
rootContext()->setContextProperty(QLatin1String("creatorTheme"), Theming::theme());
|
||||||
rootContext()->setContextProperty(QLatin1String("creatorTheme"), &m_themeProperties);
|
|
||||||
|
|
||||||
Theming::registerIconProvider(engine());
|
Theming::registerIconProvider(engine());
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ private:
|
|||||||
QPointer<StatesEditorView> m_statesEditorView;
|
QPointer<StatesEditorView> m_statesEditorView;
|
||||||
Internal::StatesEditorImageProvider *m_imageProvider;
|
Internal::StatesEditorImageProvider *m_imageProvider;
|
||||||
QShortcut *m_qmlSourceUpdateShortcut;
|
QShortcut *m_qmlSourceUpdateShortcut;
|
||||||
QQmlPropertyMap m_themeProperties;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,7 +158,6 @@ private:
|
|||||||
void sceneGraphError(QQuickWindow::SceneGraphError, const QString &message);
|
void sceneGraphError(QQuickWindow::SceneGraphError, const QString &message);
|
||||||
void facilitateQml(QQmlEngine *engine);
|
void facilitateQml(QQmlEngine *engine);
|
||||||
void addPages(const QList<IWelcomePage *> &pages);
|
void addPages(const QList<IWelcomePage *> &pages);
|
||||||
void applyTheme();
|
|
||||||
void addKeyboardShortcuts();
|
void addKeyboardShortcuts();
|
||||||
|
|
||||||
QWidget *m_modeWidget;
|
QWidget *m_modeWidget;
|
||||||
@@ -166,7 +165,6 @@ private:
|
|||||||
QMap<Id, IWelcomePage *> m_idPageMap;
|
QMap<Id, IWelcomePage *> m_idPageMap;
|
||||||
QList<IWelcomePage *> m_pluginList;
|
QList<IWelcomePage *> m_pluginList;
|
||||||
int m_activePlugin;
|
int m_activePlugin;
|
||||||
QQmlPropertyMap m_themeProperties;
|
|
||||||
QStringList m_recentProjectsShortcuts;
|
QStringList m_recentProjectsShortcuts;
|
||||||
QStringList m_sessionsShortcuts;
|
QStringList m_sessionsShortcuts;
|
||||||
};
|
};
|
||||||
@@ -197,7 +195,6 @@ WelcomeMode::WelcomeMode()
|
|||||||
layout->setSpacing(0);
|
layout->setSpacing(0);
|
||||||
|
|
||||||
m_welcomePage = new QQuickWidget;
|
m_welcomePage = new QQuickWidget;
|
||||||
applyTheme(); // initialize background color and theme properties
|
|
||||||
m_welcomePage->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
m_welcomePage->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||||
|
|
||||||
m_welcomePage->setObjectName(QLatin1String("WelcomePage"));
|
m_welcomePage->setObjectName(QLatin1String("WelcomePage"));
|
||||||
@@ -217,13 +214,6 @@ WelcomeMode::WelcomeMode()
|
|||||||
setWidget(m_modeWidget);
|
setWidget(m_modeWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WelcomeMode::applyTheme()
|
|
||||||
{
|
|
||||||
const QVariantHash creatorTheme = Utils::creatorTheme()->values();
|
|
||||||
for (auto it = creatorTheme.constBegin(); it != creatorTheme.constEnd(); ++it)
|
|
||||||
m_themeProperties.insert(it.key(), it.value());
|
|
||||||
}
|
|
||||||
|
|
||||||
void WelcomeMode::addKeyboardShortcuts()
|
void WelcomeMode::addKeyboardShortcuts()
|
||||||
{
|
{
|
||||||
const int actionsCount = 9;
|
const int actionsCount = 9;
|
||||||
@@ -294,7 +284,7 @@ void WelcomeMode::facilitateQml(QQmlEngine *engine)
|
|||||||
|
|
||||||
QQmlContext *ctx = engine->rootContext();
|
QQmlContext *ctx = engine->rootContext();
|
||||||
ctx->setContextProperty(QLatin1String("welcomeMode"), this);
|
ctx->setContextProperty(QLatin1String("welcomeMode"), this);
|
||||||
ctx->setContextProperty(QLatin1String("creatorTheme"), &m_themeProperties);
|
ctx->setContextProperty(QLatin1String("creatorTheme"), Utils::creatorTheme()->values());
|
||||||
ctx->setContextProperty(QLatin1String("useNativeText"), true);
|
ctx->setContextProperty(QLatin1String("useNativeText"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user