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
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);
47
48 static QString pluginVersion();
49 static bool isDXcbPlatform();
50
51 static void enableDXcbForWindow(QWindow *window);
52 static void enableDXcbForWindow(QWindow *window, bool redirectContent);
53 static bool isEnabledDXcb(const QWindow *window);
54
55 static bool setEnabledNoTitlebarForWindow(QWindow *window, bool enable);
56 static bool isEnabledNoTitlebar(const QWindow *window);
57
58 struct WMBlurArea {
59 qint32 x = 0;
60 qint32 y = 0;
61 qint32 width = 0;
62 qint32 height = 0;
63 qint32 xRadius = 0;
64 qint32 yRaduis = 0;
65 };
66
67 enum WallpaperScaleMode {
68 FollowScreen = 0x00000000,
69 FollowWindow = 0x00010000
70 };
71
72 enum WallpaperFillMode {
73 PreserveAspectCrop = 0x00000000,
74 PreserveAspectFit = 0x00000001
75 };
76
77 enum EffectScene {
78 EffectNoRadius = 0x01, // 取消窗口圆角
79 EffectNoShadow = 0x02, // 取消窗口阴影
80 EffectNoBorder = 0x04, // 取消窗口边框
81 EffectNoStart = 0x10, // 取消启动场景动效
82 EffectNoClose = 0x20, // 取消关闭场景动效
83 EffectNoMaximize = 0x40, // 取消最大化场景动效
84 EffectNoMinimize = 0x80 // 取消最小化场景动效
85 };
86
87 enum EffectType {
88 EffectNormal = 0x01, // 标准缩放动效
89 EffectCursor = 0x02, // 鼠标位置展开动效
90 EffectTop = 0x04, // 从上往下展开
91 EffectBottom = 0x08, // 从下往上展开
92 EffectOut = 0x10 // 由外向内
93 };
94
95 Q_ENUM(EffectScene)
96 Q_ENUM(EffectType)
97 Q_DECLARE_FLAGS(EffectScenes, EffectScene)
98 Q_DECLARE_FLAGS(EffectTypes, EffectType)
99 Q_ENUM(EffectScenes)
100 Q_ENUM(EffectTypes)
101
102 static bool setWindowBlurAreaByWM(QWindow *window, const QVector<WMBlurArea> &area);
103 static bool setWindowBlurAreaByWM(QWindow *window, const QList<QPainterPath> &paths);
104 static bool setWindowWallpaperParaByWM(QWindow *window, const QRect &area, WallpaperScaleMode sMode, WallpaperFillMode fMode);
105 static bool connectWindowManagerChangedSignal(QObject *object, std::function<void ()> slot);
106 static bool connectHasBlurWindowChanged(QObject *object, std::function<void ()> slot);
107
108 bool setWindowBlurAreaByWM(const QVector<WMBlurArea> &area);
109 bool setWindowBlurAreaByWM(const QList<QPainterPath> &paths);
110
111 static void setDisableWindowOverrideCursor(QWindow *window, bool disable);
112
113 int windowRadius() const;
114
115 int borderWidth() const;
116 QColor borderColor() const;
117
118 int shadowRadius() const;
119 QPoint shadowOffset() const;
120 QColor shadowColor() const;
121
122 EffectScene windowEffect();
123 EffectType windowStartUpEffect();
124
125 QPainterPath clipPath() const;
126 QRegion frameMask() const;
127 QMargins frameMargins() const;
128
129 bool translucentBackground() const;
130 bool enableSystemResize() const;
131 bool enableSystemMove() const;
132 bool enableBlurWindow() const;
133 bool autoInputMaskByClipPath() const;
134
135 WId realWindowId() const;
136 static WId windowLeader();
137
138public Q_SLOTS:
139 void setWindowRadius(int windowRadius);
140 void setBorderWidth(int borderWidth);
141 void setBorderColor(const QColor &borderColor);
142
143 void setWindowEffect(EffectScenes effectScene);
144 void setWindowStartUpEffect(EffectTypes effectType);
145
146 void setShadowRadius(int shadowRadius);
147 void setShadowOffset(const QPoint &shadowOffset);
148 void setShadowColor(const QColor &shadowColor);
149
150 void setClipPath(const QPainterPath &clipPath);
151 void setFrameMask(const QRegion &frameMask);
152
153 void setTranslucentBackground(bool translucentBackground);
154 void setEnableSystemResize(bool enableSystemResize);
155 void setEnableSystemMove(bool enableSystemMove);
156 void setEnableBlurWindow(bool enableBlurWindow);
157 void setAutoInputMaskByClipPath(bool autoInputMaskByClipPath);
158
159Q_SIGNALS:
167 void windowEffectChanged();
168 void windowStartUpEffectChanged();
176
177protected:
178 bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
179
180private:
181 QWindow *m_window;
182};
183
184inline DPlatformHandle::WMBlurArea dMakeWMBlurArea(quint32 x, quint32 y, quint32 width, quint32 height, quint32 xr = 0, quint32 yr = 0)
185{
187
188 a.x = x;
189 a.y = y;
190 a.width = width;
191 a.height = height;
192 a.xRadius = xr;
193 a.yRaduis = yr;
194
195 return a;
196}
197
198DGUI_END_NAMESPACE
199
200QT_BEGIN_NAMESPACE
201DGUI_USE_NAMESPACE
202QDebug operator<<(QDebug deg, const DPlatformHandle::WMBlurArea &area);
203QT_END_NAMESPACE
204
205#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
206Q_DECLARE_METATYPE(QPainterPath)
207Q_DECLARE_METATYPE(QMargins)
208#endif
209Q_DECLARE_METATYPE(QRegion)
210Q_DECLARE_OPERATORS_FOR_FLAGS(DPlatformHandle::EffectScenes)
211Q_DECLARE_OPERATORS_FOR_FLAGS(DPlatformHandle::EffectTypes)
212
213#endif // DPLATFORMHANDLE_H
一个和Qt dxcb平台插件交互的工具类.
Definition dplatformhandle.h:24
static void enableDXcbForWindow(QWindow *window)
DPlatformHandle::enableDXcbForWindow 将 QWindow 的窗口装饰设置为 DTK 风格,这将使用 Qt::FramelessWindowHint 去除本地窗口管理器...
Definition dplatformhandle.cpp:519
void translucentBackgroundChanged()
信号会在 translucentBackground 属性的值改变时被发送
static bool setWindowWallpaperParaByWM(QWindow *window, const QRect &area, WallpaperScaleMode sMode, WallpaperFillMode fMode)
DPlatformHandle::setWindowWallpaperParaByWM 设置窗口背景壁纸,示例:
Definition dplatformhandle.cpp:996
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:1051
static bool isDXcbPlatform()
DPlatformHandle::isDXcbPlatform 检查当前程序是否使用了dxcb平台插件。
Definition dplatformhandle.cpp:418
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:731
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:1111
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:684
void shadowColorChanged()
信号会在 shadowColor 属性的值改变时被发送
static QString pluginVersion()
DPlatformHandle::pluginVersion
Definition dplatformhandle.cpp:400
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:1069
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:574
QColor borderColor
窗口外边框的颜色。默认情况下,窗口管理器支持混成时,颜色为 QColor(0, 0, 0, 255 * 0.15), 否则为边框颜色和 #e0e0e0 的混合,并且会随着窗口管理器开启/关闭混成效果而变...
Definition dplatformhandle.h:29
描述窗口背景模糊区域的数据结构,包含位置、大小、圆角半径等信息.
Definition dplatformhandle.h:58