Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qgraphicseffect.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QGRAPHICSEFFECT_H
5#define QGRAPHICSEFFECT_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtCore/qobject.h>
9#include <QtCore/qpoint.h>
10#include <QtCore/qrect.h>
11#include <QtGui/qcolor.h>
12#include <QtGui/qbrush.h>
13
14QT_REQUIRE_CONFIG(graphicseffect);
15
17
18class QGraphicsItem;
19class QStyleOption;
20class QPainter;
21class QPixmap;
22
24
26class Q_WIDGETS_EXPORT QGraphicsEffect : public QObject
27{
29 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
30public:
32 SourceAttached = 0x1,
33 SourceDetached = 0x2,
34 SourceBoundingRectChanged = 0x4,
35 SourceInvalidated = 0x8
36 };
37 Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)
38 Q_FLAG(ChangeFlags)
39
43 PadToEffectiveBoundingRect
44 };
45
46 QGraphicsEffect(QObject *parent = nullptr);
47 virtual ~QGraphicsEffect();
48
49 virtual QRectF boundingRectFor(const QRectF &sourceRect) const;
50 QRectF boundingRect() const;
51
52 bool isEnabled() const;
53
54public Q_SLOTS:
55 void setEnabled(bool enable);
56 void update();
57
60
61protected:
63 virtual void draw(QPainter *painter) = 0;
64 virtual void sourceChanged(ChangeFlags flags);
65 void updateBoundingRect();
66
67 bool sourceIsPixmap() const;
68 QRectF sourceBoundingRect(Qt::CoordinateSystem system = Qt::LogicalCoordinates) const;
69 void drawSource(QPainter *painter);
71 QPoint *offset = nullptr,
72 PixmapPadMode mode = PadToEffectiveBoundingRect) const;
73
74private:
75 Q_DECLARE_PRIVATE(QGraphicsEffect)
76 Q_DISABLE_COPY(QGraphicsEffect)
77 friend class QGraphicsItem;
80 friend class QWidget;
81 friend class QWidgetPrivate;
82
83public:
84 QGraphicsEffectSource *source() const; // internal
85
86};
88
90class Q_WIDGETS_EXPORT QGraphicsColorizeEffect: public QGraphicsEffect
91{
94 Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged)
95public:
96 QGraphicsColorizeEffect(QObject *parent = nullptr);
98
99 QColor color() const;
100 qreal strength() const;
101
102public Q_SLOTS:
103 void setColor(const QColor &c);
104 void setStrength(qreal strength);
105
108 void strengthChanged(qreal strength);
109
110protected:
111 void draw(QPainter *painter) override;
112
113private:
114 Q_DECLARE_PRIVATE(QGraphicsColorizeEffect)
115 Q_DISABLE_COPY(QGraphicsColorizeEffect)
116};
117
119class Q_WIDGETS_EXPORT QGraphicsBlurEffect: public QGraphicsEffect
120{
122 Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged)
123 Q_PROPERTY(BlurHints blurHints READ blurHints WRITE setBlurHints NOTIFY blurHintsChanged)
124public:
125 enum BlurHint {
126 PerformanceHint = 0x00,
127 QualityHint = 0x01,
128 AnimationHint = 0x02
129 };
130 Q_ENUM(BlurHint)
131 Q_DECLARE_FLAGS(BlurHints, BlurHint)
132 Q_FLAG(BlurHints)
133
134 QGraphicsBlurEffect(QObject *parent = nullptr);
136
137 QRectF boundingRectFor(const QRectF &rect) const override;
138 qreal blurRadius() const;
139 BlurHints blurHints() const;
140
141public Q_SLOTS:
142 void setBlurRadius(qreal blurRadius);
143 void setBlurHints(BlurHints hints);
144
146 void blurRadiusChanged(qreal blurRadius);
147 void blurHintsChanged(BlurHints hints);
148
149protected:
150 void draw(QPainter *painter) override;
151
152private:
153 Q_DECLARE_PRIVATE(QGraphicsBlurEffect)
154 Q_DISABLE_COPY(QGraphicsBlurEffect)
155};
156
157Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsBlurEffect::BlurHints)
158
160class Q_WIDGETS_EXPORT QGraphicsDropShadowEffect: public QGraphicsEffect
161{
163 Q_PROPERTY(QPointF offset READ offset WRITE setOffset NOTIFY offsetChanged)
164 Q_PROPERTY(qreal xOffset READ xOffset WRITE setXOffset NOTIFY offsetChanged)
165 Q_PROPERTY(qreal yOffset READ yOffset WRITE setYOffset NOTIFY offsetChanged)
166 Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged)
168public:
169 QGraphicsDropShadowEffect(QObject *parent = nullptr);
171
172 QRectF boundingRectFor(const QRectF &rect) const override;
173 QPointF offset() const;
174
175 inline qreal xOffset() const
176 { return offset().x(); }
177
178 inline qreal yOffset() const
179 { return offset().y(); }
180
181 qreal blurRadius() const;
182 QColor color() const;
183
184public Q_SLOTS:
185 void setOffset(const QPointF &ofs);
186
187 inline void setOffset(qreal dx, qreal dy)
188 { setOffset(QPointF(dx, dy)); }
189
190 inline void setOffset(qreal d)
191 { setOffset(QPointF(d, d)); }
192
193 inline void setXOffset(qreal dx)
194 { setOffset(QPointF(dx, yOffset())); }
195
196 inline void setYOffset(qreal dy)
197 { setOffset(QPointF(xOffset(), dy)); }
198
199 void setBlurRadius(qreal blurRadius);
200 void setColor(const QColor &color);
201
204 void blurRadiusChanged(qreal blurRadius);
206
207protected:
208 void draw(QPainter *painter) override;
209
210private:
211 Q_DECLARE_PRIVATE(QGraphicsDropShadowEffect)
212 Q_DISABLE_COPY(QGraphicsDropShadowEffect)
213};
214
216class Q_WIDGETS_EXPORT QGraphicsOpacityEffect: public QGraphicsEffect
217{
219 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)
220 Q_PROPERTY(QBrush opacityMask READ opacityMask WRITE setOpacityMask NOTIFY opacityMaskChanged)
221public:
222 QGraphicsOpacityEffect(QObject *parent = nullptr);
224
225 qreal opacity() const;
226 QBrush opacityMask() const;
227
228public Q_SLOTS:
229 void setOpacity(qreal opacity);
230 void setOpacityMask(const QBrush &mask);
231
233 void opacityChanged(qreal opacity);
234 void opacityMaskChanged(const QBrush &mask);
235
236protected:
237 void draw(QPainter *painter) override;
238
239private:
240 Q_DECLARE_PRIVATE(QGraphicsOpacityEffect)
241 Q_DISABLE_COPY(QGraphicsOpacityEffect)
242};
243
245
246#endif // QGRAPHICSEFFECT_H
247
\inmodule QtGui
Definition qbrush.h:30
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
The QGraphicsBlurEffect class provides a blur effect.
void blurHintsChanged(BlurHints hints)
This signal is emitted whenever the effect's blur hints changes.
void blurRadiusChanged(qreal blurRadius)
This signal is emitted whenever the effect's blur radius changes.
The QGraphicsColorizeEffect class provides a colorize effect.
The QGraphicsDropShadowEffect class provides a drop shadow effect.
void colorChanged(const QColor &color)
This signal is emitted whenever the effect's color changes.
void blurRadiusChanged(qreal blurRadius)
This signal is emitted whenever the effect's blur radius changes.
void offsetChanged(const QPointF &offset)
This signal is emitted whenever the effect's shadow offset changes.
void setOffset(qreal dx, qreal dy)
The QGraphicsEffectSource class represents the source on which a QGraphicsEffect is installed on.
The QGraphicsEffect class is the base class for all graphics effects.
ChangeFlag
This enum describes what has changed in QGraphicsEffectSource.
void enabledChanged(bool enabled)
This signal is emitted whenever the effect is enabled or disabled.
PixmapPadMode
This enum describes how the pixmap returned from sourcePixmap should be padded.
virtual void draw(QPainter *painter)=0
This pure virtual function draws the effect and is called whenever the source needs to be drawn.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
The QGraphicsOpacityEffect class provides an opacity effect.
\inmodule QtCore
Definition qobject.h:103
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:484
The QStyleOption class stores the parameters used by QStyle functions.
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void colorChanged()
rect
[4]
Combined button and popup list for selecting options.
CoordinateSystem
@ LogicalCoordinates
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
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
static const QRectF boundingRect(const QPointF *points, int pointCount)
#define QT_REQUIRE_CONFIG(feature)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_FLAG(x)
#define Q_SLOTS
#define Q_SIGNALS
double qreal
Definition qtypes.h:187
effect setOpacityMask(alphaGradient)
myFilter setColor(QColor(128, 0, 0))
myFilter draw(painter, QPoint(0, 0), originalPixmap)
QPainter painter(this)
[7]