农历日历 v1.0.4
载入中...
搜索中...
未找到
LunarCalendar.h
1
6#ifndef LUNARCALENDAR_H
7#define LUNARCALENDAR_H
8
9#include <QWidget>
10#include <QTimer>
11#include <QMap>
12#include <QDate>
13#include <QTableView>
14#include <QLabel>
15#include <QComboBox>
16#include <QToolButton>
17#include <QPushButton>
18#include <QHBoxLayout>
19#include <QVBoxLayout>
20#include <QGridLayout>
21#include <QSharedPointer>
22#include "lunarcalendar_export.h"
23
24#if defined(__clang__) || defined(__GNUC__)
25#define CPP_STANDARD __cplusplus
26#elif defined(_MSC_VER)
27#define CPP_STANDARD _MSVC_LANG
28#endif
29#if CPP_STANDARD >= 199711L
30#define HAS_CPP_03 1
31#endif
32#if CPP_STANDARD >= 201103L
33#define HAS_CPP_11 1
34#endif
35#if CPP_STANDARD >= 201402L
36#define HAS_CPP_14 1
37#endif
38#if CPP_STANDARD >= 201703L
39#define HAS_CPP_17 1
40#endif
41
42#if HAS_CPP_11
43#include <functional>
44#endif
45
237class LUNARCALENDAR_EXPORT CLunarCalendar : public QWidget
238{
239 Q_OBJECT
240 Q_PROPERTY(QDate selectedDate WRITE SetSelectedDate READ SelectedDate)
241 Q_PROPERTY(QString selectLunar READ SelectedLunar)
242 Q_PROPERTY(int showYear READ GetShowYear)
243 Q_PROPERTY(int showMonth READ GetShowMonth)
244 //Q_PROPERTY(Qt::DayOfWeek firstDayOfWeek READ FirstDayOfWeek WRITE SetFirstDayOfWeek)
245 Q_PROPERTY(QDate minimumDate READ MinimumDate WRITE SetMinimumDate)
246 Q_PROPERTY(QDate maximumDate READ MaximumDate WRITE SetMaximumDate)
247
248public:
249 explicit CLunarCalendar(QWidget *parent = nullptr);
250 virtual ~CLunarCalendar() override;
251
252 enum class _CalendarType;
253
254 static const QString Version();
255
258
266 const QDate SelectedDate() const;
279 void SetSelectedDate(const QDate &date, bool bForce = false);
283 const QString SelectedLunar() const;
288 const QString SelectedSolarTerm() const;
295 int SelectedLunar(/*out*/int &year, /*out*/int &month, /*out*/int &day);
304 static int GetLunar(/*in*/const QDate date, /*out*/int &year, /*out*/int &month, /*out*/int &day);
305
307
310
311public Q_SLOTS:
317 bool EnableHolidays(bool bEnable = true);
323 bool EnableSolarTerm(bool bEnable = true);
324
325public:
345 {
346 public:
347 CTaskHandler() {}
348 virtual ~CTaskHandler(){}
367 virtual uint onHandle(/*in*/const QDate& date,
368 /*out*/QStringList& tasks) = 0;
369 };
389 int SetTaskHandle(QSharedPointer<CTaskHandler> handler);
390
391#if HAS_CPP_11
417 virtual int SetTaskHandle(
418 std::function<uint(/*in*/const QDate& date,
419 /*out*/QStringList& tasks)> cbHandler);
420#endif
421
423
426
430 const QDate MinimumDate() const;
434 void SetMinimumDate(const QDate &date);
438 const QDate MaximumDate() const;
442 void SetMaximumDate(const QDate &date);
446 void SetDateRange(const QDate &min, const QDate &max);
447
452 const int GetShowYear() const;
457 const int GetShowMonth() const;
462 const Qt::DayOfWeek FirstDayOfWeek() const;
463 //void SetFirstDayOfWeek(Qt::DayOfWeek dayOfWeek);
464
466
469
470 enum class _HEAD_position {
471 Not = 0,
472 Top,
473 Down,
474 Left,
475 Right
476 };
482 int SetHeadposition(_HEAD_position pos = _HEAD_position::Top);
483
484public Q_SLOTS:
485
490 void ShowHead(bool bShow);
495 void ShowTools(bool bShow);
500 void ShowToday(bool bShow);
505 void ShowDate(bool bShow);
510 void ShowTime(bool bShow);
511
516 void ShowWeekHead(bool bShow);
521 void ShowWeeks(bool bShow);
522
526 void ShowGrid(bool show);
527
531 void EnableToolTip(bool show);
532
536 void ShowBackgroupImage(bool show);
537
538public:
539
541 enum class _CalendarType {
542 CalendarTypeSolar = 0x01,
543 CalendarTypeLunar = 0x02
544 };
546 int SetCalendarType(_CalendarType type);
548 const _CalendarType GetCalendarType() const;
549
551 enum class _VIEW_TYPE {
552 ViewTypeMonth,
553 ViewTypeWeek
554 };
556 int SetViewType(_VIEW_TYPE type);
558 const _VIEW_TYPE GetViewType() const;
559
564 int Update();
565
566 void setFont(const QFont& font);
567
569
570 enum class _TOUCH_UP_DOWN_FUNCTION {
571 TouchChangeView,
572 TouchChangeMounth
573 };
574 int SetTouchUpDownFunction(_TOUCH_UP_DOWN_FUNCTION f);
575
576 virtual QSize sizeHint() const override;
577 virtual QSize minimumSizeHint() const override;
578
582
590 int LoadCalendarTable(const QString& szFile);
601 int GenerateCalendarTable(const QString& szFile,
602 int nThreadNumber = 2,
603 bool bClearCache = false,
604 bool bSaveAllDate = true);
605
607
608Q_SIGNALS:
620
621private Q_SLOTS:
622 void soltShowToday();
623
624private slots:
625 void on_tbNextYear_clicked();
626 void on_tbPreviousYear_clicked();
627 void on_tbNextMonth_clicked();
628 void on_tbPreviousMonth_clicked();
629 void on_cbMonth_currentIndexChanged(int index);
630 void on_cbYear_currentIndexChanged(int index);
631 void on_tvMonth_pressed(const QModelIndex &index);
632
633 void slotTimeout();
634
635protected:
636 bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
637
638private:
639 static void InitResource();
640 static void CLeanResource();
641
642 int ShowSelectTitle();
643 int UpdateViewModel(bool bForce = false);
644 int UpdateMonthMenu();
645 int EnableMonthMenu();
646 int SetBackgroup(const QString& szFile);
647 int SetYearRange(int min, int max);
648
649private:
650 QComboBox m_cmbYear;
651 QToolButton m_tbPreYear, m_tbNextYear;
652 QComboBox m_cmbMonth;
653 QToolButton m_tbPreMonth, m_tbNextMonth;
654 QPushButton m_pbToday;
655 QLabel m_lbDate, m_lbTime;
656 QTableView m_View;
657
658 QHBoxLayout* m_pToolLayout;
659 QVBoxLayout* m_pHeadLayout;
660 QGridLayout* m_pMainLayout;
661 _HEAD_position m_Headposition;
662
663 int m_oldRow, m_oldCol;
664 bool m_bShowToday;
665 QTimer m_Timer;
666 bool m_bShowBackgroupImage;
667
668 _TOUCH_UP_DOWN_FUNCTION m_TouchFunction;
669
670};
671
672#endif // LUNARCALENDAR_H
使用者自定义任务接口 类
virtual uint onHandle(const QDate &date, QStringList &tasks)=0
使用者自定义任务接口 。请遵守 农历位置显示类型优先级 。
农历日历类
void sigSelectionChanged()
当前选择日期改变时触发 可以在相应的槽函数中调用下列函数
_VIEW_TYPE
视图类型
virtual int SetTaskHandle(std::function< uint(const QDate &date, QStringList &tasks)> cbHandler)
设置 使用者自定义任务接口
_CalendarType
日历类型