Qt 4.8
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 
64 
67 {
68  Q_OBJECT
69  Q_FLAGS(ChangeFlags)
70  bool enabled;
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:
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:
120  friend class QWidget;
122 
123 public:
124  QGraphicsEffectSource *source() const; // internal
125 
126 };
128 
131 {
132  Q_OBJECT
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:
156 };
157 
160 {
161  Q_OBJECT
162  Q_FLAGS(BlurHint BlurHints)
163  qreal blurRadius;
164  BlurHints blurHints;
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:
194 };
195 
196 Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsBlurEffect::BlurHints)
197 
200 {
201  Q_OBJECT
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:
252 };
253 
256 {
257  Q_OBJECT
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:
281 };
282 
284 
286 #endif //QT_NO_GRAPHICSEFFECT
287 
288 #endif // QGRAPHICSEFFECT_H
289 
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
CoordinateSystem
Definition: qnamespace.h:1733
ChangeFlag
This enum describes what has changed in QGraphicsEffectSource.
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QGraphicsEffectSource class represents the source on which a QGraphicsEffect is installed on...
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
The QGraphicsDropShadowEffect class provides a drop shadow effect.
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
The QGraphicsBlurEffect class provides a blur effect.
#define Q_SIGNALS
Definition: qobjectdefs.h:72
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
static const QRectF boundingRect(const QPointF *points, int pointCount)
QColor color
the color of the drop shadow.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
qreal strength
the strength of the effect.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void setOffset(qreal dx, qreal dy)
The QGraphicsColorizeEffect class provides a colorize effect.
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
qreal xOffset
the horizontal shadow offset in pixels.
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
QColor color
the color of the effect.
PixmapPadMode
This enum describes how the pixmap returned from sourcePixmap should be padded.
QPointF offset
the shadow offset in pixels.
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QGraphicsOpacityEffect class provides an opacity effect.
qreal blurRadius
the blur radius in pixels of the drop shadow.
qreal yOffset
the vertical shadow offset in pixels.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
virtual QRectF boundingRectFor(const QRectF &sourceRect) const
Returns the effective bounding rectangle for this effect, given the provided rect in the device coord...
BlurHint
This enum describes the possible hints that can be used to control how blur effects are applied...
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
#define Q_FLAGS(x)
Definition: qobjectdefs.h:85
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
qreal opacity
the opacity of the effect.
#define class
#define QT_END_HEADER
Definition: qglobal.h:137
#define enabled
QBrush opacityMask
the opacity mask of the effect.
virtual void draw(QPainter *painter)=0
This pure virtual function draws the effect and is called whenever the source needs to be drawn...
The QGraphicsEffect class is the base class for all graphics effects.