|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef QGRAPHICSEFFECT_P_H |
|
43 #define QGRAPHICSEFFECT_P_H |
|
44 |
|
45 // |
|
46 // W A R N I N G |
|
47 // ------------- |
|
48 // |
|
49 // This file is not part of the Qt API. It exists for the convenience |
|
50 // of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header |
|
51 // file may change from version to version without notice, or even be removed. |
|
52 // |
|
53 // We mean it. |
|
54 // |
|
55 |
|
56 #include "qgraphicseffect.h" |
|
57 |
|
58 #include <QPixmapCache> |
|
59 |
|
60 #include <private/qobject_p.h> |
|
61 #include <private/qpixmapfilter_p.h> |
|
62 |
|
63 QT_BEGIN_NAMESPACE |
|
64 |
|
65 class QGraphicsEffectSourcePrivate : public QObjectPrivate |
|
66 { |
|
67 Q_DECLARE_PUBLIC(QGraphicsEffectSource) |
|
68 public: |
|
69 QGraphicsEffectSourcePrivate() : QObjectPrivate() {} |
|
70 virtual ~QGraphicsEffectSourcePrivate() { invalidateCache(); } |
|
71 virtual void detach() = 0; |
|
72 virtual QRectF boundingRect(Qt::CoordinateSystem system) const = 0; |
|
73 virtual QRect deviceRect() const = 0; |
|
74 virtual const QGraphicsItem *graphicsItem() const = 0; |
|
75 virtual const QWidget *widget() const = 0; |
|
76 virtual const QStyleOption *styleOption() const = 0; |
|
77 virtual void draw(QPainter *p) = 0; |
|
78 virtual void update() = 0; |
|
79 virtual bool isPixmap() const = 0; |
|
80 virtual QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset = 0) const = 0; |
|
81 virtual void effectBoundingRectChanged() = 0; |
|
82 void invalidateCache() const { QPixmapCache::remove(m_cacheKey); } |
|
83 |
|
84 friend class QGraphicsScenePrivate; |
|
85 friend class QGraphicsItem; |
|
86 friend class QGraphicsItemPrivate; |
|
87 |
|
88 private: |
|
89 mutable Qt::CoordinateSystem m_cachedSystem; |
|
90 mutable QPoint m_cachedOffset; |
|
91 mutable QPixmapCache::Key m_cacheKey; |
|
92 }; |
|
93 |
|
94 class Q_GUI_EXPORT QGraphicsEffectPrivate : public QObjectPrivate |
|
95 { |
|
96 Q_DECLARE_PUBLIC(QGraphicsEffect) |
|
97 public: |
|
98 QGraphicsEffectPrivate() : source(0), isEnabled(1) {} |
|
99 |
|
100 inline void setGraphicsEffectSource(QGraphicsEffectSource *newSource) |
|
101 { |
|
102 QGraphicsEffect::ChangeFlags flags; |
|
103 if (source) { |
|
104 flags |= QGraphicsEffect::SourceDetached; |
|
105 source->d_func()->detach(); |
|
106 source->d_func()->invalidateCache(); |
|
107 delete source; |
|
108 } |
|
109 source = newSource; |
|
110 if (newSource) |
|
111 flags |= QGraphicsEffect::SourceAttached; |
|
112 q_func()->sourceChanged(flags); |
|
113 } |
|
114 |
|
115 QGraphicsEffectSource *source; |
|
116 QRectF boundingRect; |
|
117 quint32 isEnabled : 1; |
|
118 quint32 padding : 31; // feel free to use |
|
119 }; |
|
120 |
|
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 |
|
138 class QGraphicsColorizeEffectPrivate : public QGraphicsEffectPrivate |
|
139 { |
|
140 Q_DECLARE_PUBLIC(QGraphicsColorizeEffect) |
|
141 public: |
|
142 QGraphicsColorizeEffectPrivate() |
|
143 : opaque(true) |
|
144 { |
|
145 filter = new QPixmapColorizeFilter; |
|
146 } |
|
147 ~QGraphicsColorizeEffectPrivate() { delete filter; } |
|
148 |
|
149 QPixmapColorizeFilter *filter; |
|
150 quint32 opaque : 1; |
|
151 quint32 padding : 31; |
|
152 }; |
|
153 |
|
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 |
|
164 { |
|
165 Q_DECLARE_PUBLIC(QGraphicsBlurEffect) |
|
166 public: |
|
167 QGraphicsBlurEffectPrivate() : filter(new QPixmapBlurFilter) {} |
|
168 ~QGraphicsBlurEffectPrivate() { delete filter; } |
|
169 |
|
170 QPixmapBlurFilter *filter; |
|
171 }; |
|
172 |
|
173 class QGraphicsDropShadowEffectPrivate : public QGraphicsEffectPrivate |
|
174 { |
|
175 Q_DECLARE_PUBLIC(QGraphicsDropShadowEffect) |
|
176 public: |
|
177 QGraphicsDropShadowEffectPrivate() : filter(new QPixmapDropShadowFilter) {} |
|
178 ~QGraphicsDropShadowEffectPrivate() { delete filter; } |
|
179 |
|
180 QPixmapDropShadowFilter *filter; |
|
181 }; |
|
182 |
|
183 class QGraphicsOpacityEffectPrivate : public QGraphicsEffectPrivate |
|
184 { |
|
185 Q_DECLARE_PUBLIC(QGraphicsOpacityEffect) |
|
186 public: |
|
187 QGraphicsOpacityEffectPrivate() |
|
188 : opacity(qreal(0.7)), isFullyTransparent(0), isFullyOpaque(0), hasOpacityMask(0) {} |
|
189 ~QGraphicsOpacityEffectPrivate() {} |
|
190 |
|
191 qreal opacity; |
|
192 QBrush opacityMask; |
|
193 uint isFullyTransparent : 1; |
|
194 uint isFullyOpaque : 1; |
|
195 uint hasOpacityMask : 1; |
|
196 }; |
|
197 |
|
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 |
|
211 |
|
212 #endif // QGRAPHICSEFFECT_P_H |
|
213 |