cdate.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef CDATE_H
  2. #define CDATE_H
  3. /**
  4. * 使用说明
  5. * 1、这个是仿照TimeWidget做的一个可以点击空白处隐藏自身的日历控件
  6. * 2、实现方式就是将父类的事件注册到这个控件上,拦截父类的鼠标点击,判断
  7. * 是否在这个控件上进行隐藏,因此控件显示范围就依赖于父类空间大小了
  8. * 3、使用方法:
  9. * 1) 可以选择点击空白处隐藏或者不隐藏,设置PopuType类型就行
  10. *
  11. */
  12. #include <QDialog>
  13. #include <QWidget>
  14. #include <QDate>
  15. class CalendarWidgetEx;
  16. class OneShadow;
  17. class CDate : public QWidget
  18. {
  19. Q_OBJECT
  20. const int RADIUS = 16; /* 阴影范围 */
  21. const int CALENDAR_WIDTH = 325; /* 日历大小 */
  22. const int CALENDAR_HEIGHT = 350;
  23. public:
  24. enum PopupType{
  25. Popup = 0,
  26. NoPopup = 1
  27. };
  28. CDate(const QDate& defaultDate,QWidget *parent = nullptr,PopupType type = Popup);
  29. CDate(QWidget *parent = nullptr,PopupType type = Popup);
  30. signals:
  31. void signal_DateChanged(const QDate& date);
  32. void signal_close();
  33. protected:
  34. void paintEvent(QPaintEvent *event);
  35. bool eventFilter(QObject *watched, QEvent *event);
  36. private:
  37. void init(const QDate& defaultDate);
  38. private:
  39. QDate m_date;
  40. CalendarWidgetEx* m_calendarEx = nullptr;
  41. OneShadow* m_shadow = nullptr;
  42. QWidget* m_parent = nullptr;
  43. PopupType m_type;
  44. };
  45. #endif // CDATE_H