src/gui/effects/qgraphicseffect_p.h
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    58 #include <QPixmapCache>
    58 #include <QPixmapCache>
    59 
    59 
    60 #include <private/qobject_p.h>
    60 #include <private/qobject_p.h>
    61 #include <private/qpixmapfilter_p.h>
    61 #include <private/qpixmapfilter_p.h>
    62 
    62 
       
    63 #ifndef QT_NO_GRAPHICSEFFECT
    63 QT_BEGIN_NAMESPACE
    64 QT_BEGIN_NAMESPACE
    64 
    65 
       
    66 class QGraphicsEffectSourcePrivate;
       
    67 class Q_GUI_EXPORT QGraphicsEffectSource : public QObject
       
    68 {
       
    69     Q_OBJECT
       
    70 public:
       
    71     ~QGraphicsEffectSource();
       
    72     const QGraphicsItem *graphicsItem() const;
       
    73     const QWidget *widget() const;
       
    74     const QStyleOption *styleOption() const;
       
    75 
       
    76     bool isPixmap() const;
       
    77     void draw(QPainter *painter);
       
    78     void update();
       
    79 
       
    80     QRectF boundingRect(Qt::CoordinateSystem coordinateSystem = Qt::LogicalCoordinates) const;
       
    81     QRect deviceRect() const;
       
    82     QPixmap pixmap(Qt::CoordinateSystem system = Qt::LogicalCoordinates,
       
    83                    QPoint *offset = 0,
       
    84                    QGraphicsEffect::PixmapPadMode mode = QGraphicsEffect::PadToEffectiveBoundingRect) const;
       
    85 
       
    86 protected:
       
    87     QGraphicsEffectSource(QGraphicsEffectSourcePrivate &dd, QObject *parent = 0);
       
    88 
       
    89 private:
       
    90     Q_DECLARE_PRIVATE(QGraphicsEffectSource)
       
    91     Q_DISABLE_COPY(QGraphicsEffectSource)
       
    92     friend class QGraphicsEffect;
       
    93     friend class QGraphicsEffectPrivate;
       
    94     friend class QGraphicsScenePrivate;
       
    95     friend class QGraphicsItem;
       
    96     friend class QGraphicsItemPrivate;
       
    97     friend class QWidget;
       
    98     friend class QWidgetPrivate;
       
    99 };
       
   100 
    65 class QGraphicsEffectSourcePrivate : public QObjectPrivate
   101 class QGraphicsEffectSourcePrivate : public QObjectPrivate
    66 {
   102 {
    67     Q_DECLARE_PUBLIC(QGraphicsEffectSource)
   103     Q_DECLARE_PUBLIC(QGraphicsEffectSource)
    68 public:
   104 public:
    69     QGraphicsEffectSourcePrivate() : QObjectPrivate() {}
   105     QGraphicsEffectSourcePrivate()
    70     virtual ~QGraphicsEffectSourcePrivate() { invalidateCache(); }
   106         : QObjectPrivate()
       
   107         , m_cachedSystem(Qt::DeviceCoordinates)
       
   108         , m_cachedMode(QGraphicsEffect::PadToTransparentBorder)
       
   109     {}
       
   110 
       
   111     enum InvalidateReason
       
   112     {
       
   113         TransformChanged,
       
   114         EffectRectChanged,
       
   115         SourceChanged
       
   116     };
       
   117 
       
   118     virtual ~QGraphicsEffectSourcePrivate();
    71     virtual void detach() = 0;
   119     virtual void detach() = 0;
    72     virtual QRectF boundingRect(Qt::CoordinateSystem system) const = 0;
   120     virtual QRectF boundingRect(Qt::CoordinateSystem system) const = 0;
    73     virtual QRect deviceRect() const = 0;
   121     virtual QRect deviceRect() const = 0;
    74     virtual const QGraphicsItem *graphicsItem() const = 0;
   122     virtual const QGraphicsItem *graphicsItem() const = 0;
    75     virtual const QWidget *widget() const = 0;
   123     virtual const QWidget *widget() const = 0;
    76     virtual const QStyleOption *styleOption() const = 0;
   124     virtual const QStyleOption *styleOption() const = 0;
    77     virtual void draw(QPainter *p) = 0;
   125     virtual void draw(QPainter *p) = 0;
    78     virtual void update() = 0;
   126     virtual void update() = 0;
    79     virtual bool isPixmap() const = 0;
   127     virtual bool isPixmap() const = 0;
    80     virtual QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset = 0) const = 0;
   128     virtual QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset = 0,
       
   129                            QGraphicsEffect::PixmapPadMode mode = QGraphicsEffect::PadToTransparentBorder) const = 0;
    81     virtual void effectBoundingRectChanged() = 0;
   130     virtual void effectBoundingRectChanged() = 0;
    82     void invalidateCache() const { QPixmapCache::remove(m_cacheKey); }
   131 
       
   132     void invalidateCache(InvalidateReason reason = SourceChanged) const;
       
   133     Qt::CoordinateSystem currentCachedSystem() const { return m_cachedSystem; }
    83 
   134 
    84     friend class QGraphicsScenePrivate;
   135     friend class QGraphicsScenePrivate;
    85     friend class QGraphicsItem;
   136     friend class QGraphicsItem;
    86     friend class QGraphicsItemPrivate;
   137     friend class QGraphicsItemPrivate;
    87 
   138 
    88 private:
   139 private:
    89     mutable Qt::CoordinateSystem m_cachedSystem;
   140     mutable Qt::CoordinateSystem m_cachedSystem;
       
   141     mutable QGraphicsEffect::PixmapPadMode m_cachedMode;
    90     mutable QPoint m_cachedOffset;
   142     mutable QPoint m_cachedOffset;
    91     mutable QPixmapCache::Key m_cacheKey;
   143     mutable QPixmapCache::Key m_cacheKey;
    92 };
   144 };
    93 
   145 
    94 class Q_GUI_EXPORT QGraphicsEffectPrivate : public QObjectPrivate
   146 class Q_GUI_EXPORT QGraphicsEffectPrivate : public QObjectPrivate
   100     inline void setGraphicsEffectSource(QGraphicsEffectSource *newSource)
   152     inline void setGraphicsEffectSource(QGraphicsEffectSource *newSource)
   101     {
   153     {
   102         QGraphicsEffect::ChangeFlags flags;
   154         QGraphicsEffect::ChangeFlags flags;
   103         if (source) {
   155         if (source) {
   104             flags |= QGraphicsEffect::SourceDetached;
   156             flags |= QGraphicsEffect::SourceDetached;
       
   157             source->d_func()->invalidateCache();
   105             source->d_func()->detach();
   158             source->d_func()->detach();
   106             source->d_func()->invalidateCache();
       
   107             delete source;
   159             delete source;
   108         }
   160         }
   109         source = newSource;
   161         source = newSource;
   110         if (newSource)
   162         if (newSource)
   111             flags |= QGraphicsEffect::SourceAttached;
   163             flags |= QGraphicsEffect::SourceAttached;
   116     QRectF boundingRect;
   168     QRectF boundingRect;
   117     quint32 isEnabled : 1;
   169     quint32 isEnabled : 1;
   118     quint32 padding : 31; // feel free to use
   170     quint32 padding : 31; // feel free to use
   119 };
   171 };
   120 
   172 
   121 class QGraphicsGrayscaleEffectPrivate : public QGraphicsEffectPrivate
       
   122 {
       
   123     Q_DECLARE_PUBLIC(QGraphicsGrayscaleEffect)
       
   124 public:
       
   125     QGraphicsGrayscaleEffectPrivate()
       
   126         : opaque(true)
       
   127     {
       
   128         filter = new QPixmapColorizeFilter;
       
   129         filter->setColor(Qt::black);
       
   130     }
       
   131     ~QGraphicsGrayscaleEffectPrivate() { delete filter; }
       
   132 
       
   133     QPixmapColorizeFilter *filter;
       
   134     quint32 opaque : 1;
       
   135     quint32 padding : 31;
       
   136 };
       
   137 
   173 
   138 class QGraphicsColorizeEffectPrivate : public QGraphicsEffectPrivate
   174 class QGraphicsColorizeEffectPrivate : public QGraphicsEffectPrivate
   139 {
   175 {
   140     Q_DECLARE_PUBLIC(QGraphicsColorizeEffect)
   176     Q_DECLARE_PUBLIC(QGraphicsColorizeEffect)
   141 public:
   177 public:
   149     QPixmapColorizeFilter *filter;
   185     QPixmapColorizeFilter *filter;
   150     quint32 opaque : 1;
   186     quint32 opaque : 1;
   151     quint32 padding : 31;
   187     quint32 padding : 31;
   152 };
   188 };
   153 
   189 
   154 class QGraphicsPixelizeEffectPrivate : public QGraphicsEffectPrivate
       
   155 {
       
   156     Q_DECLARE_PUBLIC(QGraphicsPixelizeEffect)
       
   157 public:
       
   158     QGraphicsPixelizeEffectPrivate() : pixelSize(3) {}
       
   159 
       
   160     int pixelSize;
       
   161 };
       
   162 
       
   163 class QGraphicsBlurEffectPrivate : public QGraphicsEffectPrivate
   190 class QGraphicsBlurEffectPrivate : public QGraphicsEffectPrivate
   164 {
   191 {
   165     Q_DECLARE_PUBLIC(QGraphicsBlurEffect)
   192     Q_DECLARE_PUBLIC(QGraphicsBlurEffect)
   166 public:
   193 public:
   167     QGraphicsBlurEffectPrivate() : filter(new QPixmapBlurFilter) {}
   194     QGraphicsBlurEffectPrivate() : filter(new QPixmapBlurFilter) {}
   193     uint isFullyTransparent : 1;
   220     uint isFullyTransparent : 1;
   194     uint isFullyOpaque : 1;
   221     uint isFullyOpaque : 1;
   195     uint hasOpacityMask : 1;
   222     uint hasOpacityMask : 1;
   196 };
   223 };
   197 
   224 
   198 class QGraphicsBloomEffectPrivate : public QGraphicsEffectPrivate
       
   199 {
       
   200     Q_DECLARE_PUBLIC(QGraphicsBlurEffect)
       
   201 public:
       
   202     QGraphicsBloomEffectPrivate() : brightness(70), strength(qreal(0.7)) {}
       
   203 
       
   204     QPixmapBlurFilter blurFilter;
       
   205     int colorTable[256];
       
   206     int brightness;
       
   207     qreal strength;
       
   208 };
       
   209 
       
   210 QT_END_NAMESPACE
   225 QT_END_NAMESPACE
   211 
   226 
       
   227 #endif //QT_NO_GRAPHICSEFFECT
   212 #endif // QGRAPHICSEFFECT_P_H
   228 #endif // QGRAPHICSEFFECT_P_H
   213 
   229