Debian Codegraph @

kysdk-qtwidgets/src/ktag.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 KTAG_H
24 #define KTAG_H
25
26 #include "gui_g.h"
27 #include <QPushButton>
28
29 namespace kdk
30 {
31 /**
32 * @defgroup TagModule
33 * {
34 */
35 class KTagPrivate;
36
37 /**
38 * @brief 支持四种风格的tag
39 */
40 enum TagStyle {
41 HighlightTag,
42 BoderTag,
43 BaseBoderTag,
44 GrayTag,
45 IconTag
46 };
47
48 /**
49 * @brief 提供四种样式的标签,响应系统主题色变化
50 * @since 1.0.0
51 */
52 class GUI_EXPORT KTag : public QPushButton
53 {
54 Q_OBJECT
55
56 public:
57 explicit KTag(QWidget *parent = nullptr);
58 /**
59 * @brief 设置关闭按钮是否可见
60 */
61 void setClosable(bool);
62 /**
63 * @brief 返回关闭按钮是否可见
64 * @return bool
65 */
66 bool closable();
67 /**
68 * @brief 设置文本
69 */
70 void setText(const QString &);
71 /**
72 * @brief 获取当前文本
73 * @return QString
74 */
75 QString text();
76
77 /**
78 * @brief 设置tag样式
79 */
80 void setTagStyle(TagStyle);
81 /**
82 * @brief 获取当前tag样式
83 * @return TagStyle
84 */
85 TagStyle tagStyle();
86
87 /**
88 * @brief 设置背景颜色
89 * @param flag
90 * @since 2.4.1.0
91 */
92 void setBackgroundColor(QColor color);
93
94 /**
95 * @brief 设置半透明
96 * @param flag
97 * @since 2.4.1.0
98 */
99 void setTranslucent(bool flag);
100
101 /**
102 * @brief 获取是否启用半透明
103 * @return bool
104 * @since 2.4.1.0
105 */
106 bool translucent();
107
108 protected:
109 void paintEvent(QPaintEvent *event);
110 QSize sizeHint() const override;
111
112 private:
113 Q_DECLARE_PRIVATE(KTag)
114 KTagPrivate *const d_ptr;
115 };
116 }
117
118 #endif // KTAG_H