DtkGui
DTK Gui module
载入中...
搜索中...
未找到
dplatformhandle.h
1// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DPLATFORMHANDLE_H
6#define DPLATFORMHANDLE_H
7
8#include <dtkgui_global.h>
9
10#include <QObject>
11#include <QPainterPath>
12#include <QColor>
13#include <QRegion>
14
15#include <functional>
16
17QT_BEGIN_NAMESPACE
18class QWindow;
19QT_END_NAMESPACE
20
21DGUI_BEGIN_NAMESPACE
22// TODO: class DPlatformHandle will be removed in the future
23class DPlatformHandle : public QObject
24{
25 Q_OBJECT
26
27 Q_PROPERTY(int windowRadius READ windowRadius WRITE setWindowRadius NOTIFY windowRadiusChanged)
28 Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged)
29 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
30 Q_PROPERTY(int shadowRadius READ shadowRadius WRITE setShadowRadius NOTIFY shadowRadiusChanged)
31 Q_PROPERTY(QPoint shadowOffset READ shadowOffset WRITE setShadowOffset NOTIFY shadowOffsetChanged)
32 Q_PROPERTY(QColor shadowColor READ shadowColor WRITE setShadowColor NOTIFY shadowColorChanged)
33 Q_PROPERTY(EffectScene windowEffect READ windowEffect WRITE setWindowEffect NOTIFY windowEffectChanged)
34 Q_PROPERTY(EffectType windowStartUpEffect READ windowStartUpEffect WRITE setWindowStartUpEffect NOTIFY windowStartUpEffectChanged)
35 Q_PROPERTY(QPainterPath clipPath READ clipPath WRITE setClipPath NOTIFY clipPathChanged)
36 Q_PROPERTY(QRegion frameMask READ frameMask WRITE setFrameMask NOTIFY frameMaskChanged)
37 Q_PROPERTY(QMargins frameMargins READ frameMargins NOTIFY frameMarginsChanged)
38 Q_PROPERTY(bool translucentBackground READ translucentBackground WRITE setTranslucentBackground NOTIFY translucentBackgroundChanged)
39 Q_PROPERTY(bool enableSystemResize READ enableSystemResize WRITE setEnableSystemResize NOTIFY enableSystemResizeChanged)
40 Q_PROPERTY(bool enableSystemMove READ enableSystemMove WRITE setEnableSystemMove NOTIFY enableSystemMoveChanged)
41 Q_PROPERTY(bool enableBlurWindow READ enableBlurWindow WRITE setEnableBlurWindow NOTIFY enableBlurWindowChanged)
42 Q_PROPERTY(bool autoInputMaskByClipPath READ autoInputMaskByClipPath WRITE setAutoInputMaskByClipPath NOTIFY autoInputMaskByClipPathChanged)
43 Q_PROPERTY(WId realWindowId READ realWindowId CONSTANT)
44
45public:
46 explicit DPlatformHandle(QWindow *window, QObject *parent = 0);
48
49 static QString pluginVersion();
50 static bool isDXcbPlatform();
51
52 static void enableDXcbForWindow(QWindow *window);
53 static void enableDXcbForWindow(QWindow *window, bool redirectContent);
54 static bool isEnabledDXcb(const QWindow *window);
55
56 static bool setEnabledNoTitlebarForWindow(QWindow *window, bool enable);
57 static bool isEnabledNoTitlebar(const QWindow *window);
58
59 struct WMBlurArea {
60 qint32 x = 0;
61 qint32 y = 0;
62 qint32 width = 0;
63 qint32 height = 0;
64 qint32 xRadius = 0;
65 qint32 yRaduis = 0;
66 };
67
68 enum WallpaperScaleMode {
69 FollowScreen = 0x00000000,
70 FollowWindow = 0x00010000
71 };
72
73 enum WallpaperFillMode {
74 PreserveAspectCrop = 0x00000000,
75 PreserveAspectFit = 0x00000001
76 };
77
78 enum EffectScene {
79 EffectNoRadius = 0x01, // 取消窗口圆角
80 EffectNoShadow = 0x02, // 取消窗口阴影
81 EffectNoBorder = 0x04, // 取消窗口边框
82 EffectNoStart = 0x10, // 取消启动场景动效
83 EffectNoClose = 0x20, // 取消关闭场景动效
84 EffectNoMaximize = 0x40, // 取消最大化场景动效
85 EffectNoMinimize = 0x80 // 取消最小化场景动效
86 };
87
88 enum EffectType {
89 EffectNormal = 0x01, // 标准缩放动效
90 EffectCursor = 0x02, // 鼠标位置展开动效
91 EffectTop = 0x04, // 从上往下展开
92 EffectBottom = 0x08, // 从下往上展开
93 EffectOut = 0x10 // 由外向内
94 };
95
96 Q_ENUM(EffectScene)
97 Q_ENUM(EffectType)
98 Q_DECLARE_FLAGS(EffectScenes, EffectScene)
99 Q_DECLARE_FLAGS(EffectTypes, EffectType)
100 Q_ENUM(EffectScenes)
101 Q_ENUM(EffectTypes)
102
103 static bool setWindowBlurAreaByWM(QWindow *window, const QVector<WMBlurArea> &area);
104 static bool setWindowBlurAreaByWM(QWindow *window, const QList<QPainterPath> &paths);
105 static bool setWindowWallpaperParaByWM(QWindow *window, const QRect &area, WallpaperScaleMode sMode, WallpaperFillMode fMode);
106 static bool connectWindowManagerChangedSignal(QObject *object, std::function<void ()> slot);
107 static bool connectHasBlurWindowChanged(QObject *object, std::function<void ()> slot);
108
109 bool setWindowBlurAreaByWM(const QVector<WMBlurArea> &area);
110 bool setWindowBlurAreaByWM(const QList<QPainterPath> &paths);
111
112 static void setDisableWindowOverrideCursor(QWindow *window, bool disable);
113
114 int windowRadius() const;
115
116 int borderWidth() const;
117 QColor borderColor() const;
118
119 int shadowRadius() const;
120 QPoint shadowOffset() const;
121 QColor shadowColor() const;
122
123 EffectScene windowEffect();
124 EffectType windowStartUpEffect();
125
126 QPainterPath clipPath() const;
127 QRegion frameMask() const;
128 QMargins frameMargins() const;
129
130 bool translucentBackground() const;
131 bool enableSystemResize() const;
132 bool enableSystemMove() const;
133 bool enableBlurWindow() const;
134 bool autoInputMaskByClipPath() const;
135
136 WId realWindowId() const;
137 static WId windowLeader();
138
139public Q_SLOTS:
140 void setWindowRadius(int windowRadius);
141 void setBorderWidth(int borderWidth);
142 void setBorderColor(const QColor &borderColor);
143
144 void setWindowEffect(EffectScenes effectScene);
145 void setWindowStartUpEffect(EffectTypes effectType);
146
147 void setShadowRadius(int shadowRadius);
148 void setShadowOffset(const QPoint &shadowOffset);
149 void setShadowColor(const QColor &shadowColor);
150
151 void setClipPath(const QPainterPath &clipPath);
152 void setFrameMask(const QRegion &frameMask);
153
154 void setTranslucentBackground(bool translucentBackground);
155 void setEnableSystemResize(bool enableSystemResize);
156 void setEnableSystemMove(bool enableSystemMove);
157 void setEnableBlurWindow(bool enableBlurWindow);
158 void setAutoInputMaskByClipPath(bool autoInputMaskByClipPath);
159
160Q_SIGNALS:
168 void windowEffectChanged();
169 void windowStartUpEffectChanged();
177
178protected:
179 bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
180
181private:
182 QWindow *m_window;
183};
184
185inline DPlatformHandle::WMBlurArea dMakeWMBlurArea(quint32 x, quint32 y, quint32 width, quint32 height, quint32 xr = 0, quint32 yr = 0)
186{
188
189 a.x = x;
190 a.y = y;
191 a.width = width;
192 a.height = height;
193 a.xRadius = xr;
194 a.yRaduis = yr;
195
196 return a;
197}
198
199DGUI_END_NAMESPACE
200
201QT_BEGIN_NAMESPACE
202DGUI_USE_NAMESPACE
203QDebug operator<<(QDebug deg, const DPlatformHandle::WMBlurArea &area);
204QT_END_NAMESPACE
205
206#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
207Q_DECLARE_METATYPE(QPainterPath)
208Q_DECLARE_METATYPE(QMargins)
209#endif
210Q_DECLARE_METATYPE(QRegion)
211Q_DECLARE_OPERATORS_FOR_FLAGS(DPlatformHandle::EffectScenes)
212Q_DECLARE_OPERATORS_FOR_FLAGS(DPlatformHandle::EffectTypes)
213
214#endif // DPLATFORMHANDLE_H
一个和Qt dxcb平台插件交互的工具类.
Definition dplatformhandle.h:24
static void enableDXcbForWindow(QWindow *window)
DPlatformHandle::enableDXcbForWindow 将 QWindow 的窗口装饰设置为 DTK 风格,这将使用 Qt::FramelessWindowHint 去除本地窗口管理器...
Definition dplatformhandle.cpp:476
void translucentBackgroundChanged()
信号会在 translucentBackground 属性的值改变时被发送
static bool setWindowWallpaperParaByWM(QWindow *window, const QRect &area, WallpaperScaleMode sMode, WallpaperFillMode fMode)
DPlatformHandle::setWindowWallpaperParaByWM 设置窗口背景壁纸,示例:
Definition dplatformhandle.cpp:701
void borderWidthChanged()
信号会在 borderWidth 属性的值改变时被发送
int windowRadius
窗口的圆角半径。默认情况下,窗口管理器支持混成时,圆角半径为4,否则为0,并且 会随着窗口管理器开启/关闭混成效果而变化
Definition dplatformhandle.h:27
static bool connectWindowManagerChangedSignal(QObject *object, std::function< void()> slot)
DPlatformHandle::connectWindowManagerChangedSignal 将窗口管理器变化的信号链接到 object 对象的 slot 槽,建议使用 DWindowManag...
Definition dplatformhandle.cpp:720
static bool isDXcbPlatform()
DPlatformHandle::isDXcbPlatform 检查当前程序是否使用了dxcb平台插件。
Definition dplatformhandle.cpp:376
QRegion frameMask
设置 Frame Window 的遮罩,和 clipPath 不同的是,它的裁剪包括阴影 部分。示例:
Definition dplatformhandle.h:36
bool translucentBackground
如果此属性值为 true,则在更新窗口绘制内容之前会先清空要更新区域内的图像, 否则不清空,默认为 false
Definition dplatformhandle.h:38
QColor shadowColor
窗口阴影的颜色。默认为 QColor(0, 0, 0, 255 * 0.6)
Definition dplatformhandle.h:32
static bool isEnabledNoTitlebar(const QWindow *window)
DPlatformHandle::isEnableNoTitlebar window
Definition dplatformhandle.cpp:547
void borderColorChanged()
信号会在 borderColor 属性的值改变时被发送
void autoInputMaskByClipPathChanged()
信号会在 autoInputMaskByClipPath 属性的值改变时被发送
bool enableBlurWindow
如果此属性为 true,则窗口有效区域内的背景将呈现出模糊效果,否则无特效。 默认为 false
Definition dplatformhandle.h:41
bool enableSystemMove
如果此属性值为 ture,则允许外界移动窗口的位置(如使用鼠标拖拽移动窗口), 否则不允许。默认为 true
Definition dplatformhandle.h:40
void shadowRadiusChanged()
信号会在 shadowRadius 属性的值改变时被发送
void enableBlurWindowChanged()
信号会在 enableBlurWindow 属性的值改变时被发送
void frameMarginsChanged()
信号会在 frameMargins 属性的值改变时被发送.
static void setDisableWindowOverrideCursor(QWindow *window, bool disable)
DPlatformHandle::setDisableWindowOverrideCursor 如果 disable 为 true,则禁止窗口 window 改变光标样式,否则允许改变光标样式。 窗口被...
Definition dplatformhandle.cpp:778
void windowRadiusChanged()
信号会在 windowRadius 属性的值改变时被发送
QMargins frameMargins
Sub Window 相对于 Frame Window 的边距
Definition dplatformhandle.h:37
void enableSystemMoveChanged()
信号会在 enableSystemMove 属性的值改变时被发送
static bool setEnabledNoTitlebarForWindow(QWindow *window, bool enable)
DPlatformHandle::setEnabledNoTitlebarForWindow.
Definition dplatformhandle.cpp:534
void shadowColorChanged()
信号会在 shadowColor 属性的值改变时被发送
static QString pluginVersion()
DPlatformHandle::pluginVersion
Definition dplatformhandle.cpp:363
int shadowRadius
窗口的阴影半径。默认为 60
Definition dplatformhandle.h:30
void shadowOffsetChanged()
信号会在 shadowOffset 属性的值改变时被发送
int borderWidth
窗口的外边框宽度。默认情况下,窗口管理器支持混成时,边框宽度为1,否则对于可以 改变大小的窗口其值为2,否则为1,并且会随着窗口管理器开启/关闭混成效果而变化
Definition dplatformhandle.h:28
QPainterPath clipPath
窗口的裁剪区域。处于路径内部的区域为窗口有效区域,非有效区域内的窗口内容 将无法显示,并且无法收到鼠标和触摸事件。示例:
Definition dplatformhandle.h:35
WId realWindowId
Sub Window 的窗口 id,直接使用 QWindow::winId 或 QWidget::winId 获取到的是 Frame Window 的窗口 id
Definition dplatformhandle.h:43
bool autoInputMaskByClipPath
如果此属性值为 true,则窗口可输入区域跟随其 clipPath 属性,否则不 跟随。默认为 true
Definition dplatformhandle.h:42
void frameMaskChanged()
信号会在 frameMask 属性的值改变时被发送
static bool connectHasBlurWindowChanged(QObject *object, std::function< void()> slot)
DPlatformHandle::connectHasBlurWindowChanged 将窗口管理器是否支持背景模糊的信号链接到 object 对象的 slot 槽,建议使用 DWindowManag...
Definition dplatformhandle.cpp:737
void enableSystemResizeChanged()
信号会在 enableSystemResize 属性的值改变时被发送
bool enableSystemResize
如果此属性值为 true,则允许外界改变窗口的大小(如使用鼠标拖拽窗口边框), 否则不允许。默认为 true
Definition dplatformhandle.h:39
void clipPathChanged()
信号会在 clipPath 属性的值改变时被发送
QPoint shadowOffset
窗口阴影的偏移量。默认为 QPoint(0,16)
Definition dplatformhandle.h:31
static bool isEnabledDXcb(const QWindow *window)
DPlatformHandle::isEnabledDXcb.
Definition dplatformhandle.cpp:515
QColor borderColor
窗口外边框的颜色。默认情况下,窗口管理器支持混成时,颜色为 QColor(0, 0, 0, 255 * 0.15), 否则为边框颜色和 #e0e0e0 的混合,并且会随着窗口管理器开启/关闭混成效果而变...
Definition dplatformhandle.h:29
描述窗口背景模糊区域的数据结构,包含位置、大小、圆角半径等信息.
Definition dplatformhandle.h:59