DtkWidget
DTK Widget module
载入中...
搜索中...
未找到
dblureffectwidget.h
1// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DBLUREFFECTWIDGET_H
6#define DBLUREFFECTWIDGET_H
7
8#include <dtkwidget_global.h>
9#include <DObject>
10
11#include <QWidget>
12
13DWIDGET_BEGIN_NAMESPACE
14
15class DBlurEffectWidgetPrivate;
16class LIBDTKWIDGETSHARED_EXPORT DBlurEffectWidget : public QWidget, public DTK_CORE_NAMESPACE::DObject
17{
18 Q_OBJECT
19
20 // The "radius" property is only support for InWindowBlend. See property "blendMode"
21 Q_PROPERTY(int radius READ radius WRITE setRadius NOTIFY radiusChanged)
22 Q_PROPERTY(BlurMode mode READ mode WRITE setMode NOTIFY modeChanged)
23 Q_PROPERTY(BlendMode blendMode READ blendMode WRITE setBlendMode NOTIFY blendModeChanged)
24 Q_PROPERTY(int blurRectXRadius READ blurRectXRadius WRITE setBlurRectXRadius NOTIFY blurRectXRadiusChanged)
25 Q_PROPERTY(int blurRectYRadius READ blurRectYRadius WRITE setBlurRectYRadius NOTIFY blurRectYRadiusChanged)
26 // ###(zccrs): The alpha channel of the color is fixed.
27 // The alpha channel is 102 if the DPlatformWindowHandle::hasBlurWindow() is true, otherwise is 204).
28 Q_PROPERTY(QColor maskColor READ maskColor WRITE setMaskColor NOTIFY maskColorChanged)
29 Q_PROPERTY(quint8 maskAlpha READ maskAlpha WRITE setMaskAlpha NOTIFY maskAlphaChanged)
30 Q_PROPERTY(bool full READ isFull WRITE setFull NOTIFY fullChanged)
31 Q_PROPERTY(bool blurEnabled READ blurEnabled WRITE setBlurEnabled NOTIFY blurEnabledChanged)
32
33public:
34 // TODO: To support MeanBlur, MedianBlur, BilateralFilter
35 enum BlurMode {
36 GaussianBlur
37 };
38
39 Q_ENUMS(BlurMode)
40
46
47 Q_ENUMS(BlendMode)
48
49 enum MaskColorType {
50 DarkColor,
51 LightColor,
52 AutoColor,
53 CustomColor
54 };
55
56 Q_ENUMS(MaskColorType)
57
58 explicit DBlurEffectWidget(QWidget *parent = 0);
59 ~DBlurEffectWidget();
60
61 int radius() const;
62 BlurMode mode() const;
63
64 BlendMode blendMode() const;
65 int blurRectXRadius() const;
66 int blurRectYRadius() const;
67
68 bool isFull() const;
69 bool blurEnabled() const;
70
71 QColor maskColor() const;
72
73 quint8 maskAlpha() const;
74
75 void setMaskPath(const QPainterPath &path);
76 void setSourceImage(const QImage &image, bool autoScale = true);
77
78public Q_SLOTS:
79 void setRadius(int radius);
80 void setMode(BlurMode mode);
81
82 void setBlendMode(BlendMode blendMode);
83 void setBlurRectXRadius(int blurRectXRadius);
84 void setBlurRectYRadius(int blurRectYRadius);
85 void setMaskAlpha(quint8 alpha);
86 void setMaskColor(QColor maskColor);
87 void setMaskColor(MaskColorType type);
88 void setFull(bool full);
89 void setBlurEnabled(bool blurEnabled);
90
91 void updateBlurSourceImage(const QRegion &ren);
92
93Q_SIGNALS:
94 void radiusChanged(int radius);
96
97 void blendModeChanged(BlendMode blendMode);
98 void blurRectXRadiusChanged(int blurRectXRadius);
99 void blurRectYRadiusChanged(int blurRectYRadius);
100 void maskAlphaChanged(quint8 alpha);
101 void maskColorChanged(QColor maskColor);
102 void fullChanged(bool full);
103 void blurEnabledChanged(bool blurEnabled);
104
105 void blurSourceImageDirtied();
106
107protected:
108 DBlurEffectWidget(DBlurEffectWidgetPrivate &dd, QWidget *parent = 0);
109
110 void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
111 void moveEvent(QMoveEvent *event) Q_DECL_OVERRIDE;
112 void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
113 void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
114 void hideEvent(QHideEvent *event) Q_DECL_OVERRIDE;
115 void changeEvent(QEvent *event) Q_DECL_OVERRIDE;
116 bool eventFilter(QObject *watched, QEvent *event) override;
117
118private:
119 D_DECLARE_PRIVATE(DBlurEffectWidget)
120 friend class DBlurEffectGroup;
121};
122
124class DBlurEffectGroup : public DTK_CORE_NAMESPACE::DObject
125{
126 D_DECLARE_PRIVATE(DBlurEffectGroup)
127public:
128 explicit DBlurEffectGroup();
130
131 void setSourceImage(QImage image, int blurRadius = 35);
132 void addWidget(DBlurEffectWidget *widget, const QPoint &offset = QPoint(0, 0));
133 void removeWidget(DBlurEffectWidget *widget);
134
135 void paint(QPainter *pa, DBlurEffectWidget *widget) const;
136};
137
138DWIDGET_END_NAMESPACE
139
140#endif // DBLUREFFECTWIDGET_H
Definition dblureffectwidget.cpp:1140
Definition dblureffectwidget.h:125
Definition dblureffectwidget_p.h:15
用于实现主窗口或控件背景的实时模糊效果.
Definition dblureffectwidget.h:17
void maskColorChanged(QColor maskColor)
信号会在 maskColor 属性的值改变时被发送
BlendMode
Definition dblureffectwidget.h:41
@ InWindowBlend
Definition dblureffectwidget.h:42
@ BehindWindowBlend
Definition dblureffectwidget.h:43
BlurMode
Definition dblureffectwidget.h:35
void blendModeChanged(BlendMode blendMode)
信号会在 blendMode 属性的值改变时被发送
void blurRectYRadiusChanged(int blurRectYRadius)
信号会在 blurRectYRadius 属性的值改变时被发送
void modeChanged(BlurMode mode)
信号会在 mode 属性的值改变时被发送.
void blurRectXRadiusChanged(int blurRectXRadius)
信号会在 blurRectXRadius 属性的值改变时被发送
void radiusChanged(int radius)
信号会在 radius 属性的值改变时被发送
void maskAlphaChanged(quint8 alpha)
信号会在 alpha 属性的值改变时被发送