QtBase  v6.3.1
qgraphicseffect.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets 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 The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QGRAPHICSEFFECT_H
41 #define QGRAPHICSEFFECT_H
42 
43 #include <QtWidgets/qtwidgetsglobal.h>
44 #include <QtCore/qobject.h>
45 #include <QtCore/qpoint.h>
46 #include <QtCore/qrect.h>
47 #include <QtGui/qcolor.h>
48 #include <QtGui/qbrush.h>
49 
50 QT_REQUIRE_CONFIG(graphicseffect);
51 
53 
54 class QGraphicsItem;
55 class QStyleOption;
56 class QPainter;
57 class QPixmap;
58 
60 
62 class Q_WIDGETS_EXPORT QGraphicsEffect : public QObject
63 {
64  Q_OBJECT
65  Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
66 public:
67  enum ChangeFlag {
68  SourceAttached = 0x1,
69  SourceDetached = 0x2,
70  SourceBoundingRectChanged = 0x4,
71  SourceInvalidated = 0x8
72  };
73  Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)
74  Q_FLAG(ChangeFlags)
75 
79  PadToEffectiveBoundingRect
80  };
81 
82  QGraphicsEffect(QObject *parent = nullptr);
83  virtual ~QGraphicsEffect();
84 
85  virtual QRectF boundingRectFor(const QRectF &sourceRect) const;
86  QRectF boundingRect() const;
87 
88  bool isEnabled() const;
89 
90 public Q_SLOTS:
91  void setEnabled(bool enable);
92  void update();
93 
94 Q_SIGNALS:
95  void enabledChanged(bool enabled);
96 
97 protected:
99  virtual void draw(QPainter *painter) = 0;
100  virtual void sourceChanged(ChangeFlags flags);
101  void updateBoundingRect();
102 
103  bool sourceIsPixmap() const;
104  QRectF sourceBoundingRect(Qt::CoordinateSystem system = Qt::LogicalCoordinates) const;
105  void drawSource(QPainter *painter);
107  QPoint *offset = nullptr,
108  PixmapPadMode mode = PadToEffectiveBoundingRect) const;
109 
110 private:
111  Q_DECLARE_PRIVATE(QGraphicsEffect)
113  friend class QGraphicsItem;
114  friend class QGraphicsItemPrivate;
115  friend class QGraphicsScenePrivate;
116  friend class QWidget;
117  friend class QWidgetPrivate;
118 
119 public:
121 
122 };
124 
126 class Q_WIDGETS_EXPORT QGraphicsColorizeEffect: public QGraphicsEffect
127 {
128  Q_OBJECT
129  Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
130  Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged)
131 public:
134 
135  QColor color() const;
136  qreal strength() const;
137 
138 public Q_SLOTS:
139  void setColor(const QColor &c);
140  void setStrength(qreal strength);
141 
142 Q_SIGNALS:
143  void colorChanged(const QColor &color);
144  void strengthChanged(qreal strength);
145 
146 protected:
147  void draw(QPainter *painter) override;
148 
149 private:
150  Q_DECLARE_PRIVATE(QGraphicsColorizeEffect)
152 };
153 
155 class Q_WIDGETS_EXPORT QGraphicsBlurEffect: public QGraphicsEffect
156 {
157  Q_OBJECT
158  Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged)
159  Q_PROPERTY(BlurHints blurHints READ blurHints WRITE setBlurHints NOTIFY blurHintsChanged)
160 public:
161  enum BlurHint {
162  PerformanceHint = 0x00,
163  QualityHint = 0x01,
164  AnimationHint = 0x02
165  };
166  Q_ENUM(BlurHint)
167  Q_DECLARE_FLAGS(BlurHints, BlurHint)
168  Q_FLAG(BlurHints)
169 
170  QGraphicsBlurEffect(QObject *parent = nullptr);
172 
173  QRectF boundingRectFor(const QRectF &rect) const override;
174  qreal blurRadius() const;
175  BlurHints blurHints() const;
176 
177 public Q_SLOTS:
178  void setBlurRadius(qreal blurRadius);
179  void setBlurHints(BlurHints hints);
180 
181 Q_SIGNALS:
182  void blurRadiusChanged(qreal blurRadius);
183  void blurHintsChanged(BlurHints hints);
184 
185 protected:
186  void draw(QPainter *painter) override;
187 
188 private:
189  Q_DECLARE_PRIVATE(QGraphicsBlurEffect)
191 };
192 
193 Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsBlurEffect::BlurHints)
194 
196 class Q_WIDGETS_EXPORT QGraphicsDropShadowEffect: public QGraphicsEffect
197 {
198  Q_OBJECT
199  Q_PROPERTY(QPointF offset READ offset WRITE setOffset NOTIFY offsetChanged)
200  Q_PROPERTY(qreal xOffset READ xOffset WRITE setXOffset NOTIFY offsetChanged)
201  Q_PROPERTY(qreal yOffset READ yOffset WRITE setYOffset NOTIFY offsetChanged)
202  Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged)
203  Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
204 public:
207 
208  QRectF boundingRectFor(const QRectF &rect) const override;
209  QPointF offset() const;
210 
211  inline qreal xOffset() const
212  { return offset().x(); }
213 
214  inline qreal yOffset() const
215  { return offset().y(); }
216 
217  qreal blurRadius() const;
218  QColor color() const;
219 
220 public Q_SLOTS:
221  void setOffset(const QPointF &ofs);
222 
223  inline void setOffset(qreal dx, qreal dy)
224  { setOffset(QPointF(dx, dy)); }
225 
226  inline void setOffset(qreal d)
227  { setOffset(QPointF(d, d)); }
228 
229  inline void setXOffset(qreal dx)
230  { setOffset(QPointF(dx, yOffset())); }
231 
232  inline void setYOffset(qreal dy)
233  { setOffset(QPointF(xOffset(), dy)); }
234 
235  void setBlurRadius(qreal blurRadius);
236  void setColor(const QColor &color);
237 
238 Q_SIGNALS:
240  void blurRadiusChanged(qreal blurRadius);
241  void colorChanged(const QColor &color);
242 
243 protected:
244  void draw(QPainter *painter) override;
245 
246 private:
247  Q_DECLARE_PRIVATE(QGraphicsDropShadowEffect)
249 };
250 
252 class Q_WIDGETS_EXPORT QGraphicsOpacityEffect: public QGraphicsEffect
253 {
254  Q_OBJECT
255  Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)
256  Q_PROPERTY(QBrush opacityMask READ opacityMask WRITE setOpacityMask NOTIFY opacityMaskChanged)
257 public:
260 
261  qreal opacity() const;
262  QBrush opacityMask() const;
263 
264 public Q_SLOTS:
265  void setOpacity(qreal opacity);
266  void setOpacityMask(const QBrush &mask);
267 
268 Q_SIGNALS:
269  void opacityChanged(qreal opacity);
271 
272 protected:
273  void draw(QPainter *painter) override;
274 
275 private:
276  Q_DECLARE_PRIVATE(QGraphicsOpacityEffect)
278 };
279 
281 
282 #endif // QGRAPHICSEFFECT_H
283 
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:66
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
The QGraphicsBlurEffect class provides a blur effect.
void blurHintsChanged(BlurHints hints)
void blurRadiusChanged(qreal blurRadius)
The QGraphicsColorizeEffect class provides a colorize effect.
void strengthChanged(qreal strength)
void colorChanged(const QColor &color)
The QGraphicsDropShadowEffect class provides a drop shadow effect.
void colorChanged(const QColor &color)
void blurRadiusChanged(qreal blurRadius)
void offsetChanged(const QPointF &offset)
void setOffset(qreal dx, qreal dy)
The QGraphicsEffect class is the base class for all graphics effects.
void enabledChanged(bool enabled)
virtual void draw(QPainter *painter)=0
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:83
The QGraphicsOpacityEffect class provides an opacity effect.
void opacityMaskChanged(const QBrush &mask)
void opacityChanged(qreal opacity)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:82
The QPixmap class is an off-screen image representation that can be used as a paint device.
Definition: qpixmap.h:63
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:52
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:75
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
void colorChanged()
rect
[4]
auto it unsigned count const
Definition: hb-iter.hh:848
CoordinateSystem
Definition: qnamespace.h:1615
@ LogicalCoordinates
Definition: qnamespace.h:1617
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition: qflags.h:210
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition: qflags.h:227
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
#define Q_DISABLE_COPY(Class)
Definition: qglobal.h:515
QT_REQUIRE_CONFIG(graphicseffect)
GLenum mode
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLuint color
[2]
GLbitfield flags
GLboolean enable
GLenum GLuint GLintptr offset
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLsizei GLsizei GLchar * source
const GLubyte * c
Definition: qopenglext.h:12701
#define Q_ENUM(x)
Definition: qtmetamacros.h:104
#define Q_PROPERTY(...)
Definition: qtmetamacros.h:92
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define Q_FLAG(x)
Definition: qtmetamacros.h:105
#define Q_SLOTS
Definition: qtmetamacros.h:80
#define Q_SIGNALS
Definition: qtmetamacros.h:81
effect setOpacityMask(alphaGradient)
myFilter setColor(QColor(128, 0, 0))
myFilter draw(painter, QPoint(0, 0), originalPixmap)
QPainter painter(this)
[7]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent