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_P_H |
5 | #define QGRAPHICSEFFECT_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists for the convenience |
12 | // of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header |
13 | // file may change from version to version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtWidgets/private/qtwidgetsglobal_p.h> |
19 | #include "qgraphicseffect.h" |
20 | |
21 | #include <QPixmapCache> |
22 | |
23 | #include <private/qobject_p.h> |
24 | #include <private/qpixmapfilter_p.h> |
25 | |
26 | QT_REQUIRE_CONFIG(graphicseffect); |
27 | |
28 | QT_BEGIN_NAMESPACE |
29 | |
30 | class QGraphicsEffectSourcePrivate; |
31 | class Q_WIDGETS_EXPORT QGraphicsEffectSource : public QObject |
32 | { |
33 | Q_OBJECT |
34 | public: |
35 | ~QGraphicsEffectSource(); |
36 | const QGraphicsItem *graphicsItem() const; |
37 | const QWidget *widget() const; |
38 | const QStyleOption *styleOption() const; |
39 | |
40 | bool isPixmap() const; |
41 | void draw(QPainter *painter); |
42 | void update(); |
43 | |
44 | QRectF boundingRect(Qt::CoordinateSystem coordinateSystem = Qt::LogicalCoordinates) const; |
45 | QRect deviceRect() const; |
46 | QPixmap pixmap(Qt::CoordinateSystem system = Qt::LogicalCoordinates, |
47 | QPoint *offset = nullptr, |
48 | QGraphicsEffect::PixmapPadMode mode = QGraphicsEffect::PadToEffectiveBoundingRect) const; |
49 | |
50 | protected: |
51 | QGraphicsEffectSource(QGraphicsEffectSourcePrivate &dd, QObject *parent = nullptr); |
52 | |
53 | private: |
54 | Q_DECLARE_PRIVATE(QGraphicsEffectSource) |
55 | Q_DISABLE_COPY_MOVE(QGraphicsEffectSource) |
56 | friend class QGraphicsEffect; |
57 | friend class QGraphicsEffectPrivate; |
58 | friend class QGraphicsScenePrivate; |
59 | friend class QGraphicsItem; |
60 | friend class QGraphicsItemPrivate; |
61 | friend class QWidget; |
62 | friend class QWidgetPrivate; |
63 | }; |
64 | |
65 | class QGraphicsEffectSourcePrivate : public QObjectPrivate |
66 | { |
67 | Q_DECLARE_PUBLIC(QGraphicsEffectSource) |
68 | public: |
69 | QGraphicsEffectSourcePrivate() |
70 | : QObjectPrivate() |
71 | , m_cachedSystem(Qt::DeviceCoordinates) |
72 | , m_cachedMode(QGraphicsEffect::PadToTransparentBorder) |
73 | {} |
74 | |
75 | enum InvalidateReason |
76 | { |
77 | TransformChanged, |
78 | EffectRectChanged, |
79 | SourceChanged |
80 | }; |
81 | |
82 | virtual ~QGraphicsEffectSourcePrivate(); |
83 | virtual void detach() = 0; |
84 | virtual QRectF boundingRect(Qt::CoordinateSystem system) const = 0; |
85 | virtual QRect deviceRect() const = 0; |
86 | virtual const QGraphicsItem *graphicsItem() const = 0; |
87 | virtual const QWidget *widget() const = 0; |
88 | virtual const QStyleOption *styleOption() const = 0; |
89 | virtual void draw(QPainter *p) = 0; |
90 | virtual void update() = 0; |
91 | virtual bool isPixmap() const = 0; |
92 | virtual QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset = nullptr, |
93 | QGraphicsEffect::PixmapPadMode mode = QGraphicsEffect::PadToTransparentBorder) const = 0; |
94 | virtual void effectBoundingRectChanged() = 0; |
95 | |
96 | void setCachedOffset(const QPoint &offset); |
97 | void invalidateCache(InvalidateReason reason = SourceChanged) const; |
98 | Qt::CoordinateSystem currentCachedSystem() const { return m_cachedSystem; } |
99 | QGraphicsEffect::PixmapPadMode currentCachedMode() const { return m_cachedMode; } |
100 | |
101 | friend class QGraphicsScenePrivate; |
102 | friend class QGraphicsItem; |
103 | friend class QGraphicsItemPrivate; |
104 | |
105 | private: |
106 | mutable Qt::CoordinateSystem m_cachedSystem; |
107 | mutable QGraphicsEffect::PixmapPadMode m_cachedMode; |
108 | mutable QPoint m_cachedOffset; |
109 | mutable QPixmapCache::Key m_cacheKey; |
110 | }; |
111 | |
112 | class Q_WIDGETS_EXPORT QGraphicsEffectPrivate : public QObjectPrivate |
113 | { |
114 | Q_DECLARE_PUBLIC(QGraphicsEffect) |
115 | public: |
116 | QGraphicsEffectPrivate() : source(nullptr), isEnabled(1) {} |
117 | ~QGraphicsEffectPrivate(); |
118 | |
119 | inline void setGraphicsEffectSource(QGraphicsEffectSource *newSource) |
120 | { |
121 | QGraphicsEffect::ChangeFlags flags; |
122 | if (source) { |
123 | flags |= QGraphicsEffect::SourceDetached; |
124 | source->d_func()->effectBoundingRectChanged(); |
125 | source->d_func()->invalidateCache(); |
126 | source->d_func()->detach(); |
127 | delete source; |
128 | } |
129 | source = newSource; |
130 | if (newSource) |
131 | flags |= QGraphicsEffect::SourceAttached; |
132 | q_func()->sourceChanged(flags); |
133 | } |
134 | |
135 | QGraphicsEffectSource *source; |
136 | QRectF boundingRect; |
137 | quint32 isEnabled : 1; |
138 | quint32 padding : 31; // feel free to use |
139 | }; |
140 | |
141 | |
142 | class QGraphicsColorizeEffectPrivate : public QGraphicsEffectPrivate |
143 | { |
144 | Q_DECLARE_PUBLIC(QGraphicsColorizeEffect) |
145 | public: |
146 | QGraphicsColorizeEffectPrivate() |
147 | : opaque(true) |
148 | { |
149 | filter = new QPixmapColorizeFilter; |
150 | } |
151 | ~QGraphicsColorizeEffectPrivate() { delete filter; } |
152 | |
153 | QPixmapColorizeFilter *filter; |
154 | quint32 opaque : 1; |
155 | quint32 padding : 31; |
156 | }; |
157 | |
158 | class QGraphicsBlurEffectPrivate : public QGraphicsEffectPrivate |
159 | { |
160 | Q_DECLARE_PUBLIC(QGraphicsBlurEffect) |
161 | public: |
162 | QGraphicsBlurEffectPrivate() : filter(new QPixmapBlurFilter) {} |
163 | ~QGraphicsBlurEffectPrivate() { delete filter; } |
164 | |
165 | QPixmapBlurFilter *filter; |
166 | }; |
167 | |
168 | class QGraphicsDropShadowEffectPrivate : public QGraphicsEffectPrivate |
169 | { |
170 | Q_DECLARE_PUBLIC(QGraphicsDropShadowEffect) |
171 | public: |
172 | QGraphicsDropShadowEffectPrivate() : filter(new QPixmapDropShadowFilter) {} |
173 | ~QGraphicsDropShadowEffectPrivate() { delete filter; } |
174 | |
175 | QPixmapDropShadowFilter *filter; |
176 | }; |
177 | |
178 | class QGraphicsOpacityEffectPrivate : public QGraphicsEffectPrivate |
179 | { |
180 | Q_DECLARE_PUBLIC(QGraphicsOpacityEffect) |
181 | public: |
182 | QGraphicsOpacityEffectPrivate() |
183 | : opacity(qreal(0.7)), isFullyTransparent(0), isFullyOpaque(0), hasOpacityMask(0) {} |
184 | ~QGraphicsOpacityEffectPrivate() {} |
185 | |
186 | qreal opacity; |
187 | QBrush opacityMask; |
188 | uint isFullyTransparent : 1; |
189 | uint isFullyOpaque : 1; |
190 | uint hasOpacityMask : 1; |
191 | }; |
192 | |
193 | QT_END_NAMESPACE |
194 | |
195 | #endif // QGRAPHICSEFFECT_P_H |
196 | |