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
40#ifndef QDATETIMEEDIT_H
41#define QDATETIMEEDIT_H
42
43#include <QtWidgets/qtwidgetsglobal.h>
44#include <QtCore/qdatetime.h>
45#include <QtCore/qvariant.h>
46#include <QtWidgets/qabstractspinbox.h>
47
48QT_REQUIRE_CONFIG(datetimeedit);
49
50QT_BEGIN_NAMESPACE
51
52class QDateTimeEditPrivate;
53class QStyleOptionSpinBox;
54class QCalendarWidget;
55
56class Q_WIDGETS_EXPORT QDateTimeEdit : public QAbstractSpinBox
57{
58 Q_OBJECT
59
60 Q_PROPERTY(QDateTime dateTime READ dateTime WRITE setDateTime NOTIFY dateTimeChanged USER true)
61 Q_PROPERTY(QDate date READ date WRITE setDate NOTIFY dateChanged)
62 Q_PROPERTY(QTime time READ time WRITE setTime NOTIFY timeChanged)
63 Q_PROPERTY(QDateTime maximumDateTime READ maximumDateTime WRITE setMaximumDateTime RESET clearMaximumDateTime)
64 Q_PROPERTY(QDateTime minimumDateTime READ minimumDateTime WRITE setMinimumDateTime RESET clearMinimumDateTime)
65 Q_PROPERTY(QDate maximumDate READ maximumDate WRITE setMaximumDate RESET clearMaximumDate)
66 Q_PROPERTY(QDate minimumDate READ minimumDate WRITE setMinimumDate RESET clearMinimumDate)
67 Q_PROPERTY(QTime maximumTime READ maximumTime WRITE setMaximumTime RESET clearMaximumTime)
68 Q_PROPERTY(QTime minimumTime READ minimumTime WRITE setMinimumTime RESET clearMinimumTime)
69 Q_PROPERTY(Section currentSection READ currentSection WRITE setCurrentSection)
70 Q_PROPERTY(Sections displayedSections READ displayedSections)
71 Q_PROPERTY(QString displayFormat READ displayFormat WRITE setDisplayFormat)
72 Q_PROPERTY(bool calendarPopup READ calendarPopup WRITE setCalendarPopup)
73 Q_PROPERTY(int currentSectionIndex READ currentSectionIndex WRITE setCurrentSectionIndex)
74 Q_PROPERTY(int sectionCount READ sectionCount)
75 Q_PROPERTY(Qt::TimeSpec timeSpec READ timeSpec WRITE setTimeSpec)
76public:
77 enum Section { // a sub-type of QDateTimeParser's like-named enum.
78 NoSection = 0x0000,
79 AmPmSection = 0x0001,
80 MSecSection = 0x0002,
81 SecondSection = 0x0004,
82 MinuteSection = 0x0008,
83 HourSection = 0x0010,
84 DaySection = 0x0100,
85 MonthSection = 0x0200,
86 YearSection = 0x0400,
87 TimeSections_Mask = AmPmSection|MSecSection|SecondSection|MinuteSection|HourSection,
88 DateSections_Mask = DaySection|MonthSection|YearSection
89 };
90 Q_ENUM(Section)
91
92 Q_DECLARE_FLAGS(Sections, Section)
93 Q_FLAG(Sections)
94
95 explicit QDateTimeEdit(QWidget *parent = nullptr);
96 explicit QDateTimeEdit(const QDateTime &dt, QWidget *parent = nullptr);
97 explicit QDateTimeEdit(const QDate &d, QWidget *parent = nullptr);
98 explicit QDateTimeEdit(const QTime &t, QWidget *parent = nullptr);
99 ~QDateTimeEdit();
100
101 QDateTime dateTime() const;
102 QDate date() const;
103 QTime time() const;
104
105 QDateTime minimumDateTime() const;
106 void clearMinimumDateTime();
107 void setMinimumDateTime(const QDateTime &dt);
108
109 QDateTime maximumDateTime() const;
110 void clearMaximumDateTime();
111 void setMaximumDateTime(const QDateTime &dt);
112
113 void setDateTimeRange(const QDateTime &min, const QDateTime &max);
114
115 QDate minimumDate() const;
116 void setMinimumDate(const QDate &min);
117 void clearMinimumDate();
118
119 QDate maximumDate() const;
120 void setMaximumDate(const QDate &max);
121 void clearMaximumDate();
122
123 void setDateRange(const QDate &min, const QDate &max);
124
125 QTime minimumTime() const;
126 void setMinimumTime(const QTime &min);
127 void clearMinimumTime();
128
129 QTime maximumTime() const;
130 void setMaximumTime(const QTime &max);
131 void clearMaximumTime();
132
133 void setTimeRange(const QTime &min, const QTime &max);
134
135 Sections displayedSections() const;
136 Section currentSection() const;
137 Section sectionAt(int index) const;
138 void setCurrentSection(Section section);
139
140 int currentSectionIndex() const;
141 void setCurrentSectionIndex(int index);
142
143 QCalendarWidget *calendarWidget() const;
144 void setCalendarWidget(QCalendarWidget *calendarWidget);
145
146 int sectionCount() const;
147
148 void setSelectedSection(Section section);
149
150 QString sectionText(Section section) const;
151
152 QString displayFormat() const;
153 void setDisplayFormat(const QString &format);
154
155 bool calendarPopup() const;
156 void setCalendarPopup(bool enable);
157
158 Qt::TimeSpec timeSpec() const;
159 void setTimeSpec(Qt::TimeSpec spec);
160
161 QSize sizeHint() const override;
162
163 void clear() override;
164 void stepBy(int steps) override;
165
166 bool event(QEvent *event) override;
167Q_SIGNALS:
168 void dateTimeChanged(const QDateTime &dateTime);
169 void timeChanged(const QTime &time);
170 void dateChanged(const QDate &date);
171
172public Q_SLOTS:
173 void setDateTime(const QDateTime &dateTime);
174 void setDate(const QDate &date);
175 void setTime(const QTime &time);
176
177protected:
178 void keyPressEvent(QKeyEvent *event) override;
179#if QT_CONFIG(wheelevent)
180 void wheelEvent(QWheelEvent *event) override;
181#endif
182 void focusInEvent(QFocusEvent *event) override;
183 bool focusNextPrevChild(bool next) override;
184 QValidator::State validate(QString &input, int &pos) const override;
185 void fixup(QString &input) const override;
186
187 virtual QDateTime dateTimeFromText(const QString &text) const;
188 virtual QString textFromDateTime(const QDateTime &dt) const;
189 StepEnabled stepEnabled() const override;
190 void mousePressEvent(QMouseEvent *event) override;
191 void paintEvent(QPaintEvent *event) override;
192 void initStyleOption(QStyleOptionSpinBox *option) const;
193
194 QDateTimeEdit(const QVariant &val, QVariant::Type parserType, QWidget *parent = nullptr);
195private:
196 Q_DECLARE_PRIVATE(QDateTimeEdit)
197 Q_DISABLE_COPY(QDateTimeEdit)
198
199 Q_PRIVATE_SLOT(d_func(), void _q_resetButton())
200};
201
202class Q_WIDGETS_EXPORT QTimeEdit : public QDateTimeEdit
203{
204 Q_OBJECT
205 Q_PROPERTY(QTime time READ time WRITE setTime NOTIFY userTimeChanged USER true)
206public:
207 explicit QTimeEdit(QWidget *parent = nullptr);
208 explicit QTimeEdit(const QTime &time, QWidget *parent = nullptr);
209 ~QTimeEdit();
210
211Q_SIGNALS:
212 void userTimeChanged(const QTime &time);
213};
214
215class Q_WIDGETS_EXPORT QDateEdit : public QDateTimeEdit
216{
217 Q_OBJECT
218 Q_PROPERTY(QDate date READ date WRITE setDate NOTIFY userDateChanged USER true)
219public:
220 explicit QDateEdit(QWidget *parent = nullptr);
221 explicit QDateEdit(const QDate &date, QWidget *parent = nullptr);
222 ~QDateEdit();
223
224Q_SIGNALS:
225 void userDateChanged(const QDate &date);
226};
227
228Q_DECLARE_OPERATORS_FOR_FLAGS(QDateTimeEdit::Sections)
229
230QT_END_NAMESPACE
231
232#endif // QDATETIMEEDIT_H
233