diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-09-26 09:42:34 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-09-26 12:36:52 +0000 |
commit | a98b02635aee2317b9e1f2b93ed8c7f96243b237 (patch) | |
tree | fa8446bc9e4d8b99b3cfdb0a2eb32276c16ae703 | |
parent | 0074d98fbb582bbfcb923bdff514b188910be0ae (diff) |
Default: make Dial use palettes
NOTE: Now that we have configurable palettes, we cannot assume that
the default color of the indicator image matches the default palette
color. Therefore we need to make ColorImage aware of the default color
to avoid unnecessary expensive colorizing (see f0697c6). An extra QML
property assignment of a constant value is much cheaper than colorizing
the image.
Starting from f0697c6, the indicator color has been defined like this:
color: control.visualFocus ? Default.focusColor : undefined
This assumes that the image has a default color of #353637 when not
focused. With this, qmlbench delegates_dial.qml gives a result of 76
frames.
The following options were considered:
A)
color: visualFocus ? palette.highlight : palette.dark
=> 71 frames
B)
color: visualFocus ? palette.highlight :
palette.dark !== "#353637" ? palette.dark : "transparent"
=> 71 frames
C)
defaultColor: "#353637"
color: visualFocus ? palette.highlight : palette.dark
=> 75 frames
The last option was a clear winner.
Task-number: QTBUG-63369
Change-Id: Ib8d56724de55b874d1c4ecdf0c09b91cfd2dc3df
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/imports/controls/Dial.qml | 5 | ||||
-rw-r--r-- | src/quickcontrols2/qquickcolorimage.cpp | 23 | ||||
-rw-r--r-- | src/quickcontrols2/qquickcolorimage_p.h | 7 |
3 files changed, 31 insertions, 4 deletions
diff --git a/src/imports/controls/Dial.qml b/src/imports/controls/Dial.qml index d7b271c4..f3706fa3 100644 --- a/src/imports/controls/Dial.qml +++ b/src/imports/controls/Dial.qml @@ -48,7 +48,7 @@ T.Dial { background: DialImpl { width: control.availableWidth height: control.availableHeight - color: control.visualFocus ? Default.focusColor : Default.frameDarkColor + color: control.visualFocus ? control.palette.highlight : control.palette.dark progress: control.position opacity: control.enabled ? 1 : 0.3 } @@ -59,7 +59,8 @@ T.Dial { y: background.y + background.height / 2 - handle.height / 2 width: 14 height: 10 - color: control.visualFocus ? Default.focusColor : undefined + defaultColor: "#353637" + color: control.visualFocus ? control.palette.highlight : control.palette.dark source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/images/dial-indicator.png" antialiasing: true opacity: control.enabled ? 1 : 0.3 diff --git a/src/quickcontrols2/qquickcolorimage.cpp b/src/quickcontrols2/qquickcolorimage.cpp index 9358c3ca..9d24a156 100644 --- a/src/quickcontrols2/qquickcolorimage.cpp +++ b/src/quickcontrols2/qquickcolorimage.cpp @@ -41,7 +41,7 @@ QT_BEGIN_NAMESPACE QQuickColorImage::QQuickColorImage(QQuickItem *parent) - : QQuickImage(parent), m_color(Qt::transparent) + : QQuickImage(parent), m_color(Qt::transparent), m_defaultColor(Qt::transparent) { } @@ -66,10 +66,29 @@ void QQuickColorImage::resetColor() setColor(Qt::transparent); } +QColor QQuickColorImage::defaultColor() const +{ + return m_defaultColor; +} + +void QQuickColorImage::setDefaultColor(const QColor &color) +{ + if (m_defaultColor == color) + return; + + m_defaultColor = color; + emit defaultColorChanged(); +} + +void QQuickColorImage::resetDefaultColor() +{ + setDefaultColor(Qt::transparent); +} + void QQuickColorImage::pixmapChange() { QQuickImage::pixmapChange(); - if (m_color.alpha() > 0) { + if (m_color.alpha() > 0 && m_color != m_defaultColor) { QQuickImageBasePrivate *d = static_cast<QQuickImageBasePrivate *>(QQuickItemPrivate::get(this)); QImage image = d->pix.image(); if (!image.isNull()) { diff --git a/src/quickcontrols2/qquickcolorimage_p.h b/src/quickcontrols2/qquickcolorimage_p.h index 6de2e21b..873bc2db 100644 --- a/src/quickcontrols2/qquickcolorimage_p.h +++ b/src/quickcontrols2/qquickcolorimage_p.h @@ -58,6 +58,7 @@ class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickColorImage : public QQuickImage { Q_OBJECT Q_PROPERTY(QColor color READ color WRITE setColor RESET resetColor NOTIFY colorChanged FINAL) + Q_PROPERTY(QColor defaultColor READ defaultColor WRITE setDefaultColor RESET resetDefaultColor NOTIFY defaultColorChanged FINAL) public: explicit QQuickColorImage(QQuickItem *parent = nullptr); @@ -66,14 +67,20 @@ public: void setColor(const QColor &color); void resetColor(); + QColor defaultColor() const; + void setDefaultColor(const QColor &color); + void resetDefaultColor(); + Q_SIGNALS: void colorChanged(); + void defaultColorChanged(); protected: void pixmapChange() override; private: QColor m_color; + QColor m_defaultColor; }; QT_END_NAMESPACE |