Debian Codegraph @

kysdk-qtwidgets/src/kwidget.h

raw
1 /*
2 * libkysdk-qtwidgets's Library
3 *
4 * Copyright (C) 2023, KylinSoft Co., Ltd.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this library. If not, see <https://www.gnu.org/licenses/>.
18 *
19 * Authors: Zhen Sun <[email protected]>
20 *
21 */
22
23 #ifndef KWIDGET_H
24 #define KWIDGET_H
25
26 #include "kiconbar.h"
27 #include "kwindowbuttonbar.h"
28 #include <QEvent>
29 #include <QIcon>
30 #include <QWidget>
31
32 namespace kdk
33 {
34 /**
35 * @brief 支持切换三种结构布局
36 */
37 enum LayoutType {
38 VerticalType, // 上下结构
39 HorizontalType, // 左右结构
40 MixedType // 过渡结构
41 };
42
43 /** @defgroup FrameModule
44 * @{
45 */
46
47 class KWidgetPrivate;
48 /**
49 * @brief 继承自QWidget,支持响应主题背景切换,图标主题切换,标题颜色响应窗口激活状态,内容区域分为side区和base区
50 * @since 1.0.0
51 */
52 class GUI_EXPORT KWidget : public QWidget, public ThemeController
53 {
54 Q_OBJECT
55
56 public:
57 explicit KWidget(QWidget *parent = nullptr);
58 ~KWidget();
59
60 /**
61 * @brief 设置窗体图标
62 * @param icon
63 */
64 void setIcon(const QIcon &icon);
65
66 /**
67 * @brief 设置窗体图标
68 * @param iconName 直接指定系统目录中的图标名称,如"kylin-music"
69 */
70 void setIcon(const QString &iconName);
71
72 /**
73 * @brief 设置窗体名称
74 * @param widgetName
75 */
76 void setWidgetName(const QString &widgetName);
77
78 /**
79 * @brief 获取左边栏widget,通过setlayout添加自定义内容
80 * @return 返回左边栏widget
81 */
82 QWidget *sideBar();
83
84 /**
85 * @brief 获取主内容区widget,通过setlayout添加自定义内容
86 * @return 返回主内容区widget
87 */
88 QWidget *baseBar();
89
90 /**
91 * @brief 获取窗口三联组合控件,以控制是否显示最大化、最小化按钮和下拉菜单按钮;也可增加自定义按钮
92 * @return 返回窗口三联组合控件
93 */
94 KWindowButtonBar *windowButtonBar();
95
96 /**
97 * @brief 获取窗口标题、图标组合控件,以控制相关样式
98 * @return 返回窗口标题、图标组合控件
99 */
100 KIconBar *iconBar();
101
102 /**
103 * @brief 设置布局结构类型
104 */
105 void setLayoutType(LayoutType type);
106
107 /**
108 * @brief 设置窗口标志
109 * @param type
110 * @since 1.2.0
111 */
112 void setWindowFlags(Qt::WindowFlags type);
113
114 /**
115 * @brief 设置窗口标志
116 * @param flag
117 * @param on
118 * @since 1.2.0
119 */
120 void setWindowFlag(Qt::WindowType flag, bool on = true);
121
122 /**
123 * @brief 设置sidebar是否遵循系统更改宽度
124 * @param flag
125 * @since 1.2.0
126 */
127 void setSidebarFollowMode(bool flag);
128
129 /**
130 * @brief 返回sidebar是否遵循系统更改宽度
131 * @return
132 * @since 1.2.0
133 */
134 bool sidebarFollowMode();
135
136 protected:
137 bool eventFilter(QObject *target, QEvent *event) override;
138 virtual void changeIconStyle();
139 virtual void changeTheme();
140
141 private:
142 Q_DECLARE_PRIVATE(KWidget)
143 KWidgetPrivate *const d_ptr;
144 };
145
146 }
147 /**
148 * @example testWidget/testwidget.h
149 * @example testWidget/testwidget.cpp
150 * @}
151 */
152 #endif // KWIDGET_H