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 QVGPixmapConvolutionFilter; |
113 | const qreal *convolutionKernel() const; |
114 | int rows() const; |
115 | int columns() const; |
116 | }; |
117 | |
118 | class QPixmapBlurFilterPrivate; |
119 | |
120 | class Q_WIDGETS_EXPORT QPixmapBlurFilter : public QPixmapFilter |
121 | { |
122 | Q_OBJECT |
123 | Q_DECLARE_PRIVATE(QPixmapBlurFilter) |
124 | |
125 | public: |
126 | QPixmapBlurFilter(QObject *parent = nullptr); |
127 | ~QPixmapBlurFilter(); |
128 | |
129 | void setRadius(qreal radius); |
130 | void setBlurHints(QGraphicsBlurEffect::BlurHints hints); |
131 | |
132 | qreal radius() const; |
133 | QGraphicsBlurEffect::BlurHints blurHints() const; |
134 | |
135 | QRectF boundingRectFor(const QRectF &rect) const override; |
136 | void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const override; |
137 | }; |
138 | |
139 | class QPixmapColorizeFilterPrivate; |
140 | |
141 | class Q_WIDGETS_EXPORT QPixmapColorizeFilter : public QPixmapFilter |
142 | { |
143 | Q_OBJECT |
144 | Q_DECLARE_PRIVATE(QPixmapColorizeFilter) |
145 | |
146 | public: |
147 | QPixmapColorizeFilter(QObject *parent = nullptr); |
148 | ~QPixmapColorizeFilter(); |
149 | |
150 | void setColor(const QColor& color); |
151 | QColor color() const; |
152 | |
153 | void setStrength(qreal strength); |
154 | qreal strength() const; |
155 | |
156 | void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const override; |
157 | }; |
158 | |
159 | class QPixmapDropShadowFilterPrivate; |
160 | |
161 | class Q_WIDGETS_EXPORT QPixmapDropShadowFilter : public QPixmapFilter |
162 | { |
163 | Q_OBJECT |
164 | Q_DECLARE_PRIVATE(QPixmapDropShadowFilter) |
165 | |
166 | public: |
167 | QPixmapDropShadowFilter(QObject *parent = nullptr); |
168 | ~QPixmapDropShadowFilter(); |
169 | |
170 | QRectF boundingRectFor(const QRectF &rect) const override; |
171 | void draw(QPainter *p, const QPointF &pos, const QPixmap &px, const QRectF &src = QRectF()) const override; |
172 | |
173 | qreal blurRadius() const; |
174 | void setBlurRadius(qreal radius); |
175 | |
176 | QColor color() const; |
177 | void setColor(const QColor &color); |
178 | |
179 | QPointF offset() const; |
180 | void setOffset(const QPointF &offset); |
181 | inline void setOffset(qreal dx, qreal dy) { setOffset(QPointF(dx, dy)); } |
182 | }; |
183 | |
184 | QT_END_NAMESPACE |
185 | |
186 | #endif // QPIXMAPFILTER_H |
187 | |