aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas Hartmann <thomas.hartmann@qt.io>2017-11-08 13:13:17 +0100
committerThomas Hartmann <thomas.hartmann@qt.io>2017-11-09 09:40:48 +0000
commit1fa7ad21165591dfb0676cb4ddfab8a1c25b1f2f (patch)
treecac36c40b3f53a0f5ad4d09f51feaf32a3e5f910 /src
parent249bea0e448a1e8fa90f53dc8c1e04260bf6ffc2 (diff)
QmlDesigner: Expose some helpers for theming
Change-Id: If86165ab9eb90b67f22c08d894b79f4db7c03765 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/qmldesigner/components/componentcore/qmldesignericonprovider.cpp11
-rw-r--r--src/plugins/qmldesigner/components/componentcore/qmldesignericonprovider.h1
-rw-r--r--src/plugins/qmldesigner/components/componentcore/theme.cpp19
-rw-r--r--src/plugins/qmldesigner/components/componentcore/theme.h3
4 files changed, 31 insertions, 3 deletions
diff --git a/src/plugins/qmldesigner/components/componentcore/qmldesignericonprovider.cpp b/src/plugins/qmldesigner/components/componentcore/qmldesignericonprovider.cpp
index 251b383ee4..3133ba932a 100644
--- a/src/plugins/qmldesigner/components/componentcore/qmldesignericonprovider.cpp
+++ b/src/plugins/qmldesigner/components/componentcore/qmldesignericonprovider.cpp
@@ -51,6 +51,15 @@ QPixmap QmlDesignerIconProvider::requestPixmap(const QString &id, QSize *size, c
{
Q_UNUSED(requestedSize)
+ QPixmap result = getPixmap(id);
+
+ if (size)
+ *size = result.size();
+ return result;
+}
+
+QPixmap QmlDesignerIconProvider::getPixmap(const QString &id)
+{
using namespace Utils;
QPixmap result;
@@ -180,8 +189,6 @@ QPixmap QmlDesignerIconProvider::requestPixmap(const QString &id, QSize *size, c
else
qWarning() << Q_FUNC_INFO << "Image not found:" << id;
- if (size)
- *size = result.size();
return result;
}
diff --git a/src/plugins/qmldesigner/components/componentcore/qmldesignericonprovider.h b/src/plugins/qmldesigner/components/componentcore/qmldesignericonprovider.h
index 8d3b3e6210..fed824ad24 100644
--- a/src/plugins/qmldesigner/components/componentcore/qmldesignericonprovider.h
+++ b/src/plugins/qmldesigner/components/componentcore/qmldesignericonprovider.h
@@ -34,6 +34,7 @@ class QmlDesignerIconProvider : public QQuickImageProvider
public:
QmlDesignerIconProvider();
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override;
+ static QPixmap getPixmap(const QString &id);
};
} // namespace QmlDesigner
diff --git a/src/plugins/qmldesigner/components/componentcore/theme.cpp b/src/plugins/qmldesigner/components/componentcore/theme.cpp
index 68b0db1346..706f06af72 100644
--- a/src/plugins/qmldesigner/components/componentcore/theme.cpp
+++ b/src/plugins/qmldesigner/components/componentcore/theme.cpp
@@ -131,6 +131,11 @@ QColor Theme::getColor(Theme::Color role)
return instance()->color(role);
}
+QPixmap Theme::getPixmap(const QString &id)
+{
+ return QmlDesignerIconProvider::getPixmap(id);
+}
+
QColor Theme::qmlDesignerBackgroundColorDarker() const
{
return m_derivedColors.value("QmlDesignerBackgroundColorDarker");
@@ -161,4 +166,18 @@ QColor Theme::qmlDesignerBorderColor() const
return m_derivedColors.value("QmlDesignerBorderColor");
}
+QPixmap Theme::tintPixmap(const QPixmap &mask, const QColor &color)
+{
+ QImage result(mask.toImage().convertToFormat(QImage::Format_ARGB32));
+ result.setDevicePixelRatio(mask.devicePixelRatio());
+ QRgb *bitsStart = reinterpret_cast<QRgb*>(result.bits());
+ const QRgb *bitsEnd = bitsStart + result.width() * result.height();
+ const QRgb tint = color.rgb() & 0x00ffffff;
+ for (QRgb *pixel = bitsStart; pixel < bitsEnd; ++pixel) {
+ QRgb pixelAlpha = ((*pixel) & 0xff000000);
+ *pixel = pixelAlpha | tint;
+ }
+ return QPixmap::fromImage(result);
+}
+
} // namespace QmlDesigner
diff --git a/src/plugins/qmldesigner/components/componentcore/theme.h b/src/plugins/qmldesigner/components/componentcore/theme.h
index 8bac71dc98..bbd9da6fcc 100644
--- a/src/plugins/qmldesigner/components/componentcore/theme.h
+++ b/src/plugins/qmldesigner/components/componentcore/theme.h
@@ -46,6 +46,8 @@ public:
static QString replaceCssColors(const QString &input);
static void setupTheme(QQmlEngine *engine);
static QColor getColor(Color role);
+ static QPixmap getPixmap(const QString &id);
+ static QPixmap tintPixmap(const QPixmap &mask, const QColor &color);
Q_INVOKABLE QColor qmlDesignerBackgroundColorDarker() const;
Q_INVOKABLE QColor qmlDesignerBackgroundColorDarkAlternate() const;
@@ -53,7 +55,6 @@ public:
Q_INVOKABLE QColor qmlDesignerTabDark() const;
Q_INVOKABLE QColor qmlDesignerButtonColor() const;
Q_INVOKABLE QColor qmlDesignerBorderColor() const;
-
private:
Theme(Utils::Theme *originTheme, QObject *parent);
QColor evaluateColorAtThemeInstance(const QString &themeColorName);