| 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 KMINICALENDARWIDGET_H |
| 24 |
#define KMINICALENDARWIDGET_H |
| 25 |
|
| 26 |
#include "gui_g.h" |
| 27 |
#include "klunarcalendarinfo.h" |
| 28 |
#include "kminicalendaritem.h" |
| 29 |
#include <QComboBox> |
| 30 |
#include <QDate> |
| 31 |
#include <QLabel> |
| 32 |
#include <QToolButton> |
| 33 |
#include <QWheelEvent> |
| 34 |
#include <QWidget> |
| 35 |
|
| 36 |
namespace kdk |
| 37 |
{ |
| 38 |
class KMiniCalendarWidgetPrivate; |
| 39 |
|
| 40 |
/** |
| 41 |
* @defgroup KMiniCalendarWidget |
| 42 |
* @since 2.5.2.0 |
| 43 |
*/ |
| 44 |
|
| 45 |
class GUI_EXPORT KMiniCalendarWidget : public QWidget |
| 46 |
{ |
| 47 |
Q_OBJECT |
| 48 |
Q_ENUMS(CalendarStyle) |
| 49 |
Q_ENUMS(WeekNameFormat) |
| 50 |
Q_ENUMS(SelectType) |
| 51 |
|
| 52 |
Q_PROPERTY(CalendarStyle calendarStyle READ getCalendarStyle WRITE setCalendarStyle) |
| 53 |
Q_PROPERTY(WeekNameFormat weekNameFormat READ getWeekNameFormat WRITE setWeekNameFormat) |
| 54 |
Q_PROPERTY(QDate date READ getDate WRITE setDate) |
| 55 |
|
| 56 |
Q_PROPERTY(QColor weekTextColor READ getWeekTextColor WRITE setWeekTextColor) |
| 57 |
Q_PROPERTY(QColor weekBgColor READ getWeekBgColor WRITE setWeekBgColor) |
| 58 |
|
| 59 |
Q_PROPERTY(bool showLunar READ getShowLunar WRITE setShowLunar) |
| 60 |
Q_PROPERTY(bool enableBorder READ getEnableBorder WRITE setEnableBorder) |
| 61 |
Q_PROPERTY(SelectType selectType READ getSelectType WRITE setSelectType) |
| 62 |
|
| 63 |
Q_PROPERTY(QColor borderColor READ getBorderColor WRITE setBorderColor) |
| 64 |
Q_PROPERTY(QColor weekColor READ getWeekColor WRITE setWeekColor) |
| 65 |
Q_PROPERTY(QColor lunarColor READ getLunarColor WRITE setLunarColor) |
| 66 |
|
| 67 |
Q_PROPERTY(QColor currentTextColor READ getCurrentTextColor WRITE setCurrentTextColor) |
| 68 |
Q_PROPERTY(QColor otherTextColor READ getOtherTextColor WRITE setOtherTextColor) |
| 69 |
Q_PROPERTY(QColor selectTextColor READ getSelectTextColor WRITE setSelectTextColor) |
| 70 |
Q_PROPERTY(QColor hoverTextColor READ getHoverTextColor WRITE setHoverTextColor) |
| 71 |
|
| 72 |
Q_PROPERTY(QColor currentLunarColor READ getCurrentLunarColor WRITE setCurrentLunarColor) |
| 73 |
Q_PROPERTY(QColor otherLunarColor READ getOtherLunarColor WRITE setOtherLunarColor) |
| 74 |
Q_PROPERTY(QColor selectLunarColor READ getSelectLunarColor WRITE setSelectLunarColor) |
| 75 |
Q_PROPERTY(QColor hoverLunarColor READ getHoverLunarColor WRITE setHoverLunarColor) |
| 76 |
|
| 77 |
Q_PROPERTY(QColor currentBgColor READ getCurrentBgColor WRITE setCurrentBgColor) |
| 78 |
Q_PROPERTY(QColor otherBgColor READ getOtherBgColor WRITE setOtherBgColor) |
| 79 |
Q_PROPERTY(QColor selectBgColor READ getSelectBgColor WRITE setSelectBgColor) |
| 80 |
Q_PROPERTY(QColor hoverBgColor READ getHoverBgColor WRITE setHoverBgColor) |
| 81 |
|
| 82 |
public: |
| 83 |
enum CalendarStyle { |
| 84 |
CalendarStyle_Red = 0 |
| 85 |
}; |
| 86 |
|
| 87 |
enum WeekNameFormat { |
| 88 |
WeekNameFormat_Short = 0, // 短名称模式 |
| 89 |
WeekNameFormat_Normal = 1, // 普通名称模式 |
| 90 |
WeekNameFormat_Long = 2, // 长名称模式 |
| 91 |
WeekNameFormat_En = 3 // 英文模式 |
| 92 |
}; |
| 93 |
|
| 94 |
enum SelectType { |
| 95 |
SelectType_Rect = 0, // 矩形背景 |
| 96 |
SelectType_Circle = 1, // 圆形背景 |
| 97 |
SelectType_Triangle = 2, // 带三角标 |
| 98 |
SelectType_Image = 3 // 图片背景 |
| 99 |
}; |
| 100 |
|
| 101 |
explicit KMiniCalendarWidget(QWidget *parent = 0); |
| 102 |
~KMiniCalendarWidget(); |
| 103 |
|
| 104 |
public: |
| 105 |
/** |
| 106 |
* @brief 获取整体样式 |
| 107 |
* @return |
| 108 |
*/ |
| 109 |
CalendarStyle getCalendarStyle() const; |
| 110 |
|
| 111 |
/** |
| 112 |
* @brief 获取星期名称格式 |
| 113 |
* @return |
| 114 |
*/ |
| 115 |
WeekNameFormat getWeekNameFormat() const; |
| 116 |
|
| 117 |
/** |
| 118 |
* @brief 获取当前日期 |
| 119 |
* @return |
| 120 |
*/ |
| 121 |
QDate getDate() const; |
| 122 |
|
| 123 |
/** |
| 124 |
* @brief 获取星期文本颜色 |
| 125 |
* @return |
| 126 |
*/ |
| 127 |
QColor getWeekTextColor() const; |
| 128 |
|
| 129 |
/** |
| 130 |
* @brief 获取周末名称背景色 |
| 131 |
* @return |
| 132 |
*/ |
| 133 |
QColor getWeekBgColor() const; |
| 134 |
|
| 135 |
/** |
| 136 |
* @brief 获取农历显示 |
| 137 |
* @return |
| 138 |
*/ |
| 139 |
bool getShowLunar() const; |
| 140 |
|
| 141 |
/** |
| 142 |
* @brief 获取启用边框 |
| 143 |
* @return |
| 144 |
*/ |
| 145 |
bool getEnableBorder() const; |
| 146 |
|
| 147 |
/** |
| 148 |
* @brief 获取选择类型 |
| 149 |
* @return |
| 150 |
*/ |
| 151 |
SelectType getSelectType() const; |
| 152 |
|
| 153 |
/** |
| 154 |
* @brief 获取边框颜色 |
| 155 |
* @return |
| 156 |
*/ |
| 157 |
QColor getBorderColor() const; |
| 158 |
|
| 159 |
/** |
| 160 |
* @brief 获取周末颜色 |
| 161 |
* @return |
| 162 |
*/ |
| 163 |
QColor getWeekColor() const; |
| 164 |
|
| 165 |
/** |
| 166 |
* @brief 获取农历节日颜色 |
| 167 |
* @return |
| 168 |
*/ |
| 169 |
QColor getLunarColor() const; |
| 170 |
|
| 171 |
/** |
| 172 |
* @brief 获取当前月文本颜色 |
| 173 |
* @return |
| 174 |
*/ |
| 175 |
QColor getCurrentTextColor() const; |
| 176 |
|
| 177 |
/** |
| 178 |
* @brief 获取其他月文本颜色 |
| 179 |
* @return |
| 180 |
*/ |
| 181 |
QColor getOtherTextColor() const; |
| 182 |
|
| 183 |
/** |
| 184 |
* @brief 获取选中日期文本颜色 |
| 185 |
* @return |
| 186 |
*/ |
| 187 |
QColor getSelectTextColor() const; |
| 188 |
|
| 189 |
/** |
| 190 |
* @brief 获取悬浮日期文本颜色 |
| 191 |
* @return |
| 192 |
*/ |
| 193 |
QColor getHoverTextColor() const; |
| 194 |
|
| 195 |
/** |
| 196 |
* @brief 获取当前月农历文字颜色 |
| 197 |
* @return |
| 198 |
*/ |
| 199 |
QColor getCurrentLunarColor() const; |
| 200 |
|
| 201 |
/** |
| 202 |
* @brief 获取其他月农历文本颜色 |
| 203 |
* @return |
| 204 |
*/ |
| 205 |
QColor getOtherLunarColor() const; |
| 206 |
|
| 207 |
/** |
| 208 |
* @brief 获取选中日期农历颜文本色 |
| 209 |
* @return |
| 210 |
*/ |
| 211 |
QColor getSelectLunarColor() const; |
| 212 |
|
| 213 |
/** |
| 214 |
* @brief 获取悬浮日期农历文本颜色 |
| 215 |
* @return |
| 216 |
*/ |
| 217 |
QColor getHoverLunarColor() const; |
| 218 |
|
| 219 |
/** |
| 220 |
* @brief 获取当前月背景色 |
| 221 |
* @return |
| 222 |
*/ |
| 223 |
QColor getCurrentBgColor() const; |
| 224 |
|
| 225 |
/** |
| 226 |
* @brief 获取其他月背景色 |
| 227 |
* @return |
| 228 |
*/ |
| 229 |
QColor getOtherBgColor() const; |
| 230 |
|
| 231 |
/** |
| 232 |
* @brief 获取选择日期背景色 |
| 233 |
* @return |
| 234 |
*/ |
| 235 |
QColor getSelectBgColor() const; |
| 236 |
|
| 237 |
/** |
| 238 |
* @brief 获取悬浮日期背景色 |
| 239 |
* @return |
| 240 |
*/ |
| 241 |
QColor getHoverBgColor() const; |
| 242 |
|
| 243 |
QSize sizeHint() const; |
| 244 |
QSize minimumSizeHint() const; |
| 245 |
|
| 246 |
public Q_SLOTS: |
| 247 |
// 上一月,下一月 |
| 248 |
void showPreviousMonth(); |
| 249 |
void showNextMonth(); |
| 250 |
|
| 251 |
// 转到今天 |
| 252 |
void showToday(); |
| 253 |
|
| 254 |
// 设置整体样式 |
| 255 |
void setCalendarStyle(const CalendarStyle &calendarStyle); |
| 256 |
// 设置星期名称格式 |
| 257 |
void setWeekNameFormat(const WeekNameFormat &weekNameFormat); |
| 258 |
|
| 259 |
// 设置日期 |
| 260 |
void setDate(const QDate &date); |
| 261 |
// 设置顶部星期名称文字颜色+背景色 |
| 262 |
void setWeekTextColor(const QColor &weekTextColor); |
| 263 |
void setWeekBgColor(const QColor &weekBgColor); |
| 264 |
|
| 265 |
// 设置是否显示农历信息 |
| 266 |
void setShowLunar(bool showLunar); |
| 267 |
// 是否显示边框 |
| 268 |
void setEnableBorder(bool bVisible); |
| 269 |
// 设置选中背景样式 |
| 270 |
void setSelectType(const SelectType &selectType); |
| 271 |
|
| 272 |
// 设置边框颜色 |
| 273 |
void setBorderColor(const QColor &borderColor); |
| 274 |
// 设置周末颜色 |
| 275 |
void setWeekColor(const QColor &weekColor); |
| 276 |
// 设置农历节日颜色 |
| 277 |
void setLunarColor(const QColor &lunarColor); |
| 278 |
|
| 279 |
// 设置当前月文字颜色 |
| 280 |
void setCurrentTextColor(const QColor ¤tTextColor); |
| 281 |
// 设置其他月文字颜色 |
| 282 |
void setOtherTextColor(const QColor &otherTextColor); |
| 283 |
// 设置选中日期文字颜色 |
| 284 |
void setSelectTextColor(const QColor &selectTextColor); |
| 285 |
// 设置悬停日期文字颜色 |
| 286 |
void setHoverTextColor(const QColor &hoverTextColor); |
| 287 |
|
| 288 |
// 设置当前月农历文字颜色 |
| 289 |
void setCurrentLunarColor(const QColor ¤tLunarColor); |
| 290 |
// 设置其他月农历文字颜色 |
| 291 |
void setOtherLunarColor(const QColor &otherLunarColor); |
| 292 |
// 设置选中日期农历文字颜色 |
| 293 |
void setSelectLunarColor(const QColor &selectLunarColor); |
| 294 |
// 设置悬停日期农历文字颜色 |
| 295 |
void setHoverLunarColor(const QColor &hoverLunarColor); |
| 296 |
|
| 297 |
// 设置当前月背景颜色 |
| 298 |
void setCurrentBgColor(const QColor ¤tBgColor); |
| 299 |
// 设置其他月背景颜色 |
| 300 |
void setOtherBgColor(const QColor &otherBgColor); |
| 301 |
// 设置选中日期背景颜色 |
| 302 |
void setSelectBgColor(const QColor &selectBgColor); |
| 303 |
// 设置悬停日期背景颜色 |
| 304 |
void setHoverBgColor(const QColor &hoverBgColor); |
| 305 |
|
| 306 |
protected: |
| 307 |
void wheelEvent(QWheelEvent *event) override; |
| 308 |
void paintEvent(QPaintEvent *event) override; |
| 309 |
|
| 310 |
signals: |
| 311 |
void clicked(const QDate &date); |
| 312 |
void selectionChanged(); |
| 313 |
|
| 314 |
private slots: |
| 315 |
void initWidget(); |
| 316 |
void initStyle(); |
| 317 |
void initDate(); |
| 318 |
void slotClicked(const QDate &date, const KMiniCalendarItem::DayType &dayType); |
| 319 |
void dayChanged(const QDate &date); |
| 320 |
void dateChanged(int year, int month, int day); |
| 321 |
|
| 322 |
private: |
| 323 |
Q_DECLARE_PRIVATE(KMiniCalendarWidget) |
| 324 |
KMiniCalendarWidgetPrivate *const d_ptr; |
| 325 |
}; |
| 326 |
} |
| 327 |
|
| 328 |
#endif // KMINICALENDARWIDGET_H |