diff options
-rw-r--r-- | doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp | 12 | ||||
-rw-r--r-- | examples/effects/blurpicker/blureffect.cpp | 4 | ||||
-rw-r--r-- | examples/effects/blurpicker/blureffect.h | 2 | ||||
-rw-r--r-- | examples/effects/customshader/blureffect.cpp | 4 | ||||
-rw-r--r-- | examples/effects/customshader/blureffect.h | 2 | ||||
-rw-r--r-- | src/gui/effects/qgraphicseffect.cpp | 233 | ||||
-rw-r--r-- | src/gui/effects/qgraphicseffect.h | 90 | ||||
-rw-r--r-- | src/gui/effects/qgraphicseffect_p.h | 41 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 6 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem_p.h | 2 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 2 | ||||
-rw-r--r-- | src/gui/image/qpixmapfilter.cpp | 22 | ||||
-rw-r--r-- | src/gui/image/qpixmapfilter_p.h | 4 | ||||
-rw-r--r-- | src/gui/kernel/qwidget.cpp | 10 | ||||
-rw-r--r-- | src/gui/kernel/qwidget_p.h | 2 | ||||
-rw-r--r-- | src/opengl/qglpixmapfilter.cpp | 46 | ||||
-rw-r--r-- | src/opengl/qgraphicsshadereffect.cpp | 10 | ||||
-rw-r--r-- | src/opengl/qgraphicsshadereffect_p.h | 2 | ||||
-rw-r--r-- | tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp | 9 |
19 files changed, 286 insertions, 217 deletions
diff --git a/doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp b/doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp index 35689f4..5ef6609 100644 --- a/doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp +++ b/doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp @@ -40,11 +40,11 @@ ****************************************************************************/ //! [0] -MyGraphicsOpacityEffect::draw(QPainter *painter, QGraphicsEffectSource *source) +MyGraphicsOpacityEffect::draw(QPainter *painter) { // Fully opaque; draw directly without going through a pixmap. if (qFuzzyCompare(m_opacity, 1)) { - source->draw(painter); + drawSource(painter); return; } ... @@ -52,18 +52,18 @@ MyGraphicsOpacityEffect::draw(QPainter *painter, QGraphicsEffectSource *source) //! [0] //! [1] -MyGraphicsEffect::draw(QPainter *painter, QGraphicsEffectSource *source) +MyGraphicsEffect::draw(QPainter *painter) { ... QPoint offset; - if (source->isPixmap()) { + if (sourceIsPixmap()) { // No point in drawing in device coordinates (pixmap will be scaled anyways). - const QPixmap pixmap = source->pixmap(Qt::LogicalCoordinates, &offset); + const QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset); ... painter->drawPixmap(offset, pixmap); } else { // Draw pixmap in device coordinates to avoid pixmap scaling; - const QPixmap pixmap = source->pixmap(Qt::DeviceCoordinates, &offset); + const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset); painter->setWorldTransform(QTransform()); ... painter->drawPixmap(offset, pixmap); diff --git a/examples/effects/blurpicker/blureffect.cpp b/examples/effects/blurpicker/blureffect.cpp index 9046cbd..956637d 100644 --- a/examples/effects/blurpicker/blureffect.cpp +++ b/examples/effects/blurpicker/blureffect.cpp @@ -62,8 +62,8 @@ QRectF BlurEffect::boundingRect() const return QGraphicsBlurEffect::boundingRect(); } -void BlurEffect::draw(QPainter *painter, QGraphicsEffectSource *source) +void BlurEffect::draw(QPainter *painter) { adjustForItem(); - QGraphicsBlurEffect::draw(painter, source); + QGraphicsBlurEffect::draw(painter); } diff --git a/examples/effects/blurpicker/blureffect.h b/examples/effects/blurpicker/blureffect.h index 6cfa55a..3d1d433 100644 --- a/examples/effects/blurpicker/blureffect.h +++ b/examples/effects/blurpicker/blureffect.h @@ -54,7 +54,7 @@ public: QRectF boundingRect() const; - void draw(QPainter *painter, QGraphicsEffectSource *source); + void draw(QPainter *painter); private: void adjustForItem(); diff --git a/examples/effects/customshader/blureffect.cpp b/examples/effects/customshader/blureffect.cpp index 9046cbd..956637d 100644 --- a/examples/effects/customshader/blureffect.cpp +++ b/examples/effects/customshader/blureffect.cpp @@ -62,8 +62,8 @@ QRectF BlurEffect::boundingRect() const return QGraphicsBlurEffect::boundingRect(); } -void BlurEffect::draw(QPainter *painter, QGraphicsEffectSource *source) +void BlurEffect::draw(QPainter *painter) { adjustForItem(); - QGraphicsBlurEffect::draw(painter, source); + QGraphicsBlurEffect::draw(painter); } diff --git a/examples/effects/customshader/blureffect.h b/examples/effects/customshader/blureffect.h index 6cfa55a..3d1d433 100644 --- a/examples/effects/customshader/blureffect.h +++ b/examples/effects/customshader/blureffect.h @@ -54,7 +54,7 @@ public: QRectF boundingRect() const; - void draw(QPainter *painter, QGraphicsEffectSource *source); + void draw(QPainter *painter); private: void adjustForItem(); diff --git a/src/gui/effects/qgraphicseffect.cpp b/src/gui/effects/qgraphicseffect.cpp index 568ff73..13f42c5 100644 --- a/src/gui/effects/qgraphicseffect.cpp +++ b/src/gui/effects/qgraphicseffect.cpp @@ -76,24 +76,21 @@ To create your own custom effect, create a subclass of QGraphicsEffect (or any other existing effects) and reimplement the virtual function draw(). This function is called whenever the effect needs to redraw. The draw() - function accepts two arguments: the painter and a pointer to the source - (QGraphicsEffectSource). The source provides extra context information, - such as a pointer to the item that is rendering the effect, any cached - pixmap data, or the device rectangle bounds. For more information, refer to - the documenation for draw(). To obtain a pointer to the current source, - simply call source(). + function takes the painter with which to draw as an argument. For more + information, refer to the documenation for draw(). In the draw() function + you can call sourcePixmap() to get a pixmap of the graphics effect source + which you can then process. If your effect changes, use update() to request for a redraw. If your custom effect changes the bounding rectangle of the source, e.g., a radial glow effect may need to apply an extra margin, you can reimplement the - virtual boundingRectFor() function, and call updateBoundingRect() to notify - the framework whenever this rectangle changes. The virtual - sourceBoundingRectChanged() function is called to notify the effects that - the source's bounding rectangle has changed - e.g., if the source is a + virtual boundingRectFor() function, and call updateBoundingRect() + to notify the framework whenever this rectangle changes. The virtual + sourceChanged() function is called to notify the effects that + the source has changed in some way - e.g., if the source is a QGraphicsRectItem and its rectangle parameters have changed. - \sa QGraphicsItem::setGraphicsEffect(), QWidget::setGraphicsEffect(), - QGraphicsEffectSource + \sa QGraphicsItem::setGraphicsEffect(), QWidget::setGraphicsEffect() */ #include "qgraphicseffect_p.h" @@ -112,10 +109,10 @@ QT_BEGIN_NAMESPACE /*! + \internal \class QGraphicsEffectSource \brief The QGraphicsEffectSource class represents the source on which a QGraphicsEffect is installed on. - \since 4.6 When a QGraphicsEffect is installed on a QGraphicsItem, for example, this class will act as a wrapper around QGraphicsItem. Then, calling update() is @@ -154,20 +151,13 @@ QGraphicsEffectSource::~QGraphicsEffectSource() {} /*! - Returns the bounds of the current painter's device. - - This function is useful when you want to draw something in device - coordinates and ensure the size of the pixmap is not bigger than the size - of the device. - - Calling QGraphicsEffectSource::pixmap(Qt::DeviceCoordinates) always returns - a pixmap which is bound to the device's size. + Returns the bounding rectangle of the source mapped to the given \a system. - \sa pixmap() + \sa draw() */ -QRect QGraphicsEffectSource::deviceRect() const +QRectF QGraphicsEffectSource::boundingRect(Qt::CoordinateSystem system) const { - return d_func()->deviceRect(); + return d_func()->boundingRect(system); } /*! @@ -175,9 +165,12 @@ QRect QGraphicsEffectSource::deviceRect() const \sa draw() */ -QRectF QGraphicsEffectSource::boundingRect(Qt::CoordinateSystem system) const +QRectF QGraphicsEffect::sourceBoundingRect(Qt::CoordinateSystem system) const { - return d_func()->boundingRect(system); + Q_D(const QGraphicsEffect); + if (d->source) + return d->source->boundingRect(system); + return QRectF(); } /*! @@ -218,10 +211,6 @@ const QStyleOption *QGraphicsEffectSource::styleOption() const This function should only be called from QGraphicsEffect::draw(). - For example: - - \snippet doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp 0 - \sa QGraphicsEffect::draw() */ void QGraphicsEffectSource::draw(QPainter *painter) @@ -246,6 +235,24 @@ void QGraphicsEffectSource::draw(QPainter *painter) } /*! + Draws the source directly using the given \a painter. + + This function should only be called from QGraphicsEffect::draw(). + + For example: + + \snippet doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp 0 + + \sa QGraphicsEffect::draw() +*/ +void QGraphicsEffect::drawSource(QPainter *painter) +{ + Q_D(const QGraphicsEffect); + if (d->source) + d->source->draw(painter); +} + +/*! Schedules a redraw of the source. Call this function whenever the source needs to be redrawn. @@ -271,6 +278,19 @@ bool QGraphicsEffectSource::isPixmap() const } /*! + Returns true if the source effectively is a pixmap, e.g., a + QGraphicsPixmapItem. + + This function is useful for optimization purposes. For instance, there's no + point in drawing the source in device coordinates to avoid pixmap scaling + if this function returns true - the source pixmap will be scaled anyways. +*/ +bool QGraphicsEffect::sourceIsPixmap() const +{ + return source() ? source()->isPixmap() : false; +} + +/*! Returns a pixmap with the source painted into it. The \a system specifies which coordinate system to be used for the source. @@ -283,15 +303,15 @@ bool QGraphicsEffectSource::isPixmap() const The returned pixmap is bound to the current painter's device rectangle when \a system is Qt::DeviceCoordinates. - \sa QGraphicsEffect::draw(), boundingRect(), deviceRect() + \sa QGraphicsEffect::draw(), boundingRect() */ -QPixmap QGraphicsEffectSource::pixmap(Qt::CoordinateSystem system, QPoint *offset, PixmapPadMode mode) const +QPixmap QGraphicsEffectSource::pixmap(Qt::CoordinateSystem system, QPoint *offset, QGraphicsEffect::PixmapPadMode mode) const { Q_D(const QGraphicsEffectSource); // Shortcut, no cache for childless pixmap items... const QGraphicsItem *item = graphicsItem(); - if (system == Qt::LogicalCoordinates && mode == NoExpandPadMode && item && isPixmap()) { + if (system == Qt::LogicalCoordinates && mode == QGraphicsEffect::NoPad && item && isPixmap()) { return ((QGraphicsPixmapItem *) item)->pixmap(); } @@ -320,6 +340,27 @@ QPixmap QGraphicsEffectSource::pixmap(Qt::CoordinateSystem system, QPoint *offse return pm; } +/*! + Returns a pixmap with the source painted into it. + + The \a system specifies which coordinate system to be used for the source. + The optional \a offset parameter returns the offset where the pixmap should + be painted at using the current painter. For control on how the pixmap is + padded use the \a mode parameter. + + The returned pixmap is clipped to the current painter's device rectangle when + \a system is Qt::DeviceCoordinates. + + \sa draw(), boundingRect() +*/ +QPixmap QGraphicsEffect::sourcePixmap(Qt::CoordinateSystem system, QPoint *offset, QGraphicsEffect::PixmapPadMode mode) const +{ + Q_D(const QGraphicsEffect); + if (d->source) + return d->source->pixmap(system, offset, mode); + return QPixmap(); +} + QGraphicsEffectSourcePrivate::~QGraphicsEffectSourcePrivate() { invalidateCache(); @@ -327,7 +368,7 @@ QGraphicsEffectSourcePrivate::~QGraphicsEffectSourcePrivate() void QGraphicsEffectSourcePrivate::invalidateCache(bool effectRectChanged) const { - if (effectRectChanged && m_cachedMode != QGraphicsEffectSource::ExpandToEffectRectPadMode) + if (effectRectChanged && m_cachedMode != QGraphicsEffect::PadToEffectiveBoundingRect) return; QPixmapCache::remove(m_cacheKey); } @@ -359,9 +400,9 @@ QGraphicsEffect::~QGraphicsEffect() } /*! - Returns the bounding rectangle for this effect, i.e., the bounding - rectangle of the source, adjusted by any margins applied by the effect - itself. + Returns the effective bounding rectangle for this effect, i.e., the + bounding rectangle of the source, adjusted by any margins applied by + the effect itself. \sa boundingRectFor(), updateBoundingRect() */ @@ -374,12 +415,13 @@ QRectF QGraphicsEffect::boundingRect() const } /*! - Returns the bounding rectangle for this effect, given the provided source - \a rect. When writing you own custom effect, you must call - updateBoundingRect() whenever any parameters are changed that may cause - this this function to return a different value. + Returns the effective bounding rectangle for this effect, given the + provided \a rect in the source's coordinate space. When writing + you own custom effect, you must call updateBoundingRect() whenever any + parameters are changed that may cause this this function to return a + different value. - \sa boundingRect() + \sa sourceBoundingRect() */ QRectF QGraphicsEffect::boundingRectFor(const QRectF &rect) const { @@ -445,6 +487,8 @@ void QGraphicsEffect::update() } /*! + \internal + Returns a pointer to the source, which provides extra context information that can be useful for the effect. @@ -464,7 +508,7 @@ QGraphicsEffectSource *QGraphicsEffect::source() const This function will call update() if this is necessary. - \sa boundingRectFor(), boundingRect() + \sa boundingRectFor(), boundingRect(), sourceBoundingRect() */ void QGraphicsEffect::updateBoundingRect() { @@ -476,15 +520,13 @@ void QGraphicsEffect::updateBoundingRect() } /*! - \fn virtual void QGraphicsEffect::draw(QPainter *painter, - QGraphicsEffectSource *source) = 0 + \fn virtual void QGraphicsEffect::draw(QPainter *painter) = 0 This pure virtual function draws the effect and is called whenever the - source() needs to be drawn. + source needs to be drawn. Reimplement this function in a QGraphicsEffect subclass to provide the - effect's drawing implementation, using \a painter. The \a source parameter - is provided for convenience; its value is the same as source(). + effect's drawing implementation, using \a painter. For example: @@ -492,8 +534,6 @@ void QGraphicsEffect::updateBoundingRect() This function should not be called explicitly by the user, since it is meant for reimplementation purposes only. - - \sa QGraphicsEffectSource */ /*! @@ -509,6 +549,20 @@ void QGraphicsEffect::updateBoundingRect() */ /*! + \enum QGraphicsEffect::PixmapPadMode + + This enum describes how the pixmap returned from sourcePixmap should be + padded. + + \value NoPad The pixmap should not receive any additional + padding. + \value PadToTransparentBorder The pixmap should be padded + to ensure it has a completely transparent border. + \value PadToEffectiveBoundingRect The pixmap should be padded to + match the effective bounding rectangle of the effect. +*/ + +/*! This virtual function is called by QGraphicsEffect to notify the effect that the source has changed. If the effect applies any cache, then this cache must be purged in order to reflect the new appearance of the source. @@ -615,26 +669,25 @@ void QGraphicsColorizeEffect::setStrength(qreal strength) /*! \reimp */ -void QGraphicsColorizeEffect::draw(QPainter *painter, QGraphicsEffectSource *source) +void QGraphicsColorizeEffect::draw(QPainter *painter) { Q_D(QGraphicsColorizeEffect); if (!d->opaque) { - source->draw(painter); + drawSource(painter); return; } QPoint offset; - if (source->isPixmap()) { + if (sourceIsPixmap()) { // No point in drawing in device coordinates (pixmap will be scaled anyways). - const QPixmap pixmap = source->pixmap(Qt::LogicalCoordinates, &offset, - QGraphicsEffectSource::NoExpandPadMode); + const QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset, NoPad); d->filter->draw(painter, offset, pixmap); return; } // Draw pixmap in deviceCoordinates to avoid pixmap scaling. - const QPixmap pixmap = source->pixmap(Qt::DeviceCoordinates, &offset); + const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset); QTransform restoreTransform = painter->worldTransform(); painter->setWorldTransform(QTransform()); d->filter->draw(painter, offset, pixmap); @@ -649,7 +702,7 @@ void QGraphicsColorizeEffect::draw(QPainter *painter, QGraphicsEffectSource *sou A blur effect blurs the source. This effect is useful for reducing details, such as when the source loses focus and you want to draw attention to other elements. The level of detail can be modified using the setBlurRadius() - function. Use setBlurHint() to choose the quality or performance blur hints. + function. Use setBlurHints() to choose the blur hints. By default, the blur radius is 5 pixels. @@ -666,15 +719,17 @@ void QGraphicsColorizeEffect::draw(QPainter *painter, QGraphicsEffectSource *sou blur effects are applied. The hints might not have an effect in all the paint engines. - \value QualityHint Indicates that rendering quality is the most important factor, - at the potential cost of lower performance. - \value PerformanceHint Indicates that rendering performance is the most important factor, at the potential cost of lower quality. + \value QualityHint Indicates that rendering quality is the most important factor, + at the potential cost of lower performance. + \value AnimationHint Indicates that the blur radius is going to be animated, hinting - that the implementation can keep a cache of blurred verisons of the source pixmap. - Do not use this hint if the source item is going to be dynamically changing. + that the implementation can keep a cache of blurred verisons of the source. + Do not use this hint if the source is going to be dynamically changing. + + \sa blurHints(), setBlurHints() */ @@ -686,7 +741,7 @@ QGraphicsBlurEffect::QGraphicsBlurEffect(QObject *parent) : QGraphicsEffect(*new QGraphicsBlurEffectPrivate, parent) { Q_D(QGraphicsBlurEffect); - d->filter->setBlurHint(QGraphicsBlurEffect::PerformanceHint); + d->filter->setBlurHints(QGraphicsBlurEffect::PerformanceHint); } /*! @@ -730,7 +785,7 @@ void QGraphicsBlurEffect::setBlurRadius(qreal radius) */ /*! - \property QGraphicsBlurEffect::blurHint + \property QGraphicsBlurEffect::blurHints \brief the blur hint of the effect. Use the PerformanceHint hint to say that you want a faster blur, @@ -739,27 +794,27 @@ void QGraphicsBlurEffect::setBlurRadius(qreal radius) By default, the blur hint is PerformanceHint. */ -QGraphicsBlurEffect::BlurHint QGraphicsBlurEffect::blurHint() const +QGraphicsBlurEffect::BlurHints QGraphicsBlurEffect::blurHints() const { Q_D(const QGraphicsBlurEffect); - return d->filter->blurHint(); + return d->filter->blurHints(); } -void QGraphicsBlurEffect::setBlurHint(QGraphicsBlurEffect::BlurHint hint) +void QGraphicsBlurEffect::setBlurHints(QGraphicsBlurEffect::BlurHints hints) { Q_D(QGraphicsBlurEffect); - if (d->filter->blurHint() == hint) + if (d->filter->blurHints() == hints) return; - d->filter->setBlurHint(hint); - emit blurHintChanged(hint); + d->filter->setBlurHints(hints); + emit blurHintsChanged(hints); } /*! - \fn void QGraphicsBlurEffect::blurHintChanged(QGraphicsBlurEffect::BlurHint hint) + \fn void QGraphicsBlurEffect::blurHintsChanged(QGraphicsBlurEffect::BlurHints hints) - This signal is emitted whenever the effect's blur hint changes. - The \a hint parameter holds the effect's new blur hint. + This signal is emitted whenever the effect's blur hints changes. + The \a hints parameter holds the effect's new blur hints. */ /*! @@ -774,21 +829,21 @@ QRectF QGraphicsBlurEffect::boundingRectFor(const QRectF &rect) const /*! \reimp */ -void QGraphicsBlurEffect::draw(QPainter *painter, QGraphicsEffectSource *source) +void QGraphicsBlurEffect::draw(QPainter *painter) { Q_D(QGraphicsBlurEffect); if (d->filter->radius() <= 0) { - source->draw(painter); + drawSource(painter); return; } - QGraphicsEffectSource::PixmapPadMode mode = QGraphicsEffectSource::ExpandToEffectRectPadMode; + PixmapPadMode mode = PadToEffectiveBoundingRect; if (painter->paintEngine()->type() == QPaintEngine::OpenGL2) - mode = QGraphicsEffectSource::ExpandToTransparentBorderPadMode; + mode = PadToTransparentBorder; // Draw pixmap in device coordinates to avoid pixmap scaling. QPoint offset; - const QPixmap pixmap = source->pixmap(Qt::DeviceCoordinates, &offset, mode); + const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset, mode); QTransform restoreTransform = painter->worldTransform(); painter->setWorldTransform(QTransform()); d->filter->draw(painter, offset, pixmap); @@ -963,21 +1018,21 @@ QRectF QGraphicsDropShadowEffect::boundingRectFor(const QRectF &rect) const /*! \reimp */ -void QGraphicsDropShadowEffect::draw(QPainter *painter, QGraphicsEffectSource *source) +void QGraphicsDropShadowEffect::draw(QPainter *painter) { Q_D(QGraphicsDropShadowEffect); if (d->filter->blurRadius() <= 0 && d->filter->offset().isNull()) { - source->draw(painter); + drawSource(painter); return; } - QGraphicsEffectSource::PixmapPadMode mode = QGraphicsEffectSource::ExpandToEffectRectPadMode; + PixmapPadMode mode = PadToEffectiveBoundingRect; if (painter->paintEngine()->type() == QPaintEngine::OpenGL2) - mode = QGraphicsEffectSource::ExpandToTransparentBorderPadMode; + mode = PadToTransparentBorder; // Draw pixmap in device coordinates to avoid pixmap scaling. QPoint offset; - const QPixmap pixmap = source->pixmap(Qt::DeviceCoordinates, &offset, mode); + const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset, mode); QTransform restoreTransform = painter->worldTransform(); painter->setWorldTransform(QTransform()); d->filter->draw(painter, offset, pixmap); @@ -1100,7 +1155,7 @@ void QGraphicsOpacityEffect::setOpacityMask(const QBrush &mask) /*! \reimp */ -void QGraphicsOpacityEffect::draw(QPainter *painter, QGraphicsEffectSource *source) +void QGraphicsOpacityEffect::draw(QPainter *painter) { Q_D(QGraphicsOpacityEffect); @@ -1110,18 +1165,16 @@ void QGraphicsOpacityEffect::draw(QPainter *painter, QGraphicsEffectSource *sour // Opaque; draw directly without going through a pixmap. if (d->isFullyOpaque && !d->hasOpacityMask) { - source->draw(painter); + drawSource(painter); return; } - QPoint offset; - Qt::CoordinateSystem system = source->isPixmap() ? Qt::LogicalCoordinates : Qt::DeviceCoordinates; - QPixmap pixmap = source->pixmap(system, &offset, QGraphicsEffectSource::NoExpandPadMode); + Qt::CoordinateSystem system = sourceIsPixmap() ? Qt::LogicalCoordinates : Qt::DeviceCoordinates; + QPixmap pixmap = sourcePixmap(system, &offset, QGraphicsEffect::NoPad); if (pixmap.isNull()) return; - painter->save(); painter->setOpacity(d->opacity); @@ -1133,7 +1186,7 @@ void QGraphicsOpacityEffect::draw(QPainter *painter, QGraphicsEffectSource *sour QTransform worldTransform = painter->worldTransform(); worldTransform *= QTransform::fromTranslate(-offset.x(), -offset.y()); pixmapPainter.setWorldTransform(worldTransform); - pixmapPainter.fillRect(source->boundingRect(), d->opacityMask); + pixmapPainter.fillRect(sourceBoundingRect(), d->opacityMask); } else { pixmapPainter.translate(-offset); pixmapPainter.fillRect(pixmap.rect(), d->opacityMask); diff --git a/src/gui/effects/qgraphicseffect.h b/src/gui/effects/qgraphicseffect.h index 5c73f4b..2257f01 100644 --- a/src/gui/effects/qgraphicseffect.h +++ b/src/gui/effects/qgraphicseffect.h @@ -60,46 +60,7 @@ class QStyleOption; class QPainter; class QPixmap; -class QGraphicsEffectSourcePrivate; -class Q_GUI_EXPORT QGraphicsEffectSource : public QObject -{ - Q_OBJECT -public: - enum PixmapPadMode { - NoExpandPadMode, - ExpandToTransparentBorderPadMode, - ExpandToEffectRectPadMode - }; - - ~QGraphicsEffectSource(); - const QGraphicsItem *graphicsItem() const; - const QWidget *widget() const; - const QStyleOption *styleOption() const; - - bool isPixmap() const; - void draw(QPainter *painter); - void update(); - - QRectF boundingRect(Qt::CoordinateSystem coordinateSystem = Qt::LogicalCoordinates) const; - QRect deviceRect() const; - QPixmap pixmap(Qt::CoordinateSystem system = Qt::LogicalCoordinates, - QPoint *offset = 0, - PixmapPadMode mode = ExpandToEffectRectPadMode) const; - -protected: - QGraphicsEffectSource(QGraphicsEffectSourcePrivate &dd, QObject *parent = 0); - -private: - Q_DECLARE_PRIVATE(QGraphicsEffectSource) - Q_DISABLE_COPY(QGraphicsEffectSource) - friend class QGraphicsEffect; - friend class QGraphicsEffectPrivate; - friend class QGraphicsScenePrivate; - friend class QGraphicsItem; - friend class QGraphicsItemPrivate; - friend class QWidget; - friend class QWidgetPrivate; -}; +class QGraphicsEffectSource; class QGraphicsEffectPrivate; class Q_GUI_EXPORT QGraphicsEffect : public QObject @@ -116,14 +77,18 @@ public: }; Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag) + enum PixmapPadMode { + NoPad, + PadToTransparentBorder, + PadToEffectiveBoundingRect + }; + QGraphicsEffect(QObject *parent = 0); virtual ~QGraphicsEffect(); - virtual QRectF boundingRectFor(const QRectF &rect) const; + virtual QRectF boundingRectFor(const QRectF &sourceRect) const; QRectF boundingRect() const; - QGraphicsEffectSource *source() const; - bool isEnabled() const; public Q_SLOTS: @@ -135,10 +100,17 @@ Q_SIGNALS: protected: QGraphicsEffect(QGraphicsEffectPrivate &d, QObject *parent = 0); - virtual void draw(QPainter *painter, QGraphicsEffectSource *source) = 0; + virtual void draw(QPainter *painter) = 0; virtual void sourceChanged(ChangeFlags flags); void updateBoundingRect(); + bool sourceIsPixmap() const; + QRectF sourceBoundingRect(Qt::CoordinateSystem system = Qt::LogicalCoordinates) const; + void drawSource(QPainter *painter); + QPixmap sourcePixmap(Qt::CoordinateSystem system = Qt::LogicalCoordinates, + QPoint *offset = 0, + PixmapPadMode mode = PadToEffectiveBoundingRect) const; + private: Q_DECLARE_PRIVATE(QGraphicsEffect) Q_DISABLE_COPY(QGraphicsEffect) @@ -147,6 +119,10 @@ private: friend class QGraphicsScenePrivate; friend class QWidget; friend class QWidgetPrivate; + +public: + QGraphicsEffectSource *source() const; // internal + }; Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsEffect::ChangeFlags) @@ -172,7 +148,7 @@ Q_SIGNALS: void strengthChanged(qreal strength); protected: - void draw(QPainter *painter, QGraphicsEffectSource *source); + void draw(QPainter *painter); private: Q_DECLARE_PRIVATE(QGraphicsColorizeEffect) @@ -183,38 +159,42 @@ class QGraphicsBlurEffectPrivate; class Q_GUI_EXPORT QGraphicsBlurEffect: public QGraphicsEffect { Q_OBJECT + Q_FLAGS(BlurHint BlurHints) Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged) - Q_PROPERTY(BlurHint blurHint READ blurHint WRITE setBlurHint NOTIFY blurHintChanged) + Q_PROPERTY(BlurHints blurHints READ blurHints WRITE setBlurHints NOTIFY blurHintsChanged) public: enum BlurHint { - QualityHint, - PerformanceHint, - AnimationHint + PerformanceHint = 0x00, + QualityHint = 0x01, + AnimationHint = 0x02 }; + Q_DECLARE_FLAGS(BlurHints, BlurHint) QGraphicsBlurEffect(QObject *parent = 0); ~QGraphicsBlurEffect(); QRectF boundingRectFor(const QRectF &rect) const; qreal blurRadius() const; - BlurHint blurHint() const; + BlurHints blurHints() const; public Q_SLOTS: void setBlurRadius(qreal blurRadius); - void setBlurHint(BlurHint hint); + void setBlurHints(BlurHints hints); Q_SIGNALS: void blurRadiusChanged(qreal blurRadius); - void blurHintChanged(BlurHint hint); + void blurHintsChanged(BlurHints hints); protected: - void draw(QPainter *painter, QGraphicsEffectSource *source); + void draw(QPainter *painter); private: Q_DECLARE_PRIVATE(QGraphicsBlurEffect) Q_DISABLE_COPY(QGraphicsBlurEffect) }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsBlurEffect::BlurHints) + class QGraphicsDropShadowEffectPrivate; class Q_GUI_EXPORT QGraphicsDropShadowEffect: public QGraphicsEffect { @@ -264,7 +244,7 @@ Q_SIGNALS: void colorChanged(const QColor &color); protected: - void draw(QPainter *painter, QGraphicsEffectSource *source); + void draw(QPainter *painter); private: Q_DECLARE_PRIVATE(QGraphicsDropShadowEffect) @@ -293,7 +273,7 @@ Q_SIGNALS: void opacityMaskChanged(const QBrush &mask); protected: - void draw(QPainter *painter, QGraphicsEffectSource *source); + void draw(QPainter *painter); private: Q_DECLARE_PRIVATE(QGraphicsOpacityEffect) diff --git a/src/gui/effects/qgraphicseffect_p.h b/src/gui/effects/qgraphicseffect_p.h index d94d08d..c67052e 100644 --- a/src/gui/effects/qgraphicseffect_p.h +++ b/src/gui/effects/qgraphicseffect_p.h @@ -63,6 +63,41 @@ #ifndef QT_NO_GRAPHICSEFFECT QT_BEGIN_NAMESPACE +class QGraphicsEffectSourcePrivate; +class Q_AUTOTEST_EXPORT QGraphicsEffectSource : public QObject +{ + Q_OBJECT +public: + ~QGraphicsEffectSource(); + const QGraphicsItem *graphicsItem() const; + const QWidget *widget() const; + const QStyleOption *styleOption() const; + + bool isPixmap() const; + void draw(QPainter *painter); + void update(); + + QRectF boundingRect(Qt::CoordinateSystem coordinateSystem = Qt::LogicalCoordinates) const; + QRect deviceRect() const; + QPixmap pixmap(Qt::CoordinateSystem system = Qt::LogicalCoordinates, + QPoint *offset = 0, + QGraphicsEffect::PixmapPadMode mode = QGraphicsEffect::PadToEffectiveBoundingRect) const; + +protected: + QGraphicsEffectSource(QGraphicsEffectSourcePrivate &dd, QObject *parent = 0); + +private: + Q_DECLARE_PRIVATE(QGraphicsEffectSource) + Q_DISABLE_COPY(QGraphicsEffectSource) + friend class QGraphicsEffect; + friend class QGraphicsEffectPrivate; + friend class QGraphicsScenePrivate; + friend class QGraphicsItem; + friend class QGraphicsItemPrivate; + friend class QWidget; + friend class QWidgetPrivate; +}; + class QGraphicsEffectSourcePrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QGraphicsEffectSource) @@ -70,7 +105,7 @@ public: QGraphicsEffectSourcePrivate() : QObjectPrivate() , m_cachedSystem(Qt::DeviceCoordinates) - , m_cachedMode(QGraphicsEffectSource::ExpandToTransparentBorderPadMode) + , m_cachedMode(QGraphicsEffect::PadToTransparentBorder) {} virtual ~QGraphicsEffectSourcePrivate(); @@ -84,7 +119,7 @@ public: virtual void update() = 0; virtual bool isPixmap() const = 0; virtual QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset = 0, - QGraphicsEffectSource::PixmapPadMode mode = QGraphicsEffectSource::ExpandToTransparentBorderPadMode) const = 0; + QGraphicsEffect::PixmapPadMode mode = QGraphicsEffect::PadToTransparentBorder) const = 0; virtual void effectBoundingRectChanged() = 0; void invalidateCache(bool effectRectChanged = false) const; @@ -94,7 +129,7 @@ public: private: mutable Qt::CoordinateSystem m_cachedSystem; - mutable QGraphicsEffectSource::PixmapPadMode m_cachedMode; + mutable QGraphicsEffect::PixmapPadMode m_cachedMode; mutable QPoint m_cachedOffset; mutable QPixmapCache::Key m_cacheKey; }; diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 723e496..9d495e9 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -10812,7 +10812,7 @@ void QGraphicsItemEffectSourcePrivate::draw(QPainter *painter) } QPixmap QGraphicsItemEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset, - QGraphicsEffectSource::PixmapPadMode mode) const + QGraphicsEffect::PixmapPadMode mode) const { const bool deviceCoordinates = (system == Qt::DeviceCoordinates); if (!info && deviceCoordinates) { @@ -10828,9 +10828,9 @@ QPixmap QGraphicsItemEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QP const QRectF sourceRect = boundingRect(system); QRect effectRect; - if (mode == QGraphicsEffectSource::ExpandToEffectRectPadMode) { + if (mode == QGraphicsEffect::PadToEffectiveBoundingRect) { effectRect = item->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect(); - } else if (mode == QGraphicsEffectSource::ExpandToTransparentBorderPadMode) { + } else if (mode == QGraphicsEffect::PadToTransparentBorder) { // adjust by 1.5 to account for cosmetic pens effectRect = sourceRect.adjusted(-1.5, -1.5, 1.5, 1.5).toAlignedRect(); } else { diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index afc2198..75c8246 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -633,7 +633,7 @@ public: void draw(QPainter *); QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset, - QGraphicsEffectSource::PixmapPadMode mode) const; + QGraphicsEffect::PixmapPadMode mode) const; QGraphicsItem *item; QGraphicsItemPaintInfo *info; diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 2748ab6..13f31b8 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -4656,7 +4656,7 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter * sourced->lastEffectTransform = painter->worldTransform(); sourced->invalidateCache(); } - item->d_ptr->graphicsEffect->draw(painter, source); + item->d_ptr->graphicsEffect->draw(painter); painter->setWorldTransform(restoreTransform); sourced->info = 0; } else diff --git a/src/gui/image/qpixmapfilter.cpp b/src/gui/image/qpixmapfilter.cpp index d83ef2c..c0b840a 100644 --- a/src/gui/image/qpixmapfilter.cpp +++ b/src/gui/image/qpixmapfilter.cpp @@ -490,7 +490,7 @@ void QPixmapConvolutionFilter::draw(QPainter *painter, const QPointF &p, const Q which is applied when \l{QPixmapFilter::}{draw()} is called. The filter lets you specialize the radius of the blur as well - as hint as to whether to prefer performance or quality. + as hints as to whether to prefer performance or quality. By default, the blur effect is produced by applying an exponential filter generated from the specified blurRadius(). Paint engines @@ -505,10 +505,10 @@ void QPixmapConvolutionFilter::draw(QPainter *painter, const QPointF &p, const Q class QPixmapBlurFilterPrivate : public QPixmapFilterPrivate { public: - QPixmapBlurFilterPrivate() : radius(5), hint(QGraphicsBlurEffect::PerformanceHint) {} + QPixmapBlurFilterPrivate() : radius(5), hints(QGraphicsBlurEffect::PerformanceHint) {} qreal radius; - QGraphicsBlurEffect::BlurHint hint; + QGraphicsBlurEffect::BlurHints hints; }; @@ -554,9 +554,9 @@ qreal QPixmapBlurFilter::radius() const } /*! - Setting the blur hint to PerformanceHint causes the implementation + Setting the blur hints to PerformanceHint causes the implementation to trade off visual quality to blur the image faster. Setting the - blur hint to QualityHint causes the implementation to improve + blur hints to QualityHint causes the implementation to improve visual quality at the expense of speed. AnimationHint causes the implementation to optimize for animating @@ -568,21 +568,21 @@ qreal QPixmapBlurFilter::radius() const \internal */ -void QPixmapBlurFilter::setBlurHint(QGraphicsBlurEffect::BlurHint hint) +void QPixmapBlurFilter::setBlurHints(QGraphicsBlurEffect::BlurHints hints) { Q_D(QPixmapBlurFilter); - d->hint = hint; + d->hints = hints; } /*! - Gets the blur hint of the blur filter. + Gets the blur hints of the blur filter. \internal */ -QGraphicsBlurEffect::BlurHint QPixmapBlurFilter::blurHint() const +QGraphicsBlurEffect::BlurHints QPixmapBlurFilter::blurHints() const { Q_D(const QPixmapBlurFilter); - return d->hint; + return d->hints; } /*! @@ -685,7 +685,7 @@ void QPixmapBlurFilter::draw(QPainter *painter, const QPointF &p, const QPixmap QPixmapBlurFilter *blurFilter = static_cast<QPixmapBlurFilter*>(filter); if (blurFilter) { blurFilter->setRadius(d->radius); - blurFilter->setBlurHint(d->hint); + blurFilter->setBlurHints(d->hints); blurFilter->draw(painter, p, src, srcRect); return; } diff --git a/src/gui/image/qpixmapfilter_p.h b/src/gui/image/qpixmapfilter_p.h index 2573fc7..46e744e 100644 --- a/src/gui/image/qpixmapfilter_p.h +++ b/src/gui/image/qpixmapfilter_p.h @@ -132,10 +132,10 @@ public: ~QPixmapBlurFilter(); void setRadius(qreal radius); - void setBlurHint(QGraphicsBlurEffect::BlurHint hint); + void setBlurHints(QGraphicsBlurEffect::BlurHints hints); qreal radius() const; - QGraphicsBlurEffect::BlurHint blurHint() const; + QGraphicsBlurEffect::BlurHints blurHints() const; QRectF boundingRectFor(const QRectF &rect) const; void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const; diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index f856b13..e764774 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -5238,7 +5238,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP QPainter p(pdev); p.translate(offset); context.painter = &p; - graphicsEffect->draw(&p, source); + graphicsEffect->draw(&p); paintEngine->d_func()->systemClip = QRegion(); } else { context.painter = sharedPainter; @@ -5248,7 +5248,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP } sharedPainter->save(); sharedPainter->translate(offset); - graphicsEffect->draw(sharedPainter, source); + graphicsEffect->draw(sharedPainter); sharedPainter->restore(); } sourced->context = 0; @@ -5470,7 +5470,7 @@ void QWidgetEffectSourcePrivate::draw(QPainter *painter) } QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset, - QGraphicsEffectSource::PixmapPadMode mode) const + QGraphicsEffect::PixmapPadMode mode) const { const bool deviceCoordinates = (system == Qt::DeviceCoordinates); if (!context && deviceCoordinates) { @@ -5491,10 +5491,10 @@ QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint * QRect effectRect; - if (mode == QGraphicsEffectSource::ExpandToEffectRectPadMode) { + if (mode == QGraphicsEffect::PadToEffectiveBoundingRect) { effectRect = m_widget->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect(); - } else if (mode == QGraphicsEffectSource::ExpandToTransparentBorderPadMode) { + } else if (mode == QGraphicsEffect::PadToTransparentBorder) { effectRect = sourceRect.adjusted(-1, -1, 1, 1).toAlignedRect(); } else { diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index 151b90a..df28bac 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -824,7 +824,7 @@ public: QRectF boundingRect(Qt::CoordinateSystem system) const; void draw(QPainter *p); QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset, - QGraphicsEffectSource::PixmapPadMode mode) const; + QGraphicsEffect::PixmapPadMode mode) const; QWidget *m_widget; QWidgetPaintContext *context; diff --git a/src/opengl/qglpixmapfilter.cpp b/src/opengl/qglpixmapfilter.cpp index 0eaab28..fcb0ea2 100644 --- a/src/opengl/qglpixmapfilter.cpp +++ b/src/opengl/qglpixmapfilter.cpp @@ -102,7 +102,7 @@ private: class QGLPixmapBlurFilter : public QGLCustomShaderStage, public QGLPixmapFilter<QPixmapBlurFilter> { public: - QGLPixmapBlurFilter(QGraphicsBlurEffect::BlurHint hint); + QGLPixmapBlurFilter(QGraphicsBlurEffect::BlurHints hints); void setUniforms(QGLShaderProgram *program); @@ -123,13 +123,13 @@ private: mutable bool m_haveCached; mutable int m_cachedRadius; - mutable QGraphicsBlurEffect::BlurHint m_hint; + mutable QGraphicsBlurEffect::BlurHints m_hints; }; class QGLPixmapDropShadowFilter : public QGLCustomShaderStage, public QGLPixmapFilter<QPixmapDropShadowFilter> { public: - QGLPixmapDropShadowFilter(QGraphicsBlurEffect::BlurHint hint); + QGLPixmapDropShadowFilter(QGraphicsBlurEffect::BlurHints hints); void setUniforms(QGLShaderProgram *program); @@ -143,7 +143,7 @@ private: mutable bool m_haveCached; mutable int m_cachedRadius; - mutable QGraphicsBlurEffect::BlurHint m_hint; + mutable QGraphicsBlurEffect::BlurHints m_hints; }; extern QGLWidget *qt_gl_share_widget(); @@ -159,19 +159,19 @@ QPixmapFilter *QGL2PaintEngineEx::pixmapFilter(int type, const QPixmapFilter *pr case QPixmapFilter::BlurFilter: { const QPixmapBlurFilter *proto = static_cast<const QPixmapBlurFilter *>(prototype); - if (proto->blurHint() == QGraphicsBlurEffect::AnimationHint) { + if (proto->blurHints() & QGraphicsBlurEffect::AnimationHint) { if (!d->animationBlurFilter) - d->animationBlurFilter.reset(new QGLPixmapBlurFilter(proto->blurHint())); + d->animationBlurFilter.reset(new QGLPixmapBlurFilter(proto->blurHints())); return d->animationBlurFilter.data(); } - if (proto->blurHint() == QGraphicsBlurEffect::PerformanceHint || proto->radius() <= 5) { - if (!d->fastBlurFilter) - d->fastBlurFilter.reset(new QGLPixmapBlurFilter(QGraphicsBlurEffect::PerformanceHint)); - return d->fastBlurFilter.data(); + if ((proto->blurHints() & QGraphicsBlurEffect::QualityHint) && proto->radius() > 5) { + if (!d->blurFilter) + d->blurFilter.reset(new QGLPixmapBlurFilter(QGraphicsBlurEffect::QualityHint)); + return d->blurFilter.data(); } - if (!d->blurFilter) - d->blurFilter.reset(new QGLPixmapBlurFilter(QGraphicsBlurEffect::QualityHint)); - return d->blurFilter.data(); + if (!d->fastBlurFilter) + d->fastBlurFilter.reset(new QGLPixmapBlurFilter(QGraphicsBlurEffect::PerformanceHint)); + return d->fastBlurFilter.data(); } case QPixmapFilter::DropShadowFilter: { @@ -316,11 +316,11 @@ static const char *qt_gl_texture_sampling_helper = " return texture2D(src, srcCoords).a;\n" "}\n"; -QGLPixmapBlurFilter::QGLPixmapBlurFilter(QGraphicsBlurEffect::BlurHint hint) +QGLPixmapBlurFilter::QGLPixmapBlurFilter(QGraphicsBlurEffect::BlurHints hints) : m_animatedBlur(false) , m_haveCached(false) , m_cachedRadius(0) - , m_hint(hint) + , m_hints(hints) { } @@ -503,7 +503,7 @@ bool QGLPixmapBlurFilter::processGL(QPainter *painter, const QPointF &pos, const QGLContext *ctx = const_cast<QGLContext *>(QGLContext::currentContext()); QGLBlurTextureCache *blurTextureCache = QGLBlurTextureCache::cacheForContext(ctx); - if (m_hint == QGraphicsBlurEffect::AnimationHint && blurTextureCache->fitsInCache(src)) { + if ((m_hints & QGraphicsBlurEffect::AnimationHint) && blurTextureCache->fitsInCache(src)) { QRect targetRect = src.rect().adjusted(-qMaxCachedBlurLevel, -qMaxCachedBlurLevel, qMaxCachedBlurLevel, qMaxCachedBlurLevel); // ensure even dimensions (going to divide by two) targetRect.setWidth((targetRect.width() + 1) & ~1); @@ -514,7 +514,7 @@ bool QGLPixmapBlurFilter::processGL(QPainter *painter, const QPointF &pos, const info = blurTextureCache->takeBlurTextureInfo(src); } else { m_animatedBlur = false; - m_hint = QGraphicsBlurEffect::QualityHint; + m_hints = QGraphicsBlurEffect::QualityHint; m_singlePass = false; QGLFramebufferObjectFormat format; @@ -594,7 +594,7 @@ bool QGLPixmapBlurFilter::processGL(QPainter *painter, const QPointF &pos, const if (!m_haveCached || !m_animatedBlur) { m_haveCached = true; m_animatedBlur = true; - m_hint = QGraphicsBlurEffect::AnimationHint; + m_hints = QGraphicsBlurEffect::AnimationHint; filter->setSource(qt_gl_interpolate_filter); } @@ -653,7 +653,7 @@ bool QGLPixmapBlurFilter::processGL(QPainter *painter, const QPointF &pos, const int actualRadius = qRound(radius()); int filterRadius = actualRadius; int fastRadii[] = { 1, 2, 3, 5, 8, 15, 25 }; - if (m_hint != QGraphicsBlurEffect::QualityHint) { + if (!(m_hints & QGraphicsBlurEffect::QualityHint)) { uint i = 0; for (; i < (sizeof(fastRadii)/sizeof(*fastRadii))-1; ++i) { if (fastRadii[i+1] > filterRadius) @@ -762,7 +762,7 @@ void QGLPixmapBlurFilter::setUniforms(QGLShaderProgram *program) return; } - if (m_hint == QGraphicsBlurEffect::QualityHint) { + if (m_hints & QGraphicsBlurEffect::QualityHint) { if (m_singlePass) program->setUniformValue("delta", 1.0 / m_textureSize.width(), 1.0 / m_textureSize.height()); else if (m_horizontalBlur) @@ -912,10 +912,10 @@ QByteArray QGLPixmapBlurFilter::generateGaussianShader(int radius, bool singlePa return source; } -QGLPixmapDropShadowFilter::QGLPixmapDropShadowFilter(QGraphicsBlurEffect::BlurHint hint) +QGLPixmapDropShadowFilter::QGLPixmapDropShadowFilter(QGraphicsBlurEffect::BlurHints hints) : m_haveCached(false) , m_cachedRadius(0) - , m_hint(hint) + , m_hints(hints) { } @@ -1018,7 +1018,7 @@ void QGLPixmapDropShadowFilter::setUniforms(QGLShaderProgram *program) alpha); } - if (m_hint == QGraphicsBlurEffect::QualityHint) { + if (m_hints & QGraphicsBlurEffect::QualityHint) { if (m_singlePass) program->setUniformValue("delta", 1.0 / m_textureSize.width(), 1.0 / m_textureSize.height()); else if (m_horizontalBlur) diff --git a/src/opengl/qgraphicsshadereffect.cpp b/src/opengl/qgraphicsshadereffect.cpp index 1c02fd0..4d7a69c 100644 --- a/src/opengl/qgraphicsshadereffect.cpp +++ b/src/opengl/qgraphicsshadereffect.cpp @@ -241,7 +241,7 @@ void QGraphicsShaderEffect::setPixelShaderFragment(const QByteArray& code) /*# \reimp */ -void QGraphicsShaderEffect::draw(QPainter *painter, QGraphicsEffectSource *source) +void QGraphicsShaderEffect::draw(QPainter *painter) { Q_D(QGraphicsShaderEffect); @@ -256,13 +256,13 @@ void QGraphicsShaderEffect::draw(QPainter *painter, QGraphicsEffectSource *sourc bool usingShader = d->customShaderStage->setOnPainter(painter); QPoint offset; - if (source->isPixmap()) { + if (sourceIsPixmap()) { // No point in drawing in device coordinates (pixmap will be scaled anyways). - const QPixmap pixmap = source->pixmap(Qt::LogicalCoordinates, &offset); + const QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset); painter->drawPixmap(offset, pixmap); } else { // Draw pixmap in device coordinates to avoid pixmap scaling. - const QPixmap pixmap = source->pixmap(Qt::DeviceCoordinates, &offset); + const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset); QTransform restoreTransform = painter->worldTransform(); painter->setWorldTransform(QTransform()); painter->drawPixmap(offset, pixmap); @@ -273,7 +273,7 @@ void QGraphicsShaderEffect::draw(QPainter *painter, QGraphicsEffectSource *sourc if (usingShader) d->customShaderStage->removeFromPainter(painter); #else - source->draw(painter); + drawSource(painter); #endif } diff --git a/src/opengl/qgraphicsshadereffect_p.h b/src/opengl/qgraphicsshadereffect_p.h index de7f00c..de65ebb 100644 --- a/src/opengl/qgraphicsshadereffect_p.h +++ b/src/opengl/qgraphicsshadereffect_p.h @@ -76,7 +76,7 @@ public: void setPixelShaderFragment(const QByteArray& code); protected: - void draw(QPainter *painter, QGraphicsEffectSource *source); + void draw(QPainter *painter); void setUniformsDirty(); virtual void setUniforms(QGLShaderProgram *program); diff --git a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp index b40cf43..d216924 100644 --- a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp +++ b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp @@ -49,6 +49,7 @@ #include <QtGui/qstyleoption.h> #include "../../shared/util.h" +#include <private/qgraphicseffect_p.h> //TESTED_CLASS= //TESTED_FILES= @@ -131,16 +132,16 @@ public: int margin() const { return m_margin; } - void draw(QPainter *painter, QGraphicsEffectSource *source) + void draw(QPainter *painter) { ++numRepaints; if (doNothingInDraw) return; - m_source = source; + m_source = source(); m_painter = painter; - m_styleOption = source->styleOption(); + m_styleOption = source()->styleOption(); m_opacity = painter->opacity(); - source->draw(painter); + drawSource(painter); } void sourceChanged(QGraphicsEffect::ChangeFlags flags) |