1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QCALENDARWIDGET_H
5#define QCALENDARWIDGET_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qwidget.h>
9#include <QtCore/qdatetime.h>
10
11QT_REQUIRE_CONFIG(calendarwidget);
12
13QT_BEGIN_NAMESPACE
14
15class QDate;
16class QTextCharFormat;
17class QCalendarWidgetPrivate;
18
19class Q_WIDGETS_EXPORT QCalendarWidget : public QWidget
20{
21 Q_OBJECT
22 Q_ENUMS(Qt::DayOfWeek)
23 Q_PROPERTY(QDate selectedDate READ selectedDate WRITE setSelectedDate)
24 Q_PROPERTY(QDate minimumDate READ minimumDate WRITE setMinimumDate RESET clearMinimumDate)
25 Q_PROPERTY(QDate maximumDate READ maximumDate WRITE setMaximumDate RESET clearMaximumDate)
26 Q_PROPERTY(Qt::DayOfWeek firstDayOfWeek READ firstDayOfWeek WRITE setFirstDayOfWeek)
27 Q_PROPERTY(bool gridVisible READ isGridVisible WRITE setGridVisible)
28 Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
29 Q_PROPERTY(HorizontalHeaderFormat horizontalHeaderFormat READ horizontalHeaderFormat
30 WRITE setHorizontalHeaderFormat)
31 Q_PROPERTY(VerticalHeaderFormat verticalHeaderFormat READ verticalHeaderFormat
32 WRITE setVerticalHeaderFormat)
33 Q_PROPERTY(bool navigationBarVisible READ isNavigationBarVisible WRITE setNavigationBarVisible)
34 Q_PROPERTY(bool dateEditEnabled READ isDateEditEnabled WRITE setDateEditEnabled)
35 Q_PROPERTY(int dateEditAcceptDelay READ dateEditAcceptDelay WRITE setDateEditAcceptDelay)
36
37public:
38 enum HorizontalHeaderFormat {
39 NoHorizontalHeader,
40 SingleLetterDayNames,
41 ShortDayNames,
42 LongDayNames
43 };
44 Q_ENUM(HorizontalHeaderFormat)
45
46 enum VerticalHeaderFormat {
47 NoVerticalHeader,
48 ISOWeekNumbers
49 };
50 Q_ENUM(VerticalHeaderFormat)
51
52 enum SelectionMode {
53 NoSelection,
54 SingleSelection
55 };
56 Q_ENUM(SelectionMode)
57
58 explicit QCalendarWidget(QWidget *parent = nullptr);
59 ~QCalendarWidget();
60
61 virtual QSize sizeHint() const override;
62 virtual QSize minimumSizeHint() const override;
63
64 QDate selectedDate() const;
65
66 int yearShown() const;
67 int monthShown() const;
68
69 QDate minimumDate() const;
70 void setMinimumDate(QDate date);
71 void clearMinimumDate();
72
73 QDate maximumDate() const;
74 void setMaximumDate(QDate date);
75 void clearMaximumDate();
76
77 Qt::DayOfWeek firstDayOfWeek() const;
78 void setFirstDayOfWeek(Qt::DayOfWeek dayOfWeek);
79
80 bool isNavigationBarVisible() const;
81 bool isGridVisible() const;
82
83 QCalendar calendar() const;
84 void setCalendar(QCalendar calendar);
85
86 SelectionMode selectionMode() const;
87 void setSelectionMode(SelectionMode mode);
88
89 HorizontalHeaderFormat horizontalHeaderFormat() const;
90 void setHorizontalHeaderFormat(HorizontalHeaderFormat format);
91
92 VerticalHeaderFormat verticalHeaderFormat() const;
93 void setVerticalHeaderFormat(VerticalHeaderFormat format);
94
95 QTextCharFormat headerTextFormat() const;
96 void setHeaderTextFormat(const QTextCharFormat &format);
97
98 QTextCharFormat weekdayTextFormat(Qt::DayOfWeek dayOfWeek) const;
99 void setWeekdayTextFormat(Qt::DayOfWeek dayOfWeek, const QTextCharFormat &format);
100
101 QMap<QDate, QTextCharFormat> dateTextFormat() const;
102 QTextCharFormat dateTextFormat(QDate date) const;
103 void setDateTextFormat(QDate date, const QTextCharFormat &format);
104
105 bool isDateEditEnabled() const;
106 void setDateEditEnabled(bool enable);
107
108 int dateEditAcceptDelay() const;
109 void setDateEditAcceptDelay(int delay);
110
111protected:
112 bool event(QEvent *event) override;
113 bool eventFilter(QObject *watched, QEvent *event) override;
114 void mousePressEvent(QMouseEvent *event) override;
115 void resizeEvent(QResizeEvent * event) override;
116 void keyPressEvent(QKeyEvent * event) override;
117
118 virtual void paintCell(QPainter *painter, const QRect &rect, QDate date) const;
119 void updateCell(QDate date);
120 void updateCells();
121
122public Q_SLOTS:
123 void setSelectedDate(QDate date);
124 void setDateRange(QDate min, 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
135Q_SIGNALS:
136 void selectionChanged();
137 void clicked(QDate date);
138 void activated(QDate date);
139 void currentPageChanged(int year, int month);
140
141private:
142 Q_DECLARE_PRIVATE(QCalendarWidget)
143 Q_DISABLE_COPY(QCalendarWidget)
144
145 Q_PRIVATE_SLOT(d_func(), void _q_slotShowDate(QDate date))
146 Q_PRIVATE_SLOT(d_func(), void _q_slotChangeDate(QDate date))
147 Q_PRIVATE_SLOT(d_func(), void _q_slotChangeDate(QDate date, bool changeMonth))
148 Q_PRIVATE_SLOT(d_func(), void _q_editingFinished())
149 Q_PRIVATE_SLOT(d_func(), void _q_prevMonthClicked())
150 Q_PRIVATE_SLOT(d_func(), void _q_nextMonthClicked())
151 Q_PRIVATE_SLOT(d_func(), void _q_yearEditingFinished())
152 Q_PRIVATE_SLOT(d_func(), void _q_yearClicked())
153 Q_PRIVATE_SLOT(d_func(), void _q_monthChanged(QAction *act))
154
155};
156
157QT_END_NAMESPACE
158
159#endif // QCALENDARWIDGET_H
160

source code of qtbase/src/widgets/widgets/qcalendarwidget.h