diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/graphicsview/graphicsview.pri | 3 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicseffect.cpp | 178 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicseffect.h | 37 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicseffect_p.h | 150 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 53 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.h | 4 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 4 |
7 files changed, 226 insertions, 203 deletions
diff --git a/src/gui/graphicsview/graphicsview.pri b/src/gui/graphicsview/graphicsview.pri index c3cb574..55bb9e0 100644 --- a/src/gui/graphicsview/graphicsview.pri +++ b/src/gui/graphicsview/graphicsview.pri @@ -21,7 +21,8 @@ HEADERS += graphicsview/qgraphicsgridlayout.h \ graphicsview/qgraphicswidget.h \ graphicsview/qgraphicswidget_p.h \ graphicsview/qgridlayoutengine_p.h \ - graphicsview/qgraphicseffect.h + graphicsview/qgraphicseffect.h \ + graphicsview/qgraphicseffect_p.h \ SOURCES += graphicsview/qgraphicsgridlayout.cpp \ graphicsview/qgraphicsitem.cpp \ diff --git a/src/gui/graphicsview/qgraphicseffect.cpp b/src/gui/graphicsview/qgraphicseffect.cpp index 6b1f12a..c173d1b 100644 --- a/src/gui/graphicsview/qgraphicseffect.cpp +++ b/src/gui/graphicsview/qgraphicseffect.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qgraphicseffect.h" +#include "qgraphicseffect_p.h" #ifndef QT_NO_GRAPHICSVIEW @@ -48,9 +48,6 @@ #include <QtGui/qgraphicsscene.h> #include <QtGui/qpainter.h> -#include <private/qobject_p.h> -#include <private/qpixmapfilter_p.h> - /* List of known drawbacks which are being discussed: @@ -105,19 +102,11 @@ */ -/*! - \internal -*/ -class QGraphicsEffectPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QGraphicsEffect) -public: - QGraphicsEffectPrivate() {} -}; - -QGraphicsEffect::QGraphicsEffect(QObject *parent) - : QObject(*new QGraphicsEffectPrivate, parent) +QGraphicsEffect::QGraphicsEffect() + : QObject(*new QGraphicsEffectPrivate, 0) { + Q_D(QGraphicsEffect); + d->parentItem = 0; } QGraphicsEffect::~QGraphicsEffect() @@ -134,9 +123,11 @@ QRectF QGraphicsEffect::boundingRectFor(const QGraphicsItem *item) /*! \internal */ -QGraphicsEffect::QGraphicsEffect(QGraphicsEffectPrivate &dd, QObject *parent) - : QObject(dd, parent) +QGraphicsEffect::QGraphicsEffect(QGraphicsEffectPrivate &dd) + : QObject(dd, 0) { + Q_D(QGraphicsEffect); + d->parentItem = 0; } // this helper function is only for subclasses of QGraphicsEffect @@ -151,27 +142,8 @@ QPixmap* QGraphicsEffect::drawItemOnPixmap(QPainter *painter, QGraphicsItem *ite return item->scene()->drawItemOnPixmap(painter, item, option, widget, flags); } -/*! - \internal -*/ -class QGraphicsGrayscaleEffectPrivate : public QGraphicsEffectPrivate -{ - Q_DECLARE_PUBLIC(QGraphicsGrayscaleEffect) -public: - QGraphicsGrayscaleEffectPrivate() { - filter = new QPixmapColorizeFilter; - filter->setColor(Qt::black); - } - - ~QGraphicsGrayscaleEffectPrivate() { - delete filter; - } - - QPixmapColorizeFilter *filter; -}; - -QGraphicsGrayscaleEffect::QGraphicsGrayscaleEffect(QObject *parent) - : QGraphicsEffect(*new QGraphicsGrayscaleEffectPrivate, parent) +QGraphicsGrayscaleEffect::QGraphicsGrayscaleEffect() + : QGraphicsEffect(*new QGraphicsGrayscaleEffectPrivate) { } @@ -201,26 +173,8 @@ void QGraphicsGrayscaleEffect::drawItem(QGraphicsItem *item, QPainter *painter, painter->setWorldTransform(restoreTransform); } -/*! - \internal -*/ -class QGraphicsColorizeEffectPrivate : public QGraphicsEffectPrivate -{ - Q_DECLARE_PUBLIC(QGraphicsColorizeEffect) -public: - QGraphicsColorizeEffectPrivate() { - filter = new QPixmapColorizeFilter; - } - - ~QGraphicsColorizeEffectPrivate() { - delete filter; - } - - QPixmapColorizeFilter *filter; -}; - -QGraphicsColorizeEffect::QGraphicsColorizeEffect(QObject *parent) - : QGraphicsEffect(*new QGraphicsColorizeEffectPrivate, parent) +QGraphicsColorizeEffect::QGraphicsColorizeEffect() + : QGraphicsEffect(*new QGraphicsColorizeEffectPrivate) { } @@ -262,21 +216,8 @@ void QGraphicsColorizeEffect::drawItem(QGraphicsItem *item, QPainter *painter, painter->setWorldTransform(restoreTransform); } -/*! - \internal -*/ -class QGraphicsPixelizeEffectPrivate : public QGraphicsEffectPrivate -{ - Q_DECLARE_PUBLIC(QGraphicsPixelizeEffect) -public: - QGraphicsPixelizeEffectPrivate() - : pixelSize(3) { } - - int pixelSize; -}; - -QGraphicsPixelizeEffect::QGraphicsPixelizeEffect(QObject *parent) - : QGraphicsEffect(*new QGraphicsPixelizeEffectPrivate, parent) +QGraphicsPixelizeEffect::QGraphicsPixelizeEffect() + : QGraphicsEffect(*new QGraphicsPixelizeEffectPrivate) { } @@ -338,27 +279,8 @@ void QGraphicsPixelizeEffect::drawItem(QGraphicsItem *item, QPainter *painter, painter->setWorldTransform(restoreTransform); } -/*! - \internal -*/ -class QGraphicsBlurEffectPrivate : public QGraphicsEffectPrivate -{ - Q_DECLARE_PUBLIC(QGraphicsBlurEffect) -public: - QGraphicsBlurEffectPrivate() - { - filter = new QPixmapBlurFilter; - } - ~QGraphicsBlurEffectPrivate() - { - delete filter; - } - - QPixmapBlurFilter *filter; -}; - -QGraphicsBlurEffect::QGraphicsBlurEffect(QObject *parent) - : QGraphicsEffect(*new QGraphicsBlurEffectPrivate, parent) +QGraphicsBlurEffect::QGraphicsBlurEffect() + : QGraphicsEffect(*new QGraphicsBlurEffectPrivate) { } @@ -471,23 +393,8 @@ void QGraphicsBlurEffect::drawItem(QGraphicsItem *item, QPainter *painter, painter->setWorldTransform(restoreTransform); } -/*! - \internal -*/ -class QGraphicsBloomEffectPrivate : public QGraphicsEffectPrivate -{ - Q_DECLARE_PUBLIC(QGraphicsBlurEffect) -public: - QGraphicsBloomEffectPrivate() - : blurRadius(6) - , opacity(0.7) { } - - int blurRadius; - qreal opacity; -}; - -QGraphicsBloomEffect::QGraphicsBloomEffect(QObject *parent) - : QGraphicsEffect(*new QGraphicsBloomEffectPrivate, parent) +QGraphicsBloomEffect::QGraphicsBloomEffect() + : QGraphicsEffect(*new QGraphicsBloomEffectPrivate) { } @@ -588,27 +495,8 @@ void QGraphicsBloomEffect::drawItem(QGraphicsItem *item, QPainter *painter, painter->setWorldTransform(restoreTransform); } -/*! - \internal -*/ -class QGraphicsFrameEffectPrivate : public QGraphicsEffectPrivate -{ - Q_DECLARE_PUBLIC(QGraphicsFrameEffect) -public: - QGraphicsFrameEffectPrivate() - : color(Qt::blue) - , width(5) - , alpha(0.6) - { - } - - QColor color; - qreal width; - qreal alpha; -}; - -QGraphicsFrameEffect::QGraphicsFrameEffect(QObject *parent) - : QGraphicsEffect(*new QGraphicsFrameEffectPrivate, parent) +QGraphicsFrameEffect::QGraphicsFrameEffect() + : QGraphicsEffect(*new QGraphicsFrameEffectPrivate) { } @@ -693,28 +581,8 @@ void QGraphicsFrameEffect::drawItem(QGraphicsItem *item, QPainter *painter, painter->restore(); } - -/*! - \internal -*/ -class QGraphicsShadowEffectPrivate : public QGraphicsEffectPrivate -{ - Q_DECLARE_PUBLIC(QGraphicsShadowEffect) -public: - QGraphicsShadowEffectPrivate() - : offset(4,4) - , radius(8) - , alpha(0.7) - { - } - - QPointF offset; - int radius; - qreal alpha; -}; - -QGraphicsShadowEffect::QGraphicsShadowEffect(QObject *parent) - : QGraphicsEffect(*new QGraphicsShadowEffectPrivate, parent) +QGraphicsShadowEffect::QGraphicsShadowEffect() + : QGraphicsEffect(*new QGraphicsShadowEffectPrivate) { } diff --git a/src/gui/graphicsview/qgraphicseffect.h b/src/gui/graphicsview/qgraphicseffect.h index 29d97a6..9f6e342 100644 --- a/src/gui/graphicsview/qgraphicseffect.h +++ b/src/gui/graphicsview/qgraphicseffect.h @@ -67,10 +67,8 @@ class QGraphicsEffectPrivate; class Q_GUI_EXPORT QGraphicsEffect : public QObject { Q_OBJECT - public: - - QGraphicsEffect(QObject *parent = 0); + QGraphicsEffect(); virtual ~QGraphicsEffect(); virtual QRectF boundingRectFor(const QGraphicsItem *item); @@ -80,11 +78,12 @@ public: QWidget *widget = 0) = 0; protected: - QGraphicsEffect(QGraphicsEffectPrivate &d, QObject* parent); + QGraphicsEffect(QGraphicsEffectPrivate &d); QPixmap* drawItemOnPixmap(QPainter *painter, QGraphicsItem *item, const QStyleOptionGraphicsItem *option, QWidget *widget, int flags); private: + friend class QGraphicsItem; Q_DECLARE_PRIVATE(QGraphicsEffect) Q_DISABLE_COPY(QGraphicsEffect) }; @@ -93,10 +92,8 @@ class QGraphicsGrayscaleEffectPrivate; class Q_GUI_EXPORT QGraphicsGrayscaleEffect: public QGraphicsEffect { Q_OBJECT - public: - - QGraphicsGrayscaleEffect(QObject *parent = 0); + QGraphicsGrayscaleEffect(); ~QGraphicsGrayscaleEffect(); void drawItem(QGraphicsItem *item, QPainter *painter, @@ -111,10 +108,8 @@ private: class QGraphicsColorizeEffectPrivate; class Q_GUI_EXPORT QGraphicsColorizeEffect: public QGraphicsEffect { Q_OBJECT - public: - - QGraphicsColorizeEffect(QObject *parent = 0); + QGraphicsColorizeEffect(); ~QGraphicsColorizeEffect(); QColor color() const; @@ -132,10 +127,8 @@ private: class QGraphicsPixelizeEffectPrivate; class Q_GUI_EXPORT QGraphicsPixelizeEffect: public QGraphicsEffect { Q_OBJECT - public: - - QGraphicsPixelizeEffect(QObject *parent = 0); + QGraphicsPixelizeEffect(); ~QGraphicsPixelizeEffect(); int pixelSize() const; @@ -153,10 +146,8 @@ private: class QGraphicsBlurEffectPrivate; class Q_GUI_EXPORT QGraphicsBlurEffect: public QGraphicsEffect { Q_OBJECT - public: - - QGraphicsBlurEffect(QObject *parent = 0); + QGraphicsBlurEffect(); ~QGraphicsBlurEffect(); int blurRadius() const; @@ -176,10 +167,8 @@ private: class QGraphicsBloomEffectPrivate; class Q_GUI_EXPORT QGraphicsBloomEffect: public QGraphicsEffect { Q_OBJECT - public: - - QGraphicsBloomEffect(QObject *parent = 0); + QGraphicsBloomEffect(); ~QGraphicsBloomEffect(); int blurRadius() const; @@ -202,10 +191,8 @@ private: class QGraphicsFrameEffectPrivate; class Q_GUI_EXPORT QGraphicsFrameEffect: public QGraphicsEffect { Q_OBJECT - public: - - QGraphicsFrameEffect(QObject *parent = 0); + QGraphicsFrameEffect(); ~QGraphicsFrameEffect(); QColor frameColor() const; @@ -230,10 +217,8 @@ private: class QGraphicsShadowEffectPrivate; class Q_GUI_EXPORT QGraphicsShadowEffect: public QGraphicsEffect { Q_OBJECT - public: - - QGraphicsShadowEffect(QObject *parent = 0); + QGraphicsShadowEffect(); ~QGraphicsShadowEffect(); QPointF shadowOffset() const; @@ -253,8 +238,6 @@ public: const QStyleOptionGraphicsItem *option = 0, QWidget *widget = 0); -protected: - private: Q_DECLARE_PRIVATE(QGraphicsShadowEffect) Q_DISABLE_COPY(QGraphicsShadowEffect) diff --git a/src/gui/graphicsview/qgraphicseffect_p.h b/src/gui/graphicsview/qgraphicseffect_p.h new file mode 100644 index 0000000..999e013 --- /dev/null +++ b/src/gui/graphicsview/qgraphicseffect_p.h @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGRAPHICSEFFECT_P_H +#define QGRAPHICSEFFECT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header +// file may change from version to version without notice, or even be removed. +// +// We mean it. +// + +#include "qgraphicseffect.h" +#include <private/qobject_p.h> +#include <private/qpixmapfilter_p.h> + +#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW + +QT_BEGIN_NAMESPACE + +class QGraphicsEffectPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QGraphicsEffect) +public: + QGraphicsEffectPrivate(): parentItem(0) {} + QGraphicsItem *parentItem; +}; + +class QGraphicsGrayscaleEffectPrivate : public QGraphicsEffectPrivate +{ + Q_DECLARE_PUBLIC(QGraphicsGrayscaleEffect) +public: + QGraphicsGrayscaleEffectPrivate() + { + filter = new QPixmapColorizeFilter; + filter->setColor(Qt::black); + } + ~QGraphicsGrayscaleEffectPrivate() { delete filter; } + + QPixmapColorizeFilter *filter; +}; + +class QGraphicsColorizeEffectPrivate : public QGraphicsEffectPrivate +{ + Q_DECLARE_PUBLIC(QGraphicsColorizeEffect) +public: + QGraphicsColorizeEffectPrivate() { filter = new QPixmapColorizeFilter; } + ~QGraphicsColorizeEffectPrivate() { delete filter; } + + QPixmapColorizeFilter *filter; +}; + +class QGraphicsPixelizeEffectPrivate : public QGraphicsEffectPrivate +{ + Q_DECLARE_PUBLIC(QGraphicsPixelizeEffect) +public: + QGraphicsPixelizeEffectPrivate() : pixelSize(3) {} + + int pixelSize; +}; + +class QGraphicsBlurEffectPrivate : public QGraphicsEffectPrivate +{ + Q_DECLARE_PUBLIC(QGraphicsBlurEffect) +public: + QGraphicsBlurEffectPrivate() : blurRadius(4) {} + + int blurRadius; +}; + +class QGraphicsBloomEffectPrivate : public QGraphicsEffectPrivate +{ + Q_DECLARE_PUBLIC(QGraphicsBlurEffect) +public: + QGraphicsBloomEffectPrivate() : blurRadius(6), opacity(0.7) {} + + int blurRadius; + qreal opacity; +}; + +class QGraphicsFrameEffectPrivate : public QGraphicsEffectPrivate +{ + Q_DECLARE_PUBLIC(QGraphicsFrameEffect) +public: + QGraphicsFrameEffectPrivate() : color(Qt::blue), width(5), alpha(0.6) {} + + QColor color; + qreal width; + qreal alpha; +}; + +class QGraphicsShadowEffectPrivate : public QGraphicsEffectPrivate +{ + Q_DECLARE_PUBLIC(QGraphicsShadowEffect) +public: + QGraphicsShadowEffectPrivate() : offset(4,4), radius(8), alpha(0.7) {} + + QPointF offset; + int radius; + qreal alpha; +}; + +QT_END_NAMESPACE + +#endif // QT_NO_GRAPHICSVIEW + +#endif // QGRAPHICSEFFECT_P_H diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index a044fbd..3a350e0 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -552,7 +552,7 @@ #ifndef QT_NO_GRAPHICSVIEW -#include "qgraphicseffect.h" +#include "qgraphicseffect_p.h" #include "qgraphicsscene.h" #include "qgraphicsscene_p.h" #include "qgraphicssceneevent.h" @@ -1180,6 +1180,8 @@ QGraphicsItem::~QGraphicsItem() else d_ptr->setParentItemHelper(0); + QGraphicsEffect *e = graphicsEffect(); + delete e; delete d_ptr->transformData; delete d_ptr; @@ -2190,11 +2192,11 @@ void QGraphicsItem::setOpacity(qreal opacity) } /*! + Returns a pointer to this item's effect if it has one; otherwise 0. + \since 4.6 - Returns this item's \e effect if it has one; otherwise, - returns 0. */ -QGraphicsEffect *QGraphicsItem::effect() const +QGraphicsEffect *QGraphicsItem::graphicsEffect() const { QGraphicsEffect *fx = 0; if (d_ptr->hasEffect) @@ -2204,22 +2206,41 @@ QGraphicsEffect *QGraphicsItem::effect() const } /*! + Sets \a effect as the item's effect. If there already is an effect installed + on this item, QGraphicsItem won't let you install another. You must first + delete the existing effect (returned by graphicsEffect()) before you can call + setGraphicsEffect() with the new effect. + + If \a effect is the installed on a different item, setGraphicsEffect() will remove + the effect from the item and install it on this item. + + \note This function will apply the effect on itself and all its children. + \since 4.6 - Sets \e effect as the item's effect. It will replace the previous effect - the item might have. */ -void QGraphicsItem::setEffect(QGraphicsEffect *effect) +void QGraphicsItem::setGraphicsEffect(QGraphicsEffect *effect) { if (effect) { - d_ptr->hasEffect = true; - d_ptr->setExtra(QGraphicsItemPrivate::ExtraEffect, QVariant::fromValue(effect)); + if (QGraphicsEffect *currentEffect = this->graphicsEffect()) { + if (currentEffect != effect) { + qWarning("QGraphicsItem::setEffect: Attempting to set QGraphicsEffect " + "%p on %p, which already has an effect", effect, this); + } + return; + } + + if (effect->d_func()->parentItem) + effect->d_func()->parentItem->setGraphicsEffect(0); + effect->d_func()->parentItem = this; + d_ptr->hasEffect = true; + d_ptr->setExtra(QGraphicsItemPrivate::ExtraEffect, QVariant::fromValue(effect)); } else { - d_ptr->hasEffect = false; - d_ptr->unsetExtra(QGraphicsItemPrivate::ExtraEffect); - void *ptr = d_ptr->extra(QGraphicsItemPrivate::ExtraEffectPixmap).value<void*>(); - QPixmap *pixmap = reinterpret_cast<QPixmap*>(ptr); - delete pixmap; - d_ptr->unsetExtra(QGraphicsItemPrivate::ExtraEffectPixmap); + d_ptr->hasEffect = false; + d_ptr->unsetExtra(QGraphicsItemPrivate::ExtraEffect); + void *ptr = d_ptr->extra(QGraphicsItemPrivate::ExtraEffectPixmap).value<void*>(); + QPixmap *pixmap = reinterpret_cast<QPixmap*>(ptr); + delete pixmap; + d_ptr->unsetExtra(QGraphicsItemPrivate::ExtraEffectPixmap); } update(); @@ -2236,7 +2257,7 @@ void QGraphicsItem::setEffect(QGraphicsEffect *effect) */ QRectF QGraphicsItem::effectiveBoundingRect() const { - QGraphicsEffect *fx = effect(); + QGraphicsEffect *fx = graphicsEffect(); if (fx) return fx->boundingRectFor(this); diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index c230928..0beb07c 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -208,8 +208,8 @@ public: void setOpacity(qreal opacity); // Effect - QGraphicsEffect *effect() const; - void setEffect(QGraphicsEffect *effect); + QGraphicsEffect *graphicsEffect() const; + void setGraphicsEffect(QGraphicsEffect *effect); QRectF effectiveBoundingRect() const; QRectF sceneEffectiveBoundingRect() const; diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 2807673..c56f34c 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -3928,8 +3928,8 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte #endif // Render using effect, works now only for no cache mode - if (noCache && itemd->hasEffect && item->effect()) { - item->effect()->drawItem(item, painter, option, widget); + if (noCache && itemd->hasEffect && item->graphicsEffect()) { + item->graphicsEffect()->drawItem(item, painter, option, widget); return; } |