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 QPIXMAPFILTER_H |
41 | #define QPIXMAPFILTER_H |
42 | |
43 | // |
44 | // W A R N I N G |
45 | // ------------- |
46 | // |
47 | // This file is not part of the Qt API. It exists purely as an |
48 | // implementation detail. This header file may change from version to |
49 | // version without notice, or even be removed. |
50 | // |
51 | // We mean it. |
52 | // |
53 | |
54 | #include <QtWidgets/private/qtwidgetsglobal_p.h> |
55 | #include <QtCore/qnamespace.h> |
56 | #include <QtGui/qpixmap.h> |
57 | #include <QtWidgets/qgraphicseffect.h> |
58 | |
59 | QT_REQUIRE_CONFIG(graphicseffect); |
60 | |
61 | QT_BEGIN_NAMESPACE |
62 | |
63 | class QPainter; |
64 | class QPlatformPixmap; |
65 | |
66 | class QPixmapFilterPrivate; |
67 | |
68 | class Q_WIDGETS_EXPORT QPixmapFilter : public QObject |
69 | { |
70 | Q_OBJECT |
71 | Q_DECLARE_PRIVATE(QPixmapFilter) |
72 | public: |
73 | virtual ~QPixmapFilter() = 0; |
74 | |
75 | enum FilterType { |
76 | ConvolutionFilter, |
77 | ColorizeFilter, |
78 | DropShadowFilter, |
79 | BlurFilter, |
80 | |
81 | UserFilter = 1024 |
82 | }; |
83 | |
84 | FilterType type() const; |
85 | |
86 | virtual QRectF boundingRectFor(const QRectF &rect) const; |
87 | |
88 | virtual void draw(QPainter *painter, const QPointF &p, const QPixmap &src, const QRectF &srcRect = QRectF()) const = 0; |
89 | |
90 | protected: |
91 | QPixmapFilter(QPixmapFilterPrivate &d, FilterType type, QObject *parent); |
92 | QPixmapFilter(FilterType type, QObject *parent); |
93 | }; |
94 | |
95 | class QPixmapConvolutionFilterPrivate; |
96 | |
97 | class Q_WIDGETS_EXPORT QPixmapConvolutionFilter : public QPixmapFilter |
98 | { |
99 | Q_OBJECT |
100 | Q_DECLARE_PRIVATE(QPixmapConvolutionFilter) |
101 | |
102 | public: |
103 | QPixmapConvolutionFilter(QObject *parent = nullptr); |
104 | ~QPixmapConvolutionFilter(); |
105 | |
106 | void setConvolutionKernel(const qreal *matrix, int rows, int columns); |
107 | |
108 | QRectF boundingRectFor(const QRectF &rect) const override; |
109 | void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const override; |
110 | |
111 | private: |
112 | friend class QGLPixmapConvolutionFilter; |
113 | friend class QVGPixmapConvolutionFilter; |
114 | const qreal *convolutionKernel() const; |
115 | int rows() const; |
116 | int columns() const; |
117 | }; |
118 | |
119 | class QPixmapBlurFilterPrivate; |
120 | |
121 | class Q_WIDGETS_EXPORT QPixmapBlurFilter : public QPixmapFilter |
122 | { |
123 | Q_OBJECT |
124 | Q_DECLARE_PRIVATE(QPixmapBlurFilter) |
125 | |
126 | public: |
127 | QPixmapBlurFilter(QObject *parent = nullptr); |
128 | ~QPixmapBlurFilter(); |
129 | |
130 | void setRadius(qreal radius); |
131 | void setBlurHints(QGraphicsBlurEffect::BlurHints hints); |
132 | |
133 | qreal radius() const; |
134 | QGraphicsBlurEffect::BlurHints blurHints() const; |
135 | |
136 | QRectF boundingRectFor(const QRectF &rect) const override; |
137 | void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const override; |
138 | |
139 | private: |
140 | friend class QGLPixmapBlurFilter; |
141 | }; |
142 | |
143 | class QPixmapColorizeFilterPrivate; |
144 | |
145 | class Q_WIDGETS_EXPORT QPixmapColorizeFilter : public QPixmapFilter |
146 | { |
147 | Q_OBJECT |
148 | Q_DECLARE_PRIVATE(QPixmapColorizeFilter) |
149 | |
150 | public: |
151 | QPixmapColorizeFilter(QObject *parent = nullptr); |
152 | ~QPixmapColorizeFilter(); |
153 | |
154 | void setColor(const QColor& color); |
155 | QColor color() const; |
156 | |
157 | void setStrength(qreal strength); |
158 | qreal strength() const; |
159 | |
160 | void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const override; |
161 | }; |
162 | |
163 | class QPixmapDropShadowFilterPrivate; |
164 | |
165 | class Q_WIDGETS_EXPORT QPixmapDropShadowFilter : public QPixmapFilter |
166 | { |
167 | Q_OBJECT |
168 | Q_DECLARE_PRIVATE(QPixmapDropShadowFilter) |
169 | |
170 | public: |
171 | QPixmapDropShadowFilter(QObject *parent = nullptr); |
172 | ~QPixmapDropShadowFilter(); |
173 | |
174 | QRectF boundingRectFor(const QRectF &rect) const override; |
175 | void draw(QPainter *p, const QPointF &pos, const QPixmap &px, const QRectF &src = QRectF()) const override; |
176 | |
177 | qreal blurRadius() const; |
178 | void setBlurRadius(qreal radius); |
179 | |
180 | QColor color() const; |
181 | void setColor(const QColor &color); |
182 | |
183 | QPointF offset() const; |
184 | void setOffset(const QPointF &offset); |
185 | inline void setOffset(qreal dx, qreal dy) { setOffset(QPointF(dx, dy)); } |
186 | }; |
187 | |
188 | QT_END_NAMESPACE |
189 | |
190 | #endif // QPIXMAPFILTER_H |
191 | |