summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAriya Hidayat <ariya.hidayat@nokia.com>2009-09-14 14:14:54 (GMT)
committerAriya Hidayat <ariya.hidayat@nokia.com>2009-09-14 14:58:08 (GMT)
commit886feff55f48ebdff0440278e611f822e6326c91 (patch)
treefe65fd694ff38ab493cbc4a307e636bfa82bac2a /src
parent3ecf8f5de029e0a67ec90f6eba60754078374f01 (diff)
downloadQt-886feff55f48ebdff0440278e611f822e6326c91.zip
Qt-886feff55f48ebdff0440278e611f822e6326c91.tar.gz
Qt-886feff55f48ebdff0440278e611f822e6326c91.tar.bz2
Add filter strength to QGraphics[Colorize,Grayscale]Effect.
Autotest: included Reviewed-by: Bjørn Erik Nilsen
Diffstat (limited to 'src')
-rw-r--r--src/gui/effects/qgraphicseffect.cpp63
-rw-r--r--src/gui/effects/qgraphicseffect.h13
-rw-r--r--src/gui/effects/qgraphicseffect_p.h11
3 files changed, 86 insertions, 1 deletions
diff --git a/src/gui/effects/qgraphicseffect.cpp b/src/gui/effects/qgraphicseffect.cpp
index 683a984..26489c5 100644
--- a/src/gui/effects/qgraphicseffect.cpp
+++ b/src/gui/effects/qgraphicseffect.cpp
@@ -467,12 +467,44 @@ QGraphicsGrayscaleEffect::~QGraphicsGrayscaleEffect()
{
}
+
+/*!
+ \property QGraphicsGrayscaleEffect::strength
+ \brief the strength of the effect.
+
+ By default, the strength is 1.0.
+ A strength 0.0 equals to no effect, while 1.0 means full grayscale.
+*/
+qreal QGraphicsGrayscaleEffect::strength() const
+{
+ Q_D(const QGraphicsGrayscaleEffect);
+ return d->filter->strength();
+}
+
+void QGraphicsGrayscaleEffect::setStrength(qreal strength)
+{
+ Q_D(QGraphicsGrayscaleEffect);
+ if (qFuzzyCompare(d->filter->strength(), strength))
+ return;
+
+ d->filter->setStrength(strength);
+ d->opaque = !qFuzzyIsNull(strength);
+ update();
+ emit strengthChanged(strength);
+}
+
/*!
\reimp
*/
void QGraphicsGrayscaleEffect::draw(QPainter *painter, QGraphicsEffectSource *source)
{
Q_D(QGraphicsGrayscaleEffect);
+
+ if (!d->opaque) {
+ source->draw(painter);
+ return;
+ }
+
QPoint offset;
if (source->isPixmap()) {
// No point in drawing in device coordinates (pixmap will be scaled anyways).
@@ -546,6 +578,31 @@ void QGraphicsColorizeEffect::setColor(const QColor &color)
}
/*!
+ \property QGraphicsColorizeEffect::strength
+ \brief the strength of the effect.
+
+ By default, the strength is 1.0.
+ A strength 0.0 equals to no effect, while 1.0 means full colorization.
+*/
+qreal QGraphicsColorizeEffect::strength() const
+{
+ Q_D(const QGraphicsColorizeEffect);
+ return d->filter->strength();
+}
+
+void QGraphicsColorizeEffect::setStrength(qreal strength)
+{
+ Q_D(QGraphicsColorizeEffect);
+ if (qFuzzyCompare(d->filter->strength(), strength))
+ return;
+
+ d->filter->setStrength(strength);
+ d->opaque = !qFuzzyIsNull(strength);
+ update();
+ emit strengthChanged(strength);
+}
+
+/*!
\fn void QGraphicsColorizeEffect::colorChanged(const QColor &color)
This signal is emitted whenever the effect's color changes.
@@ -558,6 +615,12 @@ void QGraphicsColorizeEffect::setColor(const QColor &color)
void QGraphicsColorizeEffect::draw(QPainter *painter, QGraphicsEffectSource *source)
{
Q_D(QGraphicsColorizeEffect);
+
+ if (!d->opaque) {
+ source->draw(painter);
+ return;
+ }
+
QPoint offset;
if (source->isPixmap()) {
// No point in drawing in device coordinates (pixmap will be scaled anyways).
diff --git a/src/gui/effects/qgraphicseffect.h b/src/gui/effects/qgraphicseffect.h
index 5822d8c..5062826 100644
--- a/src/gui/effects/qgraphicseffect.h
+++ b/src/gui/effects/qgraphicseffect.h
@@ -144,13 +144,22 @@ class QGraphicsGrayscaleEffectPrivate;
class Q_GUI_EXPORT QGraphicsGrayscaleEffect: public QGraphicsEffect
{
Q_OBJECT
+ Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged)
public:
QGraphicsGrayscaleEffect(QObject *parent = 0);
~QGraphicsGrayscaleEffect();
+ qreal strength() const;
+
protected:
void draw(QPainter *painter, QGraphicsEffectSource *source);
+public Q_SLOTS:
+ void setStrength(qreal strength);
+
+Q_SIGNALS:
+ void strengthChanged(qreal strength);
+
private:
Q_DECLARE_PRIVATE(QGraphicsGrayscaleEffect)
Q_DISABLE_COPY(QGraphicsGrayscaleEffect)
@@ -161,17 +170,21 @@ class Q_GUI_EXPORT QGraphicsColorizeEffect: public QGraphicsEffect
{
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
+ Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged)
public:
QGraphicsColorizeEffect(QObject *parent = 0);
~QGraphicsColorizeEffect();
QColor color() const;
+ qreal strength() const;
public Q_SLOTS:
void setColor(const QColor &c);
+ void setStrength(qreal strength);
Q_SIGNALS:
void colorChanged(const QColor &color);
+ void strengthChanged(qreal strength);
protected:
void draw(QPainter *painter, QGraphicsEffectSource *source);
diff --git a/src/gui/effects/qgraphicseffect_p.h b/src/gui/effects/qgraphicseffect_p.h
index 4771384..e109790 100644
--- a/src/gui/effects/qgraphicseffect_p.h
+++ b/src/gui/effects/qgraphicseffect_p.h
@@ -113,6 +113,7 @@ class QGraphicsGrayscaleEffectPrivate : public QGraphicsEffectPrivate
Q_DECLARE_PUBLIC(QGraphicsGrayscaleEffect)
public:
QGraphicsGrayscaleEffectPrivate()
+ : opaque(true)
{
filter = new QPixmapColorizeFilter;
filter->setColor(Qt::black);
@@ -120,16 +121,24 @@ public:
~QGraphicsGrayscaleEffectPrivate() { delete filter; }
QPixmapColorizeFilter *filter;
+ quint32 opaque : 1;
+ quint32 padding : 31;
};
class QGraphicsColorizeEffectPrivate : public QGraphicsEffectPrivate
{
Q_DECLARE_PUBLIC(QGraphicsColorizeEffect)
public:
- QGraphicsColorizeEffectPrivate() { filter = new QPixmapColorizeFilter; }
+ QGraphicsColorizeEffectPrivate()
+ : opaque(true)
+ {
+ filter = new QPixmapColorizeFilter;
+ }
~QGraphicsColorizeEffectPrivate() { delete filter; }
QPixmapColorizeFilter *filter;
+ quint32 opaque : 1;
+ quint32 padding : 31;
};
class QGraphicsPixelizeEffectPrivate : public QGraphicsEffectPrivate