Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qdatetimeedit.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 | #include <private/qdatetimeedit_p.h> | - | ||||||||||||
41 | #include <qabstractspinbox.h> | - | ||||||||||||
42 | #include <qapplication.h> | - | ||||||||||||
43 | #include <qdatetimeedit.h> | - | ||||||||||||
44 | #include <qdesktopwidget.h> | - | ||||||||||||
45 | #include <qdebug.h> | - | ||||||||||||
46 | #include <qevent.h> | - | ||||||||||||
47 | #include <qlineedit.h> | - | ||||||||||||
48 | #include <private/qlineedit_p.h> | - | ||||||||||||
49 | #include <qlocale.h> | - | ||||||||||||
50 | #include <qpainter.h> | - | ||||||||||||
51 | #include <qlayout.h> | - | ||||||||||||
52 | #include <qset.h> | - | ||||||||||||
53 | #include <qstyle.h> | - | ||||||||||||
54 | - | |||||||||||||
55 | #include <algorithm> | - | ||||||||||||
56 | - | |||||||||||||
57 | #ifndef QT_NO_DATETIMEEDIT | - | ||||||||||||
58 | - | |||||||||||||
59 | //#define QDATETIMEEDIT_QDTEDEBUG | - | ||||||||||||
60 | #ifdef QDATETIMEEDIT_QDTEDEBUG | - | ||||||||||||
61 | # define QDTEDEBUG qDebug() << QString::fromLatin1("%1:%2").arg(__FILE__).arg(__LINE__) | - | ||||||||||||
62 | # define QDTEDEBUGN qDebug | - | ||||||||||||
63 | #else | - | ||||||||||||
64 | # define QDTEDEBUG if (false) qDebug() | - | ||||||||||||
65 | # define QDTEDEBUGN if (false) qDebug | - | ||||||||||||
66 | #endif | - | ||||||||||||
67 | - | |||||||||||||
68 | QT_BEGIN_NAMESPACE | - | ||||||||||||
69 | - | |||||||||||||
70 | // --- QDateTimeEdit --- | - | ||||||||||||
71 | - | |||||||||||||
72 | /*! | - | ||||||||||||
73 | \class QDateTimeEdit | - | ||||||||||||
74 | \brief The QDateTimeEdit class provides a widget for editing dates and times. | - | ||||||||||||
75 | - | |||||||||||||
76 | \ingroup basicwidgets | - | ||||||||||||
77 | \inmodule QtWidgets | - | ||||||||||||
78 | - | |||||||||||||
79 | QDateTimeEdit allows the user to edit dates by using the keyboard or | - | ||||||||||||
80 | the arrow keys to increase and decrease date and time values. The | - | ||||||||||||
81 | arrow keys can be used to move from section to section within the | - | ||||||||||||
82 | QDateTimeEdit box. Dates and times appear in accordance with the | - | ||||||||||||
83 | format set; see setDisplayFormat(). | - | ||||||||||||
84 | - | |||||||||||||
85 | \snippet code/src_gui_widgets_qdatetimeedit.cpp 0 | - | ||||||||||||
86 | - | |||||||||||||
87 | Here we've created a new QDateTimeEdit object initialized with | - | ||||||||||||
88 | today's date, and restricted the valid date range to today plus or | - | ||||||||||||
89 | minus 365 days. We've set the order to month, day, year. | - | ||||||||||||
90 | - | |||||||||||||
91 | The minimum value for QDateTimeEdit is 14 September 1752. You can | - | ||||||||||||
92 | change this by calling setMinimumDate(), taking into account that | - | ||||||||||||
93 | the minimum value for QDate is 2 January 4713BC. | - | ||||||||||||
94 | - | |||||||||||||
95 | Other useful functions are setMaximumDate(), setMinimumTime() | - | ||||||||||||
96 | and setMaximumTime(). | - | ||||||||||||
97 | - | |||||||||||||
98 | \section1 Using a Pop-up Calendar Widget | - | ||||||||||||
99 | - | |||||||||||||
100 | QDateTimeEdit can be configured to allow a QCalendarWidget to be used | - | ||||||||||||
101 | to select dates. This is enabled by setting the calendarPopup property. | - | ||||||||||||
102 | Additionally, you can supply a custom calendar widget for use as the | - | ||||||||||||
103 | calendar pop-up by calling the setCalendarWidget() function. The existing | - | ||||||||||||
104 | calendar widget can be retrieved with calendarWidget(). | - | ||||||||||||
105 | - | |||||||||||||
106 | \table 100% | - | ||||||||||||
107 | \row \li \inlineimage windowsvista-datetimeedit.png Screenshot of a Windows Vista style date time editing widget | - | ||||||||||||
108 | \li A date time editing widget shown in the \l{Windows Vista Style Widget Gallery}{Windows Vista widget style}. | - | ||||||||||||
109 | \row \li \inlineimage macintosh-datetimeedit.png Screenshot of a Macintosh style date time editing widget | - | ||||||||||||
110 | \li A date time editing widget shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}. | - | ||||||||||||
111 | \row \li \inlineimage fusion-datetimeedit.png Screenshot of a Fusion style date time editing widget | - | ||||||||||||
112 | \li A date time editing widget shown in the \l{Fusion Style Widget Gallery}{Fusion widget style}. | - | ||||||||||||
113 | \endtable | - | ||||||||||||
114 | - | |||||||||||||
115 | \sa QDateEdit, QTimeEdit, QDate, QTime | - | ||||||||||||
116 | */ | - | ||||||||||||
117 | - | |||||||||||||
118 | /*! | - | ||||||||||||
119 | \enum QDateTimeEdit::Section | - | ||||||||||||
120 | - | |||||||||||||
121 | \value NoSection | - | ||||||||||||
122 | \value AmPmSection | - | ||||||||||||
123 | \value MSecSection | - | ||||||||||||
124 | \value SecondSection | - | ||||||||||||
125 | \value MinuteSection | - | ||||||||||||
126 | \value HourSection | - | ||||||||||||
127 | \value DaySection | - | ||||||||||||
128 | \value MonthSection | - | ||||||||||||
129 | \value YearSection | - | ||||||||||||
130 | \omitvalue DateSections_Mask | - | ||||||||||||
131 | \omitvalue TimeSections_Mask | - | ||||||||||||
132 | */ | - | ||||||||||||
133 | - | |||||||||||||
134 | /*! | - | ||||||||||||
135 | \fn void QDateTimeEdit::dateTimeChanged(const QDateTime &datetime) | - | ||||||||||||
136 | - | |||||||||||||
137 | This signal is emitted whenever the date or time is changed. The | - | ||||||||||||
138 | new date and time is passed in \a datetime. | - | ||||||||||||
139 | */ | - | ||||||||||||
140 | - | |||||||||||||
141 | /*! | - | ||||||||||||
142 | \fn void QDateTimeEdit::timeChanged(const QTime &time) | - | ||||||||||||
143 | - | |||||||||||||
144 | This signal is emitted whenever the time is changed. The new time | - | ||||||||||||
145 | is passed in \a time. | - | ||||||||||||
146 | */ | - | ||||||||||||
147 | - | |||||||||||||
148 | /*! | - | ||||||||||||
149 | \fn void QDateTimeEdit::dateChanged(const QDate &date) | - | ||||||||||||
150 | - | |||||||||||||
151 | This signal is emitted whenever the date is changed. The new date | - | ||||||||||||
152 | is passed in \a date. | - | ||||||||||||
153 | */ | - | ||||||||||||
154 | - | |||||||||||||
155 | - | |||||||||||||
156 | /*! | - | ||||||||||||
157 | Constructs an empty date time editor with a \a parent. | - | ||||||||||||
158 | */ | - | ||||||||||||
159 | - | |||||||||||||
160 | QDateTimeEdit::QDateTimeEdit(QWidget *parent) | - | ||||||||||||
161 | : QAbstractSpinBox(*new QDateTimeEditPrivate, parent) | - | ||||||||||||
162 | { | - | ||||||||||||
163 | Q_D(QDateTimeEdit); | - | ||||||||||||
164 | d->init(QDateTime(QDATETIMEEDIT_DATE_INITIAL, QDATETIMEEDIT_TIME_MIN)); | - | ||||||||||||
165 | } | - | ||||||||||||
166 | - | |||||||||||||
167 | /*! | - | ||||||||||||
168 | Constructs an empty date time editor with a \a parent. The value | - | ||||||||||||
169 | is set to \a datetime. | - | ||||||||||||
170 | */ | - | ||||||||||||
171 | - | |||||||||||||
172 | QDateTimeEdit::QDateTimeEdit(const QDateTime &datetime, QWidget *parent) | - | ||||||||||||
173 | : QAbstractSpinBox(*new QDateTimeEditPrivate, parent) | - | ||||||||||||
174 | { | - | ||||||||||||
175 | Q_D(QDateTimeEdit); | - | ||||||||||||
176 | d->init(datetime.isValid() ? datetime : QDateTime(QDATETIMEEDIT_DATE_INITIAL, | - | ||||||||||||
177 | QDATETIMEEDIT_TIME_MIN)); | - | ||||||||||||
178 | } | - | ||||||||||||
179 | - | |||||||||||||
180 | /*! | - | ||||||||||||
181 | \fn QDateTimeEdit::QDateTimeEdit(const QDate &date, QWidget *parent) | - | ||||||||||||
182 | - | |||||||||||||
183 | Constructs an empty date time editor with a \a parent. | - | ||||||||||||
184 | The value is set to \a date. | - | ||||||||||||
185 | */ | - | ||||||||||||
186 | - | |||||||||||||
187 | QDateTimeEdit::QDateTimeEdit(const QDate &date, QWidget *parent) | - | ||||||||||||
188 | : QAbstractSpinBox(*new QDateTimeEditPrivate, parent) | - | ||||||||||||
189 | { | - | ||||||||||||
190 | Q_D(QDateTimeEdit); | - | ||||||||||||
191 | d->init(date.isValid() ? date : QDATETIMEEDIT_DATE_INITIAL); | - | ||||||||||||
192 | } | - | ||||||||||||
193 | - | |||||||||||||
194 | /*! | - | ||||||||||||
195 | \fn QDateTimeEdit::QDateTimeEdit(const QTime &time, QWidget *parent) | - | ||||||||||||
196 | - | |||||||||||||
197 | Constructs an empty date time editor with a \a parent. | - | ||||||||||||
198 | The value is set to \a time. | - | ||||||||||||
199 | */ | - | ||||||||||||
200 | - | |||||||||||||
201 | QDateTimeEdit::QDateTimeEdit(const QTime &time, QWidget *parent) | - | ||||||||||||
202 | : QAbstractSpinBox(*new QDateTimeEditPrivate, parent) | - | ||||||||||||
203 | { | - | ||||||||||||
204 | Q_D(QDateTimeEdit); | - | ||||||||||||
205 | d->init(time.isValid() ? time : QDATETIMEEDIT_TIME_MIN); | - | ||||||||||||
206 | } | - | ||||||||||||
207 | - | |||||||||||||
208 | /*! | - | ||||||||||||
209 | \internal | - | ||||||||||||
210 | */ | - | ||||||||||||
211 | - | |||||||||||||
212 | QDateTimeEdit::QDateTimeEdit(const QVariant &var, QVariant::Type parserType, QWidget *parent) | - | ||||||||||||
213 | : QAbstractSpinBox(*new QDateTimeEditPrivate, parent) | - | ||||||||||||
214 | { | - | ||||||||||||
215 | Q_D(QDateTimeEdit); | - | ||||||||||||
216 | d->parserType = parserType; | - | ||||||||||||
217 | d->init(var); | - | ||||||||||||
218 | } | - | ||||||||||||
219 | - | |||||||||||||
220 | /*! | - | ||||||||||||
221 | Destructor. | - | ||||||||||||
222 | */ | - | ||||||||||||
223 | QDateTimeEdit::~QDateTimeEdit() | - | ||||||||||||
224 | { | - | ||||||||||||
225 | } | - | ||||||||||||
226 | - | |||||||||||||
227 | /*! | - | ||||||||||||
228 | \property QDateTimeEdit::dateTime | - | ||||||||||||
229 | \brief the QDateTime that is set in the QDateTimeEdit | - | ||||||||||||
230 | - | |||||||||||||
231 | When setting this property the timespec of the QDateTimeEdit remains the same | - | ||||||||||||
232 | and the timespec of the new QDateTime is ignored. | - | ||||||||||||
233 | - | |||||||||||||
234 | By default, this property contains a date that refers to January 1, | - | ||||||||||||
235 | 2000 and a time of 00:00:00 and 0 milliseconds. | - | ||||||||||||
236 | - | |||||||||||||
237 | \sa date, time | - | ||||||||||||
238 | */ | - | ||||||||||||
239 | - | |||||||||||||
240 | QDateTime QDateTimeEdit::dateTime() const | - | ||||||||||||
241 | { | - | ||||||||||||
242 | Q_D(const QDateTimeEdit); | - | ||||||||||||
243 | return d->value.toDateTime(); | - | ||||||||||||
244 | } | - | ||||||||||||
245 | - | |||||||||||||
246 | void QDateTimeEdit::setDateTime(const QDateTime &datetime) | - | ||||||||||||
247 | { | - | ||||||||||||
248 | Q_D(QDateTimeEdit); | - | ||||||||||||
249 | if (datetime.isValid()) {
| 0 | ||||||||||||
250 | d->clearCache(); | - | ||||||||||||
251 | const QDate date = datetime.date(); | - | ||||||||||||
252 | if (!(d->sections & DateSections_Mask))
| 0 | ||||||||||||
253 | setDateRange(datetime.date(), datetime., date());); never executed: setDateRange(date, date); | 0 | ||||||||||||
254 | d->setValue(QDateTime(datetime.date(),, datetime.time(), d->spec), EmitIfChanged); | - | ||||||||||||
255 | } never executed: end of block | 0 | ||||||||||||
256 | } never executed: end of block | 0 | ||||||||||||
257 | - | |||||||||||||
258 | /*! | - | ||||||||||||
259 | \property QDateTimeEdit::date | - | ||||||||||||
260 | \brief the QDate that is set in the widget | - | ||||||||||||
261 | - | |||||||||||||
262 | By default, this property contains a date that refers to January 1, 2000. | - | ||||||||||||
263 | - | |||||||||||||
264 | \sa time, dateTime | - | ||||||||||||
265 | */ | - | ||||||||||||
266 | - | |||||||||||||
267 | /*! | - | ||||||||||||
268 | Returns the date of the date time edit. | - | ||||||||||||
269 | */ | - | ||||||||||||
270 | QDate QDateTimeEdit::date() const | - | ||||||||||||
271 | { | - | ||||||||||||
272 | Q_D(const QDateTimeEdit); | - | ||||||||||||
273 | return d->value.toDate(); | - | ||||||||||||
274 | } | - | ||||||||||||
275 | - | |||||||||||||
276 | void QDateTimeEdit::setDate(const QDate &date) | - | ||||||||||||
277 | { | - | ||||||||||||
278 | Q_D(QDateTimeEdit); | - | ||||||||||||
279 | if (date.isValid()) { | - | ||||||||||||
280 | if (!(d->sections & DateSections_Mask)) | - | ||||||||||||
281 | setDateRange(date, date); | - | ||||||||||||
282 | - | |||||||||||||
283 | d->clearCache(); | - | ||||||||||||
284 | d->setValue(QDateTime(date, d->value.toTime(), d->spec), EmitIfChanged); | - | ||||||||||||
285 | d->updateTimeSpec(); | - | ||||||||||||
286 | } | - | ||||||||||||
287 | } | - | ||||||||||||
288 | - | |||||||||||||
289 | /*! | - | ||||||||||||
290 | \property QDateTimeEdit::time | - | ||||||||||||
291 | \brief the QTime that is set in the widget | - | ||||||||||||
292 | - | |||||||||||||
293 | By default, this property contains a time of 00:00:00 and 0 milliseconds. | - | ||||||||||||
294 | - | |||||||||||||
295 | \sa date, dateTime | - | ||||||||||||
296 | */ | - | ||||||||||||
297 | - | |||||||||||||
298 | /*! | - | ||||||||||||
299 | Returns the time of the date time edit. | - | ||||||||||||
300 | */ | - | ||||||||||||
301 | QTime QDateTimeEdit::time() const | - | ||||||||||||
302 | { | - | ||||||||||||
303 | Q_D(const QDateTimeEdit); | - | ||||||||||||
304 | return d->value.toTime(); | - | ||||||||||||
305 | } | - | ||||||||||||
306 | - | |||||||||||||
307 | void QDateTimeEdit::setTime(const QTime &time) | - | ||||||||||||
308 | { | - | ||||||||||||
309 | Q_D(QDateTimeEdit); | - | ||||||||||||
310 | if (time.isValid()) { | - | ||||||||||||
311 | d->clearCache(); | - | ||||||||||||
312 | d->setValue(QDateTime(d->value.toDate(), time, d->spec), EmitIfChanged); | - | ||||||||||||
313 | } | - | ||||||||||||
314 | } | - | ||||||||||||
315 | - | |||||||||||||
316 | - | |||||||||||||
317 | /*! | - | ||||||||||||
318 | \property QDateTimeEdit::minimumDateTime | - | ||||||||||||
319 | \since 4.4 | - | ||||||||||||
320 | - | |||||||||||||
321 | \brief the minimum datetime of the date time edit | - | ||||||||||||
322 | - | |||||||||||||
323 | When setting this property the \l maximumDateTime() is adjusted if | - | ||||||||||||
324 | necessary to ensure that the range remains valid. If the datetime is | - | ||||||||||||
325 | not a valid QDateTime object, this function does nothing. | - | ||||||||||||
326 | - | |||||||||||||
327 | The default minimumDateTime can be restored with | - | ||||||||||||
328 | clearMinimumDateTime() | - | ||||||||||||
329 | - | |||||||||||||
330 | By default, this property contains a date that refers to September 14, | - | ||||||||||||
331 | 1752 and a time of 00:00:00 and 0 milliseconds. | - | ||||||||||||
332 | - | |||||||||||||
333 | \sa maximumDateTime(), minimumTime(), maximumTime(), minimumDate(), | - | ||||||||||||
334 | maximumDate(), setDateTimeRange(), setDateRange(), setTimeRange(), | - | ||||||||||||
335 | clearMaximumDateTime(), clearMinimumDate(), | - | ||||||||||||
336 | clearMaximumDate(), clearMinimumTime(), clearMaximumTime() | - | ||||||||||||
337 | */ | - | ||||||||||||
338 | - | |||||||||||||
339 | QDateTime QDateTimeEdit::minimumDateTime() const | - | ||||||||||||
340 | { | - | ||||||||||||
341 | Q_D(const QDateTimeEdit); | - | ||||||||||||
342 | return d->minimum.toDateTime(); | - | ||||||||||||
343 | } | - | ||||||||||||
344 | - | |||||||||||||
345 | void QDateTimeEdit::clearMinimumDateTime() | - | ||||||||||||
346 | { | - | ||||||||||||
347 | setMinimumDateTime(QDateTime(QDATETIMEEDIT_COMPAT_DATE_MIN, QDATETIMEEDIT_TIME_MIN)); | - | ||||||||||||
348 | } | - | ||||||||||||
349 | - | |||||||||||||
350 | void QDateTimeEdit::setMinimumDateTime(const QDateTime &dt) | - | ||||||||||||
351 | { | - | ||||||||||||
352 | Q_D(QDateTimeEdit); | - | ||||||||||||
353 | if (dt.isValid() && dt.date() >= QDATETIMEEDIT_DATE_MIN) { | - | ||||||||||||
354 | const QDateTime m = dt.toTimeSpec(d->spec); | - | ||||||||||||
355 | const QDateTime max = d->maximum.toDateTime(); | - | ||||||||||||
356 | d->setRange(m, (max > m ? max : m)); | - | ||||||||||||
357 | } | - | ||||||||||||
358 | } | - | ||||||||||||
359 | - | |||||||||||||
360 | /*! | - | ||||||||||||
361 | \property QDateTimeEdit::maximumDateTime | - | ||||||||||||
362 | \since 4.4 | - | ||||||||||||
363 | - | |||||||||||||
364 | \brief the maximum datetime of the date time edit | - | ||||||||||||
365 | - | |||||||||||||
366 | When setting this property the \l minimumDateTime() is adjusted if | - | ||||||||||||
367 | necessary to ensure that the range remains valid. If the datetime is | - | ||||||||||||
368 | not a valid QDateTime object, this function does nothing. | - | ||||||||||||
369 | - | |||||||||||||
370 | The default maximumDateTime can be restored with | - | ||||||||||||
371 | clearMaximumDateTime(). | - | ||||||||||||
372 | - | |||||||||||||
373 | By default, this property contains a date that refers to 31 December, | - | ||||||||||||
374 | 7999 and a time of 23:59:59 and 999 milliseconds. | - | ||||||||||||
375 | - | |||||||||||||
376 | \sa minimumDateTime(), minimumTime(), maximumTime(), minimumDate(), | - | ||||||||||||
377 | maximumDate(), setDateTimeRange(), setDateRange(), setTimeRange(), | - | ||||||||||||
378 | clearMinimumDateTime(), clearMinimumDate(), | - | ||||||||||||
379 | clearMaximumDate(), clearMinimumTime(), clearMaximumTime() | - | ||||||||||||
380 | */ | - | ||||||||||||
381 | - | |||||||||||||
382 | QDateTime QDateTimeEdit::maximumDateTime() const | - | ||||||||||||
383 | { | - | ||||||||||||
384 | Q_D(const QDateTimeEdit); | - | ||||||||||||
385 | return d->maximum.toDateTime(); | - | ||||||||||||
386 | } | - | ||||||||||||
387 | - | |||||||||||||
388 | void QDateTimeEdit::clearMaximumDateTime() | - | ||||||||||||
389 | { | - | ||||||||||||
390 | setMaximumDateTime(QDATETIMEEDIT_DATETIME_MAX); | - | ||||||||||||
391 | } | - | ||||||||||||
392 | - | |||||||||||||
393 | void QDateTimeEdit::setMaximumDateTime(const QDateTime &dt) | - | ||||||||||||
394 | { | - | ||||||||||||
395 | Q_D(QDateTimeEdit); | - | ||||||||||||
396 | if (dt.isValid() && dt.date() <= QDATETIMEEDIT_DATE_MAX) { | - | ||||||||||||
397 | const QDateTime m = dt.toTimeSpec(d->spec); | - | ||||||||||||
398 | const QDateTime min = d->minimum.toDateTime(); | - | ||||||||||||
399 | d->setRange((min < m ? min : m), m); | - | ||||||||||||
400 | } | - | ||||||||||||
401 | } | - | ||||||||||||
402 | - | |||||||||||||
403 | - | |||||||||||||
404 | /*! | - | ||||||||||||
405 | Convenience function to set minimum and maximum date time with one | - | ||||||||||||
406 | function call. | - | ||||||||||||
407 | \since 4.4 | - | ||||||||||||
408 | - | |||||||||||||
409 | \snippet code/src_gui_widgets_qdatetimeedit.cpp 1 | - | ||||||||||||
410 | - | |||||||||||||
411 | is analogous to: | - | ||||||||||||
412 | - | |||||||||||||
413 | \snippet code/src_gui_widgets_qdatetimeedit.cpp 2 | - | ||||||||||||
414 | - | |||||||||||||
415 | If either \a min or \a max are not valid, this function does | - | ||||||||||||
416 | nothing. | - | ||||||||||||
417 | - | |||||||||||||
418 | \sa setMinimumDate(), maximumDate(), setMaximumDate(), | - | ||||||||||||
419 | clearMinimumDate(), setMinimumTime(), maximumTime(), | - | ||||||||||||
420 | setMaximumTime(), clearMinimumTime(), QDateTime::isValid() | - | ||||||||||||
421 | */ | - | ||||||||||||
422 | - | |||||||||||||
423 | void QDateTimeEdit::setDateTimeRange(const QDateTime &min, const QDateTime &max) | - | ||||||||||||
424 | { | - | ||||||||||||
425 | Q_D(QDateTimeEdit); | - | ||||||||||||
426 | const QDateTime minimum = min.toTimeSpec(d->spec); | - | ||||||||||||
427 | QDateTime maximum = max.toTimeSpec(d->spec); | - | ||||||||||||
428 | if (min > max) | - | ||||||||||||
429 | maximum = minimum; | - | ||||||||||||
430 | d->setRange(minimum, maximum); | - | ||||||||||||
431 | } | - | ||||||||||||
432 | - | |||||||||||||
433 | /*! | - | ||||||||||||
434 | \property QDateTimeEdit::minimumDate | - | ||||||||||||
435 | - | |||||||||||||
436 | \brief the minimum date of the date time edit | - | ||||||||||||
437 | - | |||||||||||||
438 | When setting this property the \l maximumDate is adjusted if | - | ||||||||||||
439 | necessary, to ensure that the range remains valid. If the date is | - | ||||||||||||
440 | not a valid QDate object, this function does nothing. | - | ||||||||||||
441 | - | |||||||||||||
442 | By default, this property contains a date that refers to September 14, 1752. | - | ||||||||||||
443 | The minimum date must be at least the first day in year 100, otherwise | - | ||||||||||||
444 | setMinimumDate() has no effect. | - | ||||||||||||
445 | - | |||||||||||||
446 | \sa minimumTime(), maximumTime(), setDateRange() | - | ||||||||||||
447 | */ | - | ||||||||||||
448 | - | |||||||||||||
449 | QDate QDateTimeEdit::minimumDate() const | - | ||||||||||||
450 | { | - | ||||||||||||
451 | Q_D(const QDateTimeEdit); | - | ||||||||||||
452 | return d->minimum.toDate(); | - | ||||||||||||
453 | } | - | ||||||||||||
454 | - | |||||||||||||
455 | void QDateTimeEdit::setMinimumDate(const QDate &min) | - | ||||||||||||
456 | { | - | ||||||||||||
457 | Q_D(QDateTimeEdit); | - | ||||||||||||
458 | if (min.isValid() && min >= QDATETIMEEDIT_DATE_MIN) { | - | ||||||||||||
459 | setMinimumDateTime(QDateTime(min, d->minimum.toTime(), d->spec)); | - | ||||||||||||
460 | } | - | ||||||||||||
461 | } | - | ||||||||||||
462 | - | |||||||||||||
463 | void QDateTimeEdit::clearMinimumDate() | - | ||||||||||||
464 | { | - | ||||||||||||
465 | setMinimumDate(QDATETIMEEDIT_COMPAT_DATE_MIN); | - | ||||||||||||
466 | } | - | ||||||||||||
467 | - | |||||||||||||
468 | /*! | - | ||||||||||||
469 | \property QDateTimeEdit::maximumDate | - | ||||||||||||
470 | - | |||||||||||||
471 | \brief the maximum date of the date time edit | - | ||||||||||||
472 | - | |||||||||||||
473 | When setting this property the \l minimumDate is adjusted if | - | ||||||||||||
474 | necessary to ensure that the range remains valid. If the date is | - | ||||||||||||
475 | not a valid QDate object, this function does nothing. | - | ||||||||||||
476 | - | |||||||||||||
477 | By default, this property contains a date that refers to December 31, 7999. | - | ||||||||||||
478 | - | |||||||||||||
479 | \sa minimumDate, minimumTime, maximumTime, setDateRange() | - | ||||||||||||
480 | */ | - | ||||||||||||
481 | - | |||||||||||||
482 | QDate QDateTimeEdit::maximumDate() const | - | ||||||||||||
483 | { | - | ||||||||||||
484 | Q_D(const QDateTimeEdit); | - | ||||||||||||
485 | return d->maximum.toDate(); | - | ||||||||||||
486 | } | - | ||||||||||||
487 | - | |||||||||||||
488 | void QDateTimeEdit::setMaximumDate(const QDate &max) | - | ||||||||||||
489 | { | - | ||||||||||||
490 | Q_D(QDateTimeEdit); | - | ||||||||||||
491 | if (max.isValid()) { | - | ||||||||||||
492 | setMaximumDateTime(QDateTime(max, d->maximum.toTime(), d->spec)); | - | ||||||||||||
493 | } | - | ||||||||||||
494 | } | - | ||||||||||||
495 | - | |||||||||||||
496 | void QDateTimeEdit::clearMaximumDate() | - | ||||||||||||
497 | { | - | ||||||||||||
498 | setMaximumDate(QDATETIMEEDIT_DATE_MAX); | - | ||||||||||||
499 | } | - | ||||||||||||
500 | - | |||||||||||||
501 | /*! | - | ||||||||||||
502 | \property QDateTimeEdit::minimumTime | - | ||||||||||||
503 | - | |||||||||||||
504 | \brief the minimum time of the date time edit | - | ||||||||||||
505 | - | |||||||||||||
506 | When setting this property the \l maximumTime is adjusted if | - | ||||||||||||
507 | necessary, to ensure that the range remains valid. If the time is | - | ||||||||||||
508 | not a valid QTime object, this function does nothing. | - | ||||||||||||
509 | - | |||||||||||||
510 | By default, this property contains a time of 00:00:00 and 0 milliseconds. | - | ||||||||||||
511 | - | |||||||||||||
512 | \sa maximumTime, minimumDate, maximumDate, setTimeRange() | - | ||||||||||||
513 | */ | - | ||||||||||||
514 | - | |||||||||||||
515 | QTime QDateTimeEdit::minimumTime() const | - | ||||||||||||
516 | { | - | ||||||||||||
517 | Q_D(const QDateTimeEdit); | - | ||||||||||||
518 | return d->minimum.toTime(); | - | ||||||||||||
519 | } | - | ||||||||||||
520 | - | |||||||||||||
521 | void QDateTimeEdit::setMinimumTime(const QTime &min) | - | ||||||||||||
522 | { | - | ||||||||||||
523 | Q_D(QDateTimeEdit); | - | ||||||||||||
524 | if (min.isValid()) { | - | ||||||||||||
525 | const QDateTime m(d->minimum.toDate(), min, d->spec); | - | ||||||||||||
526 | setMinimumDateTime(m); | - | ||||||||||||
527 | } | - | ||||||||||||
528 | } | - | ||||||||||||
529 | - | |||||||||||||
530 | void QDateTimeEdit::clearMinimumTime() | - | ||||||||||||
531 | { | - | ||||||||||||
532 | setMinimumTime(QDATETIMEEDIT_TIME_MIN); | - | ||||||||||||
533 | } | - | ||||||||||||
534 | - | |||||||||||||
535 | /*! | - | ||||||||||||
536 | \property QDateTimeEdit::maximumTime | - | ||||||||||||
537 | - | |||||||||||||
538 | \brief the maximum time of the date time edit | - | ||||||||||||
539 | - | |||||||||||||
540 | When setting this property, the \l minimumTime is adjusted if | - | ||||||||||||
541 | necessary to ensure that the range remains valid. If the time is | - | ||||||||||||
542 | not a valid QTime object, this function does nothing. | - | ||||||||||||
543 | - | |||||||||||||
544 | By default, this property contains a time of 23:59:59 and 999 milliseconds. | - | ||||||||||||
545 | - | |||||||||||||
546 | \sa minimumTime, minimumDate, maximumDate, setTimeRange() | - | ||||||||||||
547 | */ | - | ||||||||||||
548 | QTime QDateTimeEdit::maximumTime() const | - | ||||||||||||
549 | { | - | ||||||||||||
550 | Q_D(const QDateTimeEdit); | - | ||||||||||||
551 | return d->maximum.toTime(); | - | ||||||||||||
552 | } | - | ||||||||||||
553 | - | |||||||||||||
554 | void QDateTimeEdit::setMaximumTime(const QTime &max) | - | ||||||||||||
555 | { | - | ||||||||||||
556 | Q_D(QDateTimeEdit); | - | ||||||||||||
557 | if (max.isValid()) { | - | ||||||||||||
558 | const QDateTime m(d->maximum.toDate(), max); | - | ||||||||||||
559 | setMaximumDateTime(m); | - | ||||||||||||
560 | } | - | ||||||||||||
561 | } | - | ||||||||||||
562 | - | |||||||||||||
563 | void QDateTimeEdit::clearMaximumTime() | - | ||||||||||||
564 | { | - | ||||||||||||
565 | setMaximumTime(QDATETIMEEDIT_TIME_MAX); | - | ||||||||||||
566 | } | - | ||||||||||||
567 | - | |||||||||||||
568 | /*! | - | ||||||||||||
569 | Convenience function to set minimum and maximum date with one | - | ||||||||||||
570 | function call. | - | ||||||||||||
571 | - | |||||||||||||
572 | \snippet code/src_gui_widgets_qdatetimeedit.cpp 3 | - | ||||||||||||
573 | - | |||||||||||||
574 | is analogous to: | - | ||||||||||||
575 | - | |||||||||||||
576 | \snippet code/src_gui_widgets_qdatetimeedit.cpp 4 | - | ||||||||||||
577 | - | |||||||||||||
578 | If either \a min or \a max are not valid, this function does | - | ||||||||||||
579 | nothing. | - | ||||||||||||
580 | - | |||||||||||||
581 | \sa setMinimumDate(), maximumDate(), setMaximumDate(), | - | ||||||||||||
582 | clearMinimumDate(), setMinimumTime(), maximumTime(), | - | ||||||||||||
583 | setMaximumTime(), clearMinimumTime(), QDate::isValid() | - | ||||||||||||
584 | */ | - | ||||||||||||
585 | - | |||||||||||||
586 | void QDateTimeEdit::setDateRange(const QDate &min, const QDate &max) | - | ||||||||||||
587 | { | - | ||||||||||||
588 | Q_D(QDateTimeEdit); | - | ||||||||||||
589 | if (min.isValid() && max.isValid()) { | - | ||||||||||||
590 | setDateTimeRange(QDateTime(min, d->minimum.toTime(), d->spec), | - | ||||||||||||
591 | QDateTime(max, d->maximum.toTime(), d->spec)); | - | ||||||||||||
592 | } | - | ||||||||||||
593 | } | - | ||||||||||||
594 | - | |||||||||||||
595 | /*! | - | ||||||||||||
596 | Convenience function to set minimum and maximum time with one | - | ||||||||||||
597 | function call. | - | ||||||||||||
598 | - | |||||||||||||
599 | \snippet code/src_gui_widgets_qdatetimeedit.cpp 5 | - | ||||||||||||
600 | - | |||||||||||||
601 | is analogous to: | - | ||||||||||||
602 | - | |||||||||||||
603 | \snippet code/src_gui_widgets_qdatetimeedit.cpp 6 | - | ||||||||||||
604 | - | |||||||||||||
605 | If either \a min or \a max are not valid, this function does | - | ||||||||||||
606 | nothing. | - | ||||||||||||
607 | - | |||||||||||||
608 | \sa setMinimumDate(), maximumDate(), setMaximumDate(), | - | ||||||||||||
609 | clearMinimumDate(), setMinimumTime(), maximumTime(), | - | ||||||||||||
610 | setMaximumTime(), clearMinimumTime(), QTime::isValid() | - | ||||||||||||
611 | */ | - | ||||||||||||
612 | - | |||||||||||||
613 | void QDateTimeEdit::setTimeRange(const QTime &min, const QTime &max) | - | ||||||||||||
614 | { | - | ||||||||||||
615 | Q_D(QDateTimeEdit); | - | ||||||||||||
616 | if (min.isValid() && max.isValid()) { | - | ||||||||||||
617 | setDateTimeRange(QDateTime(d->minimum.toDate(), min, d->spec), | - | ||||||||||||
618 | QDateTime(d->maximum.toDate(), max, d->spec)); | - | ||||||||||||
619 | } | - | ||||||||||||
620 | } | - | ||||||||||||
621 | - | |||||||||||||
622 | /*! | - | ||||||||||||
623 | \property QDateTimeEdit::displayedSections | - | ||||||||||||
624 | - | |||||||||||||
625 | \brief the currently displayed fields of the date time edit | - | ||||||||||||
626 | - | |||||||||||||
627 | Returns a bit set of the displayed sections for this format. | - | ||||||||||||
628 | \a setDisplayFormat(), displayFormat() | - | ||||||||||||
629 | */ | - | ||||||||||||
630 | - | |||||||||||||
631 | QDateTimeEdit::Sections QDateTimeEdit::displayedSections() const | - | ||||||||||||
632 | { | - | ||||||||||||
633 | Q_D(const QDateTimeEdit); | - | ||||||||||||
634 | return d->sections; | - | ||||||||||||
635 | } | - | ||||||||||||
636 | - | |||||||||||||
637 | /*! | - | ||||||||||||
638 | \property QDateTimeEdit::currentSection | - | ||||||||||||
639 | - | |||||||||||||
640 | \brief the current section of the spinbox | - | ||||||||||||
641 | \a setCurrentSection() | - | ||||||||||||
642 | */ | - | ||||||||||||
643 | - | |||||||||||||
644 | QDateTimeEdit::Section QDateTimeEdit::currentSection() const | - | ||||||||||||
645 | { | - | ||||||||||||
646 | Q_D(const QDateTimeEdit); | - | ||||||||||||
647 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||
648 | if (QApplication::keypadNavigationEnabled() && d->focusOnButton) | - | ||||||||||||
649 | return NoSection; | - | ||||||||||||
650 | #endif | - | ||||||||||||
651 | return d->convertToPublic(d->sectionType(d->currentSectionIndex)); | - | ||||||||||||
652 | } | - | ||||||||||||
653 | - | |||||||||||||
654 | void QDateTimeEdit::setCurrentSection(Section section) | - | ||||||||||||
655 | { | - | ||||||||||||
656 | Q_D(QDateTimeEdit); | - | ||||||||||||
657 | if (section == NoSection || !(section & d->sections)) | - | ||||||||||||
658 | return; | - | ||||||||||||
659 | - | |||||||||||||
660 | d->updateCache(d->value, d->displayText()); | - | ||||||||||||
661 | const int size = d->sectionNodes.size(); | - | ||||||||||||
662 | int index = d->currentSectionIndex + 1; | - | ||||||||||||
663 | for (int i=0; i<2; ++i) { | - | ||||||||||||
664 | while (index < size) { | - | ||||||||||||
665 | if (d->convertToPublic(d->sectionType(index)) == section) { | - | ||||||||||||
666 | d->edit->setCursorPosition(d->sectionPos(index)); | - | ||||||||||||
667 | QDTEDEBUG << d->sectionPos(index); dead code: QMessageLogger(__FILE__, 667, __PRETTY_FUNCTION__).debug() << d->sectionPos(index); | - | ||||||||||||
668 | return; | - | ||||||||||||
669 | } | - | ||||||||||||
670 | ++index; | - | ||||||||||||
671 | } | - | ||||||||||||
672 | index = 0; | - | ||||||||||||
673 | } | - | ||||||||||||
674 | } | - | ||||||||||||
675 | - | |||||||||||||
676 | /*! | - | ||||||||||||
677 | \since 4.3 | - | ||||||||||||
678 | - | |||||||||||||
679 | Returns the Section at \a index. | - | ||||||||||||
680 | - | |||||||||||||
681 | If the format is 'yyyy/MM/dd', sectionAt(0) returns YearSection, | - | ||||||||||||
682 | sectionAt(1) returns MonthSection, and sectionAt(2) returns | - | ||||||||||||
683 | YearSection, | - | ||||||||||||
684 | */ | - | ||||||||||||
685 | - | |||||||||||||
686 | QDateTimeEdit::Section QDateTimeEdit::sectionAt(int index) const | - | ||||||||||||
687 | { | - | ||||||||||||
688 | Q_D(const QDateTimeEdit); | - | ||||||||||||
689 | if (index < 0 || index >= d->sectionNodes.size()) | - | ||||||||||||
690 | return NoSection; | - | ||||||||||||
691 | return d->convertToPublic(d->sectionType(index)); | - | ||||||||||||
692 | } | - | ||||||||||||
693 | - | |||||||||||||
694 | /*! | - | ||||||||||||
695 | \since 4.3 | - | ||||||||||||
696 | - | |||||||||||||
697 | \property QDateTimeEdit::sectionCount | - | ||||||||||||
698 | - | |||||||||||||
699 | \brief the number of sections displayed. | - | ||||||||||||
700 | If the format is 'yyyy/yy/yyyy', sectionCount returns 3 | - | ||||||||||||
701 | */ | - | ||||||||||||
702 | - | |||||||||||||
703 | int QDateTimeEdit::sectionCount() const | - | ||||||||||||
704 | { | - | ||||||||||||
705 | Q_D(const QDateTimeEdit); | - | ||||||||||||
706 | return d->sectionNodes.size(); | - | ||||||||||||
707 | } | - | ||||||||||||
708 | - | |||||||||||||
709 | - | |||||||||||||
710 | /*! | - | ||||||||||||
711 | \since 4.3 | - | ||||||||||||
712 | - | |||||||||||||
713 | \property QDateTimeEdit::currentSectionIndex | - | ||||||||||||
714 | - | |||||||||||||
715 | \brief the current section index of the spinbox | - | ||||||||||||
716 | - | |||||||||||||
717 | If the format is 'yyyy/MM/dd', the displayText is '2001/05/21', and | - | ||||||||||||
718 | the cursorPosition is 5, currentSectionIndex returns 1. If the | - | ||||||||||||
719 | cursorPosition is 3, currentSectionIndex is 0, and so on. | - | ||||||||||||
720 | - | |||||||||||||
721 | \a setCurrentSection() | - | ||||||||||||
722 | \sa currentSection() | - | ||||||||||||
723 | */ | - | ||||||||||||
724 | - | |||||||||||||
725 | int QDateTimeEdit::currentSectionIndex() const | - | ||||||||||||
726 | { | - | ||||||||||||
727 | Q_D(const QDateTimeEdit); | - | ||||||||||||
728 | return d->currentSectionIndex; | - | ||||||||||||
729 | } | - | ||||||||||||
730 | - | |||||||||||||
731 | void QDateTimeEdit::setCurrentSectionIndex(int index) | - | ||||||||||||
732 | { | - | ||||||||||||
733 | Q_D(QDateTimeEdit); | - | ||||||||||||
734 | if (index < 0 || index >= d->sectionNodes.size()) | - | ||||||||||||
735 | return; | - | ||||||||||||
736 | d->edit->setCursorPosition(d->sectionPos(index)); | - | ||||||||||||
737 | } | - | ||||||||||||
738 | - | |||||||||||||
739 | /*! | - | ||||||||||||
740 | \since 4.4 | - | ||||||||||||
741 | - | |||||||||||||
742 | \brief Returns the calendar widget for the editor if calendarPopup is | - | ||||||||||||
743 | set to true and (sections() & DateSections_Mask) != 0. | - | ||||||||||||
744 | - | |||||||||||||
745 | This function creates and returns a calendar widget if none has been set. | - | ||||||||||||
746 | */ | - | ||||||||||||
747 | - | |||||||||||||
748 | - | |||||||||||||
749 | QCalendarWidget *QDateTimeEdit::calendarWidget() const | - | ||||||||||||
750 | { | - | ||||||||||||
751 | Q_D(const QDateTimeEdit); | - | ||||||||||||
752 | if (!d->calendarPopup || !(d->sections & QDateTimeParser::DateSectionMask)) | - | ||||||||||||
753 | return 0; | - | ||||||||||||
754 | if (!d->monthCalendar) { | - | ||||||||||||
755 | const_cast<QDateTimeEditPrivate*>(d)->initCalendarPopup(); | - | ||||||||||||
756 | } | - | ||||||||||||
757 | return d->monthCalendar->calendarWidget(); | - | ||||||||||||
758 | } | - | ||||||||||||
759 | - | |||||||||||||
760 | /*! | - | ||||||||||||
761 | \since 4.4 | - | ||||||||||||
762 | - | |||||||||||||
763 | Sets the given \a calendarWidget as the widget to be used for the calendar | - | ||||||||||||
764 | pop-up. The editor does not automatically take ownership of the calendar widget. | - | ||||||||||||
765 | - | |||||||||||||
766 | \note calendarPopup must be set to true before setting the calendar widget. | - | ||||||||||||
767 | \sa calendarPopup | - | ||||||||||||
768 | */ | - | ||||||||||||
769 | void QDateTimeEdit::setCalendarWidget(QCalendarWidget *calendarWidget) | - | ||||||||||||
770 | { | - | ||||||||||||
771 | Q_D(QDateTimeEdit); | - | ||||||||||||
772 | if (Q_UNLIKELY(!calendarWidget))) {
| 0 | ||||||||||||
773 | qWarning("QDateTimeEdit::setCalendarWidget: Cannot set a null calendar widget"); | - | ||||||||||||
774 | return; never executed: return; | 0 | ||||||||||||
775 | } | - | ||||||||||||
776 | - | |||||||||||||
777 | if (Q_UNLIKELY(!d->calendarPopup))) {
| 0 | ||||||||||||
778 | qWarning("QDateTimeEdit::setCalendarWidget: calendarPopup is set to false"); | - | ||||||||||||
779 | return; never executed: return; | 0 | ||||||||||||
780 | } | - | ||||||||||||
781 | - | |||||||||||||
782 | if (Q_UNLIKELY(!(d->display & QDateTimeParser::DateSectionMask))))) {
| 0 | ||||||||||||
783 | qWarning("QDateTimeEdit::setCalendarWidget: no date sections specified"); | - | ||||||||||||
784 | return; never executed: return; | 0 | ||||||||||||
785 | } | - | ||||||||||||
786 | d->initCalendarPopup(calendarWidget); | - | ||||||||||||
787 | } never executed: end of block | 0 | ||||||||||||
788 | - | |||||||||||||
789 | - | |||||||||||||
790 | /*! | - | ||||||||||||
791 | \since 4.2 | - | ||||||||||||
792 | - | |||||||||||||
793 | Selects \a section. If \a section doesn't exist in the currently | - | ||||||||||||
794 | displayed sections, this function does nothing. If \a section is | - | ||||||||||||
795 | NoSection, this function will unselect all text in the editor. | - | ||||||||||||
796 | Otherwise, this function will move the cursor and the current section | - | ||||||||||||
797 | to the selected section. | - | ||||||||||||
798 | - | |||||||||||||
799 | \sa currentSection() | - | ||||||||||||
800 | */ | - | ||||||||||||
801 | - | |||||||||||||
802 | void QDateTimeEdit::setSelectedSection(Section section) | - | ||||||||||||
803 | { | - | ||||||||||||
804 | Q_D(QDateTimeEdit); | - | ||||||||||||
805 | if (section == NoSection) { | - | ||||||||||||
806 | d->edit->setSelection(d->edit->cursorPosition(), 0); | - | ||||||||||||
807 | } else if (section & d->sections) { | - | ||||||||||||
808 | if (currentSection() != section) | - | ||||||||||||
809 | setCurrentSection(section); | - | ||||||||||||
810 | d->setSelected(d->currentSectionIndex); | - | ||||||||||||
811 | } | - | ||||||||||||
812 | } | - | ||||||||||||
813 | - | |||||||||||||
814 | - | |||||||||||||
815 | - | |||||||||||||
816 | /*! | - | ||||||||||||
817 | \fn QString QDateTimeEdit::sectionText(Section section) const | - | ||||||||||||
818 | - | |||||||||||||
819 | Returns the text from the given \a section. | - | ||||||||||||
820 | - | |||||||||||||
821 | \sa currentSection() | - | ||||||||||||
822 | */ | - | ||||||||||||
823 | - | |||||||||||||
824 | QString QDateTimeEdit::sectionText(Section section) const | - | ||||||||||||
825 | { | - | ||||||||||||
826 | Q_D(const QDateTimeEdit); | - | ||||||||||||
827 | if (section == QDateTimeEdit::NoSection || !(section & d->sections)) { | - | ||||||||||||
828 | return QString(); | - | ||||||||||||
829 | } | - | ||||||||||||
830 | - | |||||||||||||
831 | d->updateCache(d->value, d->displayText()); | - | ||||||||||||
832 | const int sectionIndex = d->absoluteIndex(section, 0); | - | ||||||||||||
833 | return d->sectionText(sectionIndex); | - | ||||||||||||
834 | } | - | ||||||||||||
835 | - | |||||||||||||
836 | /*! | - | ||||||||||||
837 | \property QDateTimeEdit::displayFormat | - | ||||||||||||
838 | - | |||||||||||||
839 | \brief the format used to display the time/date of the date time edit | - | ||||||||||||
840 | - | |||||||||||||
841 | This format is described in QDateTime::toString() and QDateTime::fromString() | - | ||||||||||||
842 | - | |||||||||||||
843 | Example format strings (assuming that the date is 2nd of July 1969): | - | ||||||||||||
844 | - | |||||||||||||
845 | \table | - | ||||||||||||
846 | \header \li Format \li Result | - | ||||||||||||
847 | \row \li dd.MM.yyyy \li 02.07.1969 | - | ||||||||||||
848 | \row \li MMM d yy \li Jul 2 69 | - | ||||||||||||
849 | \row \li MMMM d yy \li July 2 69 | - | ||||||||||||
850 | \endtable | - | ||||||||||||
851 | - | |||||||||||||
852 | Note that if you specify a two digit year, it will be interpreted | - | ||||||||||||
853 | to be in the century in which the date time edit was initialized. | - | ||||||||||||
854 | The default century is the 21 (2000-2099). | - | ||||||||||||
855 | - | |||||||||||||
856 | If you specify an invalid format the format will not be set. | - | ||||||||||||
857 | - | |||||||||||||
858 | \sa QDateTime::toString(), displayedSections() | - | ||||||||||||
859 | */ | - | ||||||||||||
860 | - | |||||||||||||
861 | QString QDateTimeEdit::displayFormat() const | - | ||||||||||||
862 | { | - | ||||||||||||
863 | Q_D(const QDateTimeEdit); | - | ||||||||||||
864 | return isRightToLeft() ? d->unreversedFormat : d->displayFormat; | - | ||||||||||||
} | ||||||||||||||
template<typename C> static inline C reverse(const C &l) | ||||||||||||||
{ | ||||||||||||||
C ret; | ||||||||||||||
for (int i=l.size() - 1; i>=0; --i) | ||||||||||||||
ret.append(l.at(i)); | ||||||||||||||
return ret; | ||||||||||||||
865 | } | - | ||||||||||||
866 | - | |||||||||||||
867 | void QDateTimeEdit::setDisplayFormat(const QString &format) | - | ||||||||||||
868 | { | - | ||||||||||||
869 | Q_D(QDateTimeEdit); | - | ||||||||||||
870 | if (d->parseFormat(format)) {
| 0 | ||||||||||||
871 | d->unreversedFormat.clear(); | - | ||||||||||||
872 | if (isRightToLeft()) {
| 0 | ||||||||||||
873 | d->unreversedFormat = format; | - | ||||||||||||
874 | d->displayFormat.clear(); | - | ||||||||||||
875 | for (int i=d->sectionNodes.size() - 1; i>=0; --i) {
| 0 | ||||||||||||
876 | d->displayFormat += d->separators.at(i + 1); | - | ||||||||||||
877 | d->displayFormat += d->sectionNode(i).format(); | - | ||||||||||||
878 | } never executed: end of block | 0 | ||||||||||||
879 | d->displayFormat += d->separators.at(0); | - | ||||||||||||
880 | d->separators =std::reverse(d->separators);.begin(), d->sectionNodes =separators.end()); | - | ||||||||||||
881 | std::reverse(d->sectionNodes);.begin(), d->sectionNodes.end()); | - | ||||||||||||
882 | } never executed: end of block | 0 | ||||||||||||
883 | - | |||||||||||||
884 | d->formatExplicitlySet = true; | - | ||||||||||||
885 | d->sections = d->convertSections(d->display); | - | ||||||||||||
886 | d->clearCache(); | - | ||||||||||||
887 | - | |||||||||||||
888 | d->currentSectionIndex = qMin(d->currentSectionIndex, d->sectionNodes.size() - 1); | - | ||||||||||||
889 | const bool timeShown = (d->sections & TimeSections_Mask); | - | ||||||||||||
890 | const bool dateShown = (d->sections & DateSections_Mask); | - | ||||||||||||
891 | Q_ASSERT(dateShown || timeShown); | - | ||||||||||||
892 | if (timeShown && !dateShown) {
| 0 | ||||||||||||
893 | QTime time = d->value.toTime(); | - | ||||||||||||
894 | setDateRange(d->value.toDate(), d->value.toDate()); | - | ||||||||||||
895 | if (d->minimum.toTime() >= d->maximum.toTime()) {
| 0 | ||||||||||||
896 | setTimeRange(QDATETIMEEDIT_TIME_MIN, QDATETIMEEDIT_TIME_MAX); | - | ||||||||||||
897 | // if the time range became invalid during the adjustment, the time would have been reset | - | ||||||||||||
898 | setTime(time); | - | ||||||||||||
899 | } never executed: end of block | 0 | ||||||||||||
900 | } else if (dateShown && !timeShown) { never executed: end of block
| 0 | ||||||||||||
901 | setTimeRange(QDATETIMEEDIT_TIME_MIN, QDATETIMEEDIT_TIME_MAX); | - | ||||||||||||
902 | d->value = QDateTime(d->value.toDate(), QTime(), d->spec); | - | ||||||||||||
903 | } never executed: end of block | 0 | ||||||||||||
904 | d->updateEdit(); | - | ||||||||||||
905 | d->_q_editorCursorPositionChanged(-1, 0); | - | ||||||||||||
906 | } never executed: end of block | 0 | ||||||||||||
907 | } never executed: end of block | 0 | ||||||||||||
908 | - | |||||||||||||
909 | /*! | - | ||||||||||||
910 | \property QDateTimeEdit::calendarPopup | - | ||||||||||||
911 | \brief the current calendar pop-up show mode. | - | ||||||||||||
912 | \since 4.2 | - | ||||||||||||
913 | - | |||||||||||||
914 | The calendar pop-up will be shown upon clicking the arrow button. | - | ||||||||||||
915 | This property is valid only if there is a valid date display format. | - | ||||||||||||
916 | - | |||||||||||||
917 | \sa setDisplayFormat() | - | ||||||||||||
918 | */ | - | ||||||||||||
919 | - | |||||||||||||
920 | bool QDateTimeEdit::calendarPopup() const | - | ||||||||||||
921 | { | - | ||||||||||||
922 | Q_D(const QDateTimeEdit); | - | ||||||||||||
923 | return d->calendarPopup; | - | ||||||||||||
924 | } | - | ||||||||||||
925 | - | |||||||||||||
926 | void QDateTimeEdit::setCalendarPopup(bool enable) | - | ||||||||||||
927 | { | - | ||||||||||||
928 | Q_D(QDateTimeEdit); | - | ||||||||||||
929 | if (enable == d->calendarPopup) | - | ||||||||||||
930 | return; | - | ||||||||||||
931 | setAttribute(Qt::WA_MacShowFocusRect, !enable); | - | ||||||||||||
932 | d->calendarPopup = enable; | - | ||||||||||||
933 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||
934 | if (!enable) | - | ||||||||||||
935 | d->focusOnButton = false; | - | ||||||||||||
936 | #endif | - | ||||||||||||
937 | d->updateEditFieldGeometry(); | - | ||||||||||||
938 | update(); | - | ||||||||||||
939 | } | - | ||||||||||||
940 | - | |||||||||||||
941 | /*! | - | ||||||||||||
942 | \property QDateTimeEdit::timeSpec | - | ||||||||||||
943 | \brief the current timespec used by the date time edit. | - | ||||||||||||
944 | \since 4.4 | - | ||||||||||||
945 | */ | - | ||||||||||||
946 | - | |||||||||||||
947 | Qt::TimeSpec QDateTimeEdit::timeSpec() const | - | ||||||||||||
948 | { | - | ||||||||||||
949 | Q_D(const QDateTimeEdit); | - | ||||||||||||
950 | return d->spec; | - | ||||||||||||
951 | } | - | ||||||||||||
952 | - | |||||||||||||
953 | void QDateTimeEdit::setTimeSpec(Qt::TimeSpec spec) | - | ||||||||||||
954 | { | - | ||||||||||||
955 | Q_D(QDateTimeEdit); | - | ||||||||||||
956 | if (spec != d->spec) { | - | ||||||||||||
957 | d->spec = spec; | - | ||||||||||||
958 | d->updateTimeSpec(); | - | ||||||||||||
959 | } | - | ||||||||||||
960 | } | - | ||||||||||||
961 | - | |||||||||||||
962 | /*! | - | ||||||||||||
963 | \reimp | - | ||||||||||||
964 | */ | - | ||||||||||||
965 | - | |||||||||||||
966 | QSize QDateTimeEdit::sizeHint() const | - | ||||||||||||
967 | { | - | ||||||||||||
968 | Q_D(const QDateTimeEdit); | - | ||||||||||||
969 | if (d->cachedSizeHint.isEmpty()) { | - | ||||||||||||
970 | ensurePolished(); | - | ||||||||||||
971 | - | |||||||||||||
972 | const QFontMetrics fm(fontMetrics()); | - | ||||||||||||
973 | int h = d->edit->sizeHint().height(); | - | ||||||||||||
974 | int w = 0; | - | ||||||||||||
975 | QString s; | - | ||||||||||||
976 | s = d->textFromValue(d->minimum) + QLatin1Char(' '); | - | ||||||||||||
977 | w = qMax<int>(w, fm.width(s)); | - | ||||||||||||
978 | s = d->textFromValue(d->maximum) + QLatin1Char(' '); | - | ||||||||||||
979 | w = qMax<int>(w, fm.width(s)); | - | ||||||||||||
980 | if (d->specialValueText.size()) { | - | ||||||||||||
981 | s = d->specialValueText; | - | ||||||||||||
982 | w = qMax<int>(w, fm.width(s)); | - | ||||||||||||
983 | } | - | ||||||||||||
984 | w += 2; // cursor blinking space | - | ||||||||||||
985 | - | |||||||||||||
986 | QSize hint(w, h); | - | ||||||||||||
987 | - | |||||||||||||
988 | #ifdef Q_OS_MAC | - | ||||||||||||
989 | if (d->calendarPopupEnabled()) { | - | ||||||||||||
990 | QStyleOptionComboBox opt; | - | ||||||||||||
991 | d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_ComboBox, &opt, hint, this); | - | ||||||||||||
992 | } else | - | ||||||||||||
993 | #endif | - | ||||||||||||
994 | { | - | ||||||||||||
995 | QStyleOptionSpinBox opt; | - | ||||||||||||
996 | initStyleOption(&opt); | - | ||||||||||||
997 | d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this) | - | ||||||||||||
998 | .expandedTo(QApplication::globalStrut()); | - | ||||||||||||
999 | } | - | ||||||||||||
1000 | - | |||||||||||||
1001 | d->cachedMinimumSizeHint = d->cachedSizeHint; | - | ||||||||||||
1002 | // essentially make minimumSizeHint return the same as sizeHint for datetimeedits | - | ||||||||||||
1003 | } | - | ||||||||||||
1004 | return d->cachedSizeHint; | - | ||||||||||||
1005 | } | - | ||||||||||||
1006 | - | |||||||||||||
1007 | - | |||||||||||||
1008 | /*! | - | ||||||||||||
1009 | \reimp | - | ||||||||||||
1010 | */ | - | ||||||||||||
1011 | - | |||||||||||||
1012 | bool QDateTimeEdit::event(QEvent *event) | - | ||||||||||||
1013 | { | - | ||||||||||||
1014 | Q_D(QDateTimeEdit); | - | ||||||||||||
1015 | switch (event->type()) { | - | ||||||||||||
1016 | case QEvent::ApplicationLayoutDirectionChange: { | - | ||||||||||||
1017 | const bool was = d->formatExplicitlySet; | - | ||||||||||||
1018 | const QString oldFormat = d->displayFormat; | - | ||||||||||||
1019 | d->displayFormat.clear(); | - | ||||||||||||
1020 | setDisplayFormat(oldFormat); | - | ||||||||||||
1021 | d->formatExplicitlySet = was; | - | ||||||||||||
1022 | break; } | - | ||||||||||||
1023 | case QEvent::LocaleChange: | - | ||||||||||||
1024 | d->updateEdit(); | - | ||||||||||||
1025 | break; | - | ||||||||||||
1026 | case QEvent::StyleChange: | - | ||||||||||||
1027 | #ifdef Q_OS_MAC | - | ||||||||||||
1028 | case QEvent::MacSizeChange: | - | ||||||||||||
1029 | #endif | - | ||||||||||||
1030 | d->setLayoutItemMargins(QStyle::SE_DateTimeEditLayoutItem); | - | ||||||||||||
1031 | break; | - | ||||||||||||
1032 | default: | - | ||||||||||||
1033 | break; | - | ||||||||||||
1034 | } | - | ||||||||||||
1035 | return QAbstractSpinBox::event(event); | - | ||||||||||||
1036 | } | - | ||||||||||||
1037 | - | |||||||||||||
1038 | /*! | - | ||||||||||||
1039 | \reimp | - | ||||||||||||
1040 | */ | - | ||||||||||||
1041 | - | |||||||||||||
1042 | void QDateTimeEdit::clear() | - | ||||||||||||
1043 | { | - | ||||||||||||
1044 | Q_D(QDateTimeEdit); | - | ||||||||||||
1045 | d->clearSection(d->currentSectionIndex); | - | ||||||||||||
1046 | } | - | ||||||||||||
1047 | /*! | - | ||||||||||||
1048 | \reimp | - | ||||||||||||
1049 | */ | - | ||||||||||||
1050 | - | |||||||||||||
1051 | void QDateTimeEdit::keyPressEvent(QKeyEvent *event) | - | ||||||||||||
1052 | { | - | ||||||||||||
1053 | Q_D(QDateTimeEdit); | - | ||||||||||||
1054 | int oldCurrent = d->currentSectionIndex; | - | ||||||||||||
1055 | bool select = true; | - | ||||||||||||
1056 | bool inserted = false; | - | ||||||||||||
1057 | - | |||||||||||||
1058 | switch (event->key()) { | - | ||||||||||||
1059 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||
1060 | case Qt::Key_NumberSign: //shortcut to popup calendar | - | ||||||||||||
1061 | if (QApplication::keypadNavigationEnabled() && d->calendarPopupEnabled()) { | - | ||||||||||||
1062 | d->initCalendarPopup(); | - | ||||||||||||
1063 | d->positionCalendarPopup(); | - | ||||||||||||
1064 | d->monthCalendar->show(); | - | ||||||||||||
1065 | return; | - | ||||||||||||
1066 | } | - | ||||||||||||
1067 | break; | - | ||||||||||||
1068 | case Qt::Key_Select: | - | ||||||||||||
1069 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||
1070 | if (hasEditFocus()) { | - | ||||||||||||
1071 | if (d->focusOnButton) { | - | ||||||||||||
1072 | d->initCalendarPopup(); | - | ||||||||||||
1073 | d->positionCalendarPopup(); | - | ||||||||||||
1074 | d->monthCalendar->show(); | - | ||||||||||||
1075 | d->focusOnButton = false; | - | ||||||||||||
1076 | return; | - | ||||||||||||
1077 | } | - | ||||||||||||
1078 | setEditFocus(false); | - | ||||||||||||
1079 | selectAll(); | - | ||||||||||||
1080 | } else { | - | ||||||||||||
1081 | setEditFocus(true); | - | ||||||||||||
1082 | - | |||||||||||||
1083 | //hide cursor | - | ||||||||||||
1084 | d->edit->d_func()->setCursorVisible(false); | - | ||||||||||||
1085 | d->edit->d_func()->control->setCursorBlinkPeriod(0); | - | ||||||||||||
1086 | d->setSelected(0); | - | ||||||||||||
1087 | } | - | ||||||||||||
1088 | } | - | ||||||||||||
1089 | return; | - | ||||||||||||
1090 | #endif | - | ||||||||||||
1091 | case Qt::Key_Enter: | - | ||||||||||||
1092 | case Qt::Key_Return: | - | ||||||||||||
1093 | d->interpret(AlwaysEmit); | - | ||||||||||||
1094 | d->setSelected(d->currentSectionIndex, true); | - | ||||||||||||
1095 | event->ignore(); | - | ||||||||||||
1096 | emit editingFinished(); | - | ||||||||||||
1097 | return; | - | ||||||||||||
1098 | default: | - | ||||||||||||
1099 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||
1100 | if (QApplication::keypadNavigationEnabled() && !hasEditFocus() | - | ||||||||||||
1101 | && !event->text().isEmpty() && event->text().at(0).isLetterOrNumber()) { | - | ||||||||||||
1102 | setEditFocus(true); | - | ||||||||||||
1103 | - | |||||||||||||
1104 | //hide cursor | - | ||||||||||||
1105 | d->edit->d_func()->setCursorVisible(false); | - | ||||||||||||
1106 | d->edit->d_func()->control->setCursorBlinkPeriod(0); | - | ||||||||||||
1107 | d->setSelected(0); | - | ||||||||||||
1108 | oldCurrent = 0; | - | ||||||||||||
1109 | } | - | ||||||||||||
1110 | #endif | - | ||||||||||||
1111 | if (!d->isSeparatorKey(event)) { | - | ||||||||||||
1112 | inserted = select = !event->text().isEmpty() && event->text().at(0).isPrint() | - | ||||||||||||
1113 | && !(event->modifiers() & ~(Qt::ShiftModifier|Qt::KeypadModifier)); | - | ||||||||||||
1114 | break; | - | ||||||||||||
1115 | } | - | ||||||||||||
1116 | case Qt::Key_Left: | - | ||||||||||||
1117 | case Qt::Key_Right: | - | ||||||||||||
1118 | if (event->key() == Qt::Key_Left || event->key() == Qt::Key_Right) { | - | ||||||||||||
1119 | if ( | - | ||||||||||||
1120 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||
1121 | QApplication::keypadNavigationEnabled() && !hasEditFocus() | - | ||||||||||||
1122 | || !QApplication::keypadNavigationEnabled() && | - | ||||||||||||
1123 | #endif | - | ||||||||||||
1124 | !(event->modifiers() & Qt::ControlModifier)) { | - | ||||||||||||
1125 | select = false; | - | ||||||||||||
1126 | break; | - | ||||||||||||
1127 | } | - | ||||||||||||
1128 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||
1129 | else | - | ||||||||||||
1130 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||
1131 | if (!QApplication::keypadNavigationEnabled()) | - | ||||||||||||
1132 | #endif | - | ||||||||||||
1133 | { | - | ||||||||||||
1134 | select = (event->modifiers() & Qt::ShiftModifier); | - | ||||||||||||
1135 | break; | - | ||||||||||||
1136 | } | - | ||||||||||||
1137 | #endif | - | ||||||||||||
1138 | } | - | ||||||||||||
1139 | // else fall through | - | ||||||||||||
1140 | case Qt::Key_Backtab: | - | ||||||||||||
1141 | case Qt::Key_Tab: { | - | ||||||||||||
1142 | event->accept(); | - | ||||||||||||
1143 | if (d->specialValue()) { | - | ||||||||||||
1144 | d->edit->setSelection(d->edit->cursorPosition(), 0); | - | ||||||||||||
1145 | return; | - | ||||||||||||
1146 | } | - | ||||||||||||
1147 | const bool forward = event->key() != Qt::Key_Left && event->key() != Qt::Key_Backtab | - | ||||||||||||
1148 | && (event->key() != Qt::Key_Tab || !(event->modifiers() & Qt::ShiftModifier)); | - | ||||||||||||
1149 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||
1150 | int newSection = d->nextPrevSection(d->currentSectionIndex, forward); | - | ||||||||||||
1151 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||
1152 | if (d->focusOnButton) { | - | ||||||||||||
1153 | newSection = forward ? 0 : d->sectionNodes.size() - 1; | - | ||||||||||||
1154 | d->focusOnButton = false; | - | ||||||||||||
1155 | update(); | - | ||||||||||||
1156 | } else if (newSection < 0 && select && d->calendarPopupEnabled()) { | - | ||||||||||||
1157 | setSelectedSection(NoSection); | - | ||||||||||||
1158 | d->focusOnButton = true; | - | ||||||||||||
1159 | update(); | - | ||||||||||||
1160 | return; | - | ||||||||||||
1161 | } | - | ||||||||||||
1162 | } | - | ||||||||||||
1163 | // only allow date/time sections to be selected. | - | ||||||||||||
1164 | if (newSection & ~(QDateTimeParser::TimeSectionMask | QDateTimeParser::DateSectionMask)) | - | ||||||||||||
1165 | return; | - | ||||||||||||
1166 | #endif | - | ||||||||||||
1167 | //key tab and backtab will be managed thrgout QWidget::event | - | ||||||||||||
1168 | if (event->key() != Qt::Key_Backtab && event->key() != Qt::Key_Tab) | - | ||||||||||||
1169 | focusNextPrevChild(forward); | - | ||||||||||||
1170 | - | |||||||||||||
1171 | return; } | - | ||||||||||||
1172 | } | - | ||||||||||||
1173 | QAbstractSpinBox::keyPressEvent(event); | - | ||||||||||||
1174 | if (select && !d->edit->hasSelectedText()) { | - | ||||||||||||
1175 | if (inserted && d->sectionAt(d->edit->cursorPosition()) == QDateTimeParser::NoSectionIndex) { | - | ||||||||||||
1176 | QString str = d->displayText(); | - | ||||||||||||
1177 | int pos = d->edit->cursorPosition(); | - | ||||||||||||
1178 | if (validate(str, pos) == QValidator::Acceptable | - | ||||||||||||
1179 | && (d->sectionNodes.at(oldCurrent).count != 1 | - | ||||||||||||
1180 | || d->sectionMaxSize(oldCurrent) == d->sectionSize(oldCurrent) | - | ||||||||||||
1181 | || d->skipToNextSection(oldCurrent, d->value.toDateTime(), d->sectionText(oldCurrent)))) { | - | ||||||||||||
1182 | QDTEDEBUG << "Setting currentsection to" dead code: QMessageLogger(__FILE__, 1182, __PRETTY_FUNCTION__).debug() << "Setting currentsection to" << d->closestSection(d->edit->cursorPosition(), true) << event->key() << oldCurrent << str; | - | ||||||||||||
1183 | << d->closestSection(d->edit->cursorPosition(), true) << event->key() dead code: QMessageLogger(__FILE__, 1182, __PRETTY_FUNCTION__).debug() << "Setting currentsection to" << d->closestSection(d->edit->cursorPosition(), true) << event->key() << oldCurrent << str; | - | ||||||||||||
1184 | << oldCurrent << str; dead code: QMessageLogger(__FILE__, 1182, __PRETTY_FUNCTION__).debug() << "Setting currentsection to" << d->closestSection(d->edit->cursorPosition(), true) << event->key() << oldCurrent << str; | - | ||||||||||||
1185 | const int tmp = d->closestSection(d->edit->cursorPosition(), true); | - | ||||||||||||
1186 | if (tmp >= 0) | - | ||||||||||||
1187 | d->currentSectionIndex = tmp; | - | ||||||||||||
1188 | } | - | ||||||||||||
1189 | } | - | ||||||||||||
1190 | if (d->currentSectionIndex != oldCurrent) { | - | ||||||||||||
1191 | d->setSelected(d->currentSectionIndex); | - | ||||||||||||
1192 | } | - | ||||||||||||
1193 | } | - | ||||||||||||
1194 | if (d->specialValue()) { | - | ||||||||||||
1195 | d->edit->setSelection(d->edit->cursorPosition(), 0); | - | ||||||||||||
1196 | } | - | ||||||||||||
1197 | } | - | ||||||||||||
1198 | - | |||||||||||||
1199 | /*! | - | ||||||||||||
1200 | \reimp | - | ||||||||||||
1201 | */ | - | ||||||||||||
1202 | - | |||||||||||||
1203 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||
1204 | void QDateTimeEdit::wheelEvent(QWheelEvent *event) | - | ||||||||||||
1205 | { | - | ||||||||||||
1206 | QAbstractSpinBox::wheelEvent(event); | - | ||||||||||||
1207 | } | - | ||||||||||||
1208 | #endif | - | ||||||||||||
1209 | - | |||||||||||||
1210 | /*! | - | ||||||||||||
1211 | \reimp | - | ||||||||||||
1212 | */ | - | ||||||||||||
1213 | - | |||||||||||||
1214 | void QDateTimeEdit::focusInEvent(QFocusEvent *event) | - | ||||||||||||
1215 | { | - | ||||||||||||
1216 | Q_D(QDateTimeEdit); | - | ||||||||||||
1217 | QAbstractSpinBox::focusInEvent(event); | - | ||||||||||||
1218 | QString *frm = 0; | - | ||||||||||||
1219 | const int oldPos = d->edit->cursorPosition(); | - | ||||||||||||
1220 | if (!d->formatExplicitlySet) { | - | ||||||||||||
1221 | if (d->displayFormat == d->defaultTimeFormat) { | - | ||||||||||||
1222 | frm = &d->defaultTimeFormat; | - | ||||||||||||
1223 | } else if (d->displayFormat == d->defaultDateFormat) { | - | ||||||||||||
1224 | frm = &d->defaultDateFormat; | - | ||||||||||||
1225 | } else if (d->displayFormat == d->defaultDateTimeFormat) { | - | ||||||||||||
1226 | frm = &d->defaultDateTimeFormat; | - | ||||||||||||
1227 | } | - | ||||||||||||
1228 | - | |||||||||||||
1229 | if (frm) { | - | ||||||||||||
1230 | d->readLocaleSettings(); | - | ||||||||||||
1231 | if (d->displayFormat != *frm) { | - | ||||||||||||
1232 | setDisplayFormat(*frm); | - | ||||||||||||
1233 | d->formatExplicitlySet = false; | - | ||||||||||||
1234 | d->edit->setCursorPosition(oldPos); | - | ||||||||||||
1235 | } | - | ||||||||||||
1236 | } | - | ||||||||||||
1237 | } | - | ||||||||||||
1238 | const bool oldHasHadFocus = d->hasHadFocus; | - | ||||||||||||
1239 | d->hasHadFocus = true; | - | ||||||||||||
1240 | bool first = true; | - | ||||||||||||
1241 | switch (event->reason()) { | - | ||||||||||||
1242 | case Qt::BacktabFocusReason: | - | ||||||||||||
1243 | first = false; | - | ||||||||||||
1244 | break; | - | ||||||||||||
1245 | case Qt::MouseFocusReason: | - | ||||||||||||
1246 | case Qt::PopupFocusReason: | - | ||||||||||||
1247 | return; | - | ||||||||||||
1248 | case Qt::ActiveWindowFocusReason: | - | ||||||||||||
1249 | if (oldHasHadFocus) | - | ||||||||||||
1250 | return; | - | ||||||||||||
1251 | case Qt::ShortcutFocusReason: | - | ||||||||||||
1252 | case Qt::TabFocusReason: | - | ||||||||||||
1253 | default: | - | ||||||||||||
1254 | break; | - | ||||||||||||
1255 | } | - | ||||||||||||
1256 | if (isRightToLeft()) | - | ||||||||||||
1257 | first = !first; | - | ||||||||||||
1258 | d->updateEdit(); // needed to make it update specialValueText | - | ||||||||||||
1259 | - | |||||||||||||
1260 | d->setSelected(first ? 0 : d->sectionNodes.size() - 1); | - | ||||||||||||
1261 | } | - | ||||||||||||
1262 | - | |||||||||||||
1263 | /*! | - | ||||||||||||
1264 | \reimp | - | ||||||||||||
1265 | */ | - | ||||||||||||
1266 | - | |||||||||||||
1267 | bool QDateTimeEdit::focusNextPrevChild(bool next) | - | ||||||||||||
1268 | { | - | ||||||||||||
1269 | Q_D(QDateTimeEdit); | - | ||||||||||||
1270 | const int newSection = d->nextPrevSection(d->currentSectionIndex, next); | - | ||||||||||||
1271 | switch (d->sectionType(newSection)) { | - | ||||||||||||
1272 | case QDateTimeParser::NoSection: | - | ||||||||||||
1273 | case QDateTimeParser::FirstSection: | - | ||||||||||||
1274 | case QDateTimeParser::LastSection: | - | ||||||||||||
1275 | return QAbstractSpinBox::focusNextPrevChild(next); | - | ||||||||||||
1276 | default: | - | ||||||||||||
1277 | d->edit->deselect(); | - | ||||||||||||
1278 | d->edit->setCursorPosition(d->sectionPos(newSection)); | - | ||||||||||||
1279 | QDTEDEBUG << d->sectionPos(newSection); dead code: QMessageLogger(__FILE__, 1279, __PRETTY_FUNCTION__).debug() << d->sectionPos(newSection); | - | ||||||||||||
1280 | d->setSelected(newSection, true); | - | ||||||||||||
1281 | return false; | - | ||||||||||||
1282 | } | - | ||||||||||||
1283 | } | - | ||||||||||||
1284 | - | |||||||||||||
1285 | /*! | - | ||||||||||||
1286 | \reimp | - | ||||||||||||
1287 | */ | - | ||||||||||||
1288 | - | |||||||||||||
1289 | void QDateTimeEdit::stepBy(int steps) | - | ||||||||||||
1290 | { | - | ||||||||||||
1291 | Q_D(QDateTimeEdit); | - | ||||||||||||
1292 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||
1293 | // with keypad navigation and not editFocus, left right change the date/time by a fixed amount. | - | ||||||||||||
1294 | if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { | - | ||||||||||||
1295 | // if date based, shift by day. else shift by 15min | - | ||||||||||||
1296 | if (d->sections & DateSections_Mask) { | - | ||||||||||||
1297 | setDateTime(dateTime().addDays(steps)); | - | ||||||||||||
1298 | } else { | - | ||||||||||||
1299 | int minutes = time().hour()*60 + time().minute(); | - | ||||||||||||
1300 | int blocks = minutes/15; | - | ||||||||||||
1301 | blocks += steps; | - | ||||||||||||
1302 | /* rounding involved */ | - | ||||||||||||
1303 | if (minutes % 15) { | - | ||||||||||||
1304 | if (steps < 0) { | - | ||||||||||||
1305 | blocks += 1; // do one less step; | - | ||||||||||||
1306 | } | - | ||||||||||||
1307 | } | - | ||||||||||||
1308 | - | |||||||||||||
1309 | minutes = blocks * 15; | - | ||||||||||||
1310 | - | |||||||||||||
1311 | /* need to take wrapping into account */ | - | ||||||||||||
1312 | if (!d->wrapping) { | - | ||||||||||||
1313 | int max_minutes = d->maximum.toTime().hour()*60 + d->maximum.toTime().minute(); | - | ||||||||||||
1314 | int min_minutes = d->minimum.toTime().hour()*60 + d->minimum.toTime().minute(); | - | ||||||||||||
1315 | - | |||||||||||||
1316 | if (minutes >= max_minutes) { | - | ||||||||||||
1317 | setTime(maximumTime()); | - | ||||||||||||
1318 | return; | - | ||||||||||||
1319 | } else if (minutes <= min_minutes) { | - | ||||||||||||
1320 | setTime(minimumTime()); | - | ||||||||||||
1321 | return; | - | ||||||||||||
1322 | } | - | ||||||||||||
1323 | } | - | ||||||||||||
1324 | setTime(QTime(minutes/60, minutes%60)); | - | ||||||||||||
1325 | } | - | ||||||||||||
1326 | return; | - | ||||||||||||
1327 | } | - | ||||||||||||
1328 | #endif | - | ||||||||||||
1329 | // don't optimize away steps == 0. This is the only way to select | - | ||||||||||||
1330 | // the currentSection in Qt 4.1.x | - | ||||||||||||
1331 | if (d->specialValue() && displayedSections() != AmPmSection) { | - | ||||||||||||
1332 | for (int i=0; i<d->sectionNodes.size(); ++i) { | - | ||||||||||||
1333 | if (d->sectionType(i) != QDateTimeParser::AmPmSection) { | - | ||||||||||||
1334 | d->currentSectionIndex = i; | - | ||||||||||||
1335 | break; | - | ||||||||||||
1336 | } | - | ||||||||||||
1337 | } | - | ||||||||||||
1338 | } | - | ||||||||||||
1339 | d->setValue(d->stepBy(d->currentSectionIndex, steps, false), EmitIfChanged); | - | ||||||||||||
1340 | d->updateCache(d->value, d->displayText()); | - | ||||||||||||
1341 | - | |||||||||||||
1342 | d->setSelected(d->currentSectionIndex); | - | ||||||||||||
1343 | d->updateTimeSpec(); | - | ||||||||||||
1344 | } | - | ||||||||||||
1345 | - | |||||||||||||
1346 | /*! | - | ||||||||||||
1347 | This virtual function is used by the date time edit whenever it | - | ||||||||||||
1348 | needs to display \a dateTime. | - | ||||||||||||
1349 | - | |||||||||||||
1350 | If you reimplement this, you may also need to reimplement validate(). | - | ||||||||||||
1351 | - | |||||||||||||
1352 | \sa dateTimeFromText(), validate() | - | ||||||||||||
1353 | */ | - | ||||||||||||
1354 | QString QDateTimeEdit::textFromDateTime(const QDateTime &dateTime) const | - | ||||||||||||
1355 | { | - | ||||||||||||
1356 | Q_D(const QDateTimeEdit); | - | ||||||||||||
1357 | return locale().toString(dateTime, d->displayFormat); | - | ||||||||||||
1358 | } | - | ||||||||||||
1359 | - | |||||||||||||
1360 | - | |||||||||||||
1361 | /*! | - | ||||||||||||
1362 | Returns an appropriate datetime for the given \a text. | - | ||||||||||||
1363 | - | |||||||||||||
1364 | This virtual function is used by the datetime edit whenever it | - | ||||||||||||
1365 | needs to interpret text entered by the user as a value. | - | ||||||||||||
1366 | - | |||||||||||||
1367 | \sa textFromDateTime(), validate() | - | ||||||||||||
1368 | */ | - | ||||||||||||
1369 | QDateTime QDateTimeEdit::dateTimeFromText(const QString &text) const | - | ||||||||||||
1370 | { | - | ||||||||||||
1371 | Q_D(const QDateTimeEdit); | - | ||||||||||||
1372 | QString copy = text; | - | ||||||||||||
1373 | int pos = d->edit->cursorPosition(); | - | ||||||||||||
1374 | QValidator::State state = QValidator::Acceptable; | - | ||||||||||||
1375 | return d->validateAndInterpret(copy, pos, state); | - | ||||||||||||
1376 | } | - | ||||||||||||
1377 | - | |||||||||||||
1378 | /*! | - | ||||||||||||
1379 | \reimp | - | ||||||||||||
1380 | */ | - | ||||||||||||
1381 | - | |||||||||||||
1382 | QValidator::State QDateTimeEdit::validate(QString &text, int &pos) const | - | ||||||||||||
1383 | { | - | ||||||||||||
1384 | Q_D(const QDateTimeEdit); | - | ||||||||||||
1385 | QValidator::State state; | - | ||||||||||||
1386 | d->validateAndInterpret(text, pos, state); | - | ||||||||||||
1387 | return state; | - | ||||||||||||
1388 | } | - | ||||||||||||
1389 | - | |||||||||||||
1390 | /*! | - | ||||||||||||
1391 | \reimp | - | ||||||||||||
1392 | */ | - | ||||||||||||
1393 | - | |||||||||||||
1394 | - | |||||||||||||
1395 | void QDateTimeEdit::fixup(QString &input) const | - | ||||||||||||
1396 | { | - | ||||||||||||
1397 | Q_D(const QDateTimeEdit); | - | ||||||||||||
1398 | QValidator::State state; | - | ||||||||||||
1399 | int copy = d->edit->cursorPosition(); | - | ||||||||||||
1400 | - | |||||||||||||
1401 | d->validateAndInterpret(input, copy, state, true); | - | ||||||||||||
1402 | } | - | ||||||||||||
1403 | - | |||||||||||||
1404 | - | |||||||||||||
1405 | /*! | - | ||||||||||||
1406 | \reimp | - | ||||||||||||
1407 | */ | - | ||||||||||||
1408 | - | |||||||||||||
1409 | QDateTimeEdit::StepEnabled QDateTimeEdit::stepEnabled() const | - | ||||||||||||
1410 | { | - | ||||||||||||
1411 | Q_D(const QDateTimeEdit); | - | ||||||||||||
1412 | if (d->readOnly) | - | ||||||||||||
1413 | return StepEnabled(0); | - | ||||||||||||
1414 | if (d->specialValue()) { | - | ||||||||||||
1415 | return (d->minimum == d->maximum ? StepEnabled(0) : StepEnabled(StepUpEnabled)); | - | ||||||||||||
1416 | } | - | ||||||||||||
1417 | - | |||||||||||||
1418 | QAbstractSpinBox::StepEnabled ret = 0; | - | ||||||||||||
1419 | - | |||||||||||||
1420 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||
1421 | if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { | - | ||||||||||||
1422 | if (d->wrapping) | - | ||||||||||||
1423 | return StepEnabled(StepUpEnabled | StepDownEnabled); | - | ||||||||||||
1424 | // 3 cases. date, time, datetime. each case look | - | ||||||||||||
1425 | // at just the relavant component. | - | ||||||||||||
1426 | QVariant max, min, val; | - | ||||||||||||
1427 | if (!(d->sections & DateSections_Mask)) { | - | ||||||||||||
1428 | // time only, no date | - | ||||||||||||
1429 | max = d->maximum.toTime(); | - | ||||||||||||
1430 | min = d->minimum.toTime(); | - | ||||||||||||
1431 | val = d->value.toTime(); | - | ||||||||||||
1432 | } else if (!(d->sections & TimeSections_Mask)) { | - | ||||||||||||
1433 | // date only, no time | - | ||||||||||||
1434 | max = d->maximum.toDate(); | - | ||||||||||||
1435 | min = d->minimum.toDate(); | - | ||||||||||||
1436 | val = d->value.toDate(); | - | ||||||||||||
1437 | } else { | - | ||||||||||||
1438 | // both | - | ||||||||||||
1439 | max = d->maximum; | - | ||||||||||||
1440 | min = d->minimum; | - | ||||||||||||
1441 | val = d->value; | - | ||||||||||||
1442 | } | - | ||||||||||||
1443 | if (val != min) | - | ||||||||||||
1444 | ret |= QAbstractSpinBox::StepDownEnabled; | - | ||||||||||||
1445 | if (val != max) | - | ||||||||||||
1446 | ret |= QAbstractSpinBox::StepUpEnabled; | - | ||||||||||||
1447 | return ret; | - | ||||||||||||
1448 | } | - | ||||||||||||
1449 | #endif | - | ||||||||||||
1450 | switch (d->sectionType(d->currentSectionIndex)) { | - | ||||||||||||
1451 | case QDateTimeParser::NoSection: | - | ||||||||||||
1452 | case QDateTimeParser::FirstSection: | - | ||||||||||||
1453 | case QDateTimeParser::LastSection: return 0; | - | ||||||||||||
1454 | default: break; | - | ||||||||||||
1455 | } | - | ||||||||||||
1456 | if (d->wrapping) | - | ||||||||||||
1457 | return StepEnabled(StepDownEnabled|StepUpEnabled); | - | ||||||||||||
1458 | - | |||||||||||||
1459 | QVariant v = d->stepBy(d->currentSectionIndex, 1, true); | - | ||||||||||||
1460 | if (v != d->value) { | - | ||||||||||||
1461 | ret |= QAbstractSpinBox::StepUpEnabled; | - | ||||||||||||
1462 | } | - | ||||||||||||
1463 | v = d->stepBy(d->currentSectionIndex, -1, true); | - | ||||||||||||
1464 | if (v != d->value) { | - | ||||||||||||
1465 | ret |= QAbstractSpinBox::StepDownEnabled; | - | ||||||||||||
1466 | } | - | ||||||||||||
1467 | - | |||||||||||||
1468 | return ret; | - | ||||||||||||
1469 | } | - | ||||||||||||
1470 | - | |||||||||||||
1471 | - | |||||||||||||
1472 | /*! | - | ||||||||||||
1473 | \reimp | - | ||||||||||||
1474 | */ | - | ||||||||||||
1475 | - | |||||||||||||
1476 | void QDateTimeEdit::mousePressEvent(QMouseEvent *event) | - | ||||||||||||
1477 | { | - | ||||||||||||
1478 | Q_D(QDateTimeEdit); | - | ||||||||||||
1479 | if (!d->calendarPopupEnabled()) { | - | ||||||||||||
1480 | QAbstractSpinBox::mousePressEvent(event); | - | ||||||||||||
1481 | return; | - | ||||||||||||
1482 | } | - | ||||||||||||
1483 | d->updateHoverControl(event->pos()); | - | ||||||||||||
1484 | if (d->hoverControl == QStyle::SC_ComboBoxArrow) { | - | ||||||||||||
1485 | event->accept(); | - | ||||||||||||
1486 | if (d->readOnly) { | - | ||||||||||||
1487 | return; | - | ||||||||||||
1488 | } | - | ||||||||||||
1489 | d->updateArrow(QStyle::State_Sunken); | - | ||||||||||||
1490 | d->initCalendarPopup(); | - | ||||||||||||
1491 | d->positionCalendarPopup(); | - | ||||||||||||
1492 | //Show the calendar | - | ||||||||||||
1493 | d->monthCalendar->show(); | - | ||||||||||||
1494 | } else { | - | ||||||||||||
1495 | QAbstractSpinBox::mousePressEvent(event); | - | ||||||||||||
1496 | } | - | ||||||||||||
1497 | } | - | ||||||||||||
1498 | - | |||||||||||||
1499 | /*! | - | ||||||||||||
1500 | \class QTimeEdit | - | ||||||||||||
1501 | \brief The QTimeEdit class provides a widget for editing times based on | - | ||||||||||||
1502 | the QDateTimeEdit widget. | - | ||||||||||||
1503 | - | |||||||||||||
1504 | \ingroup basicwidgets | - | ||||||||||||
1505 | \inmodule QtWidgets | - | ||||||||||||
1506 | - | |||||||||||||
1507 | Many of the properties and functions provided by QTimeEdit are implemented in | - | ||||||||||||
1508 | QDateTimeEdit. These are the relevant properties of this class: | - | ||||||||||||
1509 | - | |||||||||||||
1510 | \list | - | ||||||||||||
1511 | \li \l{QDateTimeEdit::time}{time} holds the time displayed by the widget. | - | ||||||||||||
1512 | \li \l{QDateTimeEdit::minimumTime}{minimumTime} defines the minimum (earliest) time | - | ||||||||||||
1513 | that can be set by the user. | - | ||||||||||||
1514 | \li \l{QDateTimeEdit::maximumTime}{maximumTime} defines the maximum (latest) time | - | ||||||||||||
1515 | that can be set by the user. | - | ||||||||||||
1516 | \li \l{QDateTimeEdit::displayFormat}{displayFormat} contains a string that is used | - | ||||||||||||
1517 | to format the time displayed in the widget. | - | ||||||||||||
1518 | \endlist | - | ||||||||||||
1519 | - | |||||||||||||
1520 | \table 100% | - | ||||||||||||
1521 | \row \li \inlineimage windowsvista-timeedit.png Screenshot of a Windows Vista style time editing widget | - | ||||||||||||
1522 | \li A time editing widget shown in the \l{Windows Vista Style Widget Gallery}{Windows Vista widget style}. | - | ||||||||||||
1523 | \row \li \inlineimage macintosh-timeedit.png Screenshot of a Macintosh style time editing widget | - | ||||||||||||
1524 | \li A time editing widget shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}. | - | ||||||||||||
1525 | \row \li \inlineimage fusion-timeedit.png Screenshot of a Fusion style time editing widget | - | ||||||||||||
1526 | \li A time editing widget shown in the \l{Fusion Style Widget Gallery}{Fusion widget style}. | - | ||||||||||||
1527 | \endtable | - | ||||||||||||
1528 | - | |||||||||||||
1529 | \sa QDateEdit, QDateTimeEdit | - | ||||||||||||
1530 | */ | - | ||||||||||||
1531 | - | |||||||||||||
1532 | /*! | - | ||||||||||||
1533 | Constructs an empty time editor with a \a parent. | - | ||||||||||||
1534 | */ | - | ||||||||||||
1535 | - | |||||||||||||
1536 | - | |||||||||||||
1537 | QTimeEdit::QTimeEdit(QWidget *parent) | - | ||||||||||||
1538 | : QDateTimeEdit(QDATETIMEEDIT_TIME_MIN, QVariant::Time, parent) | - | ||||||||||||
1539 | { | - | ||||||||||||
1540 | connect(this, SIGNAL(timeChanged(QTime)), SIGNAL(userTimeChanged(QTime))); | - | ||||||||||||
1541 | } | - | ||||||||||||
1542 | - | |||||||||||||
1543 | /*! | - | ||||||||||||
1544 | Constructs an empty time editor with a \a parent. The time is set | - | ||||||||||||
1545 | to \a time. | - | ||||||||||||
1546 | */ | - | ||||||||||||
1547 | - | |||||||||||||
1548 | QTimeEdit::QTimeEdit(const QTime &time, QWidget *parent) | - | ||||||||||||
1549 | : QDateTimeEdit(time, QVariant::Time, parent) | - | ||||||||||||
1550 | { | - | ||||||||||||
1551 | } | - | ||||||||||||
1552 | - | |||||||||||||
1553 | /*! | - | ||||||||||||
1554 | Destructor. | - | ||||||||||||
1555 | */ | - | ||||||||||||
1556 | QTimeEdit::~QTimeEdit() | - | ||||||||||||
1557 | { | - | ||||||||||||
1558 | } | - | ||||||||||||
1559 | - | |||||||||||||
1560 | /*! | - | ||||||||||||
1561 | \property QTimeEdit::time | - | ||||||||||||
1562 | \internal | - | ||||||||||||
1563 | \sa QDateTimeEdit::time | - | ||||||||||||
1564 | */ | - | ||||||||||||
1565 | - | |||||||||||||
1566 | /*! | - | ||||||||||||
1567 | \fn void QTimeEdit::userTimeChanged(const QTime &time) | - | ||||||||||||
1568 | - | |||||||||||||
1569 | This signal only exists to fully implement the time Q_PROPERTY on the class. | - | ||||||||||||
1570 | Normally timeChanged should be used instead. | - | ||||||||||||
1571 | - | |||||||||||||
1572 | \internal | - | ||||||||||||
1573 | */ | - | ||||||||||||
1574 | - | |||||||||||||
1575 | - | |||||||||||||
1576 | /*! | - | ||||||||||||
1577 | \class QDateEdit | - | ||||||||||||
1578 | \brief The QDateEdit class provides a widget for editing dates based on | - | ||||||||||||
1579 | the QDateTimeEdit widget. | - | ||||||||||||
1580 | - | |||||||||||||
1581 | \ingroup basicwidgets | - | ||||||||||||
1582 | \inmodule QtWidgets | - | ||||||||||||
1583 | - | |||||||||||||
1584 | Many of the properties and functions provided by QDateEdit are implemented in | - | ||||||||||||
1585 | QDateTimeEdit. These are the relevant properties of this class: | - | ||||||||||||
1586 | - | |||||||||||||
1587 | \list | - | ||||||||||||
1588 | \li \l{QDateTimeEdit::date}{date} holds the date displayed by the widget. | - | ||||||||||||
1589 | \li \l{QDateTimeEdit::minimumDate}{minimumDate} defines the minimum (earliest) | - | ||||||||||||
1590 | date that can be set by the user. | - | ||||||||||||
1591 | \li \l{QDateTimeEdit::maximumDate}{maximumDate} defines the maximum (latest) date | - | ||||||||||||
1592 | that can be set by the user. | - | ||||||||||||
1593 | \li \l{QDateTimeEdit::displayFormat}{displayFormat} contains a string that is used | - | ||||||||||||
1594 | to format the date displayed in the widget. | - | ||||||||||||
1595 | \endlist | - | ||||||||||||
1596 | - | |||||||||||||
1597 | \table 100% | - | ||||||||||||
1598 | \row \li \inlineimage windowsvista-dateedit.png Screenshot of a Windows Vista style date editing widget | - | ||||||||||||
1599 | \li A date editing widget shown in the \l{Windows Vista Style Widget Gallery}{Windows Vista widget style}. | - | ||||||||||||
1600 | \row \li \inlineimage macintosh-dateedit.png Screenshot of a Macintosh style date editing widget | - | ||||||||||||
1601 | \li A date editing widget shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}. | - | ||||||||||||
1602 | \row \li \inlineimage fusion-dateedit.png Screenshot of a Fusion style date editing widget | - | ||||||||||||
1603 | \li A date editing widget shown in the \l{Fusion Style Widget Gallery}{Fusion widget style}. | - | ||||||||||||
1604 | \endtable | - | ||||||||||||
1605 | - | |||||||||||||
1606 | \sa QTimeEdit, QDateTimeEdit | - | ||||||||||||
1607 | */ | - | ||||||||||||
1608 | - | |||||||||||||
1609 | /*! | - | ||||||||||||
1610 | Constructs an empty date editor with a \a parent. | - | ||||||||||||
1611 | */ | - | ||||||||||||
1612 | - | |||||||||||||
1613 | QDateEdit::QDateEdit(QWidget *parent) | - | ||||||||||||
1614 | : QDateTimeEdit(QDATETIMEEDIT_DATE_INITIAL, QVariant::Date, parent) | - | ||||||||||||
1615 | { | - | ||||||||||||
1616 | connect(this, SIGNAL(dateChanged(QDate)), SIGNAL(userDateChanged(QDate))); | - | ||||||||||||
1617 | } | - | ||||||||||||
1618 | - | |||||||||||||
1619 | /*! | - | ||||||||||||
1620 | Constructs an empty date editor with a \a parent. The date is set | - | ||||||||||||
1621 | to \a date. | - | ||||||||||||
1622 | */ | - | ||||||||||||
1623 | - | |||||||||||||
1624 | QDateEdit::QDateEdit(const QDate &date, QWidget *parent) | - | ||||||||||||
1625 | : QDateTimeEdit(date, QVariant::Date, parent) | - | ||||||||||||
1626 | { | - | ||||||||||||
1627 | } | - | ||||||||||||
1628 | - | |||||||||||||
1629 | /*! | - | ||||||||||||
1630 | Destructor. | - | ||||||||||||
1631 | */ | - | ||||||||||||
1632 | QDateEdit::~QDateEdit() | - | ||||||||||||
1633 | { | - | ||||||||||||
1634 | } | - | ||||||||||||
1635 | - | |||||||||||||
1636 | /*! | - | ||||||||||||
1637 | \property QDateEdit::date | - | ||||||||||||
1638 | \internal | - | ||||||||||||
1639 | \sa QDateTimeEdit::date | - | ||||||||||||
1640 | */ | - | ||||||||||||
1641 | - | |||||||||||||
1642 | /*! | - | ||||||||||||
1643 | \fn void QDateEdit::userDateChanged(const QDate &date) | - | ||||||||||||
1644 | - | |||||||||||||
1645 | This signal only exists to fully implement the date Q_PROPERTY on the class. | - | ||||||||||||
1646 | Normally dateChanged should be used instead. | - | ||||||||||||
1647 | - | |||||||||||||
1648 | \internal | - | ||||||||||||
1649 | */ | - | ||||||||||||
1650 | - | |||||||||||||
1651 | - | |||||||||||||
1652 | // --- QDateTimeEditPrivate --- | - | ||||||||||||
1653 | - | |||||||||||||
1654 | /*! | - | ||||||||||||
1655 | \internal | - | ||||||||||||
1656 | Constructs a QDateTimeEditPrivate object | - | ||||||||||||
1657 | */ | - | ||||||||||||
1658 | - | |||||||||||||
1659 | - | |||||||||||||
1660 | QDateTimeEditPrivate::QDateTimeEditPrivate() | - | ||||||||||||
1661 | : QDateTimeParser(QVariant::DateTime, QDateTimeParser::DateTimeEdit) | - | ||||||||||||
1662 | { | - | ||||||||||||
1663 | hasHadFocus = false; | - | ||||||||||||
1664 | formatExplicitlySet = false; | - | ||||||||||||
1665 | cacheGuard = false; | - | ||||||||||||
1666 | fixday = true; | - | ||||||||||||
1667 | type = QVariant::DateTime; | - | ||||||||||||
1668 | sections = 0; | - | ||||||||||||
1669 | cachedDay = -1; | - | ||||||||||||
1670 | currentSectionIndex = FirstSectionIndex; | - | ||||||||||||
1671 | - | |||||||||||||
1672 | first.pos = 0; | - | ||||||||||||
1673 | sections = 0; | - | ||||||||||||
1674 | calendarPopup = false; | - | ||||||||||||
1675 | minimum = QDATETIMEEDIT_COMPAT_DATETIME_MIN; | - | ||||||||||||
1676 | maximum = QDATETIMEEDIT_DATETIME_MAX; | - | ||||||||||||
1677 | arrowState = QStyle::State_None; | - | ||||||||||||
1678 | monthCalendar = 0; | - | ||||||||||||
1679 | readLocaleSettings(); | - | ||||||||||||
1680 | - | |||||||||||||
1681 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||
1682 | focusOnButton = false; | - | ||||||||||||
1683 | #endif | - | ||||||||||||
1684 | } | - | ||||||||||||
1685 | - | |||||||||||||
1686 | QDateTimeEditPrivate::~QDateTimeEditPrivate() | - | ||||||||||||
1687 | { | - | ||||||||||||
1688 | } | - | ||||||||||||
1689 | - | |||||||||||||
1690 | void QDateTimeEditPrivate::updateTimeSpec() | - | ||||||||||||
1691 | { | - | ||||||||||||
1692 | minimum = minimum.toDateTime().toTimeSpec(spec); | - | ||||||||||||
1693 | maximum = maximum.toDateTime().toTimeSpec(spec); | - | ||||||||||||
1694 | value = value.toDateTime().toTimeSpec(spec); | - | ||||||||||||
1695 | - | |||||||||||||
1696 | // time zone changes can lead to 00:00:00 becomes 01:00:00 and 23:59:59 becomes 00:59:59 (invalid range) | - | ||||||||||||
1697 | const bool dateShown = (sections & QDateTimeEdit::DateSections_Mask); | - | ||||||||||||
1698 | if (!dateShown) { | - | ||||||||||||
1699 | if (minimum.toTime() >= maximum.toTime()){ | - | ||||||||||||
1700 | minimum = QDateTime(value.toDate(), QDATETIMEEDIT_TIME_MIN, spec); | - | ||||||||||||
1701 | maximum = QDateTime(value.toDate(), QDATETIMEEDIT_TIME_MAX, spec); | - | ||||||||||||
1702 | } | - | ||||||||||||
1703 | } | - | ||||||||||||
1704 | } | - | ||||||||||||
1705 | - | |||||||||||||
1706 | void QDateTimeEditPrivate::updateEdit() | - | ||||||||||||
1707 | { | - | ||||||||||||
1708 | const QString newText = (specialValue() ? specialValueText : textFromValue(value)); | - | ||||||||||||
1709 | if (newText == displayText()) | - | ||||||||||||
1710 | return; | - | ||||||||||||
1711 | int selsize = edit->selectedText().size(); | - | ||||||||||||
1712 | const QSignalBlocker blocker(edit); | - | ||||||||||||
1713 | - | |||||||||||||
1714 | edit->setText(newText); | - | ||||||||||||
1715 | - | |||||||||||||
1716 | if (!specialValue() | - | ||||||||||||
1717 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||
1718 | && !(QApplication::keypadNavigationEnabled() && !edit->hasEditFocus()) | - | ||||||||||||
1719 | #endif | - | ||||||||||||
1720 | ) { | - | ||||||||||||
1721 | int cursor = sectionPos(currentSectionIndex); | - | ||||||||||||
1722 | QDTEDEBUG << "cursor is " << cursor << currentSectionIndex; dead code: QMessageLogger(__FILE__, 1722, __PRETTY_FUNCTION__).debug() << "cursor is " << cursor << currentSectionIndex; | - | ||||||||||||
1723 | cursor = qBound(0, cursor, displayText().size()); | - | ||||||||||||
1724 | QDTEDEBUG << cursor; dead code: QMessageLogger(__FILE__, 1724, __PRETTY_FUNCTION__).debug() << cursor; | - | ||||||||||||
1725 | if (selsize > 0) { | - | ||||||||||||
1726 | edit->setSelection(cursor, selsize); | - | ||||||||||||
1727 | QDTEDEBUG << cursor << selsize; dead code: QMessageLogger(__FILE__, 1727, __PRETTY_FUNCTION__).debug() << cursor << selsize; | - | ||||||||||||
1728 | } else { | - | ||||||||||||
1729 | edit->setCursorPosition(cursor); | - | ||||||||||||
1730 | QDTEDEBUG << cursor; dead code: QMessageLogger(__FILE__, 1730, __PRETTY_FUNCTION__).debug() << cursor; | - | ||||||||||||
1731 | - | |||||||||||||
1732 | } | - | ||||||||||||
1733 | } | - | ||||||||||||
1734 | } | - | ||||||||||||
1735 | - | |||||||||||||
1736 | - | |||||||||||||
1737 | /*! | - | ||||||||||||
1738 | \internal | - | ||||||||||||
1739 | - | |||||||||||||
1740 | Selects the section \a s. If \a forward is false selects backwards. | - | ||||||||||||
1741 | */ | - | ||||||||||||
1742 | - | |||||||||||||
1743 | void QDateTimeEditPrivate::setSelected(int sectionIndex, bool forward) | - | ||||||||||||
1744 | { | - | ||||||||||||
1745 | if (specialValue() | - | ||||||||||||
1746 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||
1747 | || (QApplication::keypadNavigationEnabled() && !edit->hasEditFocus()) | - | ||||||||||||
1748 | #endif | - | ||||||||||||
1749 | ) { | - | ||||||||||||
1750 | edit->selectAll(); | - | ||||||||||||
1751 | } else { | - | ||||||||||||
1752 | const SectionNode &node = sectionNode(sectionIndex); | - | ||||||||||||
1753 | if (node.type == NoSection || node.type == LastSection || node.type == FirstSection) | - | ||||||||||||
1754 | return; | - | ||||||||||||
1755 | - | |||||||||||||
1756 | updateCache(value, displayText()); | - | ||||||||||||
1757 | const int size = sectionSize(sectionIndex); | - | ||||||||||||
1758 | if (forward) { | - | ||||||||||||
1759 | edit->setSelection(sectionPos(node), size); | - | ||||||||||||
1760 | } else { | - | ||||||||||||
1761 | edit->setSelection(sectionPos(node) + size, -size); | - | ||||||||||||
1762 | } | - | ||||||||||||
1763 | } | - | ||||||||||||
1764 | } | - | ||||||||||||
1765 | - | |||||||||||||
1766 | /*! | - | ||||||||||||
1767 | \internal | - | ||||||||||||
1768 | - | |||||||||||||
1769 | Returns the section at index \a index or NoSection if there are no sections there. | - | ||||||||||||
1770 | */ | - | ||||||||||||
1771 | - | |||||||||||||
1772 | int QDateTimeEditPrivate::sectionAt(int pos) const | - | ||||||||||||
1773 | { | - | ||||||||||||
1774 | if (pos < separators.first().size())
| 0 | ||||||||||||
1775 | {return (pos == 0 ? FirstSectionIndex : NoSectionIndex); never executed: return (pos == 0 ? FirstSectionIndex : NoSectionIndex); | 0 | ||||||||||||
1776 | - | |||||||||||||
1777 | } else if (const QString text = displayText().(); | - | ||||||||||||
1778 | const int textSize = text.size()(); | - | ||||||||||||
1779 | if (textSize
| 0 | ||||||||||||
1780 | if (separators.last().size() == 0) {
| 0 | ||||||||||||
1781 | return sectionNodes.count() - 1; never executed: return sectionNodes.count() - 1; | 0 | ||||||||||||
1782 | } | - | ||||||||||||
1783 | return (pos == displayText().size()textSize ? LastSectionIndex : NoSectionIndex); never executed: return (pos == textSize ? LastSectionIndex : NoSectionIndex); | 0 | ||||||||||||
1784 | } | - | ||||||||||||
1785 | updateCache(value, displayText());text); | - | ||||||||||||
1786 | - | |||||||||||||
1787 | for (int i=0; i<sectionNodes.size(); ++i) {
| 0 | ||||||||||||
1788 | const int tmp = sectionPos(i); | - | ||||||||||||
1789 | if (pos < tmp + sectionSize(i)) {
| 0 | ||||||||||||
1790 | return (pos < tmp ? -1 : i); never executed: return (pos < tmp ? -1 : i); | 0 | ||||||||||||
1791 | } | - | ||||||||||||
1792 | } never executed: end of block | 0 | ||||||||||||
1793 | return -1; never executed: return -1; | 0 | ||||||||||||
1794 | } | - | ||||||||||||
1795 | - | |||||||||||||
1796 | /*! | - | ||||||||||||
1797 | \internal | - | ||||||||||||
1798 | - | |||||||||||||
1799 | Returns the closest section of index \a index. Searches forward | - | ||||||||||||
1800 | for a section if \a forward is true. Otherwise searches backwards. | - | ||||||||||||
1801 | */ | - | ||||||||||||
1802 | - | |||||||||||||
1803 | int QDateTimeEditPrivate::closestSection(int pos, bool forward) const | - | ||||||||||||
1804 | { | - | ||||||||||||
1805 | Q_ASSERT(pos >= 0); | - | ||||||||||||
1806 | if (pos < separators.first().size())
| 0 | ||||||||||||
1807 | {return forward ? 0 : FirstSectionIndex; never executed: return forward ? 0 : FirstSectionIndex; | 0 | ||||||||||||
1808 | - | |||||||||||||
1809 | } elseconst QString text = displayText(); | - | ||||||||||||
1810 | if (displayText().text.size() - pos < separators.last().size() + 1)
| 0 | ||||||||||||
1811 | {return forward ? LastSectionIndex : sectionNodes.size() - 1; never executed: return forward ? LastSectionIndex : sectionNodes.size() - 1; | 0 | ||||||||||||
1812 | - | |||||||||||||
1813 | }updateCache(value, displayText());text); | - | ||||||||||||
1814 | for (int i=0; i<sectionNodes.size(); ++i) {
| 0 | ||||||||||||
1815 | const int tmp = sectionPos(sectionNodes.at(i)); | - | ||||||||||||
1816 | if (pos < tmp + sectionSize(i)) {
| 0 | ||||||||||||
1817 | if (pos < tmp && !forward) {
| 0 | ||||||||||||
1818 | return i-1; never executed: return i-1; | 0 | ||||||||||||
1819 | } | - | ||||||||||||
1820 | return i; never executed: return i; | 0 | ||||||||||||
1821 | } else if (i == sectionNodes.size() - 1 && pos > tmp) {
| 0 | ||||||||||||
1822 | return i; never executed: return i; | 0 | ||||||||||||
1823 | } | - | ||||||||||||
1824 | } never executed: end of block | 0 | ||||||||||||
1825 | qWarning("QDateTimeEdit: Internal Error: closestSection returned NoSection"); | - | ||||||||||||
1826 | return NoSectionIndex; never executed: return NoSectionIndex; | 0 | ||||||||||||
1827 | } | - | ||||||||||||
1828 | - | |||||||||||||
1829 | /*! | - | ||||||||||||
1830 | \internal | - | ||||||||||||
1831 | - | |||||||||||||
1832 | Returns a copy of the section that is before or after \a current, depending on \a forward. | - | ||||||||||||
1833 | */ | - | ||||||||||||
1834 | - | |||||||||||||
1835 | int QDateTimeEditPrivate::nextPrevSection(int current, bool forward) const | - | ||||||||||||
1836 | { | - | ||||||||||||
1837 | Q_Q(const QDateTimeEdit); | - | ||||||||||||
1838 | if (q->isRightToLeft()) | - | ||||||||||||
1839 | forward = !forward; | - | ||||||||||||
1840 | - | |||||||||||||
1841 | switch (current) { | - | ||||||||||||
1842 | case FirstSectionIndex: return forward ? 0 : FirstSectionIndex; | - | ||||||||||||
1843 | case LastSectionIndex: return (forward ? LastSectionIndex : sectionNodes.size() - 1); | - | ||||||||||||
1844 | case NoSectionIndex: return FirstSectionIndex; | - | ||||||||||||
1845 | default: break; | - | ||||||||||||
1846 | } | - | ||||||||||||
1847 | Q_ASSERT(current >= 0 && current < sectionNodes.size()); | - | ||||||||||||
1848 | - | |||||||||||||
1849 | current += (forward ? 1 : -1); | - | ||||||||||||
1850 | if (current >= sectionNodes.size()) { | - | ||||||||||||
1851 | return LastSectionIndex; | - | ||||||||||||
1852 | } else if (current < 0) { | - | ||||||||||||
1853 | return FirstSectionIndex; | - | ||||||||||||
1854 | } | - | ||||||||||||
1855 | - | |||||||||||||
1856 | return current; | - | ||||||||||||
1857 | } | - | ||||||||||||
1858 | - | |||||||||||||
1859 | /*! | - | ||||||||||||
1860 | \internal | - | ||||||||||||
1861 | - | |||||||||||||
1862 | Clears the text of section \a s. | - | ||||||||||||
1863 | */ | - | ||||||||||||
1864 | - | |||||||||||||
1865 | void QDateTimeEditPrivate::clearSection(int index) | - | ||||||||||||
1866 | { | - | ||||||||||||
1867 | const QLatin1Char space(' '); | - | ||||||||||||
1868 | int cursorPos = edit->cursorPosition(); | - | ||||||||||||
1869 | const QSignalBlocker blocker(edit); | - | ||||||||||||
1870 | QString t = edit->text(); | - | ||||||||||||
1871 | const int pos = sectionPos(index); | - | ||||||||||||
1872 | if (Q_UNLIKELY(pos == -1))) {
| 0 | ||||||||||||
1873 | qWarning("QDateTimeEdit: Internal error (%s:%d)", __FILE__, __LINE__); | - | ||||||||||||
1874 | return; never executed: return; | 0 | ||||||||||||
1875 | } | - | ||||||||||||
1876 | const int size = sectionSize(index); | - | ||||||||||||
1877 | t.replace(pos, size, QString().fill(space, size)); | - | ||||||||||||
1878 | edit->setText(t); | - | ||||||||||||
1879 | edit->setCursorPosition(cursorPos); | - | ||||||||||||
1880 | QDTEDEBUG << cursorPos; dead code: QMessageLogger(__FILE__, 1880, __PRETTY_FUNCTION__).debug() << cursorPos; | - | ||||||||||||
1881 | } never executed: end of block | 0 | ||||||||||||
1882 | - | |||||||||||||
1883 | - | |||||||||||||
1884 | /*! | - | ||||||||||||
1885 | \internal | - | ||||||||||||
1886 | - | |||||||||||||
1887 | updates the cached values | - | ||||||||||||
1888 | */ | - | ||||||||||||
1889 | - | |||||||||||||
1890 | void QDateTimeEditPrivate::updateCache(const QVariant &val, const QString &str) const | - | ||||||||||||
1891 | { | - | ||||||||||||
1892 | if (val != cachedValue || str != cachedText || cacheGuard) { | - | ||||||||||||
1893 | cacheGuard = true; | - | ||||||||||||
1894 | QString copy = str; | - | ||||||||||||
1895 | int unused = edit->cursorPosition(); | - | ||||||||||||
1896 | QValidator::State unusedState; | - | ||||||||||||
1897 | validateAndInterpret(copy, unused, unusedState); | - | ||||||||||||
1898 | cacheGuard = false; | - | ||||||||||||
1899 | } | - | ||||||||||||
1900 | } | - | ||||||||||||
1901 | - | |||||||||||||
1902 | /*! | - | ||||||||||||
1903 | \internal | - | ||||||||||||
1904 | - | |||||||||||||
1905 | parses and validates \a input | - | ||||||||||||
1906 | */ | - | ||||||||||||
1907 | - | |||||||||||||
1908 | QDateTime QDateTimeEditPrivate::validateAndInterpret(QString &input, int &position, | - | ||||||||||||
1909 | QValidator::State &state, bool fixup) const | - | ||||||||||||
1910 | { | - | ||||||||||||
1911 | if (input.isEmpty()) { | - | ||||||||||||
1912 | if (sectionNodes.size() == 1 || !specialValueText.isEmpty()) { | - | ||||||||||||
1913 | state = QValidator::Intermediate; | - | ||||||||||||
1914 | } else { | - | ||||||||||||
1915 | state = QValidator::Invalid; | - | ||||||||||||
1916 | } | - | ||||||||||||
1917 | return getZeroVariant().toDateTime(); | - | ||||||||||||
1918 | } else if (cachedText == input && !fixup) { | - | ||||||||||||
1919 | state = cachedState; | - | ||||||||||||
1920 | return cachedValue.toDateTime(); | - | ||||||||||||
1921 | } else if (!specialValueText.isEmpty()) { | - | ||||||||||||
1922 | bool changeCase = false; | - | ||||||||||||
1923 | const int max = qMin(specialValueText.size(), input.size()); | - | ||||||||||||
1924 | int i; | - | ||||||||||||
1925 | for (i=0; i<max; ++i) { | - | ||||||||||||
1926 | const QChar ic = input.at(i); | - | ||||||||||||
1927 | const QChar sc = specialValueText.at(i); | - | ||||||||||||
1928 | if (ic != sc) { | - | ||||||||||||
1929 | if (sc.toLower() == ic.toLower()) { | - | ||||||||||||
1930 | changeCase = true; | - | ||||||||||||
1931 | } else { | - | ||||||||||||
1932 | break; | - | ||||||||||||
1933 | } | - | ||||||||||||
1934 | } | - | ||||||||||||
1935 | } | - | ||||||||||||
1936 | if (i == max) { | - | ||||||||||||
1937 | state = specialValueText.size() == input.size() ? QValidator::Acceptable : QValidator::Intermediate; | - | ||||||||||||
1938 | if (changeCase) { | - | ||||||||||||
1939 | input = specialValueText.left(max); | - | ||||||||||||
1940 | } | - | ||||||||||||
1941 | return minimum.toDateTime(); | - | ||||||||||||
1942 | } | - | ||||||||||||
1943 | } | - | ||||||||||||
1944 | StateNode tmp = parse(input, position, value.toDateTime(), fixup); | - | ||||||||||||
1945 | input = tmp.input; | - | ||||||||||||
1946 | state = QValidator::State(int(tmp.state)); | - | ||||||||||||
1947 | if (state == QValidator::Acceptable) { | - | ||||||||||||
1948 | if (tmp.conflicts && conflictGuard != tmp.value) { | - | ||||||||||||
1949 | conflictGuard = tmp.value; | - | ||||||||||||
1950 | clearCache(); | - | ||||||||||||
1951 | input = textFromValue(tmp.value); | - | ||||||||||||
1952 | updateCache(tmp.value, input); | - | ||||||||||||
1953 | conflictGuard.clear(); | - | ||||||||||||
1954 | } else { | - | ||||||||||||
1955 | cachedText = input; | - | ||||||||||||
1956 | cachedState = state; | - | ||||||||||||
1957 | cachedValue = tmp.value; | - | ||||||||||||
1958 | } | - | ||||||||||||
1959 | } else { | - | ||||||||||||
1960 | clearCache(); | - | ||||||||||||
1961 | } | - | ||||||||||||
1962 | return (tmp.value.isNull() ? getZeroVariant().toDateTime() : tmp.value); | - | ||||||||||||
1963 | } | - | ||||||||||||
1964 | - | |||||||||||||
1965 | - | |||||||||||||
1966 | /*! | - | ||||||||||||
1967 | \internal | - | ||||||||||||
1968 | */ | - | ||||||||||||
1969 | - | |||||||||||||
1970 | QString QDateTimeEditPrivate::textFromValue(const QVariant &f) const | - | ||||||||||||
1971 | { | - | ||||||||||||
1972 | Q_Q(const QDateTimeEdit); | - | ||||||||||||
1973 | return q->textFromDateTime(f.toDateTime()); | - | ||||||||||||
1974 | } | - | ||||||||||||
1975 | - | |||||||||||||
1976 | /*! | - | ||||||||||||
1977 | \internal | - | ||||||||||||
1978 | - | |||||||||||||
1979 | This function's name is slightly confusing; it is not to be confused | - | ||||||||||||
1980 | with QAbstractSpinBox::valueFromText(). | - | ||||||||||||
1981 | */ | - | ||||||||||||
1982 | - | |||||||||||||
1983 | QVariant QDateTimeEditPrivate::valueFromText(const QString &f) const | - | ||||||||||||
1984 | { | - | ||||||||||||
1985 | Q_Q(const QDateTimeEdit); | - | ||||||||||||
1986 | return q->dateTimeFromText(f).toTimeSpec(spec); | - | ||||||||||||
1987 | } | - | ||||||||||||
1988 | - | |||||||||||||
1989 | - | |||||||||||||
1990 | /*! | - | ||||||||||||
1991 | \internal | - | ||||||||||||
1992 | - | |||||||||||||
1993 | Internal function called by QDateTimeEdit::stepBy(). Also takes a | - | ||||||||||||
1994 | Section for which section to step on and a bool \a test for | - | ||||||||||||
1995 | whether or not to modify the internal cachedDay variable. This is | - | ||||||||||||
1996 | necessary because the function is called from the const function | - | ||||||||||||
1997 | QDateTimeEdit::stepEnabled() as well as QDateTimeEdit::stepBy(). | - | ||||||||||||
1998 | */ | - | ||||||||||||
1999 | - | |||||||||||||
2000 | QDateTime QDateTimeEditPrivate::stepBy(int sectionIndex, int steps, bool test) const | - | ||||||||||||
2001 | { | - | ||||||||||||
2002 | Q_Q(const QDateTimeEdit); | - | ||||||||||||
2003 | QDateTime v = value.toDateTime(); | - | ||||||||||||
2004 | QString str = displayText(); | - | ||||||||||||
2005 | int pos = edit->cursorPosition(); | - | ||||||||||||
2006 | const SectionNode sn = sectionNode(sectionIndex); | - | ||||||||||||
2007 | - | |||||||||||||
2008 | int val; | - | ||||||||||||
2009 | // to make sure it behaves reasonably when typing something and then stepping in non-tracking mode | - | ||||||||||||
2010 | if (!test && pendingEmit) { | - | ||||||||||||
2011 | if (q->validate(str, pos) != QValidator::Acceptable) { | - | ||||||||||||
2012 | v = value.toDateTime(); | - | ||||||||||||
2013 | } else { | - | ||||||||||||
2014 | v = q->dateTimeFromText(str); | - | ||||||||||||
2015 | } | - | ||||||||||||
2016 | val = getDigit(v, sectionIndex); | - | ||||||||||||
2017 | } else { | - | ||||||||||||
2018 | val = getDigit(v, sectionIndex); | - | ||||||||||||
2019 | } | - | ||||||||||||
2020 | - | |||||||||||||
2021 | val += steps; | - | ||||||||||||
2022 | - | |||||||||||||
2023 | const int min = absoluteMin(sectionIndex); | - | ||||||||||||
2024 | const int max = absoluteMax(sectionIndex, value.toDateTime()); | - | ||||||||||||
2025 | - | |||||||||||||
2026 | if (val < min) { | - | ||||||||||||
2027 | val = (wrapping ? max - (min - val) + 1 : min); | - | ||||||||||||
2028 | } else if (val > max) { | - | ||||||||||||
2029 | val = (wrapping ? min + val - max - 1 : max); | - | ||||||||||||
2030 | } | - | ||||||||||||
2031 | - | |||||||||||||
2032 | - | |||||||||||||
2033 | const int oldDay = v.date().day(); | - | ||||||||||||
2034 | - | |||||||||||||
2035 | setDigit(v, sectionIndex, val); | - | ||||||||||||
2036 | // if this sets year or month it will make | - | ||||||||||||
2037 | // sure that days are lowered if needed. | - | ||||||||||||
2038 | - | |||||||||||||
2039 | const QDateTime minimumDateTime = minimum.toDateTime(); | - | ||||||||||||
2040 | const QDateTime maximumDateTime = maximum.toDateTime(); | - | ||||||||||||
2041 | // changing one section should only modify that section, if possible | - | ||||||||||||
2042 | if (sn.type != AmPmSection && (v < minimumDateTime || v > maximumDateTime)) { | - | ||||||||||||
2043 | const int localmin = getDigit(minimumDateTime, sectionIndex); | - | ||||||||||||
2044 | const int localmax = getDigit(maximumDateTime, sectionIndex); | - | ||||||||||||
2045 | - | |||||||||||||
2046 | if (wrapping) { | - | ||||||||||||
2047 | // just because we hit the roof in one direction, it | - | ||||||||||||
2048 | // doesn't mean that we hit the floor in the other | - | ||||||||||||
2049 | if (steps > 0) { | - | ||||||||||||
2050 | setDigit(v, sectionIndex, min); | - | ||||||||||||
2051 | if (!(sn.type & DaySectionMask) && sections & DateSectionMask) { | - | ||||||||||||
2052 | const int daysInMonth = v.date().daysInMonth(); | - | ||||||||||||
2053 | if (v.date().day() < oldDay && v.date().day() < daysInMonth) { | - | ||||||||||||
2054 | const int adds = qMin(oldDay, daysInMonth); | - | ||||||||||||
2055 | v = v.addDays(adds - v.date().day()); | - | ||||||||||||
2056 | } | - | ||||||||||||
2057 | } | - | ||||||||||||
2058 | - | |||||||||||||
2059 | if (v < minimumDateTime) { | - | ||||||||||||
2060 | setDigit(v, sectionIndex, localmin); | - | ||||||||||||
2061 | if (v < minimumDateTime) | - | ||||||||||||
2062 | setDigit(v, sectionIndex, localmin + 1); | - | ||||||||||||
2063 | } | - | ||||||||||||
2064 | } else { | - | ||||||||||||
2065 | setDigit(v, sectionIndex, max); | - | ||||||||||||
2066 | if (!(sn.type & DaySectionMask) && sections & DateSectionMask) { | - | ||||||||||||
2067 | const int daysInMonth = v.date().daysInMonth(); | - | ||||||||||||
2068 | if (v.date().day() < oldDay && v.date().day() < daysInMonth) { | - | ||||||||||||
2069 | const int adds = qMin(oldDay, daysInMonth); | - | ||||||||||||
2070 | v = v.addDays(adds - v.date().day()); | - | ||||||||||||
2071 | } | - | ||||||||||||
2072 | } | - | ||||||||||||
2073 | - | |||||||||||||
2074 | if (v > maximumDateTime) { | - | ||||||||||||
2075 | setDigit(v, sectionIndex, localmax); | - | ||||||||||||
2076 | if (v > maximumDateTime) | - | ||||||||||||
2077 | setDigit(v, sectionIndex, localmax - 1); | - | ||||||||||||
2078 | } | - | ||||||||||||
2079 | } | - | ||||||||||||
2080 | } else { | - | ||||||||||||
2081 | setDigit(v, sectionIndex, (steps > 0 ? localmax : localmin)); | - | ||||||||||||
2082 | } | - | ||||||||||||
2083 | } | - | ||||||||||||
2084 | if (!test && oldDay != v.date().day() && !(sn.type & DaySectionMask)) { | - | ||||||||||||
2085 | // this should not happen when called from stepEnabled | - | ||||||||||||
2086 | cachedDay = qMax<int>(oldDay, cachedDay); | - | ||||||||||||
2087 | } | - | ||||||||||||
2088 | - | |||||||||||||
2089 | if (v < minimumDateTime) { | - | ||||||||||||
2090 | if (wrapping) { | - | ||||||||||||
2091 | QDateTime t = v; | - | ||||||||||||
2092 | setDigit(t, sectionIndex, steps < 0 ? max : min); | - | ||||||||||||
2093 | bool mincmp = (t >= minimumDateTime); | - | ||||||||||||
2094 | bool maxcmp = (t <= maximumDateTime); | - | ||||||||||||
2095 | if (!mincmp || !maxcmp) { | - | ||||||||||||
2096 | setDigit(t, sectionIndex, getDigit(steps < 0 | - | ||||||||||||
2097 | ? maximumDateTime | - | ||||||||||||
2098 | : minimumDateTime, sectionIndex)); | - | ||||||||||||
2099 | mincmp = (t >= minimumDateTime); | - | ||||||||||||
2100 | maxcmp = (t <= maximumDateTime); | - | ||||||||||||
2101 | } | - | ||||||||||||
2102 | if (mincmp && maxcmp) { | - | ||||||||||||
2103 | v = t; | - | ||||||||||||
2104 | } | - | ||||||||||||
2105 | } else { | - | ||||||||||||
2106 | v = value.toDateTime(); | - | ||||||||||||
2107 | } | - | ||||||||||||
2108 | } else if (v > maximumDateTime) { | - | ||||||||||||
2109 | if (wrapping) { | - | ||||||||||||
2110 | QDateTime t = v; | - | ||||||||||||
2111 | setDigit(t, sectionIndex, steps > 0 ? min : max); | - | ||||||||||||
2112 | bool mincmp = (t >= minimumDateTime); | - | ||||||||||||
2113 | bool maxcmp = (t <= maximumDateTime); | - | ||||||||||||
2114 | if (!mincmp || !maxcmp) { | - | ||||||||||||
2115 | setDigit(t, sectionIndex, getDigit(steps > 0 ? | - | ||||||||||||
2116 | minimumDateTime : | - | ||||||||||||
2117 | maximumDateTime, sectionIndex)); | - | ||||||||||||
2118 | mincmp = (t >= minimumDateTime); | - | ||||||||||||
2119 | maxcmp = (t <= maximumDateTime); | - | ||||||||||||
2120 | } | - | ||||||||||||
2121 | if (mincmp && maxcmp) { | - | ||||||||||||
2122 | v = t; | - | ||||||||||||
2123 | } | - | ||||||||||||
2124 | } else { | - | ||||||||||||
2125 | v = value.toDateTime(); | - | ||||||||||||
2126 | } | - | ||||||||||||
2127 | } | - | ||||||||||||
2128 | - | |||||||||||||
2129 | const QDateTime ret = bound(v, value, steps).toDateTime().toTimeSpec(spec); | - | ||||||||||||
2130 | return ret; | - | ||||||||||||
2131 | } | - | ||||||||||||
2132 | - | |||||||||||||
2133 | /*! | - | ||||||||||||
2134 | \internal | - | ||||||||||||
2135 | */ | - | ||||||||||||
2136 | - | |||||||||||||
2137 | void QDateTimeEditPrivate::emitSignals(EmitPolicy ep, const QVariant &old) | - | ||||||||||||
2138 | { | - | ||||||||||||
2139 | Q_Q(QDateTimeEdit); | - | ||||||||||||
2140 | if (ep == NeverEmit) { | - | ||||||||||||
2141 | return; | - | ||||||||||||
2142 | } | - | ||||||||||||
2143 | pendingEmit = false; | - | ||||||||||||
2144 | - | |||||||||||||
2145 | const bool dodate = value.toDate().isValid() && (sections & DateSectionMask); | - | ||||||||||||
2146 | const bool datechanged = (ep == AlwaysEmit || old.toDate() != value.toDate()); | - | ||||||||||||
2147 | const bool dotime = value.toTime().isValid() && (sections & TimeSectionMask); | - | ||||||||||||
2148 | const bool timechanged = (ep == AlwaysEmit || old.toTime() != value.toTime()); | - | ||||||||||||
2149 | - | |||||||||||||
2150 | updateCache(value, displayText()); | - | ||||||||||||
2151 | - | |||||||||||||
2152 | syncCalendarWidget(); | - | ||||||||||||
2153 | if (datechanged || timechanged) | - | ||||||||||||
2154 | emit q->dateTimeChanged(value.toDateTime()); | - | ||||||||||||
2155 | if (dodate && datechanged) | - | ||||||||||||
2156 | emit q->dateChanged(value.toDate()); | - | ||||||||||||
2157 | if (dotime && timechanged) | - | ||||||||||||
2158 | emit q->timeChanged(value.toTime()); | - | ||||||||||||
2159 | - | |||||||||||||
2160 | } | - | ||||||||||||
2161 | - | |||||||||||||
2162 | /*! | - | ||||||||||||
2163 | \internal | - | ||||||||||||
2164 | */ | - | ||||||||||||
2165 | - | |||||||||||||
2166 | void QDateTimeEditPrivate::_q_editorCursorPositionChanged(int oldpos, int newpos) | - | ||||||||||||
2167 | { | - | ||||||||||||
2168 | if (ignoreCursorPositionChanged || specialValue()) | - | ||||||||||||
2169 | return; | - | ||||||||||||
2170 | const QString oldText = displayText(); | - | ||||||||||||
2171 | updateCache(value, oldText); | - | ||||||||||||
2172 | - | |||||||||||||
2173 | const bool allowChange = !edit->hasSelectedText(); | - | ||||||||||||
2174 | const bool forward = oldpos <= newpos; | - | ||||||||||||
2175 | ignoreCursorPositionChanged = true; | - | ||||||||||||
2176 | int s = sectionAt(newpos); | - | ||||||||||||
2177 | if (s == NoSectionIndex && forward && newpos > 0) { | - | ||||||||||||
2178 | s = sectionAt(newpos - 1); | - | ||||||||||||
2179 | } | - | ||||||||||||
2180 | - | |||||||||||||
2181 | int c = newpos; | - | ||||||||||||
2182 | - | |||||||||||||
2183 | const int selstart = edit->selectionStart(); | - | ||||||||||||
2184 | const int selSection = sectionAt(selstart); | - | ||||||||||||
2185 | const int l = selSection != -1 ? sectionSize(selSection) : 0; | - | ||||||||||||
2186 | - | |||||||||||||
2187 | if (s == NoSectionIndex) { | - | ||||||||||||
2188 | if (l > 0 && selstart == sectionPos(selSection) && edit->selectedText().size() == l) { | - | ||||||||||||
2189 | s = selSection; | - | ||||||||||||
2190 | if (allowChange) | - | ||||||||||||
2191 | setSelected(selSection, true); | - | ||||||||||||
2192 | c = -1; | - | ||||||||||||
2193 | } else { | - | ||||||||||||
2194 | int closest = closestSection(newpos, forward); | - | ||||||||||||
2195 | c = sectionPos(closest) + (forward ? 0 : qMax<int>(0, sectionSize(closest))); | - | ||||||||||||
2196 | - | |||||||||||||
2197 | if (allowChange) { | - | ||||||||||||
2198 | edit->setCursorPosition(c); | - | ||||||||||||
2199 | QDTEDEBUG << c; dead code: QMessageLogger(__FILE__, 2199, __PRETTY_FUNCTION__).debug() << c; | - | ||||||||||||
2200 | } | - | ||||||||||||
2201 | s = closest; | - | ||||||||||||
2202 | } | - | ||||||||||||
2203 | } | - | ||||||||||||
2204 | - | |||||||||||||
2205 | if (allowChange && currentSectionIndex != s) { | - | ||||||||||||
2206 | interpret(EmitIfChanged); | - | ||||||||||||
2207 | } | - | ||||||||||||
2208 | if (c == -1) { | - | ||||||||||||
2209 | setSelected(s, true); | - | ||||||||||||
2210 | } else if (!edit->hasSelectedText()) { | - | ||||||||||||
2211 | if (oldpos < newpos) { | - | ||||||||||||
2212 | edit->setCursorPosition(displayText().size() - (oldText.size() - c)); | - | ||||||||||||
2213 | } else { | - | ||||||||||||
2214 | edit->setCursorPosition(c); | - | ||||||||||||
2215 | } | - | ||||||||||||
2216 | } | - | ||||||||||||
2217 | - | |||||||||||||
2218 | QDTEDEBUG << "currentSectionIndex is set to" << sectionNode(s).name() dead code: QMessageLogger(__FILE__, 2218, __PRETTY_FUNCTION__).debug() << "currentSectionIndex is set to" << sectionNode(s).name() << oldpos << newpos << "was" << sectionNode(currentSectionIndex).name(); | - | ||||||||||||
2219 | << oldpos << newpos dead code: QMessageLogger(__FILE__, 2218, __PRETTY_FUNCTION__).debug() << "currentSectionIndex is set to" << sectionNode(s).name() << oldpos << newpos << "was" << sectionNode(currentSectionIndex).name(); | - | ||||||||||||
2220 | << "was" << sectionNode(currentSectionIndex).name(); dead code: QMessageLogger(__FILE__, 2218, __PRETTY_FUNCTION__).debug() << "currentSectionIndex is set to" << sectionNode(s).name() << oldpos << newpos << "was" << sectionNode(currentSectionIndex).name(); | - | ||||||||||||
2221 | - | |||||||||||||
2222 | currentSectionIndex = s; | - | ||||||||||||
2223 | Q_ASSERT_X(currentSectionIndex < sectionNodes.size(), | - | ||||||||||||
2224 | "QDateTimeEditPrivate::_q_editorCursorPositionChanged()", | - | ||||||||||||
2225 | qPrintable(QString::fromLatin1("Internal error (%1 %2)"). | - | ||||||||||||
2226 | arg(currentSectionIndex). | - | ||||||||||||
2227 | arg(sectionNodes.size()))); | - | ||||||||||||
2228 | - | |||||||||||||
2229 | ignoreCursorPositionChanged = false; | - | ||||||||||||
2230 | } | - | ||||||||||||
2231 | - | |||||||||||||
2232 | /*! | - | ||||||||||||
2233 | \internal | - | ||||||||||||
2234 | - | |||||||||||||
2235 | Try to get the format from the local settings | - | ||||||||||||
2236 | */ | - | ||||||||||||
2237 | void QDateTimeEditPrivate::readLocaleSettings() | - | ||||||||||||
2238 | { | - | ||||||||||||
2239 | const QLocale loc; | - | ||||||||||||
2240 | defaultTimeFormat = loc.timeFormat(QLocale::ShortFormat); | - | ||||||||||||
2241 | defaultDateFormat = loc.dateFormat(QLocale::ShortFormat); | - | ||||||||||||
2242 | defaultDateTimeFormat = loc.dateTimeFormat(QLocale::ShortFormat); | - | ||||||||||||
2243 | } | - | ||||||||||||
2244 | - | |||||||||||||
2245 | QDateTimeEdit::Section QDateTimeEditPrivate::convertToPublic(QDateTimeParser::Section s) | - | ||||||||||||
2246 | { | - | ||||||||||||
2247 | switch (s & ~Internal) { | - | ||||||||||||
2248 | case AmPmSection: return QDateTimeEdit::AmPmSection; | - | ||||||||||||
2249 | case MSecSection: return QDateTimeEdit::MSecSection; | - | ||||||||||||
2250 | case SecondSection: return QDateTimeEdit::SecondSection; | - | ||||||||||||
2251 | case MinuteSection: return QDateTimeEdit::MinuteSection; | - | ||||||||||||
2252 | case DayOfWeekSectionShort: | - | ||||||||||||
2253 | case DayOfWeekSectionLong: | - | ||||||||||||
2254 | case DaySection: return QDateTimeEdit::DaySection; | - | ||||||||||||
2255 | case MonthSection: return QDateTimeEdit::MonthSection; | - | ||||||||||||
2256 | case YearSection2Digits: | - | ||||||||||||
2257 | case YearSection: return QDateTimeEdit::YearSection; | - | ||||||||||||
2258 | case Hour12Section: | - | ||||||||||||
2259 | case Hour24Section: return QDateTimeEdit::HourSection; | - | ||||||||||||
2260 | case FirstSection: | - | ||||||||||||
2261 | case NoSection: | - | ||||||||||||
2262 | case LastSection: break; | - | ||||||||||||
2263 | } | - | ||||||||||||
2264 | return QDateTimeEdit::NoSection; | - | ||||||||||||
2265 | } | - | ||||||||||||
2266 | - | |||||||||||||
2267 | QDateTimeEdit::Sections QDateTimeEditPrivate::convertSections(QDateTimeParser::Sections s) | - | ||||||||||||
2268 | { | - | ||||||||||||
2269 | QDateTimeEdit::Sections ret = 0; | - | ||||||||||||
2270 | if (s & QDateTimeParser::MSecSection) | - | ||||||||||||
2271 | ret |= QDateTimeEdit::MSecSection; | - | ||||||||||||
2272 | if (s & QDateTimeParser::SecondSection) | - | ||||||||||||
2273 | ret |= QDateTimeEdit::SecondSection; | - | ||||||||||||
2274 | if (s & QDateTimeParser::MinuteSection) | - | ||||||||||||
2275 | ret |= QDateTimeEdit::MinuteSection; | - | ||||||||||||
2276 | if (s & (QDateTimeParser::HourSectionMask)) | - | ||||||||||||
2277 | ret |= QDateTimeEdit::HourSection; | - | ||||||||||||
2278 | if (s & QDateTimeParser::AmPmSection) | - | ||||||||||||
2279 | ret |= QDateTimeEdit::AmPmSection; | - | ||||||||||||
2280 | if (s & (QDateTimeParser::DaySectionMask)) | - | ||||||||||||
2281 | ret |= QDateTimeEdit::DaySection; | - | ||||||||||||
2282 | if (s & QDateTimeParser::MonthSection) | - | ||||||||||||
2283 | ret |= QDateTimeEdit::MonthSection; | - | ||||||||||||
2284 | if (s & (QDateTimeParser::YearSectionMask)) | - | ||||||||||||
2285 | ret |= QDateTimeEdit::YearSection; | - | ||||||||||||
2286 | - | |||||||||||||
2287 | return ret; | - | ||||||||||||
2288 | } | - | ||||||||||||
2289 | - | |||||||||||||
2290 | /*! | - | ||||||||||||
2291 | \reimp | - | ||||||||||||
2292 | */ | - | ||||||||||||
2293 | - | |||||||||||||
2294 | void QDateTimeEdit::paintEvent(QPaintEvent *event) | - | ||||||||||||
2295 | { | - | ||||||||||||
2296 | Q_D(QDateTimeEdit); | - | ||||||||||||
2297 | if (!d->calendarPopupEnabled()) { | - | ||||||||||||
2298 | QAbstractSpinBox::paintEvent(event); | - | ||||||||||||
2299 | return; | - | ||||||||||||
2300 | } | - | ||||||||||||
2301 | - | |||||||||||||
2302 | QStyleOptionSpinBox opt; | - | ||||||||||||
2303 | initStyleOption(&opt); | - | ||||||||||||
2304 | - | |||||||||||||
2305 | QStyleOptionComboBox optCombo; | - | ||||||||||||
2306 | - | |||||||||||||
2307 | optCombo.init(this); | - | ||||||||||||
2308 | optCombo.editable = true; | - | ||||||||||||
2309 | optCombo.frame = opt.frame; | - | ||||||||||||
2310 | optCombo.subControls = opt.subControls; | - | ||||||||||||
2311 | optCombo.activeSubControls = opt.activeSubControls; | - | ||||||||||||
2312 | optCombo.state = opt.state; | - | ||||||||||||
2313 | if (d->readOnly) { | - | ||||||||||||
2314 | optCombo.state &= ~QStyle::State_Enabled; | - | ||||||||||||
2315 | } | - | ||||||||||||
2316 | - | |||||||||||||
2317 | QPainter p(this); | - | ||||||||||||
2318 | style()->drawComplexControl(QStyle::CC_ComboBox, &optCombo, &p, this); | - | ||||||||||||
2319 | } | - | ||||||||||||
2320 | - | |||||||||||||
2321 | QString QDateTimeEditPrivate::getAmPmText(AmPm ap, Case cs) const | - | ||||||||||||
2322 | { | - | ||||||||||||
2323 | if (ap == AmText) { | - | ||||||||||||
2324 | return (cs == UpperCase ? QDateTimeParser::tr("AM") : QDateTimeParser::tr("am")); | - | ||||||||||||
2325 | } else { | - | ||||||||||||
2326 | return (cs == UpperCase ? QDateTimeParser::tr("PM") : QDateTimeParser::tr("pm")); | - | ||||||||||||
2327 | } | - | ||||||||||||
2328 | } | - | ||||||||||||
2329 | - | |||||||||||||
2330 | int QDateTimeEditPrivate::absoluteIndex(QDateTimeEdit::Section s, int index) const | - | ||||||||||||
2331 | { | - | ||||||||||||
2332 | for (int i=0; i<sectionNodes.size(); ++i) { | - | ||||||||||||
2333 | if (convertToPublic(sectionNodes.at(i).type) == s && index-- == 0) { | - | ||||||||||||
2334 | return i; | - | ||||||||||||
2335 | } | - | ||||||||||||
2336 | } | - | ||||||||||||
2337 | return NoSectionIndex; | - | ||||||||||||
2338 | } | - | ||||||||||||
2339 | - | |||||||||||||
2340 | int QDateTimeEditPrivate::absoluteIndex(const SectionNode &s) const | - | ||||||||||||
2341 | { | - | ||||||||||||
2342 | return sectionNodes.indexOf(s); | - | ||||||||||||
2343 | } | - | ||||||||||||
2344 | - | |||||||||||||
2345 | void QDateTimeEditPrivate::interpret(EmitPolicy ep) | - | ||||||||||||
2346 | { | - | ||||||||||||
2347 | Q_Q(QDateTimeEdit); | - | ||||||||||||
2348 | QString tmp = displayText(); | - | ||||||||||||
2349 | int pos = edit->cursorPosition(); | - | ||||||||||||
2350 | const QValidator::State state = q->validate(tmp, pos); | - | ||||||||||||
2351 | if (state != QValidator::Acceptable | - | ||||||||||||
2352 | && correctionMode == QAbstractSpinBox::CorrectToPreviousValue | - | ||||||||||||
2353 | && (state == QValidator::Invalid | - | ||||||||||||
2354 | || currentSectionIndex < 0 | - | ||||||||||||
2355 | || !(fieldInfo(currentSectionIndex) & AllowPartial))) { | - | ||||||||||||
2356 | setValue(value, ep); | - | ||||||||||||
2357 | updateTimeSpec(); | - | ||||||||||||
2358 | } else { | - | ||||||||||||
2359 | QAbstractSpinBoxPrivate::interpret(ep); | - | ||||||||||||
2360 | } | - | ||||||||||||
2361 | } | - | ||||||||||||
2362 | - | |||||||||||||
2363 | void QDateTimeEditPrivate::clearCache() const | - | ||||||||||||
2364 | { | - | ||||||||||||
2365 | QAbstractSpinBoxPrivate::clearCache(); | - | ||||||||||||
2366 | cachedDay = -1; | - | ||||||||||||
2367 | } | - | ||||||||||||
2368 | - | |||||||||||||
2369 | /*! | - | ||||||||||||
2370 | Initialize \a option with the values from this QDataTimeEdit. This method | - | ||||||||||||
2371 | is useful for subclasses when they need a QStyleOptionSpinBox, but don't want | - | ||||||||||||
2372 | to fill in all the information themselves. | - | ||||||||||||
2373 | - | |||||||||||||
2374 | \sa QStyleOption::initFrom() | - | ||||||||||||
2375 | */ | - | ||||||||||||
2376 | void QDateTimeEdit::initStyleOption(QStyleOptionSpinBox *option) const | - | ||||||||||||
2377 | { | - | ||||||||||||
2378 | if (!option) | - | ||||||||||||
2379 | return; | - | ||||||||||||
2380 | - | |||||||||||||
2381 | Q_D(const QDateTimeEdit); | - | ||||||||||||
2382 | QAbstractSpinBox::initStyleOption(option); | - | ||||||||||||
2383 | if (d->calendarPopupEnabled()) { | - | ||||||||||||
2384 | option->subControls = QStyle::SC_ComboBoxFrame | QStyle::SC_ComboBoxEditField | - | ||||||||||||
2385 | | QStyle::SC_ComboBoxArrow; | - | ||||||||||||
2386 | if (d->arrowState == QStyle::State_Sunken) | - | ||||||||||||
2387 | option->state |= QStyle::State_Sunken; | - | ||||||||||||
2388 | else | - | ||||||||||||
2389 | option->state &= ~QStyle::State_Sunken; | - | ||||||||||||
2390 | } | - | ||||||||||||
2391 | } | - | ||||||||||||
2392 | - | |||||||||||||
2393 | void QDateTimeEditPrivate::init(const QVariant &var) | - | ||||||||||||
2394 | { | - | ||||||||||||
2395 | Q_Q(QDateTimeEdit); | - | ||||||||||||
2396 | switch (var.type()) { | - | ||||||||||||
2397 | case QVariant::Date: | - | ||||||||||||
2398 | value = QDateTime(var.toDate(), QDATETIMEEDIT_TIME_MIN); | - | ||||||||||||
2399 | updateTimeSpec(); | - | ||||||||||||
2400 | q->setDisplayFormat(defaultDateFormat); | - | ||||||||||||
2401 | if (sectionNodes.isEmpty()) // ### safeguard for broken locale | - | ||||||||||||
2402 | q->setDisplayFormat(QLatin1String("dd/MM/yyyy")); | - | ||||||||||||
2403 | break; | - | ||||||||||||
2404 | case QVariant::DateTime: | - | ||||||||||||
2405 | value = var; | - | ||||||||||||
2406 | updateTimeSpec(); | - | ||||||||||||
2407 | q->setDisplayFormat(defaultDateTimeFormat); | - | ||||||||||||
2408 | if (sectionNodes.isEmpty()) // ### safeguard for broken locale | - | ||||||||||||
2409 | q->setDisplayFormat(QLatin1String("dd/MM/yyyy hh:mm:ss")); | - | ||||||||||||
2410 | break; | - | ||||||||||||
2411 | case QVariant::Time: | - | ||||||||||||
2412 | value = QDateTime(QDATETIMEEDIT_DATE_INITIAL, var.toTime()); | - | ||||||||||||
2413 | updateTimeSpec(); | - | ||||||||||||
2414 | q->setDisplayFormat(defaultTimeFormat); | - | ||||||||||||
2415 | if (sectionNodes.isEmpty()) // ### safeguard for broken locale | - | ||||||||||||
2416 | q->setDisplayFormat(QLatin1String("hh:mm:ss")); | - | ||||||||||||
2417 | break; | - | ||||||||||||
2418 | default: | - | ||||||||||||
2419 | Q_ASSERT_X(0, "QDateTimeEditPrivate::init", "Internal error"); | - | ||||||||||||
2420 | break; | - | ||||||||||||
2421 | } | - | ||||||||||||
2422 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||
2423 | if (QApplication::keypadNavigationEnabled()) | - | ||||||||||||
2424 | q->setCalendarPopup(true); | - | ||||||||||||
2425 | #endif | - | ||||||||||||
2426 | q->setInputMethodHints(Qt::ImhPreferNumbers); | - | ||||||||||||
2427 | setLayoutItemMargins(QStyle::SE_DateTimeEditLayoutItem); | - | ||||||||||||
2428 | } | - | ||||||||||||
2429 | - | |||||||||||||
2430 | void QDateTimeEditPrivate::_q_resetButton() | - | ||||||||||||
2431 | { | - | ||||||||||||
2432 | updateArrow(QStyle::State_None); | - | ||||||||||||
2433 | } | - | ||||||||||||
2434 | - | |||||||||||||
2435 | void QDateTimeEditPrivate::updateArrow(QStyle::StateFlag state) | - | ||||||||||||
2436 | { | - | ||||||||||||
2437 | Q_Q(QDateTimeEdit); | - | ||||||||||||
2438 | - | |||||||||||||
2439 | if (arrowState == state) | - | ||||||||||||
2440 | return; | - | ||||||||||||
2441 | arrowState = state; | - | ||||||||||||
2442 | if (arrowState != QStyle::State_None) | - | ||||||||||||
2443 | buttonState |= Mouse; | - | ||||||||||||
2444 | else { | - | ||||||||||||
2445 | buttonState = 0; | - | ||||||||||||
2446 | hoverControl = QStyle::SC_ComboBoxFrame; | - | ||||||||||||
2447 | } | - | ||||||||||||
2448 | q->update(); | - | ||||||||||||
2449 | } | - | ||||||||||||
2450 | - | |||||||||||||
2451 | /*! | - | ||||||||||||
2452 | \internal | - | ||||||||||||
2453 | Returns the hover control at \a pos. | - | ||||||||||||
2454 | This will update the hoverRect and hoverControl. | - | ||||||||||||
2455 | */ | - | ||||||||||||
2456 | QStyle::SubControl QDateTimeEditPrivate::newHoverControl(const QPoint &pos) | - | ||||||||||||
2457 | { | - | ||||||||||||
2458 | if (!calendarPopupEnabled()) | - | ||||||||||||
2459 | return QAbstractSpinBoxPrivate::newHoverControl(pos); | - | ||||||||||||
2460 | - | |||||||||||||
2461 | Q_Q(QDateTimeEdit); | - | ||||||||||||
2462 | - | |||||||||||||
2463 | QStyleOptionComboBox optCombo; | - | ||||||||||||
2464 | optCombo.init(q); | - | ||||||||||||
2465 | optCombo.editable = true; | - | ||||||||||||
2466 | optCombo.subControls = QStyle::SC_All; | - | ||||||||||||
2467 | hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ComboBox, &optCombo, pos, q); | - | ||||||||||||
2468 | return hoverControl; | - | ||||||||||||
2469 | } | - | ||||||||||||
2470 | - | |||||||||||||
2471 | void QDateTimeEditPrivate::updateEditFieldGeometry() | - | ||||||||||||
2472 | { | - | ||||||||||||
2473 | if (!calendarPopupEnabled()) { | - | ||||||||||||
2474 | QAbstractSpinBoxPrivate::updateEditFieldGeometry(); | - | ||||||||||||
2475 | return; | - | ||||||||||||
2476 | } | - | ||||||||||||
2477 | - | |||||||||||||
2478 | Q_Q(QDateTimeEdit); | - | ||||||||||||
2479 | - | |||||||||||||
2480 | QStyleOptionComboBox optCombo; | - | ||||||||||||
2481 | optCombo.init(q); | - | ||||||||||||
2482 | optCombo.editable = true; | - | ||||||||||||
2483 | optCombo.subControls = QStyle::SC_ComboBoxEditField; | - | ||||||||||||
2484 | edit->setGeometry(q->style()->subControlRect(QStyle::CC_ComboBox, &optCombo, | - | ||||||||||||
2485 | QStyle::SC_ComboBoxEditField, q)); | - | ||||||||||||
2486 | } | - | ||||||||||||
2487 | - | |||||||||||||
2488 | QVariant QDateTimeEditPrivate::getZeroVariant() const | - | ||||||||||||
2489 | { | - | ||||||||||||
2490 | Q_ASSERT(type == QVariant::DateTime); | - | ||||||||||||
2491 | return QDateTime(QDATETIMEEDIT_DATE_INITIAL, QTime(), spec); | - | ||||||||||||
2492 | } | - | ||||||||||||
2493 | - | |||||||||||||
2494 | void QDateTimeEditPrivate::setRange(const QVariant &min, const QVariant &max) | - | ||||||||||||
2495 | { | - | ||||||||||||
2496 | QAbstractSpinBoxPrivate::setRange(min, max); | - | ||||||||||||
2497 | syncCalendarWidget(); | - | ||||||||||||
2498 | } | - | ||||||||||||
2499 | - | |||||||||||||
2500 | - | |||||||||||||
2501 | bool QDateTimeEditPrivate::isSeparatorKey(const QKeyEvent *ke) const | - | ||||||||||||
2502 | { | - | ||||||||||||
2503 | if (!ke->text().isEmpty() && currentSectionIndex + 1 < sectionNodes.size() && currentSectionIndex >= 0) { | - | ||||||||||||
2504 | if (fieldInfo(currentSectionIndex) & Numeric) { | - | ||||||||||||
2505 | if (ke->text().at(0).isNumber()) | - | ||||||||||||
2506 | return false; | - | ||||||||||||
2507 | } else if (ke->text().at(0).isLetterOrNumber()) { | - | ||||||||||||
2508 | return false; | - | ||||||||||||
2509 | } | - | ||||||||||||
2510 | return separators.at(currentSectionIndex + 1).contains(ke->text()); | - | ||||||||||||
2511 | } | - | ||||||||||||
2512 | return false; | - | ||||||||||||
2513 | } | - | ||||||||||||
2514 | - | |||||||||||||
2515 | void QDateTimeEditPrivate::initCalendarPopup(QCalendarWidget *cw) | - | ||||||||||||
2516 | { | - | ||||||||||||
2517 | Q_Q(QDateTimeEdit); | - | ||||||||||||
2518 | if (!monthCalendar) { | - | ||||||||||||
2519 | monthCalendar = new QCalendarPopup(q, cw); | - | ||||||||||||
2520 | monthCalendar->setObjectName(QLatin1String("qt_datetimedit_calendar")); | - | ||||||||||||
2521 | QObject::connect(monthCalendar, SIGNAL(newDateSelected(QDate)), q, SLOT(setDate(QDate))); | - | ||||||||||||
2522 | QObject::connect(monthCalendar, SIGNAL(hidingCalendar(QDate)), q, SLOT(setDate(QDate))); | - | ||||||||||||
2523 | QObject::connect(monthCalendar, SIGNAL(activated(QDate)), q, SLOT(setDate(QDate))); | - | ||||||||||||
2524 | QObject::connect(monthCalendar, SIGNAL(activated(QDate)), monthCalendar, SLOT(close())); | - | ||||||||||||
2525 | QObject::connect(monthCalendar, SIGNAL(resetButton()), q, SLOT(_q_resetButton())); | - | ||||||||||||
2526 | } else if (cw) { | - | ||||||||||||
2527 | monthCalendar->setCalendarWidget(cw); | - | ||||||||||||
2528 | } | - | ||||||||||||
2529 | syncCalendarWidget(); | - | ||||||||||||
2530 | } | - | ||||||||||||
2531 | - | |||||||||||||
2532 | void QDateTimeEditPrivate::positionCalendarPopup() | - | ||||||||||||
2533 | { | - | ||||||||||||
2534 | Q_Q(QDateTimeEdit); | - | ||||||||||||
2535 | QPoint pos = (q->layoutDirection() == Qt::RightToLeft) ? q->rect().bottomRight() : q->rect().bottomLeft(); | - | ||||||||||||
2536 | QPoint pos2 = (q->layoutDirection() == Qt::RightToLeft) ? q->rect().topRight() : q->rect().topLeft(); | - | ||||||||||||
2537 | pos = q->mapToGlobal(pos); | - | ||||||||||||
2538 | pos2 = q->mapToGlobal(pos2); | - | ||||||||||||
2539 | QSize size = monthCalendar->sizeHint(); | - | ||||||||||||
2540 | QRect screen = QApplication::desktop()->availableGeometry(pos); | - | ||||||||||||
2541 | //handle popup falling "off screen" | - | ||||||||||||
2542 | if (q->layoutDirection() == Qt::RightToLeft) { | - | ||||||||||||
2543 | pos.setX(pos.x()-size.width()); | - | ||||||||||||
2544 | pos2.setX(pos2.x()-size.width()); | - | ||||||||||||
2545 | if (pos.x() < screen.left()) | - | ||||||||||||
2546 | pos.setX(qMax(pos.x(), screen.left())); | - | ||||||||||||
2547 | else if (pos.x()+size.width() > screen.right()) | - | ||||||||||||
2548 | pos.setX(qMax(pos.x()-size.width(), screen.right()-size.width())); | - | ||||||||||||
2549 | } else { | - | ||||||||||||
2550 | if (pos.x()+size.width() > screen.right()) | - | ||||||||||||
2551 | pos.setX(screen.right()-size.width()); | - | ||||||||||||
2552 | pos.setX(qMax(pos.x(), screen.left())); | - | ||||||||||||
2553 | } | - | ||||||||||||
2554 | if (pos.y() + size.height() > screen.bottom()) | - | ||||||||||||
2555 | pos.setY(pos2.y() - size.height()); | - | ||||||||||||
2556 | else if (pos.y() < screen.top()) | - | ||||||||||||
2557 | pos.setY(screen.top()); | - | ||||||||||||
2558 | if (pos.y() < screen.top()) | - | ||||||||||||
2559 | pos.setY(screen.top()); | - | ||||||||||||
2560 | if (pos.y()+size.height() > screen.bottom()) | - | ||||||||||||
2561 | pos.setY(screen.bottom()-size.height()); | - | ||||||||||||
2562 | monthCalendar->move(pos); | - | ||||||||||||
2563 | } | - | ||||||||||||
2564 | - | |||||||||||||
2565 | bool QDateTimeEditPrivate::calendarPopupEnabled() const | - | ||||||||||||
2566 | { | - | ||||||||||||
2567 | return (calendarPopup && (sections & (DateSectionMask))); | - | ||||||||||||
2568 | } | - | ||||||||||||
2569 | - | |||||||||||||
2570 | void QDateTimeEditPrivate::syncCalendarWidget() | - | ||||||||||||
2571 | { | - | ||||||||||||
2572 | Q_Q(QDateTimeEdit); | - | ||||||||||||
2573 | if (monthCalendar) { | - | ||||||||||||
2574 | const QSignalBlocker blocker(monthCalendar); | - | ||||||||||||
2575 | monthCalendar->setDateRange(q->minimumDate(), q->maximumDate()); | - | ||||||||||||
2576 | monthCalendar->setDate(q->date()); | - | ||||||||||||
2577 | } | - | ||||||||||||
2578 | } | - | ||||||||||||
2579 | - | |||||||||||||
2580 | QCalendarPopup::QCalendarPopup(QWidget * parent, QCalendarWidget *cw) | - | ||||||||||||
2581 | : QWidget(parent, Qt::Popup) | - | ||||||||||||
2582 | { | - | ||||||||||||
2583 | setAttribute(Qt::WA_WindowPropagation); | - | ||||||||||||
2584 | - | |||||||||||||
2585 | dateChanged = false; | - | ||||||||||||
2586 | if (!cw) { | - | ||||||||||||
2587 | verifyCalendarInstance(); | - | ||||||||||||
2588 | } else { | - | ||||||||||||
2589 | setCalendarWidget(cw); | - | ||||||||||||
2590 | } | - | ||||||||||||
2591 | } | - | ||||||||||||
2592 | - | |||||||||||||
2593 | QCalendarWidget *QCalendarPopup::verifyCalendarInstance() | - | ||||||||||||
2594 | { | - | ||||||||||||
2595 | if (calendar.isNull()) { | - | ||||||||||||
2596 | QCalendarWidget *cw = new QCalendarWidget(this); | - | ||||||||||||
2597 | cw->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader); | - | ||||||||||||
2598 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||
2599 | if (QApplication::keypadNavigationEnabled()) | - | ||||||||||||
2600 | cw->setHorizontalHeaderFormat(QCalendarWidget::SingleLetterDayNames); | - | ||||||||||||
2601 | #endif | - | ||||||||||||
2602 | setCalendarWidget(cw); | - | ||||||||||||
2603 | return cw; | - | ||||||||||||
2604 | } else { | - | ||||||||||||
2605 | return calendar.data(); | - | ||||||||||||
2606 | } | - | ||||||||||||
2607 | } | - | ||||||||||||
2608 | - | |||||||||||||
2609 | void QCalendarPopup::setCalendarWidget(QCalendarWidget *cw) | - | ||||||||||||
2610 | { | - | ||||||||||||
2611 | Q_ASSERT(cw); | - | ||||||||||||
2612 | QVBoxLayout *widgetLayout = qobject_cast<QVBoxLayout*>(layout()); | - | ||||||||||||
2613 | if (!widgetLayout) { | - | ||||||||||||
2614 | widgetLayout = new QVBoxLayout(this); | - | ||||||||||||
2615 | widgetLayout->setMargin(0); | - | ||||||||||||
2616 | widgetLayout->setSpacing(0); | - | ||||||||||||
2617 | } | - | ||||||||||||
2618 | delete calendar.data(); | - | ||||||||||||
2619 | calendar = QPointer<QCalendarWidget>(cw); | - | ||||||||||||
2620 | widgetLayout->addWidget(cw); | - | ||||||||||||
2621 | - | |||||||||||||
2622 | connect(cw, SIGNAL(activated(QDate)), this, SLOT(dateSelected(QDate))); | - | ||||||||||||
2623 | connect(cw, SIGNAL(clicked(QDate)), this, SLOT(dateSelected(QDate))); | - | ||||||||||||
2624 | connect(cw, SIGNAL(selectionChanged()), this, SLOT(dateSelectionChanged())); | - | ||||||||||||
2625 | - | |||||||||||||
2626 | cw->setFocus(); | - | ||||||||||||
2627 | } | - | ||||||||||||
2628 | - | |||||||||||||
2629 | - | |||||||||||||
2630 | void QCalendarPopup::setDate(const QDate &date) | - | ||||||||||||
2631 | { | - | ||||||||||||
2632 | oldDate = date; | - | ||||||||||||
2633 | verifyCalendarInstance()->setSelectedDate(date); | - | ||||||||||||
2634 | } | - | ||||||||||||
2635 | - | |||||||||||||
2636 | void QCalendarPopup::setDateRange(const QDate &min, const QDate &max) | - | ||||||||||||
2637 | { | - | ||||||||||||
2638 | QCalendarWidget *cw = verifyCalendarInstance(); | - | ||||||||||||
2639 | cw->setMinimumDate(min); | - | ||||||||||||
2640 | cw->setMaximumDate(max); | - | ||||||||||||
2641 | } | - | ||||||||||||
2642 | - | |||||||||||||
2643 | void QCalendarPopup::mousePressEvent(QMouseEvent *event) | - | ||||||||||||
2644 | { | - | ||||||||||||
2645 | QDateTimeEdit *dateTime = qobject_cast<QDateTimeEdit *>(parentWidget()); | - | ||||||||||||
2646 | if (dateTime) { | - | ||||||||||||
2647 | QStyleOptionComboBox opt; | - | ||||||||||||
2648 | opt.init(dateTime); | - | ||||||||||||
2649 | QRect arrowRect = dateTime->style()->subControlRect(QStyle::CC_ComboBox, &opt, | - | ||||||||||||
2650 | QStyle::SC_ComboBoxArrow, dateTime); | - | ||||||||||||
2651 | arrowRect.moveTo(dateTime->mapToGlobal(arrowRect .topLeft())); | - | ||||||||||||
2652 | if (arrowRect.contains(event->globalPos()) || rect().contains(event->pos())) | - | ||||||||||||
2653 | setAttribute(Qt::WA_NoMouseReplay); | - | ||||||||||||
2654 | } | - | ||||||||||||
2655 | QWidget::mousePressEvent(event); | - | ||||||||||||
2656 | } | - | ||||||||||||
2657 | - | |||||||||||||
2658 | void QCalendarPopup::mouseReleaseEvent(QMouseEvent*) | - | ||||||||||||
2659 | { | - | ||||||||||||
2660 | emit resetButton(); | - | ||||||||||||
2661 | } | - | ||||||||||||
2662 | - | |||||||||||||
2663 | bool QCalendarPopup::event(QEvent *event) | - | ||||||||||||
2664 | { | - | ||||||||||||
2665 | if (event->type() == QEvent::KeyPress) { | - | ||||||||||||
2666 | QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); | - | ||||||||||||
2667 | if (keyEvent->matches(QKeySequence::Cancel)) | - | ||||||||||||
2668 | dateChanged = false; | - | ||||||||||||
2669 | } | - | ||||||||||||
2670 | return QWidget::event(event); | - | ||||||||||||
2671 | } | - | ||||||||||||
2672 | - | |||||||||||||
2673 | void QCalendarPopup::dateSelectionChanged() | - | ||||||||||||
2674 | { | - | ||||||||||||
2675 | dateChanged = true; | - | ||||||||||||
2676 | emit newDateSelected(verifyCalendarInstance()->selectedDate()); | - | ||||||||||||
2677 | } | - | ||||||||||||
2678 | void QCalendarPopup::dateSelected(const QDate &date) | - | ||||||||||||
2679 | { | - | ||||||||||||
2680 | dateChanged = true; | - | ||||||||||||
2681 | emit activated(date); | - | ||||||||||||
2682 | close(); | - | ||||||||||||
2683 | } | - | ||||||||||||
2684 | - | |||||||||||||
2685 | void QCalendarPopup::hideEvent(QHideEvent *) | - | ||||||||||||
2686 | { | - | ||||||||||||
2687 | emit resetButton(); | - | ||||||||||||
2688 | if (!dateChanged) | - | ||||||||||||
2689 | emit hidingCalendar(oldDate); | - | ||||||||||||
2690 | } | - | ||||||||||||
2691 | - | |||||||||||||
2692 | QT_END_NAMESPACE | - | ||||||||||||
2693 | #include "moc_qdatetimeedit.cpp" | - | ||||||||||||
2694 | #include "moc_qdatetimeedit_p.cpp" | - | ||||||||||||
2695 | - | |||||||||||||
2696 | #endif // QT_NO_DATETIMEEDIT | - | ||||||||||||
Source code | Switch to Preprocessed file |