QtGui/qgraphicseffect.h Source File

qgraphicseffect.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QGRAPHICSEFFECT_H
43 #define QGRAPHICSEFFECT_H
44 
45 #include <QtCore/qobject.h>
46 #include <QtCore/qpoint.h>
47 #include <QtCore/qrect.h>
48 #include <QtGui/qcolor.h>
49 #include <QtGui/qbrush.h>
50 
51 #ifndef QT_NO_GRAPHICSEFFECT
53 
55 
56 QT_MODULE(Gui)
57 
58 class QGraphicsItem;
59 class QStyleOption;
60 class QPainter;
61 class QPixmap;
62 
63 class QGraphicsEffectSource;
64 
65 class QGraphicsEffectPrivate;
66 class Q_GUI_EXPORT QGraphicsEffect : public QObject
67 {
68  Q_OBJECT
69  Q_FLAGS(ChangeFlags)
70  Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
71 public:
72  enum ChangeFlag {
73  SourceAttached = 0x1,
74  SourceDetached = 0x2,
75  SourceBoundingRectChanged = 0x4,
76  SourceInvalidated = 0x8
77  };
78  Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)
79 
83  PadToEffectiveBoundingRect
84  };
85 
86  QGraphicsEffect(QObject *parent = 0);
87  virtual ~QGraphicsEffect();
88 
89  virtual QRectF boundingRectFor(const QRectF &sourceRect) const;
90  QRectF boundingRect() const;
91 
92  bool isEnabled() const;
93 
94 public Q_SLOTS:
95  void setEnabled(bool enable);
96  void update();
97 
98 Q_SIGNALS:
99  void enabledChanged(bool enabled);
100 
101 protected:
102  QGraphicsEffect(QGraphicsEffectPrivate &d, QObject *parent = 0);
103  virtual void draw(QPainter *painter) = 0;
104  virtual void sourceChanged(ChangeFlags flags);
105  void updateBoundingRect();
106 
107  bool sourceIsPixmap() const;
108  QRectF sourceBoundingRect(Qt::CoordinateSystem system = Qt::LogicalCoordinates) const;
109  void drawSource(QPainter *painter);
111  QPoint *offset = 0,
112  PixmapPadMode mode = PadToEffectiveBoundingRect) const;
113 
114 private:
115  Q_DECLARE_PRIVATE(QGraphicsEffect)
116  Q_DISABLE_COPY(QGraphicsEffect)
117  friend class QGraphicsItem;
118  friend class QGraphicsItemPrivate;
119  friend class QGraphicsScenePrivate;
120  friend class QWidget;
121  friend class QWidgetPrivate;
122 
123 public:
124  QGraphicsEffectSource *source() const; // internal
125 
126 };
127 Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsEffect::ChangeFlags)
128 
129 class QGraphicsColorizeEffectPrivate;
130 class Q_GUI_EXPORT QGraphicsColorizeEffect: public QGraphicsEffect
131 {
132  Q_OBJECT
133  Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
134  Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged)
135 public:
136  QGraphicsColorizeEffect(QObject *parent = 0);
138 
139  QColor color() const;
140  qreal strength() const;
141 
142 public Q_SLOTS:
143  void setColor(const QColor &c);
144  void setStrength(qreal strength);
145 
146 Q_SIGNALS:
147  void colorChanged(const QColor &color);
148  void strengthChanged(qreal strength);
149 
150 protected:
151  void draw(QPainter *painter);
152 
153 private:
154  Q_DECLARE_PRIVATE(QGraphicsColorizeEffect)
155  Q_DISABLE_COPY(QGraphicsColorizeEffect)
156 };
157 
158 class QGraphicsBlurEffectPrivate;
159 class Q_GUI_EXPORT QGraphicsBlurEffect: public QGraphicsEffect
160 {
161  Q_OBJECT
162  Q_FLAGS(BlurHint BlurHints)
163  Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged)
164  Q_PROPERTY(BlurHints blurHints READ blurHints WRITE setBlurHints NOTIFY blurHintsChanged)
165 public:
166  enum BlurHint {
167  PerformanceHint = 0x00,
168  QualityHint = 0x01,
169  AnimationHint = 0x02
170  };
171  Q_DECLARE_FLAGS(BlurHints, BlurHint)
172 
173  QGraphicsBlurEffect(QObject *parent = 0);
175 
176  QRectF boundingRectFor(const QRectF &rect) const;
177  qreal blurRadius() const;
178  BlurHints blurHints() const;
179 
180 public Q_SLOTS:
181  void setBlurRadius(qreal blurRadius);
182  void setBlurHints(BlurHints hints);
183 
184 Q_SIGNALS:
185  void blurRadiusChanged(qreal blurRadius);
186  void blurHintsChanged(BlurHints hints);
187 
188 protected:
189  void draw(QPainter *painter);
190 
191 private:
192  Q_DECLARE_PRIVATE(QGraphicsBlurEffect)
193  Q_DISABLE_COPY(QGraphicsBlurEffect)
194 };
195 
196 Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsBlurEffect::BlurHints)
197 
198 class QGraphicsDropShadowEffectPrivate;
199 class Q_GUI_EXPORT QGraphicsDropShadowEffect: public QGraphicsEffect
200 {
201  Q_OBJECT
202  Q_PROPERTY(QPointF offset READ offset WRITE setOffset NOTIFY offsetChanged)
203  Q_PROPERTY(qreal xOffset READ xOffset WRITE setXOffset NOTIFY offsetChanged)
204  Q_PROPERTY(qreal yOffset READ yOffset WRITE setYOffset NOTIFY offsetChanged)
205  Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged)
206  Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
207 public:
208  QGraphicsDropShadowEffect(QObject *parent = 0);
210 
211  QRectF boundingRectFor(const QRectF &rect) const;
212  QPointF offset() const;
213 
214  inline qreal xOffset() const
215  { return offset().x(); }
216 
217  inline qreal yOffset() const
218  { return offset().y(); }
219 
220  qreal blurRadius() const;
221  QColor color() const;
222 
223 public Q_SLOTS:
224  void setOffset(const QPointF &ofs);
225 
226  inline void setOffset(qreal dx, qreal dy)
227  { setOffset(QPointF(dx, dy)); }
228 
229  inline void setOffset(qreal d)
230  { setOffset(QPointF(d, d)); }
231 
232  inline void setXOffset(qreal dx)
233  { setOffset(QPointF(dx, yOffset())); }
234 
235  inline void setYOffset(qreal dy)
236  { setOffset(QPointF(xOffset(), dy)); }
237 
238  void setBlurRadius(qreal blurRadius);
239  void setColor(const QColor &color);
240 
241 Q_SIGNALS:
242  void offsetChanged(const QPointF &offset);
243  void blurRadiusChanged(qreal blurRadius);
244  void colorChanged(const QColor &color);
245 
246 protected:
247  void draw(QPainter *painter);
248 
249 private:
250  Q_DECLARE_PRIVATE(QGraphicsDropShadowEffect)
251  Q_DISABLE_COPY(QGraphicsDropShadowEffect)
252 };
253 
254 class QGraphicsOpacityEffectPrivate;
255 class Q_GUI_EXPORT QGraphicsOpacityEffect: public QGraphicsEffect
256 {
257  Q_OBJECT
258  Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)
259  Q_PROPERTY(QBrush opacityMask READ opacityMask WRITE setOpacityMask NOTIFY opacityMaskChanged)
260 public:
261  QGraphicsOpacityEffect(QObject *parent = 0);
263 
264  qreal opacity() const;
265  QBrush opacityMask() const;
266 
267 public Q_SLOTS:
268  void setOpacity(qreal opacity);
269  void setOpacityMask(const QBrush &mask);
270 
271 Q_SIGNALS:
272  void opacityChanged(qreal opacity);
273  void opacityMaskChanged(const QBrush &mask);
274 
275 protected:
276  void draw(QPainter *painter);
277 
278 private:
279  Q_DECLARE_PRIVATE(QGraphicsOpacityEffect)
280  Q_DISABLE_COPY(QGraphicsOpacityEffect)
281 };
282 
284 
286 #endif //QT_NO_GRAPHICSEFFECT
287 
288 #endif // QGRAPHICSEFFECT_H
289 
GLsizei GLsizei GLchar * source
Definition: GLee.h:1721
GLint mode
Definition: GLee.h:4479
int int int int * dy
Definition: GLee.h:10535
#define QT_END_NAMESPACE
Definition: qglobal.h:128
GLintptr offset
Definition: GLee.h:1562
#define Q_PROPERTY(text)
Definition: qobjectdefs.h:80
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
Definition: qcolor.h:67
#define Q_SLOTS
Definition: qobjectdefs.h:71
#define inline
Definition: image.h:2490
#define Q_SIGNALS
Definition: qobjectdefs.h:72
void setOffset(qreal dx, qreal dy)
Definition: qpoint.h:53
CoordinateSystem
Definition: qnamespace.h:1733
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
#define Q_OBJECT
Definition: qobjectdefs.h:157
GLXDrawable draw
Definition: GLee.h:10241
Definition: qrect.h:511
const GLubyte * c
Definition: GLee.h:5419
int int int * dx
Definition: GLee.h:10535
Definition: qbrush.h:76
#define Q_FLAGS(x)
Definition: qobjectdefs.h:85
GLenum GLint GLuint mask
Definition: GLee.h:1701
#define QT_END_HEADER
Definition: qglobal.h:142
GLuint color
Definition: GLee.h:8456