Debian Codegraph @

kysdk-qtwidgets/src/kminicalendaritem.h

raw
1 /*
2 * libkysdk-qtwidgets's Library
3 *
4 * Copyright (C) 2024, 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 KMINICALENDARITEM_H
24 #define KMINICALENDARITEM_H
25
26 #include "gui_g.h"
27 #include <QDate>
28 #include <QWidget>
29
30 namespace kdk
31 {
32
33 /**
34 * @defgroup KMiniCalendarItem
35 * @since 2.5.2.0
36 */
37
38 class KMiniCalendarItemPrivate;
39 class GUI_EXPORT KMiniCalendarItem : public QWidget
40 {
41 Q_OBJECT
42 Q_ENUMS(DayType)
43 Q_ENUMS(SelectType)
44
45 Q_PROPERTY(bool select READ getSelect WRITE setSelect)
46 Q_PROPERTY(bool showLunar READ getShowLunar WRITE setShowLunar)
47 Q_PROPERTY(bool enableBorder READ getEnableBorder WRITE setEnableBorder)
48 Q_PROPERTY(SelectType selectType READ getSelectType WRITE setSelectType)
49
50 Q_PROPERTY(QDate date READ getDate WRITE setDate)
51 Q_PROPERTY(QString lunar READ getLunar WRITE setLunar)
52 Q_PROPERTY(DayType dayType READ getDayType WRITE setDayType)
53
54 Q_PROPERTY(QColor borderColor READ getBorderColor WRITE setBorderColor)
55 Q_PROPERTY(QColor weekColor READ getWeekColor WRITE setWeekColor)
56 Q_PROPERTY(QColor superColor READ getSuperColor WRITE setSuperColor)
57 Q_PROPERTY(QColor lunarColor READ getLunarColor WRITE setLunarColor)
58
59 Q_PROPERTY(QColor currentTextColor READ getCurrentTextColor WRITE setCurrentTextColor)
60 Q_PROPERTY(QColor otherTextColor READ getOtherTextColor WRITE setOtherTextColor)
61 Q_PROPERTY(QColor selectTextColor READ getSelectTextColor WRITE setSelectTextColor)
62 Q_PROPERTY(QColor hoverTextColor READ getHoverTextColor WRITE setHoverTextColor)
63
64 Q_PROPERTY(QColor currentLunarColor READ getCurrentLunarColor WRITE setCurrentLunarColor)
65 Q_PROPERTY(QColor otherLunarColor READ getOtherLunarColor WRITE setOtherLunarColor)
66 Q_PROPERTY(QColor selectLunarColor READ getSelectLunarColor WRITE setSelectLunarColor)
67 Q_PROPERTY(QColor hoverLunarColor READ getHoverLunarColor WRITE setHoverLunarColor)
68
69 Q_PROPERTY(QColor currentBgColor READ getCurrentBgColor WRITE setCurrentBgColor)
70 Q_PROPERTY(QColor otherBgColor READ getOtherBgColor WRITE setOtherBgColor)
71 Q_PROPERTY(QColor selectBgColor READ getSelectBgColor WRITE setSelectBgColor)
72 Q_PROPERTY(QColor hoverBgColor READ getHoverBgColor WRITE setHoverBgColor)
73
74 public:
75 enum DayType {
76 DayType_MonthPre = 0, // 上月剩余天数
77 DayType_MonthNext = 1, // 下个月的天数
78 DayType_MonthCurrent = 2, // 当月天数
79 DayType_WeekEnd = 3 // 周末
80 };
81
82 enum SelectType {
83 SelectType_Rect = 0, // 矩形背景
84 SelectType_Circle = 1, // 圆形背景
85 SelectType_Triangle = 2, // 带三角标
86 SelectType_Image = 3 // 图片背景
87 };
88
89 explicit KMiniCalendarItem(QWidget *parent = 0);
90
91 protected:
92 void enterEvent(QEvent *);
93 void leaveEvent(QEvent *);
94 void mousePressEvent(QMouseEvent *);
95 void mouseReleaseEvent(QMouseEvent *);
96 void paintEvent(QPaintEvent *);
97 void drawBg(QPainter *painter);
98 void drawBgCurrent(QPainter *painter, const QColor &color);
99 void drawDay(QPainter *painter);
100 void drawLunar(QPainter *painter);
101
102 public:
103 /**
104 * @brief 获取是否选中
105 * @return
106 */
107 bool getSelect() const;
108
109 /**
110 * @brief 获取是否显示农历
111 * @return
112 */
113 bool getShowLunar() const;
114
115 /**
116 * @brief 获取启用边界
117 * @return
118 */
119 bool getEnableBorder() const;
120
121 /**
122 * @brief 获取选择类型
123 * @return
124 */
125 SelectType getSelectType() const;
126
127 /**
128 * @brief 获取当前日期
129 * @return
130 */
131 QDate getDate() const;
132
133 /**
134 * @brief 获取农历信息
135 * @return
136 */
137 QString getLunar() const;
138
139 /**
140 * @brief 获取日期类型
141 * @return
142 */
143 DayType getDayType() const;
144
145 /**
146 * @brief 获取边框颜色
147 * @return
148 */
149 QColor getBorderColor() const;
150
151 /**
152 * @brief 获取周颜色
153 * @return
154 */
155 QColor getWeekColor() const;
156
157 /**
158 * @brief 获取角标颜色
159 * @return
160 */
161 QColor getSuperColor() const;
162
163 /**
164 * @brief 获取农历节日颜色
165 * @return
166 */
167 QColor getLunarColor() const;
168
169 /**
170 * @brief 获取当前月文字颜色
171 * @return
172 */
173 QColor getCurrentTextColor() const;
174
175 /**
176 * @brief 获取其他月文字颜色
177 * @return
178 */
179 QColor getOtherTextColor() const;
180
181 /**
182 * @brief 获取选中日期文字颜色
183 * @return
184 */
185 QColor getSelectTextColor() const;
186
187 /**
188 * @brief 获取悬停日期文字颜色
189 * @return
190 */
191 QColor getHoverTextColor() const;
192
193 /**
194 * @brief 获取当前月农历文字颜色
195 * @return
196 */
197 QColor getCurrentLunarColor() const;
198
199 /**
200 * @brief 获取其他月农历文字颜色
201 * @return
202 */
203 QColor getOtherLunarColor() const;
204
205 /**
206 * @brief 获取选中日期农历文字颜色
207 * @return
208 */
209 QColor getSelectLunarColor() const;
210
211 /**
212 * @brief 获取悬停日期农历文字颜色
213 * @return
214 */
215 QColor getHoverLunarColor() const;
216
217 /**
218 * @brief 获取当前月背景颜色
219 * @return
220 */
221 QColor getCurrentBgColor() const;
222
223 /**
224 * @brief 获取其他月背景颜色
225 * @return
226 */
227 QColor getOtherBgColor() const;
228
229 /**
230 * @brief 获取选中日期背景颜色
231 * @return
232 */
233 QColor getSelectBgColor() const;
234
235 /**
236 * @brief 获取悬停日期背景颜色
237 * @return
238 */
239 QColor getHoverBgColor() const;
240
241 QSize sizeHint() const;
242 QSize minimumSizeHint() const;
243
244 public Q_SLOTS:
245 // 设置是否选中
246 void setSelect(bool select);
247 // 设置是否显示农历信息
248 void setShowLunar(bool showLunar);
249 // 设置选中背景样式
250 void setSelectType(const SelectType &selectType);
251
252 // 设置日期
253 void setDate(const QDate &date);
254 // 设置农历
255 void setLunar(const QString &lunar);
256 // 设置类型
257 void setDayType(const DayType &dayType);
258 // 设置日期/农历/类型
259 void setDate(const QDate &date, const QString &lunar, const DayType &dayType);
260 // 是否显示边框
261 void setEnableBorder(bool bVisible);
262 // 设置边框颜色
263 void setBorderColor(const QColor &borderColor);
264 // 设置周末颜色
265 void setWeekColor(const QColor &weekColor);
266 // 设置角标颜色
267 void setSuperColor(const QColor &superColor);
268 // 设置农历节日颜色
269 void setLunarColor(const QColor &lunarColor);
270
271 // 设置当前月文字颜色
272 void setCurrentTextColor(const QColor &currentTextColor);
273 // 设置其他月文字颜色
274 void setOtherTextColor(const QColor &otherTextColor);
275 // 设置选中日期文字颜色
276 void setSelectTextColor(const QColor &selectTextColor);
277 // 设置悬停日期文字颜色
278 void setHoverTextColor(const QColor &hoverTextColor);
279
280 // 设置当前月农历文字颜色
281 void setCurrentLunarColor(const QColor &currentLunarColor);
282 // 设置其他月农历文字颜色
283 void setOtherLunarColor(const QColor &otherLunarColor);
284 // 设置选中日期农历文字颜色
285 void setSelectLunarColor(const QColor &selectLunarColor);
286 // 设置悬停日期农历文字颜色
287 void setHoverLunarColor(const QColor &hoverLunarColor);
288
289 // 设置当前月背景颜色
290 void setCurrentBgColor(const QColor &currentBgColor);
291 // 设置其他月背景颜色
292 void setOtherBgColor(const QColor &otherBgColor);
293 // 设置选中日期背景颜色
294 void setSelectBgColor(const QColor &selectBgColor);
295 // 设置悬停日期背景颜色
296 void setHoverBgColor(const QColor &hoverBgColor);
297
298 signals:
299 void clicked(const QDate &date, const KMiniCalendarItem::DayType &dayType);
300
301 private:
302 Q_DECLARE_PRIVATE(KMiniCalendarItem)
303 KMiniCalendarItemPrivate *const d_ptr;
304 };
305 }
306
307 #endif // KMINICALENDARITEM_H