diff options
author | Gunnar Sletta <gunnar@trolltech.com> | 2009-10-23 07:30:26 (GMT) |
---|---|---|
committer | Gunnar Sletta <gunnar@trolltech.com> | 2009-10-23 07:48:45 (GMT) |
commit | d576d770b9b8251f1b5b4808a84045af33e62dba (patch) | |
tree | 5160da545e020afa796dad8a6fe222edb89c5236 | |
parent | 5de213210ef4f14e698c3fd970cf7e6c5b27c72d (diff) | |
download | Qt-d576d770b9b8251f1b5b4808a84045af33e62dba.zip Qt-d576d770b9b8251f1b5b4808a84045af33e62dba.tar.gz Qt-d576d770b9b8251f1b5b4808a84045af33e62dba.tar.bz2 |
Removed pixelize, bloom and grayscale filter
This is new API and we don't want to add several items that are not
strictly needed. This is a new set of features and we can grow them
once we have more input from users on what is needed.
The Bloom filter was added based on input from designers, but is not
implemented according to how designers think of blook, so the effect
doesn't meet the requirements.
The Grayscale filter is functionally a duplicate of the colorize
filter and is therefore not needed.
The Pixelize filter has no genuine usecase.
Reviewed-by: Samuel
-rw-r--r-- | src/gui/effects/qgraphicseffect.cpp | 453 | ||||
-rw-r--r-- | src/gui/effects/qgraphicseffect.h | 88 | ||||
-rw-r--r-- | src/gui/effects/qgraphicseffect_p.h | 37 |
3 files changed, 4 insertions, 574 deletions
diff --git a/src/gui/effects/qgraphicseffect.cpp b/src/gui/effects/qgraphicseffect.cpp index 96d35b0..e25b40b 100644 --- a/src/gui/effects/qgraphicseffect.cpp +++ b/src/gui/effects/qgraphicseffect.cpp @@ -65,9 +65,6 @@ \o QGraphicsDropShadowEffect - renders a dropshadow behind the item \o QGraphicsColorizeEffect - renders the item in shades of any given color \o QGraphicsOpacityEffect - renders the item with an opacity - \o QGraphicsPixelizeEffect - pixelizes the item with any pixel size - \o QGraphicsGrayscaleEffect - renders the item in shades of gray - \o QGraphicsBloomEffect - applies a blooming / glowing effect \endlist \img graphicseffect-effects.png @@ -458,96 +455,6 @@ void QGraphicsEffect::sourceChanged(ChangeFlags flags) } /*! - \class QGraphicsGrayscaleEffect - \brief The QGraphicsGrayscaleEffect class provides a grayscale effect. - \since 4.6 - - A grayscale effect renders the source in shades of gray. - - \img graphicseffect-grayscale.png - - \sa QGraphicsDropShadowEffect, QGraphicsBlurEffect, QGraphicsPixelizeEffect, - QGraphicsColorizeEffect, QGraphicsOpacityEffect -*/ - -/*! - Constructs a new QGraphicsGrayscale instance. - The \a parent parameter is passed to QGraphicsEffect's constructor. -*/ -QGraphicsGrayscaleEffect::QGraphicsGrayscaleEffect(QObject *parent) - : QGraphicsEffect(*new QGraphicsGrayscaleEffectPrivate, parent) -{ -} - -/*! - Destroys the effect. -*/ -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); -} - -/*! \fn void QGraphicsGrayscaleEffect::strengthChanged(qreal strength) - This signal is emitted whenever setStrength() changes the grayscale - strength property. \a strength contains the new strength value of - the grayscale effect. - */ - -/*! - \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). - const QPixmap pixmap = source->pixmap(Qt::LogicalCoordinates, &offset); - d->filter->draw(painter, offset, pixmap); - return; - } - - // Draw pixmap in device coordinates to avoid pixmap scaling; - const QPixmap pixmap = source->pixmap(Qt::DeviceCoordinates, &offset); - QTransform restoreTransform = painter->worldTransform(); - painter->setWorldTransform(QTransform()); - d->filter->draw(painter, offset, pixmap); - painter->setWorldTransform(restoreTransform); - -} - -/*! \class QGraphicsColorizeEffect \brief The QGraphicsColorizeEffect class provides a colorize effect. \since 4.6 @@ -559,8 +466,7 @@ void QGraphicsGrayscaleEffect::draw(QPainter *painter, QGraphicsEffectSource *so \img graphicseffect-colorize.png - \sa QGraphicsDropShadowEffect, QGraphicsBlurEffect, QGraphicsPixelizeEffect, - QGraphicsGrayscaleEffect, QGraphicsOpacityEffect + \sa QGraphicsDropShadowEffect, QGraphicsBlurEffect, QGraphicsOpacityEffect */ /*! @@ -669,126 +575,6 @@ void QGraphicsColorizeEffect::draw(QPainter *painter, QGraphicsEffectSource *sou } /*! - \class QGraphicsPixelizeEffect - \brief The QGraphicsPixelizeEffect class provides a pixelize effect. - \since 4.6 - - A pixelize effect renders the source in lower resolution. This effect is - useful for reducing details, like censorship. The resolution can be - modified using the setPixelSize() function. - - By default, the pixel size is 3. - - \img graphicseffect-pixelize.png - - \sa QGraphicsDropShadowEffect, QGraphicsBlurEffect, QGraphicsGrayscaleEffect, - QGraphicsColorizeEffect, QGraphicsOpacityEffect -*/ - -/*! - Constructs a new QGraphicsPixelizeEffect instance. - The \a parent parameter is passed to QGraphicsEffect's constructor. -*/ -QGraphicsPixelizeEffect::QGraphicsPixelizeEffect(QObject *parent) - : QGraphicsEffect(*new QGraphicsPixelizeEffectPrivate, parent) -{ -} - -/*! - Destroys the effect. -*/ -QGraphicsPixelizeEffect::~QGraphicsPixelizeEffect() -{ -} - -/*! - \property QGraphicsPixelizeEffect::pixelSize - \brief the size of a pixel in the effect. - - Setting the pixel size to 2 means two pixels in the source will be used to - represent one pixel. Using a bigger size results in lower resolution. - - By default, the pixel size is 3. -*/ -int QGraphicsPixelizeEffect::pixelSize() const -{ - Q_D(const QGraphicsPixelizeEffect); - return d->pixelSize; -} - -void QGraphicsPixelizeEffect::setPixelSize(int size) -{ - Q_D(QGraphicsPixelizeEffect); - if (d->pixelSize == size) - return; - - d->pixelSize = size; - update(); - emit pixelSizeChanged(size); -} - -/*! - \fn void QGraphicsPixelizeEffect::pixelSizeChanged(int size) - - This signal is emitted whenever the effect's pixel size changes. - The \a size parameter holds the effect's new pixel size. -*/ - -static inline void pixelize(QImage *image, int pixelSize) -{ - Q_ASSERT(pixelSize > 0); - Q_ASSERT(image); - int width = image->width(); - int height = image->height(); - for (int y = 0; y < height; y += pixelSize) { - int ys = qMin(height - 1, y + pixelSize / 2); - QRgb *sbuf = reinterpret_cast<QRgb*>(image->scanLine(ys)); - for (int x = 0; x < width; x += pixelSize) { - int xs = qMin(width - 1, x + pixelSize / 2); - QRgb color = sbuf[xs]; - for (int yi = 0; yi < qMin(pixelSize, height - y); ++yi) { - QRgb *buf = reinterpret_cast<QRgb*>(image->scanLine(y + yi)); - for (int xi = 0; xi < qMin(pixelSize, width - x); ++xi) - buf[x + xi] = color; - } - } - } -} - -/*! - \reimp -*/ -void QGraphicsPixelizeEffect::draw(QPainter *painter, QGraphicsEffectSource *source) -{ - Q_D(QGraphicsPixelizeEffect); - if (d->pixelSize <= 0) { - source->draw(painter); - return; - } - - QPoint offset; - if (source->isPixmap()) { - const QPixmap pixmap = source->pixmap(Qt::LogicalCoordinates, &offset); - QImage image = pixmap.toImage().convertToFormat(QImage::Format_ARGB32); - pixelize(&image, d->pixelSize); - painter->drawImage(offset, image); - return; - } - - // Draw pixmap in device coordinates to avoid pixmap scaling. - const QPixmap pixmap = source->pixmap(Qt::DeviceCoordinates, &offset); - - // pixelize routine - QImage image = pixmap.toImage().convertToFormat(QImage::Format_ARGB32); - pixelize(&image, d->pixelSize); - - QTransform restoreTransform = painter->worldTransform(); - painter->setWorldTransform(QTransform()); - painter->drawImage(offset, image); - painter->setWorldTransform(restoreTransform); -} - -/*! \class QGraphicsBlurEffect \brief The QGraphicsBlurEffect class provides a blur effect. \since 4.6 @@ -802,8 +588,7 @@ void QGraphicsPixelizeEffect::draw(QPainter *painter, QGraphicsEffectSource *sou \img graphicseffect-blur.png - \sa QGraphicsDropShadowEffect, QGraphicsPixelizeEffect, QGraphicsGrayscaleEffect, - QGraphicsColorizeEffect, QGraphicsOpacityEffect + \sa QGraphicsDropShadowEffect, QGraphicsColorizeEffect, QGraphicsOpacityEffect */ /*! @@ -937,8 +722,7 @@ void QGraphicsBlurEffect::draw(QPainter *painter, QGraphicsEffectSource *source) \img graphicseffect-drop-shadow.png - \sa QGraphicsBlurEffect, QGraphicsPixelizeEffect, QGraphicsGrayscaleEffect, - QGraphicsColorizeEffect, QGraphicsOpacityEffect + \sa QGraphicsBlurEffect, QGraphicsColorizeEffect, QGraphicsOpacityEffect */ /*! @@ -1117,8 +901,7 @@ void QGraphicsDropShadowEffect::draw(QPainter *painter, QGraphicsEffectSource *s \img graphicseffect-opacity.png - \sa QGraphicsDropShadowEffect, QGraphicsBlurEffect, QGraphicsPixelizeEffect, - QGraphicsGrayscaleEffect, QGraphicsColorizeEffect + \sa QGraphicsDropShadowEffect, QGraphicsBlurEffect, QGraphicsColorizeEffect */ /*! @@ -1296,234 +1079,6 @@ void QGraphicsOpacityEffect::draw(QPainter *painter, QGraphicsEffectSource *sour painter->restore(); } -/*! - \class QGraphicsBloomEffect - \brief The QGraphicsBloomEffect class provides a bloom/glow effect. - \since 4.6 - - A bloom/glow effect adds fringes of light around bright areas in the source. - - \img graphicseffect-bloom.png - - \sa QGraphicsDropShadowEffect, QGraphicsBlurEffect, QGraphicsPixelizeEffect, - QGraphicsGrayscaleEffect, QGraphicsColorizeEffect -*/ - -/*! - Constructs a new QGraphicsBloomEffect instance. - The \a parent parameter is passed to QGraphicsEffect's constructor. -*/ -QGraphicsBloomEffect::QGraphicsBloomEffect(QObject *parent) - : QGraphicsEffect(*new QGraphicsBloomEffectPrivate, parent) -{ - Q_D(QGraphicsBloomEffect); - for (int i = 0; i < 256; ++i) - d->colorTable[i] = qMin(i + d->brightness, 255); -} - -/*! - Destroys the effect. -*/ -QGraphicsBloomEffect::~QGraphicsBloomEffect() -{ -} - -/*! - \reimp -*/ -QRectF QGraphicsBloomEffect::boundingRectFor(const QRectF &rect) const -{ - Q_D(const QGraphicsBloomEffect); - const qreal delta = d->blurFilter.radius() * 2; - return rect.adjusted(-delta, -delta, delta, delta); -} - -/*! - \property QGraphicsBloomEffect::blurRadius - \brief the blur radius in pixels of the effect. - - Using a smaller radius results in a sharper appearance, whereas a bigger - radius results in a more blurred appearance. - - By default, the blur radius is 5 pixels. - - \sa strength(), brightness() -*/ -int QGraphicsBloomEffect::blurRadius() const -{ - Q_D(const QGraphicsBloomEffect); - return d->blurFilter.radius(); -} - -void QGraphicsBloomEffect::setBlurRadius(int radius) -{ - Q_D(QGraphicsBloomEffect); - if (d->blurFilter.radius() == radius) - return; - - d->blurFilter.setRadius(radius); - updateBoundingRect(); - emit blurRadiusChanged(radius); -} - -/*! - \fn void QGraphicsBloomEffect::blurRadiusChanged(int blurRadius) - - This signal is emitted whenever the effect's blur radius changes. - The \a blurRadius parameter holds the effect's new blur radius. -*/ - -/*! - \property QGraphicsBloomEffect::blurHint - \brief the blur hint of the effect. - - Use the Qt::PerformanceHint hint to say that you want a faster blur, - and the Qt::QualityHint hint to say that you prefer a higher quality blur. - - When animating the blur radius it's recommended to use Qt::PerformanceHint. - - By default, the blur hint is Qt::PerformanceHint. -*/ -Qt::RenderHint QGraphicsBloomEffect::blurHint() const -{ - Q_D(const QGraphicsBloomEffect); - return d->blurFilter.blurHint(); -} - -void QGraphicsBloomEffect::setBlurHint(Qt::RenderHint hint) -{ - Q_D(QGraphicsBloomEffect); - if (d->blurFilter.blurHint() == hint) - return; - - d->blurFilter.setBlurHint(hint); - emit blurHintChanged(hint); -} - -/*! - \fn void QGraphicsBloomEffect::blurHintChanged(Qt::RenderHint hint) - - This signal is emitted whenever the effect's blur hint changes. - The \a hint parameter holds the effect's new blur hint. -*/ - -/*! - \property QGraphicsBloomEffect::brightness - \brief the brightness of the glow. - - The value should be in the range of 0 to 255, where 0 is dark - and 255 is bright. - - By default, the brightness is 70. - - \sa strength(), blurRadius() -*/ -int QGraphicsBloomEffect::brightness() const -{ - Q_D(const QGraphicsBloomEffect); - return d->brightness; -} - -void QGraphicsBloomEffect::setBrightness(int brightness) -{ - Q_D(QGraphicsBloomEffect); - brightness = qBound(0, brightness, 255); - if (d->brightness == brightness) - return; - - d->brightness = brightness; - for (int i = 0; i < 256; ++i) - d->colorTable[i] = qMin(i + brightness, 255); - - update(); - emit brightnessChanged(brightness); -} - -/*! - \fn void QGraphicsBloomEffect::brightnessChanged(int brightness) - - This signal is emitted whenever the effect's brightness changes. - The \a brightness parameter holds the effect's new brightness. -*/ - -/*! - \property QGraphicsBloomEffect::strength - \brief the strength of the effect. - - A strength 0.0 equals to no effect, while 1.0 means maximum glow. - - By default, the strength is 0.7. -*/ -qreal QGraphicsBloomEffect::strength() const -{ - Q_D(const QGraphicsBloomEffect); - return d->strength; -} - -void QGraphicsBloomEffect::setStrength(qreal strength) -{ - Q_D(QGraphicsBloomEffect); - strength = qBound(qreal(0.0), strength, qreal(1.0)); - if (qFuzzyCompare(d->strength, strength)) - return; - - d->strength = strength; - update(); - emit strengthChanged(strength); -} - -/*! - \fn void QGraphicsBloomEffect::strengthChanged(qreal strength) - - This signal is emitted whenever the effect's strength changes. - The \a strength parameter holds the effect's new strength. -*/ - -extern QPixmap qt_toRasterPixmap(const QPixmap &pixmap); - -/*! - \reimp -*/ -void QGraphicsBloomEffect::draw(QPainter *painter, QGraphicsEffectSource *source) -{ - Q_D(QGraphicsBloomEffect); - if (d->strength < 0.001) { - source->draw(painter); - return; - } - - QPoint offset; - QPixmap pixmap = qt_toRasterPixmap(source->pixmap(Qt::DeviceCoordinates, &offset)); - - // Blur. - QImage overlay(pixmap.size(), QImage::Format_ARGB32_Premultiplied); - overlay.fill(0); - - QPainter blurPainter(&overlay); - d->blurFilter.draw(&blurPainter, QPointF(), pixmap); - blurPainter.end(); - - // Brighten. - const int numBits = overlay.width() * overlay.height(); - QRgb *bits = reinterpret_cast<QRgb *>(overlay.bits()); - for (int i = 0; i < numBits; ++i) { - const QRgb pixel = INV_PREMUL(bits[i]); - bits[i] = PREMUL(qRgba(d->colorTable[qRed(pixel)], d->colorTable[qGreen(pixel)], - d->colorTable[qBlue(pixel)], qAlpha(pixel))); - } - - // Composite. - QPainter compPainter(&pixmap); - compPainter.setCompositionMode(QPainter::CompositionMode_Overlay); - compPainter.setOpacity(d->strength); - compPainter.drawImage(0, 0, overlay); - compPainter.end(); - - QTransform restoreTransform = painter->worldTransform(); - painter->setWorldTransform(QTransform()); - painter->drawPixmap(offset, pixmap); - painter->setWorldTransform(restoreTransform); -} QT_END_NAMESPACE diff --git a/src/gui/effects/qgraphicseffect.h b/src/gui/effects/qgraphicseffect.h index c89851e..019e808 100644 --- a/src/gui/effects/qgraphicseffect.h +++ b/src/gui/effects/qgraphicseffect.h @@ -141,31 +141,6 @@ private: }; Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsEffect::ChangeFlags) -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) -}; - class QGraphicsColorizeEffectPrivate; class Q_GUI_EXPORT QGraphicsColorizeEffect: public QGraphicsEffect { @@ -195,31 +170,6 @@ private: Q_DISABLE_COPY(QGraphicsColorizeEffect) }; -class QGraphicsPixelizeEffectPrivate; -class Q_GUI_EXPORT QGraphicsPixelizeEffect: public QGraphicsEffect -{ - Q_OBJECT - Q_PROPERTY(int pixelSize READ pixelSize WRITE setPixelSize NOTIFY pixelSizeChanged) -public: - QGraphicsPixelizeEffect(QObject *parent = 0); - ~QGraphicsPixelizeEffect(); - - int pixelSize() const; - -public Q_SLOTS: - void setPixelSize(int pixelSize); - -Q_SIGNALS: - void pixelSizeChanged(int pixelSize); - -protected: - void draw(QPainter *painter, QGraphicsEffectSource *source); - -private: - Q_DECLARE_PRIVATE(QGraphicsPixelizeEffect) - Q_DISABLE_COPY(QGraphicsPixelizeEffect) -}; - class QGraphicsBlurEffectPrivate; class Q_GUI_EXPORT QGraphicsBlurEffect: public QGraphicsEffect { @@ -335,44 +285,6 @@ private: Q_DISABLE_COPY(QGraphicsOpacityEffect) }; -class QGraphicsBloomEffectPrivate; -class Q_GUI_EXPORT QGraphicsBloomEffect: public QGraphicsEffect -{ - Q_OBJECT - Q_PROPERTY(int blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged) - Q_PROPERTY(Qt::RenderHint blurHint READ blurHint WRITE setBlurHint NOTIFY blurHintChanged) - Q_PROPERTY(int brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged) - Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged) -public: - QGraphicsBloomEffect(QObject *parent = 0); - ~QGraphicsBloomEffect(); - - QRectF boundingRectFor(const QRectF &rect) const; - int blurRadius() const; - Qt::RenderHint blurHint() const; - int brightness() const; - qreal strength() const; - -public Q_SLOTS: - void setBlurRadius(int blurRadius); - void setBlurHint(Qt::RenderHint hint); - void setBrightness(int brightness); - void setStrength(qreal strength); - -Q_SIGNALS: - void blurRadiusChanged(int blurRadius); - void blurHintChanged(Qt::RenderHint hint); - void brightnessChanged(int brightness); - void strengthChanged(qreal strength); - -protected: - void draw(QPainter *painter, QGraphicsEffectSource *source); - -private: - Q_DECLARE_PRIVATE(QGraphicsBloomEffect) - Q_DISABLE_COPY(QGraphicsBloomEffect) -}; - QT_END_NAMESPACE QT_END_HEADER diff --git a/src/gui/effects/qgraphicseffect_p.h b/src/gui/effects/qgraphicseffect_p.h index 8fb55d8..87abbbc 100644 --- a/src/gui/effects/qgraphicseffect_p.h +++ b/src/gui/effects/qgraphicseffect_p.h @@ -118,22 +118,6 @@ public: quint32 padding : 31; // feel free to use }; -class QGraphicsGrayscaleEffectPrivate : public QGraphicsEffectPrivate -{ - Q_DECLARE_PUBLIC(QGraphicsGrayscaleEffect) -public: - QGraphicsGrayscaleEffectPrivate() - : opaque(true) - { - filter = new QPixmapColorizeFilter; - filter->setColor(Qt::black); - } - ~QGraphicsGrayscaleEffectPrivate() { delete filter; } - - QPixmapColorizeFilter *filter; - quint32 opaque : 1; - quint32 padding : 31; -}; class QGraphicsColorizeEffectPrivate : public QGraphicsEffectPrivate { @@ -151,15 +135,6 @@ public: quint32 padding : 31; }; -class QGraphicsPixelizeEffectPrivate : public QGraphicsEffectPrivate -{ - Q_DECLARE_PUBLIC(QGraphicsPixelizeEffect) -public: - QGraphicsPixelizeEffectPrivate() : pixelSize(3) {} - - int pixelSize; -}; - class QGraphicsBlurEffectPrivate : public QGraphicsEffectPrivate { Q_DECLARE_PUBLIC(QGraphicsBlurEffect) @@ -195,18 +170,6 @@ public: uint hasOpacityMask : 1; }; -class QGraphicsBloomEffectPrivate : public QGraphicsEffectPrivate -{ - Q_DECLARE_PUBLIC(QGraphicsBlurEffect) -public: - QGraphicsBloomEffectPrivate() : brightness(70), strength(qreal(0.7)) {} - - QPixmapBlurFilter blurFilter; - int colorTable[256]; - int brightness; - qreal strength; -}; - QT_END_NAMESPACE #endif // QGRAPHICSEFFECT_P_H |