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)
|
||||
{
|
||||
QQmlPropertyMap *themePropertyMap = new QQmlPropertyMap(engine);
|
||||
const QVariantHash creatorTheme = 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->rootContext()->setContextProperty(QLatin1String("creatorTheme"),
|
||||
Utils::creatorTheme()->values());
|
||||
|
||||
engine->addImageProvider(QLatin1String("icons"), new TimelineImageIconProvider);
|
||||
}
|
||||
|
||||
@@ -141,26 +141,27 @@ void Theme::setDisplayName(const QString &name)
|
||||
d->displayName = name;
|
||||
}
|
||||
|
||||
QVariantHash Theme::values() const
|
||||
const QVariantMap &Theme::values() const
|
||||
{
|
||||
QVariantHash result;
|
||||
if (d->values.isEmpty()) {
|
||||
const QMetaObject &m = *metaObject();
|
||||
{
|
||||
const QMetaEnum e = m.enumerator(m.indexOfEnumerator("Color"));
|
||||
for (int i = 0, total = e.keyCount(); i < total; ++i) {
|
||||
const QString key = QLatin1String(e.key(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));
|
||||
result.insert(key, flag(static_cast<Theme::Flag>(i)));
|
||||
d->values.insert(key, flag(static_cast<Theme::Flag>(i)));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return d->values;
|
||||
}
|
||||
|
||||
static QColor readColor(const QString &color)
|
||||
|
||||
@@ -340,7 +340,7 @@ public:
|
||||
QString displayName() const;
|
||||
void setDisplayName(const QString &displayName);
|
||||
|
||||
QVariantHash values() const;
|
||||
const QVariantMap &values() const;
|
||||
|
||||
void readSettings(QSettings &settings);
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ public:
|
||||
QVector<QGradientStops> gradients;
|
||||
QVector<bool> flags;
|
||||
QMap<QString, QColor> palette;
|
||||
|
||||
QVariantMap values;
|
||||
};
|
||||
|
||||
QTCREATOR_UTILS_EXPORT void setCreatorTheme(Theme *theme);
|
||||
|
||||
@@ -33,11 +33,13 @@
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
void Theming::insertTheme(QQmlPropertyMap *map)
|
||||
const QVariantMap &Theming::theme()
|
||||
{
|
||||
const QVariantHash creatorTheme = Utils::creatorTheme()->values();
|
||||
for (auto it = creatorTheme.constBegin(); it != creatorTheme.constEnd(); ++it)
|
||||
map->insert(it.key(), it.value());
|
||||
static QVariantMap map;
|
||||
if (!map.isEmpty())
|
||||
return map;
|
||||
|
||||
map = Utils::creatorTheme()->values();
|
||||
|
||||
/* Define QmlDesigner colors and remove alpha channels */
|
||||
const QColor backgroundColor = Utils::creatorTheme()->color(Utils::Theme::QmlDesigner_BackgroundColor);
|
||||
@@ -58,18 +60,18 @@ void Theming::insertTheme(QQmlPropertyMap *map)
|
||||
tabDark = tabDark.darker(260);
|
||||
}
|
||||
|
||||
map->insert("QmlDesignerBackgroundColorDarker", darkerBackground);
|
||||
map->insert("QmlDesignerBackgroundColorDarkAlternate", backgroundColor);
|
||||
map->insert("QmlDesignerTabLight", tabLight);
|
||||
map->insert("QmlDesignerTabDark", tabDark);
|
||||
map->insert("QmlDesignerButtonColor", buttonColor);
|
||||
map->insert("QmlDesignerBorderColor", Utils::creatorTheme()->color(Utils::Theme::SplitterColor));
|
||||
map.insert("QmlDesignerBackgroundColorDarker", darkerBackground);
|
||||
map.insert("QmlDesignerBackgroundColorDarkAlternate", backgroundColor);
|
||||
map.insert("QmlDesignerTabLight", tabLight);
|
||||
map.insert("QmlDesignerTabDark", tabDark);
|
||||
map.insert("QmlDesignerButtonColor", buttonColor);
|
||||
map.insert("QmlDesignerBorderColor", Utils::creatorTheme()->color(Utils::Theme::SplitterColor));
|
||||
return map;
|
||||
}
|
||||
|
||||
QString Theming::replaceCssColors(const QString &input)
|
||||
{
|
||||
QQmlPropertyMap map;
|
||||
insertTheme(&map);
|
||||
const QVariantMap &map = theme();
|
||||
QRegExp rx("creatorTheme\\.(\\w+);");
|
||||
|
||||
int pos = 0;
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace QmlDesigner {
|
||||
class Theming
|
||||
{
|
||||
public:
|
||||
static void insertTheme(QQmlPropertyMap *map);
|
||||
static const QVariantMap &theme();
|
||||
static QString replaceCssColors(const QString &input);
|
||||
static void registerIconProvider(QQmlEngine *engine);
|
||||
};
|
||||
|
||||
@@ -83,8 +83,7 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
|
||||
rootContext->setContextProperty(QStringLiteral("itemLibraryIconWidth"), m_itemIconSize.width());
|
||||
rootContext->setContextProperty(QStringLiteral("itemLibraryIconHeight"), m_itemIconSize.height());
|
||||
rootContext->setContextProperty(QStringLiteral("rootView"), this);
|
||||
Theming::insertTheme(&m_themeProperties);
|
||||
rootContext->setContextProperty(QLatin1String("creatorTheme"), &m_themeProperties);
|
||||
rootContext->setContextProperty(QLatin1String("creatorTheme"), Theming::theme());
|
||||
|
||||
m_itemViewQuickWidget->rootContext()->setContextProperty(QStringLiteral("highlightColor"), Utils::StyleHelper::notTooBrightHighlightColor());
|
||||
|
||||
|
||||
@@ -132,7 +132,6 @@ private:
|
||||
QPointer<Model> m_model;
|
||||
FilterChangeFlag m_filterFlag;
|
||||
ItemLibraryEntry m_currentitemLibraryEntry;
|
||||
QQmlPropertyMap m_themeProperties;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -103,8 +103,7 @@ PropertyEditorQmlBackend::PropertyEditorQmlBackend(PropertyEditorView *propertyE
|
||||
m_contextObject->setModel(propertyEditor->model());
|
||||
m_contextObject->insertInQmlContext(context());
|
||||
|
||||
Theming::insertTheme(&m_themeProperties);
|
||||
context()->setContextProperty(QLatin1String("creatorTheme"), &m_themeProperties);
|
||||
context()->setContextProperty(QLatin1String("creatorTheme"), Theming::theme());
|
||||
|
||||
QObject::connect(&m_backendValuesPropertyMap, &DesignerPropertyMap::valueChanged, propertyEditor, &PropertyEditorView::changeValue);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,6 @@ private:
|
||||
QScopedPointer<PropertyEditorTransaction> m_propertyEditorTransaction;
|
||||
QScopedPointer<PropertyEditorValue> m_dummyPropertyEditorValue;
|
||||
QScopedPointer<PropertyEditorContextObject> m_contextObject;
|
||||
QQmlPropertyMap m_themeProperties;
|
||||
};
|
||||
|
||||
} //QmlDesigner
|
||||
|
||||
@@ -99,8 +99,7 @@ StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, State
|
||||
|
||||
rootContext()->setContextProperty(QLatin1String("canAddNewStates"), true);
|
||||
|
||||
Theming::insertTheme(&m_themeProperties);
|
||||
rootContext()->setContextProperty(QLatin1String("creatorTheme"), &m_themeProperties);
|
||||
rootContext()->setContextProperty(QLatin1String("creatorTheme"), Theming::theme());
|
||||
|
||||
Theming::registerIconProvider(engine());
|
||||
|
||||
|
||||
@@ -67,7 +67,6 @@ private:
|
||||
QPointer<StatesEditorView> m_statesEditorView;
|
||||
Internal::StatesEditorImageProvider *m_imageProvider;
|
||||
QShortcut *m_qmlSourceUpdateShortcut;
|
||||
QQmlPropertyMap m_themeProperties;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -158,7 +158,6 @@ private:
|
||||
void sceneGraphError(QQuickWindow::SceneGraphError, const QString &message);
|
||||
void facilitateQml(QQmlEngine *engine);
|
||||
void addPages(const QList<IWelcomePage *> &pages);
|
||||
void applyTheme();
|
||||
void addKeyboardShortcuts();
|
||||
|
||||
QWidget *m_modeWidget;
|
||||
@@ -166,7 +165,6 @@ private:
|
||||
QMap<Id, IWelcomePage *> m_idPageMap;
|
||||
QList<IWelcomePage *> m_pluginList;
|
||||
int m_activePlugin;
|
||||
QQmlPropertyMap m_themeProperties;
|
||||
QStringList m_recentProjectsShortcuts;
|
||||
QStringList m_sessionsShortcuts;
|
||||
};
|
||||
@@ -197,7 +195,6 @@ WelcomeMode::WelcomeMode()
|
||||
layout->setSpacing(0);
|
||||
|
||||
m_welcomePage = new QQuickWidget;
|
||||
applyTheme(); // initialize background color and theme properties
|
||||
m_welcomePage->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||
|
||||
m_welcomePage->setObjectName(QLatin1String("WelcomePage"));
|
||||
@@ -217,13 +214,6 @@ WelcomeMode::WelcomeMode()
|
||||
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()
|
||||
{
|
||||
const int actionsCount = 9;
|
||||
@@ -294,7 +284,7 @@ void WelcomeMode::facilitateQml(QQmlEngine *engine)
|
||||
|
||||
QQmlContext *ctx = engine->rootContext();
|
||||
ctx->setContextProperty(QLatin1String("welcomeMode"), this);
|
||||
ctx->setContextProperty(QLatin1String("creatorTheme"), &m_themeProperties);
|
||||
ctx->setContextProperty(QLatin1String("creatorTheme"), Utils::creatorTheme()->values());
|
||||
ctx->setContextProperty(QLatin1String("useNativeText"), true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user