Debian Codegraph @

kysdk-qtwidgets/src/klabel.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: Zhenyu Wang <[email protected]>
20 *
21 */
22
23 #ifndef KLABEL_H
24 #define KLABEL_H
25
26 #include "gui_g.h"
27 #include <QLabel>
28
29 namespace kdk
30 {
31
32 /**
33 * @defgroup LabelModule
34 * {
35 */
36
37 enum KLabelType {
38 NormalType,
39 DataType,
40 CircleType
41 };
42
43 class KLabelPrivate;
44
45 /**
46 * @brief 继承qlabel
47 * @since 2.4.1.0
48 */
49 class GUI_EXPORT KLabel : public QLabel
50 {
51 Q_OBJECT
52 public:
53 KLabel(QWidget *parent = nullptr);
54
55 /**
56 * @brief 设置label类型,NormalType和IconAndTextType
57 * @param type
58 */
59 void setLabelType(KLabelType type = KLabelType::DataType);
60
61 /**
62 * @brief 设置是否启用文本/图标高亮色
63 * @param flag
64 */
65 void setDataHightColor(bool flag);
66
67 /**
68 * @brief 设置图标pixmap
69 * @param pixmap
70 */
71 void setPixmap(const QPixmap &pixmap);
72
73 /**
74 * @brief 设置图标icon
75 * @param icon
76 * @since 2.5.2.0-0k0.3
77 */
78 void setPixmap(QIcon icon, int width, int height);
79
80 /**
81 * @brief 获取图标
82 * @return
83 */
84 const QPixmap *pixmap() const;
85
86 /**
87 * @brief 设置文本
88 * @since 2.5.2.0
89 * @param str
90 */
91 void setText(const QString &str);
92
93 /**
94 * @brief 获取文本
95 * @since 2.5.2.0
96 * @return
97 */
98 QString text();
99
100 /**
101 * @brief 设置背景颜色
102 * @param flag
103 */
104 void setBackgroundColor(bool flag, QColor color = Qt::white);
105
106 /**
107 * @brief 设置是否启用背景高亮色
108 * @since 2.5.2.0
109 * @param flag
110 */
111 void setHighlightBackground(bool flag);
112
113 /**
114 * @brief 设置圆角
115 * @param bottomLeft
116 * @param topLeft
117 * @param topRight
118 * @param bottomRight
119 */
120 void setBorderRadius(int bottomLeft, int topLeft, int topRight, int bottomRight);
121
122 /**
123 * @brief 设置圆角
124 * @param radius
125 */
126 void setBorderRadius(int radius);
127
128 /**
129 * @brief 设置是否启用换行
130 * @since 2.5.2.0
131 * @param flag
132 */
133 void setWordWrap(bool flag);
134
135 /**
136 * @brief 获取是否启用换行
137 * @since 2.5.2.0
138 * @return
139 */
140 bool wordWrap();
141
142 /**
143 * @brief 设置字体颜色
144 * @param color
145 * @since 2.5.2.0
146 */
147 void setFontColor(QColor color);
148
149 /**
150 * @brief 设置字体颜色colorRole
151 * @param role
152 * @since 3.0.1.0
153 */
154 void setFontColorRole(QPalette::ColorRole role); // lightlabel
155
156 /**
157 * @brief 设置三态是否开启
158 * @param flag
159 * @since 3.0.1.0
160 */
161 void setTristate(bool flag); // tristatelabel
162
163 /**
164 * @brief 获取三态是否开启
165 * @return
166 * @since 3.0.1.0
167 */
168 bool isTristate();
169
170 Q_SIGNALS:
171 /**
172 * @brief 鼠标进入信号
173 * @since 3.0.1.0
174 */
175 void enterWidget(); // iconlabel
176
177 /**
178 * @brief 鼠标离开信号
179 * @since 3.0.1.0
180 */
181 void leaveWidget();
182
183 /**
184 * @brief 鼠标点击信号
185 * @param clicked
186 * @since 3.0.1.0
187 */
188 void clicked(bool clicked); // eyelabel
189
190 /**
191 * @brief 鼠标双击信号
192 * @since 3.0.1.0
193 */
194 void doubleClicked();
195
196 protected:
197 void paintEvent(QPaintEvent *event);
198 QSize sizeHint() const;
199 void resizeEvent(QResizeEvent *event);
200 virtual void enterEvent(QEnterEvent *event);
201 virtual void leaveEvent(QEvent *event);
202 void mousePressEvent(QMouseEvent *event);
203 void mouseReleaseEvent(QMouseEvent *event);
204 void mouseDoubleClickEvent(QMouseEvent *event);
205
206 private:
207 Q_DECLARE_PRIVATE(KLabel)
208 KLabelPrivate *const d_ptr;
209 };
210
211 }
212 #endif // KLABEL_H