Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
5#ifndef QGRAPHICSEFFECT_H
6#define QGRAPHICSEFFECT_H
7
8#include <QtWidgets/qtwidgetsglobal.h>
9#include <QtCore/qobject.h>
10#include <QtCore/qpoint.h>
11#include <QtCore/qrect.h>
12#include <QtGui/qcolor.h>
13#include <QtGui/qbrush.h>
14
16
17QT_BEGIN_NAMESPACE
18
19class QGraphicsItem;
20class QStyleOption;
21class QPainter;
22class QPixmap;
23
24class QGraphicsEffectSource;
25
26class QGraphicsEffectPrivate;
27class Q_WIDGETS_EXPORT QGraphicsEffect : public QObject
28{
29 Q_OBJECT
30 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
31public:
32 enum ChangeFlag {
33 SourceAttached = 0x1,
34 SourceDetached = 0x2,
35 SourceBoundingRectChanged = 0x4,
36 SourceInvalidated = 0x8
37 };
38 Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)
39 Q_FLAG(ChangeFlags)
40
41 enum PixmapPadMode {
42 NoPad,
43 PadToTransparentBorder,
44 PadToEffectiveBoundingRect
45 };
46
47 QGraphicsEffect(QObject *parent = nullptr);
48 virtual ~QGraphicsEffect();
49
50 virtual QRectF boundingRectFor(const QRectF &sourceRect) const;
51 QRectF boundingRect() const;
52
53 bool isEnabled() const;
54
55public Q_SLOTS:
56 void setEnabled(bool enable);
57 void update();
58
59Q_SIGNALS:
60 void enabledChanged(bool enabled);
61
62protected:
63 QGraphicsEffect(QGraphicsEffectPrivate &d, QObject *parent = nullptr);
64 virtual void draw(QPainter *painter) = 0;
65 virtual void sourceChanged(ChangeFlags flags);
66 void updateBoundingRect();
67
68 bool sourceIsPixmap() const;
69 QRectF sourceBoundingRect(Qt::CoordinateSystem system = Qt::LogicalCoordinates) const;
70 void drawSource(QPainter *painter);
71 QPixmap sourcePixmap(Qt::CoordinateSystem system = Qt::LogicalCoordinates,
72 QPoint *offset = nullptr,
73 PixmapPadMode mode = PadToEffectiveBoundingRect) const;
74
75private:
76 Q_DECLARE_PRIVATE(QGraphicsEffect)
77 Q_DISABLE_COPY(QGraphicsEffect)
78 friend class QGraphicsItem;
79 friend class QGraphicsItemPrivate;
80 friend class QGraphicsScenePrivate;
81 friend class QWidget;
82 friend class QWidgetPrivate;
83
84public:
85 QGraphicsEffectSource *source() const; // internal
86
87};
88Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsEffect::ChangeFlags)
89
90class QGraphicsColorizeEffectPrivate;
91class Q_WIDGETS_EXPORT QGraphicsColorizeEffect: public QGraphicsEffect
92{
93 Q_OBJECT
94 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
95 Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged)
96public:
97 QGraphicsColorizeEffect(QObject *parent = nullptr);
98 ~QGraphicsColorizeEffect();
99
100 QColor color() const;
101 qreal strength() const;
102
103public Q_SLOTS:
104 void setColor(const QColor &c);
105 void setStrength(qreal strength);
106
107Q_SIGNALS:
108 void colorChanged(const QColor &color);
109 void strengthChanged(qreal strength);
110
111protected:
112 void draw(QPainter *painter) override;
113
114private:
115 Q_DECLARE_PRIVATE(QGraphicsColorizeEffect)
116 Q_DISABLE_COPY(QGraphicsColorizeEffect)
117};
118
120class Q_WIDGETS_EXPORT QGraphicsBlurEffect: public QGraphicsEffect
121{
122 Q_OBJECT
123 Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged)
124 Q_PROPERTY(BlurHints blurHints READ blurHints WRITE setBlurHints NOTIFY blurHintsChanged)
125public:
126 enum BlurHint {
127 PerformanceHint = 0x00,
128 QualityHint = 0x01,
129 AnimationHint = 0x02
130 };
131 Q_ENUM(BlurHint)
132 Q_DECLARE_FLAGS(BlurHints, BlurHint)
133 Q_FLAG(BlurHints)
134
135 QGraphicsBlurEffect(QObject *parent = nullptr);
136 ~QGraphicsBlurEffect();
137
138 QRectF boundingRectFor(const QRectF &rect) const override;
139 qreal blurRadius() const;
140 BlurHints blurHints() const;
141
142public Q_SLOTS:
143 void setBlurRadius(qreal blurRadius);
144 void setBlurHints(BlurHints hints);
145
146Q_SIGNALS:
147 void blurRadiusChanged(qreal blurRadius);
148 void blurHintsChanged(BlurHints hints);
149
150protected:
151 void draw(QPainter *painter) override;
152
153private:
154 Q_DECLARE_PRIVATE(QGraphicsBlurEffect)
155 Q_DISABLE_COPY(QGraphicsBlurEffect)
156};
157
158Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsBlurEffect::BlurHints)
159
160class QGraphicsDropShadowEffectPrivate;
161class Q_WIDGETS_EXPORT QGraphicsDropShadowEffect: public QGraphicsEffect
162{
163 Q_OBJECT
164 Q_PROPERTY(QPointF offset READ offset WRITE setOffset NOTIFY offsetChanged)
165 Q_PROPERTY(qreal xOffset READ xOffset WRITE setXOffset NOTIFY offsetChanged)
166 Q_PROPERTY(qreal yOffset READ yOffset WRITE setYOffset NOTIFY offsetChanged)
167 Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged)
168 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
169public:
170 QGraphicsDropShadowEffect(QObject *parent = nullptr);
171 ~QGraphicsDropShadowEffect();
172
173 QRectF boundingRectFor(const QRectF &rect) const override;
174 QPointF offset() const;
175
176 inline qreal xOffset() const
177 { return offset().x(); }
178
179 inline qreal yOffset() const
180 { return offset().y(); }
181
182 qreal blurRadius() const;
183 QColor color() const;
184
185public Q_SLOTS:
186 void setOffset(const QPointF &ofs);
187
188 inline void setOffset(qreal dx, qreal dy)
189 { setOffset(QPointF(dx, dy)); }
190
191 inline void setOffset(qreal d)
192 { setOffset(QPointF(d, d)); }
193
194 inline void setXOffset(qreal dx)
195 { setOffset(QPointF(dx, yOffset())); }
196
197 inline void setYOffset(qreal dy)
198 { setOffset(QPointF(xOffset(), dy)); }
199
200 void setBlurRadius(qreal blurRadius);
201 void setColor(const QColor &color);
202
203Q_SIGNALS:
204 void offsetChanged(const QPointF &offset);
205 void blurRadiusChanged(qreal blurRadius);
206 void colorChanged(const QColor &color);
207
208protected:
209 void draw(QPainter *painter) override;
210
211private:
212 Q_DECLARE_PRIVATE(QGraphicsDropShadowEffect)
213 Q_DISABLE_COPY(QGraphicsDropShadowEffect)
214};
215
217class Q_WIDGETS_EXPORT QGraphicsOpacityEffect: public QGraphicsEffect
218{
219 Q_OBJECT
220 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)
221 Q_PROPERTY(QBrush opacityMask READ opacityMask WRITE setOpacityMask NOTIFY opacityMaskChanged)
222public:
223 QGraphicsOpacityEffect(QObject *parent = nullptr);
224 ~QGraphicsOpacityEffect();
225
226 qreal opacity() const;
227 QBrush opacityMask() const;
228
229public Q_SLOTS:
230 void setOpacity(qreal opacity);
231 void setOpacityMask(const QBrush &mask);
232
233Q_SIGNALS:
234 void opacityChanged(qreal opacity);
235 void opacityMaskChanged(const QBrush &mask);
236
237protected:
238 void draw(QPainter *painter) override;
239
240private:
241 Q_DECLARE_PRIVATE(QGraphicsOpacityEffect)
242 Q_DISABLE_COPY(QGraphicsOpacityEffect)
243};
244
245QT_END_NAMESPACE
246
247#endif // QGRAPHICSEFFECT_H
The QGraphicsBlurEffect class provides a blur effect.
The QGraphicsColorizeEffect class provides a colorize effect.
The QGraphicsDropShadowEffect class provides a drop shadow effect.
void setCachedOffset(const QPoint &offset)
virtual const QGraphicsItem * graphicsItem() const =0
virtual bool isPixmap() const =0
virtual QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset=nullptr, QGraphicsEffect::PixmapPadMode mode=QGraphicsEffect::PadToTransparentBorder) const =0
void invalidateCache(InvalidateReason reason=SourceChanged) const
virtual QRectF boundingRect(Qt::CoordinateSystem system) const =0
Qt::CoordinateSystem currentCachedSystem() const
virtual const QStyleOption * styleOption() const =0
virtual void draw(QPainter *p)=0
virtual QRect deviceRect() const =0
virtual void effectBoundingRectChanged()=0
virtual const QWidget * widget() const =0
The QGraphicsEffectSource class represents the source on which a QGraphicsEffect is installed on.
The QGraphicsEffect class is the base class for all graphics effects.
The QGraphicsOpacityEffect class provides an opacity effect.
friend class QPainter
Combined button and popup list for selecting options.
QT_REQUIRE_CONFIG(animation)
QT_REQUIRE_CONFIG(graphicseffect)