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 QPIXMAPFILTER_H |
5 | #define QPIXMAPFILTER_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 purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtWidgets/private/qtwidgetsglobal_p.h> |
19 | #include <QtCore/qnamespace.h> |
20 | #include <QtGui/qpixmap.h> |
21 | #include <QtWidgets/qgraphicseffect.h> |
22 | |
23 | QT_REQUIRE_CONFIG(graphicseffect); |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | class QPainter; |
28 | class QPlatformPixmap; |
29 | |
30 | class QPixmapFilterPrivate; |
31 | |
32 | class Q_WIDGETS_EXPORT QPixmapFilter : public QObject |
33 | { |
34 | Q_OBJECT |
35 | Q_DECLARE_PRIVATE(QPixmapFilter) |
36 | public: |
37 | virtual ~QPixmapFilter() = 0; |
38 | |
39 | enum FilterType { |
40 | ConvolutionFilter, |
41 | ColorizeFilter, |
42 | DropShadowFilter, |
43 | BlurFilter, |
44 | |
45 | UserFilter = 1024 |
46 | }; |
47 | |
48 | FilterType type() const; |
49 | |
50 | virtual QRectF boundingRectFor(const QRectF &rect) const; |
51 | |
52 | virtual void draw(QPainter *painter, const QPointF &p, const QPixmap &src, const QRectF &srcRect = QRectF()) const = 0; |
53 | |
54 | protected: |
55 | QPixmapFilter(QPixmapFilterPrivate &d, FilterType type, QObject *parent); |
56 | QPixmapFilter(FilterType type, QObject *parent); |
57 | }; |
58 | |
59 | class QPixmapConvolutionFilterPrivate; |
60 | |
61 | class Q_WIDGETS_EXPORT QPixmapConvolutionFilter : public QPixmapFilter |
62 | { |
63 | Q_OBJECT |
64 | Q_DECLARE_PRIVATE(QPixmapConvolutionFilter) |
65 | |
66 | public: |
67 | QPixmapConvolutionFilter(QObject *parent = nullptr); |
68 | ~QPixmapConvolutionFilter(); |
69 | |
70 | void setConvolutionKernel(const qreal *matrix, int rows, int columns); |
71 | |
72 | QRectF boundingRectFor(const QRectF &rect) const override; |
73 | void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const override; |
74 | |
75 | private: |
76 | friend class QVGPixmapConvolutionFilter; |
77 | const qreal *convolutionKernel() const; |
78 | int rows() const; |
79 | int columns() const; |
80 | }; |
81 | |
82 | class QPixmapBlurFilterPrivate; |
83 | |
84 | class Q_WIDGETS_EXPORT QPixmapBlurFilter : public QPixmapFilter |
85 | { |
86 | Q_OBJECT |
87 | Q_DECLARE_PRIVATE(QPixmapBlurFilter) |
88 | |
89 | public: |
90 | QPixmapBlurFilter(QObject *parent = nullptr); |
91 | ~QPixmapBlurFilter(); |
92 | |
93 | void setRadius(qreal radius); |
94 | void setBlurHints(QGraphicsBlurEffect::BlurHints hints); |
95 | |
96 | qreal radius() const; |
97 | QGraphicsBlurEffect::BlurHints blurHints() const; |
98 | |
99 | QRectF boundingRectFor(const QRectF &rect) const override; |
100 | void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const override; |
101 | }; |
102 | |
103 | class QPixmapColorizeFilterPrivate; |
104 | |
105 | class Q_WIDGETS_EXPORT QPixmapColorizeFilter : public QPixmapFilter |
106 | { |
107 | Q_OBJECT |
108 | Q_DECLARE_PRIVATE(QPixmapColorizeFilter) |
109 | |
110 | public: |
111 | QPixmapColorizeFilter(QObject *parent = nullptr); |
112 | ~QPixmapColorizeFilter(); |
113 | |
114 | void setColor(const QColor& color); |
115 | QColor color() const; |
116 | |
117 | void setStrength(qreal strength); |
118 | qreal strength() const; |
119 | |
120 | void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect = QRectF()) const override; |
121 | }; |
122 | |
123 | class QPixmapDropShadowFilterPrivate; |
124 | |
125 | class Q_WIDGETS_EXPORT QPixmapDropShadowFilter : public QPixmapFilter |
126 | { |
127 | Q_OBJECT |
128 | Q_DECLARE_PRIVATE(QPixmapDropShadowFilter) |
129 | |
130 | public: |
131 | QPixmapDropShadowFilter(QObject *parent = nullptr); |
132 | ~QPixmapDropShadowFilter(); |
133 | |
134 | QRectF boundingRectFor(const QRectF &rect) const override; |
135 | void draw(QPainter *p, const QPointF &pos, const QPixmap &px, const QRectF &src = QRectF()) const override; |
136 | |
137 | qreal blurRadius() const; |
138 | void setBlurRadius(qreal radius); |
139 | |
140 | QColor color() const; |
141 | void setColor(const QColor &color); |
142 | |
143 | QPointF offset() const; |
144 | void setOffset(const QPointF &offset); |
145 | inline void setOffset(qreal dx, qreal dy) { setOffset(QPointF(dx, dy)); } |
146 | }; |
147 | |
148 | QT_END_NAMESPACE |
149 | |
150 | #endif // QPIXMAPFILTER_H |
151 | |