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
23QT_REQUIRE_CONFIG(graphicseffect);
24
25QT_BEGIN_NAMESPACE
26
27class QPainter;
28class QPlatformPixmap;
29
30class QPixmapFilterPrivate;
31
32class Q_WIDGETS_EXPORT QPixmapFilter : public QObject
33{
34 Q_OBJECT
35 Q_DECLARE_PRIVATE(QPixmapFilter)
36public:
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
54protected:
55 QPixmapFilter(QPixmapFilterPrivate &d, FilterType type, QObject *parent);
56 QPixmapFilter(FilterType type, QObject *parent);
57};
58
59class QPixmapConvolutionFilterPrivate;
60
61class Q_WIDGETS_EXPORT QPixmapConvolutionFilter : public QPixmapFilter
62{
63 Q_OBJECT
64 Q_DECLARE_PRIVATE(QPixmapConvolutionFilter)
65
66public:
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
75private:
76 friend class QVGPixmapConvolutionFilter;
77 const qreal *convolutionKernel() const;
78 int rows() const;
79 int columns() const;
80};
81
82class QPixmapBlurFilterPrivate;
83
84class Q_WIDGETS_EXPORT QPixmapBlurFilter : public QPixmapFilter
85{
86 Q_OBJECT
87 Q_DECLARE_PRIVATE(QPixmapBlurFilter)
88
89public:
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
103class QPixmapColorizeFilterPrivate;
104
105class Q_WIDGETS_EXPORT QPixmapColorizeFilter : public QPixmapFilter
106{
107 Q_OBJECT
108 Q_DECLARE_PRIVATE(QPixmapColorizeFilter)
109
110public:
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
123class QPixmapDropShadowFilterPrivate;
124
125class Q_WIDGETS_EXPORT QPixmapDropShadowFilter : public QPixmapFilter
126{
127 Q_OBJECT
128 Q_DECLARE_PRIVATE(QPixmapDropShadowFilter)
129
130public:
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
148QT_END_NAMESPACE
149
150#endif // QPIXMAPFILTER_H
151

source code of qtbase/src/widgets/effects/qpixmapfilter_p.h