qcalendarwidget.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtWidgets module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QCALENDARWIDGET_H
  40. #define QCALENDARWIDGET_H
  41. #include <QtWidgets/qwidget.h>
  42. #include <QtCore/qdatetime.h>
  43. QT_BEGIN_NAMESPACE
  44. #ifndef QT_NO_CALENDARWIDGET
  45. class QDate;
  46. class QTextCharFormat;
  47. class QCalendarWidgetPrivate;
  48. class Q_WIDGETS_EXPORT QCalendarWidget : public QWidget
  49. {
  50. Q_OBJECT
  51. Q_ENUMS(Qt::DayOfWeek)
  52. Q_PROPERTY(QDate selectedDate READ selectedDate WRITE setSelectedDate)
  53. Q_PROPERTY(QDate minimumDate READ minimumDate WRITE setMinimumDate)
  54. Q_PROPERTY(QDate maximumDate READ maximumDate WRITE setMaximumDate)
  55. Q_PROPERTY(Qt::DayOfWeek firstDayOfWeek READ firstDayOfWeek WRITE setFirstDayOfWeek)
  56. Q_PROPERTY(bool gridVisible READ isGridVisible WRITE setGridVisible)
  57. Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
  58. Q_PROPERTY(HorizontalHeaderFormat horizontalHeaderFormat READ horizontalHeaderFormat WRITE setHorizontalHeaderFormat)
  59. Q_PROPERTY(VerticalHeaderFormat verticalHeaderFormat READ verticalHeaderFormat WRITE setVerticalHeaderFormat)
  60. Q_PROPERTY(bool navigationBarVisible READ isNavigationBarVisible WRITE setNavigationBarVisible)
  61. Q_PROPERTY(bool dateEditEnabled READ isDateEditEnabled WRITE setDateEditEnabled)
  62. Q_PROPERTY(int dateEditAcceptDelay READ dateEditAcceptDelay WRITE setDateEditAcceptDelay)
  63. public:
  64. enum HorizontalHeaderFormat {
  65. NoHorizontalHeader,
  66. SingleLetterDayNames,
  67. ShortDayNames,
  68. LongDayNames
  69. };
  70. Q_ENUM(HorizontalHeaderFormat)
  71. enum VerticalHeaderFormat {
  72. NoVerticalHeader,
  73. ISOWeekNumbers
  74. };
  75. Q_ENUM(VerticalHeaderFormat)
  76. enum SelectionMode {
  77. NoSelection,
  78. SingleSelection
  79. };
  80. Q_ENUM(SelectionMode)
  81. explicit QCalendarWidget(QWidget *parent = Q_NULLPTR);
  82. ~QCalendarWidget();
  83. virtual QSize sizeHint() const Q_DECL_OVERRIDE;
  84. virtual QSize minimumSizeHint() const Q_DECL_OVERRIDE;
  85. QDate selectedDate() const;
  86. int yearShown() const;
  87. int monthShown() const;
  88. QDate minimumDate() const;
  89. void setMinimumDate(const QDate &date);
  90. QDate maximumDate() const;
  91. void setMaximumDate(const QDate &date);
  92. Qt::DayOfWeek firstDayOfWeek() const;
  93. void setFirstDayOfWeek(Qt::DayOfWeek dayOfWeek);
  94. bool isNavigationBarVisible() const;
  95. bool isGridVisible() const;
  96. SelectionMode selectionMode() const;
  97. void setSelectionMode(SelectionMode mode);
  98. HorizontalHeaderFormat horizontalHeaderFormat() const;
  99. void setHorizontalHeaderFormat(HorizontalHeaderFormat format);
  100. VerticalHeaderFormat verticalHeaderFormat() const;
  101. void setVerticalHeaderFormat(VerticalHeaderFormat format);
  102. QTextCharFormat headerTextFormat() const;
  103. void setHeaderTextFormat(const QTextCharFormat &format);
  104. QTextCharFormat weekdayTextFormat(Qt::DayOfWeek dayOfWeek) const;
  105. void setWeekdayTextFormat(Qt::DayOfWeek dayOfWeek, const QTextCharFormat &format);
  106. QMap<QDate, QTextCharFormat> dateTextFormat() const;
  107. QTextCharFormat dateTextFormat(const QDate &date) const;
  108. void setDateTextFormat(const QDate &date, const QTextCharFormat &format);
  109. bool isDateEditEnabled() const;
  110. void setDateEditEnabled(bool enable);
  111. int dateEditAcceptDelay() const;
  112. void setDateEditAcceptDelay(int delay);
  113. protected:
  114. bool event(QEvent *event) Q_DECL_OVERRIDE;
  115. bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
  116. void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  117. void resizeEvent(QResizeEvent * event) Q_DECL_OVERRIDE;
  118. void keyPressEvent(QKeyEvent * event) Q_DECL_OVERRIDE;
  119. virtual void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const;
  120. void updateCell(const QDate &date);
  121. void updateCells();
  122. public Q_SLOTS:
  123. void setSelectedDate(const QDate &date);
  124. void setDateRange(const QDate &min, const QDate &max);
  125. void setCurrentPage(int year, int month);
  126. void setGridVisible(bool show);
  127. void setNavigationBarVisible(bool visible);
  128. void showNextMonth();
  129. void showPreviousMonth();
  130. void showNextYear();
  131. void showPreviousYear();
  132. void showSelectedDate();
  133. void showToday();
  134. Q_SIGNALS:
  135. void selectionChanged();
  136. void clicked(const QDate &date);
  137. void activated(const QDate &date);
  138. void currentPageChanged(int year, int month);
  139. private:
  140. Q_DECLARE_PRIVATE(QCalendarWidget)
  141. Q_DISABLE_COPY(QCalendarWidget)
  142. Q_PRIVATE_SLOT(d_func(), void _q_slotShowDate(const QDate &date))
  143. Q_PRIVATE_SLOT(d_func(), void _q_slotChangeDate(const QDate &date))
  144. Q_PRIVATE_SLOT(d_func(), void _q_slotChangeDate(const QDate &date, bool changeMonth))
  145. Q_PRIVATE_SLOT(d_func(), void _q_editingFinished())
  146. Q_PRIVATE_SLOT(d_func(), void _q_prevMonthClicked())
  147. Q_PRIVATE_SLOT(d_func(), void _q_nextMonthClicked())
  148. Q_PRIVATE_SLOT(d_func(), void _q_yearEditingFinished())
  149. Q_PRIVATE_SLOT(d_func(), void _q_yearClicked())
  150. Q_PRIVATE_SLOT(d_func(), void _q_monthChanged(QAction *act))
  151. };
  152. #endif // QT_NO_CALENDARWIDGET
  153. QT_END_NAMESPACE
  154. #endif // QCALENDARWIDGET_H