Debian Codegraph @

kysdk-qtwidgets/src/kpushbutton.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: Xiangwei Liu <[email protected]>
20 *
21 */
22
23 #ifndef KPUSHBUTTON_H
24 #define KPUSHBUTTON_H
25
26 #include "gui_g.h"
27 #include <QPushButton>
28 #include <QWidget>
29
30 namespace kdk
31 {
32
33 /**
34 * @defgroup PushbuttonModule
35 * {
36 */
37 class KPushButtonPrivate;
38
39 /**
40 * @brief 1.提供半透明效果
41 * 2.可以设置按钮圆角、背景色、图标是否跟随系统高亮
42 * 3.可以设置按钮类型,分为正常类型和圆形(需要设置大小实现正圆),其余同QPushButton
43 * @since 1.2.0
44 */
45
46 class GUI_EXPORT KPushButton : public QPushButton
47 {
48 Q_OBJECT
49 public:
50 /**
51 * @brief 支持两种样式的按钮
52 */
53 enum ButtonType {
54 NormalType,
55 CircleType,
56 GrayType,
57 ShadowType
58 };
59
60 enum ArrowDirection {
61 ArrowTop,
62 ArrowBottom,
63 ArrowLeft,
64 ArrowRight
65 };
66
67 KPushButton(QWidget *parent = nullptr);
68
69 ~KPushButton();
70
71 /**
72 * @brief 设置按钮圆角
73 * 通过圆角半径设置按钮圆角(每个圆角相同)
74 * @param radius
75 */
76 void setBorderRadius(int radius);
77
78 /**
79 * @brief 设置按钮圆角
80 * 通过四个点来设置圆角
81 * @param bottomLeft(左下)
82 * @param topLeft(左上)
83 * @param topRight(右上)
84 * @param bottomRight(右下)
85 */
86 void setBorderRadius(int bottomLeft, int topLeft, int topRight, int bottomRight);
87
88 /**
89 * @brief 获取按钮圆角
90 * @return radius
91 */
92 int borderRadius();
93
94 /**
95 * @brief 设置按钮背景色
96 * @param color
97 */
98 void setBackgroundColor(QColor color);
99
100 /**
101 * @brief 获取按钮背景色
102 * @return color
103 */
104 QColor backgroundColor();
105
106 /**
107 * @brief 设置KPushButton的类型
108 * @param type
109 */
110 void setButtonType(ButtonType type);
111
112 /**
113 * @brief 获取KPushButton的类型
114 * @return
115 */
116 ButtonType buttonType();
117
118 /**
119 * @brief 设置KPushButton是否为半透明
120 * @param flag
121 */
122 void setTranslucent(bool flag);
123
124 /**
125 * @brief 判断KPushButton是否为半透明
126 * @return
127 */
128 bool isTranslucent();
129
130 /**
131 * @brief 设置图标是否跟随系统高亮色,默认不跟随
132 * @param flag
133 */
134 void setIconHighlight(bool flag);
135
136 /**
137 * @brief 判断图标是否跟随系统高亮色
138 * @return
139 */
140 bool isIconHighlight();
141
142 /**
143 * @brief 设置按钮添加图标的颜色
144 * @param color
145 */
146 void setIconColor(QColor color);
147
148 /**
149 * @brief 获取按钮添加图标的颜色
150 * @return
151 */
152 QColor IconColor();
153
154 /**
155 * @brief 设置按钮背景色是否跟随系统高亮色,默认不跟随
156 * @param flag
157 */
158 void setBackgroundColorHighlight(bool flag);
159
160 /**
161 * @brief 判断按钮背景色是否跟随系统高亮色
162 * @return
163 */
164 bool isBackgroundColorHighlight();
165
166 /**
167 * @brief 设置是否显示箭头flag,设置箭头方向arrowDirection
168 * @param flag
169 * @param arrowDirection
170 * @since 2.4.1.0
171 */
172 void setArrow(bool flag, ArrowDirection arrowDirection = ArrowBottom);
173
174 /**
175 * @brief 返回是否显示箭头
176 * @return bool
177 * @since 2.4.1.0
178 */
179 bool hasArrow() const;
180
181 /**
182 * @brief 设置加载样式
183 * @param flag
184 * @since 2.5.2.0
185 */
186 void setLoaingStatus(bool flag);
187
188 /**
189 * @brief 返回加载样式
190 * @return
191 * @since 2.5.2.0
192 */
193 bool isLoading();
194
195 protected:
196 bool eventFilter(QObject *watched, QEvent *event);
197 void paintEvent(QPaintEvent *event);
198
199 private:
200 Q_DECLARE_PRIVATE(KPushButton)
201 KPushButtonPrivate *const d_ptr;
202 };
203
204 }
205
206 #endif // KPUSHBUTTON_H