1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2018 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 40 #ifndef QCALENDARWIDGET_H 41 #define QCALENDARWIDGET_H 42 43 #include <QtWidgets/qtwidgetsglobal.h> 44 #include <QtWidgets/qwidget.h> 45 #include <QtCore/qdatetime.h> 46 47 QT_REQUIRE_CONFIG(calendarwidget); 48 49 QT_BEGIN_NAMESPACE 50 51 class QDate; 52 class QTextCharFormat; 53 class QCalendarWidgetPrivate; 54 55 class Q_WIDGETS_EXPORT QCalendarWidget : public QWidget 56 { 57 Q_OBJECT 58 Q_ENUMS(Qt::DayOfWeek) 59 Q_PROPERTY(QDate selectedDate READ selectedDate WRITE setSelectedDate) 60 Q_PROPERTY(QDate minimumDate READ minimumDate WRITE setMinimumDate) 61 Q_PROPERTY(QDate maximumDate READ maximumDate WRITE setMaximumDate) 62 Q_PROPERTY(Qt::DayOfWeek firstDayOfWeek READ firstDayOfWeek WRITE setFirstDayOfWeek) 63 Q_PROPERTY(bool gridVisible READ isGridVisible WRITE setGridVisible) 64 Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) 65 Q_PROPERTY(HorizontalHeaderFormat horizontalHeaderFormat READ horizontalHeaderFormat WRITE setHorizontalHeaderFormat) 66 Q_PROPERTY(VerticalHeaderFormat verticalHeaderFormat READ verticalHeaderFormat WRITE setVerticalHeaderFormat) 67 Q_PROPERTY(bool navigationBarVisible READ isNavigationBarVisible WRITE setNavigationBarVisible) 68 Q_PROPERTY(bool dateEditEnabled READ isDateEditEnabled WRITE setDateEditEnabled) 69 Q_PROPERTY(int dateEditAcceptDelay READ dateEditAcceptDelay WRITE setDateEditAcceptDelay) 70 71 public: 72 enum HorizontalHeaderFormat { 73 NoHorizontalHeader, 74 SingleLetterDayNames, 75 ShortDayNames, 76 LongDayNames 77 }; 78 Q_ENUM(HorizontalHeaderFormat) 79 80 enum VerticalHeaderFormat { 81 NoVerticalHeader, 82 ISOWeekNumbers 83 }; 84 Q_ENUM(VerticalHeaderFormat) 85 86 enum SelectionMode { 87 NoSelection, 88 SingleSelection 89 }; 90 Q_ENUM(SelectionMode) 91 92 explicit QCalendarWidget(QWidget *parent = nullptr); 93 ~QCalendarWidget(); 94 95 virtual QSize sizeHint() const override; 96 virtual QSize minimumSizeHint() const override; 97 98 QDate selectedDate() const; 99 100 int yearShown() const; 101 int monthShown() const; 102 103 QDate minimumDate() const; 104 void setMinimumDate(const QDate &date); 105 106 QDate maximumDate() const; 107 void setMaximumDate(const QDate &date); 108 109 Qt::DayOfWeek firstDayOfWeek() const; 110 void setFirstDayOfWeek(Qt::DayOfWeek dayOfWeek); 111 112 bool isNavigationBarVisible() const; 113 bool isGridVisible() const; 114 115 QCalendar calendar() const; 116 void setCalendar(QCalendar calendar); 117 118 SelectionMode selectionMode() const; 119 void setSelectionMode(SelectionMode mode); 120 121 HorizontalHeaderFormat horizontalHeaderFormat() const; 122 void setHorizontalHeaderFormat(HorizontalHeaderFormat format); 123 124 VerticalHeaderFormat verticalHeaderFormat() const; 125 void setVerticalHeaderFormat(VerticalHeaderFormat format); 126 127 QTextCharFormat headerTextFormat() const; 128 void setHeaderTextFormat(const QTextCharFormat &format); 129 130 QTextCharFormat weekdayTextFormat(Qt::DayOfWeek dayOfWeek) const; 131 void setWeekdayTextFormat(Qt::DayOfWeek dayOfWeek, const QTextCharFormat &format); 132 133 QMap<QDate, QTextCharFormat> dateTextFormat() const; 134 QTextCharFormat dateTextFormat(const QDate &date) const; 135 void setDateTextFormat(const QDate &date, const QTextCharFormat &format); 136 137 bool isDateEditEnabled() const; 138 void setDateEditEnabled(bool enable); 139 140 int dateEditAcceptDelay() const; 141 void setDateEditAcceptDelay(int delay); 142 143 protected: 144 bool event(QEvent *event) override; 145 bool eventFilter(QObject *watched, QEvent *event) override; 146 void mousePressEvent(QMouseEvent *event) override; 147 void resizeEvent(QResizeEvent * event) override; 148 void keyPressEvent(QKeyEvent * event) override; 149 150 virtual void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const; 151 void updateCell(const QDate &date); 152 void updateCells(); 153 154 public Q_SLOTS: 155 void setSelectedDate(const QDate &date); 156 void setDateRange(const QDate &min, const QDate &max); 157 void setCurrentPage(int year, int month); 158 void setGridVisible(bool show); 159 void setNavigationBarVisible(bool visible); 160 void showNextMonth(); 161 void showPreviousMonth(); 162 void showNextYear(); 163 void showPreviousYear(); 164 void showSelectedDate(); 165 void showToday(); 166 167 Q_SIGNALS: 168 void selectionChanged(); 169 void clicked(const QDate &date); 170 void activated(const QDate &date); 171 void currentPageChanged(int year, int month); 172 173 private: 174 Q_DECLARE_PRIVATE(QCalendarWidget) 175 Q_DISABLE_COPY(QCalendarWidget) 176 177 Q_PRIVATE_SLOT(d_func(), void _q_slotShowDate(const QDate &date)) 178 Q_PRIVATE_SLOT(d_func(), void _q_slotChangeDate(const QDate &date)) 179 Q_PRIVATE_SLOT(d_func(), void _q_slotChangeDate(const QDate &date, bool changeMonth)) 180 Q_PRIVATE_SLOT(d_func(), void _q_editingFinished()) 181 Q_PRIVATE_SLOT(d_func(), void _q_prevMonthClicked()) 182 Q_PRIVATE_SLOT(d_func(), void _q_nextMonthClicked()) 183 Q_PRIVATE_SLOT(d_func(), void _q_yearEditingFinished()) 184 Q_PRIVATE_SLOT(d_func(), void _q_yearClicked()) 185 Q_PRIVATE_SLOT(d_func(), void _q_monthChanged(QAction *act)) 186 187 }; 188 189 QT_END_NAMESPACE 190 191 #endif // QCALENDARWIDGET_H 192