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