From 9f95bd8f6e6ccf3575216285b29f2a42dcfd328d Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 29 May 2009 11:32:39 +1000 Subject: Update in reaction to GradientStops changing. --- src/declarative/fx/qfxrect.cpp | 17 +++++++++++++++++ src/declarative/fx/qfxrect.h | 14 ++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/declarative/fx/qfxrect.cpp b/src/declarative/fx/qfxrect.cpp index b10594e..9718344 100644 --- a/src/declarative/fx/qfxrect.cpp +++ b/src/declarative/fx/qfxrect.cpp @@ -133,6 +133,12 @@ void QFxPen::setWidth(int w) Sets a \e color at a \e position in a gradient. */ +void QFxGradientStop::updateGradient() +{ + if (QFxGradient *grad = qobject_cast(parent())) + grad->doUpdate(); +} + /*! \qmlclass Gradient QFxGradient \brief The Gradient item defines a gradient fill. @@ -171,6 +177,13 @@ const QGradient *QFxGradient::gradient() const return m_gradient; } +void QFxGradient::doUpdate() +{ + delete m_gradient; + m_gradient = 0; + emit updated(); +} + QML_DEFINE_TYPE(QFxRect,Rect) /*! @@ -310,7 +323,11 @@ void QFxRect::setGradient(QFxGradient *gradient) Q_D(QFxRect); if (d->gradient == gradient) return; + if (d->gradient) + disconnect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); d->gradient = gradient; + if (d->gradient) + connect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); update(); } diff --git a/src/declarative/fx/qfxrect.h b/src/declarative/fx/qfxrect.h index 864b1cd..c279a1c 100644 --- a/src/declarative/fx/qfxrect.h +++ b/src/declarative/fx/qfxrect.h @@ -90,10 +90,13 @@ public: QFxGradientStop(QObject *parent=0) : QObject(parent) {} qreal position() const { return m_position; } - void setPosition(qreal position) { m_position = position; } + void setPosition(qreal position) { m_position = position; updateGradient(); } QColor color() const { return m_color; } - void setColor(const QColor &color) { m_color = color; } + void setColor(const QColor &color) { m_color = color; updateGradient(); } + +private: + void updateGradient(); private: qreal m_position; @@ -116,9 +119,16 @@ public: const QGradient *gradient() const; +Q_SIGNALS: + void updated(); + +private: + void doUpdate(); + private: QList m_stops; mutable QGradient *m_gradient; + friend class QFxGradientStop; }; QML_DECLARE_TYPE(QFxGradient) -- cgit v0.12