qdatetimeedit.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qdatetimeedit.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2QDateTimeEdit::QDateTimeEdit(QWidget *parent)-
3 : QAbstractSpinBox(*new QDateTimeEditPrivate, parent)-
4{-
5 QDateTimeEditPrivate * const d = d_func();-
6 d->init(QDateTime(QDate(2000, 1, 1), QTime(0, 0, 0, 0)));-
7}-
8-
9-
10-
11-
12-
13-
14QDateTimeEdit::QDateTimeEdit(const QDateTime &datetime, QWidget *parent)-
15 : QAbstractSpinBox(*new QDateTimeEditPrivate, parent)-
16{-
17 QDateTimeEditPrivate * const d = d_func();-
18 d->init(datetime.isValid() ? datetime : QDateTime(QDate(2000, 1, 1),-
19 QTime(0, 0, 0, 0)));-
20}-
21QDateTimeEdit::QDateTimeEdit(const QDate &date, QWidget *parent)-
22 : QAbstractSpinBox(*new QDateTimeEditPrivate, parent)-
23{-
24 QDateTimeEditPrivate * const d = d_func();-
25 d->init(date.isValid() ? date : QDate(2000, 1, 1));-
26}-
27QDateTimeEdit::QDateTimeEdit(const QTime &time, QWidget *parent)-
28 : QAbstractSpinBox(*new QDateTimeEditPrivate, parent)-
29{-
30 QDateTimeEditPrivate * const d = d_func();-
31 d->init(time.isValid() ? time : QTime(0, 0, 0, 0));-
32}-
33-
34-
35-
36-
37-
38QDateTimeEdit::QDateTimeEdit(const QVariant &var, QVariant::Type parserType, QWidget *parent)-
39 : QAbstractSpinBox(*new QDateTimeEditPrivate, parent)-
40{-
41 QDateTimeEditPrivate * const d = d_func();-
42 d->parserType = parserType;-
43 d->init(var);-
44}-
45-
46-
47-
48-
49QDateTimeEdit::~QDateTimeEdit()-
50{-
51}-
52QDateTime QDateTimeEdit::dateTime() const-
53{-
54 const QDateTimeEditPrivate * const d = d_func();-
55 return d->value.toDateTime();-
56}-
57-
58void QDateTimeEdit::setDateTime(const QDateTime &datetime)-
59{-
60 QDateTimeEditPrivate * const d = d_func();-
61 if (datetime.isValid()
datetime.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
62 d->clearCache();-
63 const QDate date = datetime.date();-
64 if (!(d->sections & DateSections_Mask)
!(d->sections ...Sections_Mask)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
65 setDateRange(datetime.date(), datetime., date()););
never executed: setDateRange(date, date);
0
66 d->setValue(QDateTime(datetime.date(),, datetime.time(), d->spec), EmitIfChanged);-
67 }
never executed: end of block
0
68}
never executed: end of block
0
69QDate QDateTimeEdit::date() const-
70{-
71 const QDateTimeEditPrivate * const d = d_func();-
72 return d->value.toDate();-
73}-
74-
75void QDateTimeEdit::setDate(const QDate &date)-
76{-
77 QDateTimeEditPrivate * const d = d_func();-
78 if (date.isValid()) {-
79 if (!(d->sections & DateSections_Mask))-
80 setDateRange(date, date);-
81-
82 d->clearCache();-
83 d->setValue(QDateTime(date, d->value.toTime(), d->spec), EmitIfChanged);-
84 d->updateTimeSpec();-
85 }-
86}-
87QTime QDateTimeEdit::time() const-
88{-
89 const QDateTimeEditPrivate * const d = d_func();-
90 return d->value.toTime();-
91}-
92-
93void QDateTimeEdit::setTime(const QTime &time)-
94{-
95 QDateTimeEditPrivate * const d = d_func();-
96 if (time.isValid()) {-
97 d->clearCache();-
98 d->setValue(QDateTime(d->value.toDate(), time, d->spec), EmitIfChanged);-
99 }-
100}-
101QDateTime QDateTimeEdit::minimumDateTime() const-
102{-
103 const QDateTimeEditPrivate * const d = d_func();-
104 return d->minimum.toDateTime();-
105}-
106-
107void QDateTimeEdit::clearMinimumDateTime()-
108{-
109 setMinimumDateTime(QDateTime(QDate(1752, 9, 14), QTime(0, 0, 0, 0)));-
110}-
111-
112void QDateTimeEdit::setMinimumDateTime(const QDateTime &dt)-
113{-
114 QDateTimeEditPrivate * const d = d_func();-
115 if (dt.isValid() && dt.date() >= QDate(100, 1, 1)) {-
116 const QDateTime m = dt.toTimeSpec(d->spec);-
117 const QDateTime max = d->maximum.toDateTime();-
118 d->setRange(m, (max > m ? max : m));-
119 }-
120}-
121QDateTime QDateTimeEdit::maximumDateTime() const-
122{-
123 const QDateTimeEditPrivate * const d = d_func();-
124 return d->maximum.toDateTime();-
125}-
126-
127void QDateTimeEdit::clearMaximumDateTime()-
128{-
129 setMaximumDateTime(QDateTime(QDate(7999, 12, 31), QTime(23, 59, 59, 999)));-
130}-
131-
132void QDateTimeEdit::setMaximumDateTime(const QDateTime &dt)-
133{-
134 QDateTimeEditPrivate * const d = d_func();-
135 if (dt.isValid() && dt.date() <= QDate(7999, 12, 31)) {-
136 const QDateTime m = dt.toTimeSpec(d->spec);-
137 const QDateTime min = d->minimum.toDateTime();-
138 d->setRange((min < m ? min : m), m);-
139 }-
140}-
141void QDateTimeEdit::setDateTimeRange(const QDateTime &min, const QDateTime &max)-
142{-
143 QDateTimeEditPrivate * const d = d_func();-
144 const QDateTime minimum = min.toTimeSpec(d->spec);-
145 QDateTime maximum = max.toTimeSpec(d->spec);-
146 if (min > max)-
147 maximum = minimum;-
148 d->setRange(minimum, maximum);-
149}-
150QDate QDateTimeEdit::minimumDate() const-
151{-
152 const QDateTimeEditPrivate * const d = d_func();-
153 return d->minimum.toDate();-
154}-
155-
156void QDateTimeEdit::setMinimumDate(const QDate &min)-
157{-
158 QDateTimeEditPrivate * const d = d_func();-
159 if (min.isValid() && min >= QDate(100, 1, 1)) {-
160 setMinimumDateTime(QDateTime(min, d->minimum.toTime(), d->spec));-
161 }-
162}-
163-
164void QDateTimeEdit::clearMinimumDate()-
165{-
166 setMinimumDate(QDate(1752, 9, 14));-
167}-
168QDate QDateTimeEdit::maximumDate() const-
169{-
170 const QDateTimeEditPrivate * const d = d_func();-
171 return d->maximum.toDate();-
172}-
173-
174void QDateTimeEdit::setMaximumDate(const QDate &max)-
175{-
176 QDateTimeEditPrivate * const d = d_func();-
177 if (max.isValid()) {-
178 setMaximumDateTime(QDateTime(max, d->maximum.toTime(), d->spec));-
179 }-
180}-
181-
182void QDateTimeEdit::clearMaximumDate()-
183{-
184 setMaximumDate(QDate(7999, 12, 31));-
185}-
186QTime QDateTimeEdit::minimumTime() const-
187{-
188 const QDateTimeEditPrivate * const d = d_func();-
189 return d->minimum.toTime();-
190}-
191-
192void QDateTimeEdit::setMinimumTime(const QTime &min)-
193{-
194 QDateTimeEditPrivate * const d = d_func();-
195 if (min.isValid()) {-
196 const QDateTime m(d->minimum.toDate(), min, d->spec);-
197 setMinimumDateTime(m);-
198 }-
199}-
200-
201void QDateTimeEdit::clearMinimumTime()-
202{-
203 setMinimumTime(QTime(0, 0, 0, 0));-
204}-
205QTime QDateTimeEdit::maximumTime() const-
206{-
207 const QDateTimeEditPrivate * const d = d_func();-
208 return d->maximum.toTime();-
209}-
210-
211void QDateTimeEdit::setMaximumTime(const QTime &max)-
212{-
213 QDateTimeEditPrivate * const d = d_func();-
214 if (max.isValid()) {-
215 const QDateTime m(d->maximum.toDate(), max);-
216 setMaximumDateTime(m);-
217 }-
218}-
219-
220void QDateTimeEdit::clearMaximumTime()-
221{-
222 setMaximumTime(QTime(23, 59, 59, 999));-
223}-
224void QDateTimeEdit::setDateRange(const QDate &min, const QDate &max)-
225{-
226 QDateTimeEditPrivate * const d = d_func();-
227 if (min.isValid() && max.isValid()) {-
228 setDateTimeRange(QDateTime(min, d->minimum.toTime(), d->spec),-
229 QDateTime(max, d->maximum.toTime(), d->spec));-
230 }-
231}-
232void QDateTimeEdit::setTimeRange(const QTime &min, const QTime &max)-
233{-
234 QDateTimeEditPrivate * const d = d_func();-
235 if (min.isValid() && max.isValid()) {-
236 setDateTimeRange(QDateTime(d->minimum.toDate(), min, d->spec),-
237 QDateTime(d->maximum.toDate(), max, d->spec));-
238 }-
239}-
240QDateTimeEdit::Sections QDateTimeEdit::displayedSections() const-
241{-
242 const QDateTimeEditPrivate * const d = d_func();-
243 return d->sections;-
244}-
245QDateTimeEdit::Section QDateTimeEdit::currentSection() const-
246{-
247 const QDateTimeEditPrivate * const d = d_func();-
248-
249-
250-
251-
252 return d->convertToPublic(d->sectionType(d->currentSectionIndex));-
253}-
254-
255void QDateTimeEdit::setCurrentSection(Section section)-
256{-
257 QDateTimeEditPrivate * const d = d_func();-
258 if (section == NoSection || !(section & d->sections))-
259 return;-
260-
261 d->updateCache(d->value, d->displayText());-
262 const int size = d->sectionNodes.size();-
263 int index = d->currentSectionIndex + 1;-
264 for (int i=0; i<2; ++i) {-
265 while (index < size) {-
266 if (d->convertToPublic(d->sectionType(index)) == section) {-
267 d->edit->setCursorPosition(d->sectionPos(index));-
268 if (false) QMessageLogger(__FILE__, 658667, __PRETTY_FUNCTION__).debug() << d->sectionPos(index);
dead code: QMessageLogger(__FILE__, 667, __PRETTY_FUNCTION__).debug() << d->sectionPos(index);
-
269 return;-
270 }-
271 ++index;-
272 }-
273 index = 0;-
274 }-
275}-
276QDateTimeEdit::Section QDateTimeEdit::sectionAt(int index) const-
277{-
278 const QDateTimeEditPrivate * const d = d_func();-
279 if (index < 0 || index >= d->sectionNodes.size())-
280 return NoSection;-
281 return d->convertToPublic(d->sectionType(index));-
282}-
283int QDateTimeEdit::sectionCount() const-
284{-
285 const QDateTimeEditPrivate * const d = d_func();-
286 return d->sectionNodes.size();-
287}-
288int QDateTimeEdit::currentSectionIndex() const-
289{-
290 const QDateTimeEditPrivate * const d = d_func();-
291 return d->currentSectionIndex;-
292}-
293-
294void QDateTimeEdit::setCurrentSectionIndex(int index)-
295{-
296 QDateTimeEditPrivate * const d = d_func();-
297 if (index < 0 || index >= d->sectionNodes.size())-
298 return;-
299 d->edit->setCursorPosition(d->sectionPos(index));-
300}-
301QCalendarWidget *QDateTimeEdit::calendarWidget() const-
302{-
303 const QDateTimeEditPrivate * const d = d_func();-
304 if (!d->calendarPopup || !(d->sections & QDateTimeParser::DateSectionMask))-
305 return 0;-
306 if (!d->monthCalendar) {-
307 const_cast<QDateTimeEditPrivate*>(d)->initCalendarPopup();-
308 }-
309 return d->monthCalendar->calendarWidget();-
310}-
311void QDateTimeEdit::setCalendarWidget(QCalendarWidget *calendarWidget)-
312{-
313 QDateTimeEditPrivate * const d = d_func();-
314 if (!(__builtin_expect(!!(!
__builtin_expe...idget), false)Description
TRUEnever evaluated
FALSEnever evaluated
calendarWidget)), false)
__builtin_expe...idget), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
315 QMessageLogger(__FILE__, 764773, __PRETTY_FUNCTION__).warning("QDateTimeEdit::setCalendarWidget: Cannot set a null calendar widget");-
316 return;
never executed: return;
0
317 }-
318-
319 if (!(__builtin_expect(!!(!
__builtin_expe...Popup), false)Description
TRUEnever evaluated
FALSEnever evaluated
d->calendarPopup)), false)
__builtin_expe...Popup), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
320 QMessageLogger(__FILE__, 769778, __PRETTY_FUNCTION__).warning("QDateTimeEdit::setCalendarWidget: calendarPopup is set to false");-
321 return;
never executed: return;
0
322 }-
323-
324 if (!((__builtin_expect(!!(!(
__builtin_expe...Mask)), false)Description
TRUEnever evaluated
FALSEnever evaluated
d->display & QDateTimeParser::DateSectionMask)), false)
__builtin_expe...Mask)), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
325 QMessageLogger(__FILE__, 774783, __PRETTY_FUNCTION__).warning("QDateTimeEdit::setCalendarWidget: no date sections specified");-
326 return;
never executed: return;
0
327 }-
328 d->initCalendarPopup(calendarWidget);-
329}
never executed: end of block
0
330void QDateTimeEdit::setSelectedSection(Section section)-
331{-
332 QDateTimeEditPrivate * const d = d_func();-
333 if (section == NoSection) {-
334 d->edit->setSelection(d->edit->cursorPosition(), 0);-
335 } else if (section & d->sections) {-
336 if (currentSection() != section)-
337 setCurrentSection(section);-
338 d->setSelected(d->currentSectionIndex);-
339 }-
340}-
341QString QDateTimeEdit::sectionText(Section section) const-
342{-
343 const QDateTimeEditPrivate * const d = d_func();-
344 if (section == QDateTimeEdit::NoSection || !(section & d->sections)) {-
345 return QString();-
346 }-
347-
348 d->updateCache(d->value, d->displayText());-
349 const int sectionIndex = d->absoluteIndex(section, 0);-
350 return d->sectionText(sectionIndex);-
351}-
352QString QDateTimeEdit::displayFormat() const-
353{-
354 const QDateTimeEditPrivate * const d = d_func();-
355 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;
356}-
357-
358void QDateTimeEdit::setDisplayFormat(const QString &format)-
359{-
360 QDateTimeEditPrivate * const d = d_func();-
361 if (d->parseFormat(format)
d->parseFormat(format)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
362 d->unreversedFormat.clear();-
363 if (isRightToLeft()
isRightToLeft()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
364 d->unreversedFormat = format;-
365 d->displayFormat.clear();-
366 for (int i=d->sectionNodes.size() - 1; i>=0
i>=0Description
TRUEnever evaluated
FALSEnever evaluated
; --i) {
0
367 d->displayFormat += d->separators.at(i + 1);-
368 d->displayFormat += d->sectionNode(i).format();-
369 }
never executed: end of block
0
370 d->displayFormat += d->separators.at(0);-
371 d->separators =std::reverse(d->separators);.begin(), d->sectionNodes =separators.end());-
372 std::reverse(d->sectionNodes);.begin(), d->sectionNodes.end());-
373 }
never executed: end of block
0
374-
375 d->formatExplicitlySet = true;-
376 d->sections = d->convertSections(d->display);-
377 d->clearCache();-
378-
379 d->currentSectionIndex = qMin(d->currentSectionIndex, d->sectionNodes.size() - 1);-
380 const bool timeShown = (d->sections & TimeSections_Mask);-
381 const bool dateShown = (d->sections & DateSections_Mask);-
382 ((!(dateShown || timeShown)) ? qt_assert("dateShown || timeShown",__FILE__,890891) : qt_noop());-
383 if (timeShown
timeShownDescription
TRUEnever evaluated
FALSEnever evaluated
&& !dateShown
!dateShownDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
384 QTime time = d->value.toTime();-
385 setDateRange(d->value.toDate(), d->value.toDate());-
386 if (d->minimum.toTime() >= d->maximum.toTime()
d->minimum.toT...ximum.toTime()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
387 setTimeRange(QTime(0, 0, 0, 0), QTime(23, 59, 59, 999));-
388-
389 setTime(time);-
390 }
never executed: end of block
0
391 }
never executed: end of block
else if (dateShown
dateShownDescription
TRUEnever evaluated
FALSEnever evaluated
&& !timeShown
!timeShownDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
392 setTimeRange(QTime(0, 0, 0, 0), QTime(23, 59, 59, 999));-
393 d->value = QDateTime(d->value.toDate(), QTime(), d->spec);-
394 }
never executed: end of block
0
395 d->updateEdit();-
396 d->_q_editorCursorPositionChanged(-1, 0);-
397 }
never executed: end of block
0
398}
never executed: end of block
0
399bool QDateTimeEdit::calendarPopup() const-
400{-
401 const QDateTimeEditPrivate * const d = d_func();-
402 return d->calendarPopup;-
403}-
404-
405void QDateTimeEdit::setCalendarPopup(bool enable)-
406{-
407 QDateTimeEditPrivate * const d = d_func();-
408 if (enable == d->calendarPopup)-
409 return;-
410 setAttribute(Qt::WA_MacShowFocusRect, !enable);-
411 d->calendarPopup = enable;-
412-
413-
414-
415-
416 d->updateEditFieldGeometry();-
417 update();-
418}-
419-
420-
421-
422-
423-
424-
425-
426Qt::TimeSpec QDateTimeEdit::timeSpec() const-
427{-
428 const QDateTimeEditPrivate * const d = d_func();-
429 return d->spec;-
430}-
431-
432void QDateTimeEdit::setTimeSpec(Qt::TimeSpec spec)-
433{-
434 QDateTimeEditPrivate * const d = d_func();-
435 if (spec != d->spec) {-
436 d->spec = spec;-
437 d->updateTimeSpec();-
438 }-
439}-
440-
441-
442-
443-
444-
445QSize QDateTimeEdit::sizeHint() const-
446{-
447 const QDateTimeEditPrivate * const d = d_func();-
448 if (d->cachedSizeHint.isEmpty()) {-
449 ensurePolished();-
450-
451 const QFontMetrics fm(fontMetrics());-
452 int h = d->edit->sizeHint().height();-
453 int w = 0;-
454 QString s;-
455 s = d->textFromValue(d->minimum) + QLatin1Char(' ');-
456 w = qMax<int>(w, fm.width(s));-
457 s = d->textFromValue(d->maximum) + QLatin1Char(' ');-
458 w = qMax<int>(w, fm.width(s));-
459 if (d->specialValueText.size()) {-
460 s = d->specialValueText;-
461 w = qMax<int>(w, fm.width(s));-
462 }-
463 w += 2;-
464-
465 QSize hint(w, h);-
466-
467-
468-
469-
470-
471-
472-
473 {-
474 QStyleOptionSpinBox opt;-
475 initStyleOption(&opt);-
476 d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this)-
477 .expandedTo(QApplication::globalStrut());-
478 }-
479-
480 d->cachedMinimumSizeHint = d->cachedSizeHint;-
481-
482 }-
483 return d->cachedSizeHint;-
484}-
485-
486-
487-
488-
489-
490-
491bool QDateTimeEdit::event(QEvent *event)-
492{-
493 QDateTimeEditPrivate * const d = d_func();-
494 switch (event->type()) {-
495 case QEvent::ApplicationLayoutDirectionChange: {-
496 const bool was = d->formatExplicitlySet;-
497 const QString oldFormat = d->displayFormat;-
498 d->displayFormat.clear();-
499 setDisplayFormat(oldFormat);-
500 d->formatExplicitlySet = was;-
501 break; }-
502 case QEvent::LocaleChange:-
503 d->updateEdit();-
504 break;-
505 case QEvent::StyleChange:-
506-
507-
508-
509 d->setLayoutItemMargins(QStyle::SE_DateTimeEditLayoutItem);-
510 break;-
511 default:-
512 break;-
513 }-
514 return QAbstractSpinBox::event(event);-
515}-
516-
517-
518-
519-
520-
521void QDateTimeEdit::clear()-
522{-
523 QDateTimeEditPrivate * const d = d_func();-
524 d->clearSection(d->currentSectionIndex);-
525}-
526-
527-
528-
529-
530void QDateTimeEdit::keyPressEvent(QKeyEvent *event)-
531{-
532 QDateTimeEditPrivate * const d = d_func();-
533 int oldCurrent = d->currentSectionIndex;-
534 bool select = true;-
535 bool inserted = false;-
536-
537 switch (event->key()) {-
538 case Qt::Key_Enter:-
539 case Qt::Key_Return:-
540 d->interpret(AlwaysEmit);-
541 d->setSelected(d->currentSectionIndex, true);-
542 event->ignore();-
543 editingFinished();-
544 return;-
545 default:-
546 if (!d->isSeparatorKey(event)) {-
547 inserted = select = !event->text().isEmpty() && event->text().at(0).isPrint()-
548 && !(event->modifiers() & ~(Qt::ShiftModifier|Qt::KeypadModifier));-
549 break;-
550 }-
551 case Qt::Key_Left:-
552 case Qt::Key_Right:-
553 if (event->key() == Qt::Key_Left || event->key() == Qt::Key_Right) {-
554 if (-
555-
556-
557-
558-
559 !(event->modifiers() & Qt::ControlModifier)) {-
560 select = false;-
561 break;-
562 }-
563 }-
564-
565 case Qt::Key_Backtab:-
566 case Qt::Key_Tab: {-
567 event->accept();-
568 if (d->specialValue()) {-
569 d->edit->setSelection(d->edit->cursorPosition(), 0);-
570 return;-
571 }-
572 const bool forward = event->key() != Qt::Key_Left && event->key() != Qt::Key_Backtab-
573 && (event->key() != Qt::Key_Tab || !(event->modifiers() & Qt::ShiftModifier));-
574 if (event->key() != Qt::Key_Backtab && event->key() != Qt::Key_Tab)-
575 focusNextPrevChild(forward);-
576-
577 return; }-
578 }-
579 QAbstractSpinBox::keyPressEvent(event);-
580 if (select && !d->edit->hasSelectedText()) {-
581 if (inserted && d->sectionAt(d->edit->cursorPosition()) == QDateTimeParser::NoSectionIndex) {-
582 QString str = d->displayText();-
583 int pos = d->edit->cursorPosition();-
584 if (validate(str, pos) == QValidator::Acceptable-
585 && (d->sectionNodes.at(oldCurrent).count != 1-
586 || d->sectionMaxSize(oldCurrent) == d->sectionSize(oldCurrent)-
587 || d->skipToNextSection(oldCurrent, d->value.toDateTime(), d->sectionText(oldCurrent)))) {-
588 if (false) QMessageLogger(__FILE__, 11811182, __PRETTY_FUNCTION__).debug() << "Setting currentsection to"
dead code: QMessageLogger(__FILE__, 1182, __PRETTY_FUNCTION__).debug() << "Setting currentsection to" << d->closestSection(d->edit->cursorPosition(), true) << event->key() << oldCurrent << str;
-
589 << 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;
-
590 << oldCurrent << str;
dead code: QMessageLogger(__FILE__, 1182, __PRETTY_FUNCTION__).debug() << "Setting currentsection to" << d->closestSection(d->edit->cursorPosition(), true) << event->key() << oldCurrent << str;
-
591 const int tmp = d->closestSection(d->edit->cursorPosition(), true);-
592 if (tmp >= 0)-
593 d->currentSectionIndex = tmp;-
594 }-
595 }-
596 if (d->currentSectionIndex != oldCurrent) {-
597 d->setSelected(d->currentSectionIndex);-
598 }-
599 }-
600 if (d->specialValue()) {-
601 d->edit->setSelection(d->edit->cursorPosition(), 0);-
602 }-
603}-
604-
605-
606-
607-
608-
609-
610void QDateTimeEdit::wheelEvent(QWheelEvent *event)-
611{-
612 QAbstractSpinBox::wheelEvent(event);-
613}-
614-
615-
616-
617-
618-
619-
620void QDateTimeEdit::focusInEvent(QFocusEvent *event)-
621{-
622 QDateTimeEditPrivate * const d = d_func();-
623 QAbstractSpinBox::focusInEvent(event);-
624 QString *frm = 0;-
625 const int oldPos = d->edit->cursorPosition();-
626 if (!d->formatExplicitlySet) {-
627 if (d->displayFormat == d->defaultTimeFormat) {-
628 frm = &d->defaultTimeFormat;-
629 } else if (d->displayFormat == d->defaultDateFormat) {-
630 frm = &d->defaultDateFormat;-
631 } else if (d->displayFormat == d->defaultDateTimeFormat) {-
632 frm = &d->defaultDateTimeFormat;-
633 }-
634-
635 if (frm) {-
636 d->readLocaleSettings();-
637 if (d->displayFormat != *frm) {-
638 setDisplayFormat(*frm);-
639 d->formatExplicitlySet = false;-
640 d->edit->setCursorPosition(oldPos);-
641 }-
642 }-
643 }-
644 const bool oldHasHadFocus = d->hasHadFocus;-
645 d->hasHadFocus = true;-
646 bool first = true;-
647 switch (event->reason()) {-
648 case Qt::BacktabFocusReason:-
649 first = false;-
650 break;-
651 case Qt::MouseFocusReason:-
652 case Qt::PopupFocusReason:-
653 return;-
654 case Qt::ActiveWindowFocusReason:-
655 if (oldHasHadFocus)-
656 return;-
657 case Qt::ShortcutFocusReason:-
658 case Qt::TabFocusReason:-
659 default:-
660 break;-
661 }-
662 if (isRightToLeft())-
663 first = !first;-
664 d->updateEdit();-
665-
666 d->setSelected(first ? 0 : d->sectionNodes.size() - 1);-
667}-
668-
669-
670-
671-
672-
673bool QDateTimeEdit::focusNextPrevChild(bool next)-
674{-
675 QDateTimeEditPrivate * const d = d_func();-
676 const int newSection = d->nextPrevSection(d->currentSectionIndex, next);-
677 switch (d->sectionType(newSection)) {-
678 case QDateTimeParser::NoSection:-
679 case QDateTimeParser::FirstSection:-
680 case QDateTimeParser::LastSection:-
681 return QAbstractSpinBox::focusNextPrevChild(next);-
682 default:-
683 d->edit->deselect();-
684 d->edit->setCursorPosition(d->sectionPos(newSection));-
685 if (false) QMessageLogger(__FILE__, 12781279, __PRETTY_FUNCTION__).debug() << d->sectionPos(newSection);
dead code: QMessageLogger(__FILE__, 1279, __PRETTY_FUNCTION__).debug() << d->sectionPos(newSection);
-
686 d->setSelected(newSection, true);-
687 return false;-
688 }-
689}-
690-
691-
692-
693-
694-
695void QDateTimeEdit::stepBy(int steps)-
696{-
697 QDateTimeEditPrivate * const d = d_func();-
698 if (d->specialValue() && displayedSections() != AmPmSection) {-
699 for (int i=0; i<d->sectionNodes.size(); ++i) {-
700 if (d->sectionType(i) != QDateTimeParser::AmPmSection) {-
701 d->currentSectionIndex = i;-
702 break;-
703 }-
704 }-
705 }-
706 d->setValue(d->stepBy(d->currentSectionIndex, steps, false), EmitIfChanged);-
707 d->updateCache(d->value, d->displayText());-
708-
709 d->setSelected(d->currentSectionIndex);-
710 d->updateTimeSpec();-
711}-
712QString QDateTimeEdit::textFromDateTime(const QDateTime &dateTime) const-
713{-
714 const QDateTimeEditPrivate * const d = d_func();-
715 return locale().toString(dateTime, d->displayFormat);-
716}-
717QDateTime QDateTimeEdit::dateTimeFromText(const QString &text) const-
718{-
719 const QDateTimeEditPrivate * const d = d_func();-
720 QString copy = text;-
721 int pos = d->edit->cursorPosition();-
722 QValidator::State state = QValidator::Acceptable;-
723 return d->validateAndInterpret(copy, pos, state);-
724}-
725-
726-
727-
728-
729-
730QValidator::State QDateTimeEdit::validate(QString &text, int &pos) const-
731{-
732 const QDateTimeEditPrivate * const d = d_func();-
733 QValidator::State state;-
734 d->validateAndInterpret(text, pos, state);-
735 return state;-
736}-
737-
738-
739-
740-
741-
742-
743void QDateTimeEdit::fixup(QString &input) const-
744{-
745 const QDateTimeEditPrivate * const d = d_func();-
746 QValidator::State state;-
747 int copy = d->edit->cursorPosition();-
748-
749 d->validateAndInterpret(input, copy, state, true);-
750}-
751-
752-
753-
754-
755-
756-
757QDateTimeEdit::StepEnabled QDateTimeEdit::stepEnabled() const-
758{-
759 const QDateTimeEditPrivate * const d = d_func();-
760 if (d->readOnly)-
761 return StepEnabled(0);-
762 if (d->specialValue()) {-
763 return (d->minimum == d->maximum ? StepEnabled(0) : StepEnabled(StepUpEnabled));-
764 }-
765-
766 QAbstractSpinBox::StepEnabled ret = 0;-
767 switch (d->sectionType(d->currentSectionIndex)) {-
768 case QDateTimeParser::NoSection:-
769 case QDateTimeParser::FirstSection:-
770 case QDateTimeParser::LastSection: return 0;-
771 default: break;-
772 }-
773 if (d->wrapping)-
774 return StepEnabled(StepDownEnabled|StepUpEnabled);-
775-
776 QVariant v = d->stepBy(d->currentSectionIndex, 1, true);-
777 if (v != d->value) {-
778 ret |= QAbstractSpinBox::StepUpEnabled;-
779 }-
780 v = d->stepBy(d->currentSectionIndex, -1, true);-
781 if (v != d->value) {-
782 ret |= QAbstractSpinBox::StepDownEnabled;-
783 }-
784-
785 return ret;-
786}-
787-
788-
789-
790-
791-
792-
793void QDateTimeEdit::mousePressEvent(QMouseEvent *event)-
794{-
795 QDateTimeEditPrivate * const d = d_func();-
796 if (!d->calendarPopupEnabled()) {-
797 QAbstractSpinBox::mousePressEvent(event);-
798 return;-
799 }-
800 d->updateHoverControl(event->pos());-
801 if (d->hoverControl == QStyle::SC_ComboBoxArrow) {-
802 event->accept();-
803 if (d->readOnly) {-
804 return;-
805 }-
806 d->updateArrow(QStyle::State_Sunken);-
807 d->initCalendarPopup();-
808 d->positionCalendarPopup();-
809-
810 d->monthCalendar->show();-
811 } else {-
812 QAbstractSpinBox::mousePressEvent(event);-
813 }-
814}-
815QTimeEdit::QTimeEdit(QWidget *parent)-
816 : QDateTimeEdit(QTime(0, 0, 0, 0), QVariant::Time, parent)-
817{-
818 connect(this, qFlagLocation("2""timeChanged(QTime)" "\0" __FILE__ ":" "1539""1540"), qFlagLocation("2""userTimeChanged(QTime)" "\0" __FILE__ ":" "1539""1540"));-
819}-
820-
821-
822-
823-
824-
825-
826QTimeEdit::QTimeEdit(const QTime &time, QWidget *parent)-
827 : QDateTimeEdit(time, QVariant::Time, parent)-
828{-
829}-
830-
831-
832-
833-
834QTimeEdit::~QTimeEdit()-
835{-
836}-
837QDateEdit::QDateEdit(QWidget *parent)-
838 : QDateTimeEdit(QDate(2000, 1, 1), QVariant::Date, parent)-
839{-
840 connect(this, qFlagLocation("2""dateChanged(QDate)" "\0" __FILE__ ":" "1615""1616"), qFlagLocation("2""userDateChanged(QDate)" "\0" __FILE__ ":" "1615""1616"));-
841}-
842-
843-
844-
845-
846-
847-
848QDateEdit::QDateEdit(const QDate &date, QWidget *parent)-
849 : QDateTimeEdit(date, QVariant::Date, parent)-
850{-
851}-
852-
853-
854-
855-
856QDateEdit::~QDateEdit()-
857{-
858}-
859QDateTimeEditPrivate::QDateTimeEditPrivate()-
860 : QDateTimeParser(QVariant::DateTime, QDateTimeParser::DateTimeEdit)-
861{-
862 hasHadFocus = false;-
863 formatExplicitlySet = false;-
864 cacheGuard = false;-
865 fixday = true;-
866 type = QVariant::DateTime;-
867 sections = 0;-
868 cachedDay = -1;-
869 currentSectionIndex = FirstSectionIndex;-
870-
871 first.pos = 0;-
872 sections = 0;-
873 calendarPopup = false;-
874 minimum = QDateTime(QDate(1752, 9, 14), QTime(0, 0, 0, 0));-
875 maximum = QDateTime(QDate(7999, 12, 31), QTime(23, 59, 59, 999));-
876 arrowState = QStyle::State_None;-
877 monthCalendar = 0;-
878 readLocaleSettings();-
879-
880-
881-
882-
883}-
884-
885QDateTimeEditPrivate::~QDateTimeEditPrivate()-
886{-
887}-
888-
889void QDateTimeEditPrivate::updateTimeSpec()-
890{-
891 minimum = minimum.toDateTime().toTimeSpec(spec);-
892 maximum = maximum.toDateTime().toTimeSpec(spec);-
893 value = value.toDateTime().toTimeSpec(spec);-
894-
895-
896 const bool dateShown = (sections & QDateTimeEdit::DateSections_Mask);-
897 if (!dateShown) {-
898 if (minimum.toTime() >= maximum.toTime()){-
899 minimum = QDateTime(value.toDate(), QTime(0, 0, 0, 0), spec);-
900 maximum = QDateTime(value.toDate(), QTime(23, 59, 59, 999), spec);-
901 }-
902 }-
903}-
904-
905void QDateTimeEditPrivate::updateEdit()-
906{-
907 const QString newText = (specialValue() ? specialValueText : textFromValue(value));-
908 if (newText == displayText())-
909 return;-
910 int selsize = edit->selectedText().size();-
911 const QSignalBlocker blocker(edit);-
912-
913 edit->setText(newText);-
914-
915 if (!specialValue()-
916-
917-
918-
919 ) {-
920 int cursor = sectionPos(currentSectionIndex);-
921 if (false) QMessageLogger(__FILE__, 17211722, __PRETTY_FUNCTION__).debug() << "cursor is " << cursor << currentSectionIndex;
dead code: QMessageLogger(__FILE__, 1722, __PRETTY_FUNCTION__).debug() << "cursor is " << cursor << currentSectionIndex;
-
922 cursor = qBound(0, cursor, displayText().size());-
923 if (false) QMessageLogger(__FILE__, 17231724, __PRETTY_FUNCTION__).debug() << cursor;
dead code: QMessageLogger(__FILE__, 1724, __PRETTY_FUNCTION__).debug() << cursor;
-
924 if (selsize > 0) {-
925 edit->setSelection(cursor, selsize);-
926 if (false) QMessageLogger(__FILE__, 17261727, __PRETTY_FUNCTION__).debug() << cursor << selsize;
dead code: QMessageLogger(__FILE__, 1727, __PRETTY_FUNCTION__).debug() << cursor << selsize;
-
927 } else {-
928 edit->setCursorPosition(cursor);-
929 if (false) QMessageLogger(__FILE__, 17291730, __PRETTY_FUNCTION__).debug() << cursor;
dead code: QMessageLogger(__FILE__, 1730, __PRETTY_FUNCTION__).debug() << cursor;
-
930-
931 }-
932 }-
933}-
934void QDateTimeEditPrivate::setSelected(int sectionIndex, bool forward)-
935{-
936 if (specialValue()-
937-
938-
939-
940 ) {-
941 edit->selectAll();-
942 } else {-
943 const SectionNode &node = sectionNode(sectionIndex);-
944 if (node.type == NoSection || node.type == LastSection || node.type == FirstSection)-
945 return;-
946-
947 updateCache(value, displayText());-
948 const int size = sectionSize(sectionIndex);-
949 if (forward) {-
950 edit->setSelection(sectionPos(node), size);-
951 } else {-
952 edit->setSelection(sectionPos(node) + size, -size);-
953 }-
954 }-
955}-
956-
957-
958-
959-
960-
961-
962-
963int QDateTimeEditPrivate::sectionAt(int pos) const-
964{-
965 if (pos < separators.first().size()
pos < separato...first().size()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
966 {return
never executed: return (pos == 0 ? FirstSectionIndex : NoSectionIndex);
(pos == 0 ? FirstSectionIndex : NoSectionIndex);
never executed: return (pos == 0 ? FirstSectionIndex : NoSectionIndex);
0
967-
968 } else if (const QString text = displayText().();-
969 const int textSize = text.size()();-
970 if (textSize
textSize - pos...t().size() + 1Description
TRUEnever evaluated
FALSEnever evaluated
textSize - pos...t().size() + 1Description
TRUEnever evaluated
FALSEnever evaluated
- pos < separators.last().size() + 1
textSize - pos...t().size() + 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
971 if (separators.last().size() == 0
separators.last().size() == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
972 return
never executed: return sectionNodes.count() - 1;
sectionNodes.count() - 1;
never executed: return sectionNodes.count() - 1;
0
973 }-
974 return
never executed: return (pos == textSize ? LastSectionIndex : NoSectionIndex);
(pos == displayText().size()textSize ? LastSectionIndex : NoSectionIndex);
never executed: return (pos == textSize ? LastSectionIndex : NoSectionIndex);
0
975 }-
976 updateCache(value, displayText());text);-
977-
978 for (int i=0; i<sectionNodes.size()
i<sectionNodes.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
979 const int tmp = sectionPos(i);-
980 if (pos < tmp + sectionSize(i)
pos < tmp + sectionSize(i)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
981 return
never executed: return (pos < tmp ? -1 : i);
(pos < tmp ? -1 : i);
never executed: return (pos < tmp ? -1 : i);
0
982 }-
983 }
never executed: end of block
0
984 return
never executed: return -1;
-1;
never executed: return -1;
0
985}-
986int QDateTimeEditPrivate::closestSection(int pos, bool forward) const-
987{-
988 ((!(pos >= 0)) ? qt_assert("pos >= 0",__FILE__,18011805) : qt_noop());-
989 if (pos < separators.first().size()
pos < separato...first().size()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
990 {return
never executed: return forward ? 0 : FirstSectionIndex;
forward ? 0 : FirstSectionIndex;
never executed: return forward ? 0 : FirstSectionIndex;
0
991-
992 } elseconst QString text = displayText();-
993 if (displayText().text.
text.size() - ...t().size() + 1Description
TRUEnever evaluated
FALSEnever evaluated
size() - pos < separators.last().size() + 1
text.size() - ...t().size() + 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
994 {return
never executed: return forward ? LastSectionIndex : sectionNodes.size() - 1;
forward ? LastSectionIndex : sectionNodes.size() - 1;
never executed: return forward ? LastSectionIndex : sectionNodes.size() - 1;
0
995-
996 }updateCache(value, displayText());text);-
997 for (int i=0; i<sectionNodes.size()
i<sectionNodes.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
998 const int tmp = sectionPos(sectionNodes.at(i));-
999 if (pos < tmp + sectionSize(i)
pos < tmp + sectionSize(i)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1000 if (pos < tmp
pos < tmpDescription
TRUEnever evaluated
FALSEnever evaluated
&& !forward
!forwardDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1001 return
never executed: return i-1;
i-1;
never executed: return i-1;
0
1002 }-
1003 return
never executed: return i;
i;
never executed: return i;
0
1004 } else if (i == sectionNodes.size() - 1
i == sectionNodes.size() - 1Description
TRUEnever evaluated
FALSEnever evaluated
&& pos > tmp
pos > tmpDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1005 return
never executed: return i;
i;
never executed: return i;
0
1006 }-
1007 }
never executed: end of block
0
1008 QMessageLogger(__FILE__, 18191825, __PRETTY_FUNCTION__).warning("QDateTimeEdit: Internal Error: closestSection returned NoSection");-
1009 return
never executed: return NoSectionIndex;
NoSectionIndex;
never executed: return NoSectionIndex;
0
1010}-
1011-
1012-
1013-
1014-
1015-
1016-
1017-
1018int QDateTimeEditPrivate::nextPrevSection(int current, bool forward) const-
1019{-
1020 const QDateTimeEdit * const q = q_func();-
1021 if (q->isRightToLeft())-
1022 forward = !forward;-
1023-
1024 switch (current) {-
1025 case FirstSectionIndex: return forward ? 0 : FirstSectionIndex;-
1026 case LastSectionIndex: return (forward ? LastSectionIndex : sectionNodes.size() - 1);-
1027 case NoSectionIndex: return FirstSectionIndex;-
1028 default: break;-
1029 }-
1030 ((!(current >= 0 && current < sectionNodes.size())) ? qt_assert("current >= 0 && current < sectionNodes.size()",__FILE__,18411847) : qt_noop());-
1031-
1032 current += (forward ? 1 : -1);-
1033 if (current >= sectionNodes.size()) {-
1034 return LastSectionIndex;-
1035 } else if (current < 0) {-
1036 return FirstSectionIndex;-
1037 }-
1038-
1039 return current;-
1040}-
1041-
1042-
1043-
1044-
1045-
1046-
1047-
1048void QDateTimeEditPrivate::clearSection(int index)-
1049{-
1050 const QLatin1Char space(' ');-
1051 int cursorPos = edit->cursorPosition();-
1052 const QSignalBlocker blocker(edit);-
1053 QString t = edit->text();-
1054 const int pos = sectionPos(index);-
1055 if (__builtin_expect(!!(
__builtin_expe...== -1), false)Description
TRUEnever evaluated
FALSEnever evaluated
pos == -1)), false)
__builtin_expe...== -1), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1056 QMessageLogger(__FILE__, 18671873, __PRETTY_FUNCTION__).warning("QDateTimeEdit: Internal error (%s:%d)", __FILE__, 18671873);-
1057 return;
never executed: return;
0
1058 }-
1059 const int size = sectionSize(index);-
1060 t.replace(pos, size, QString().fill(space, size));-
1061 edit->setText(t);-
1062 edit->setCursorPosition(cursorPos);-
1063 if (false) QMessageLogger(__FILE__, 18741880, __PRETTY_FUNCTION__).debug() << cursorPos;
dead code: QMessageLogger(__FILE__, 1880, __PRETTY_FUNCTION__).debug() << cursorPos;
-
1064}
never executed: end of block
0
1065void QDateTimeEditPrivate::updateCache(const QVariant &val, const QString &str) const-
1066{-
1067 if (val != cachedValue || str != cachedText || cacheGuard) {-
1068 cacheGuard = true;-
1069 QString copy = str;-
1070 int unused = edit->cursorPosition();-
1071 QValidator::State unusedState;-
1072 validateAndInterpret(copy, unused, unusedState);-
1073 cacheGuard = false;-
1074 }-
1075}-
1076-
1077-
1078-
1079-
1080-
1081-
1082-
1083QDateTime QDateTimeEditPrivate::validateAndInterpret(QString &input, int &position,-
1084 QValidator::State &state, bool fixup) const-
1085{-
1086 if (input.isEmpty()) {-
1087 if (sectionNodes.size() == 1 || !specialValueText.isEmpty()) {-
1088 state = QValidator::Intermediate;-
1089 } else {-
1090 state = QValidator::Invalid;-
1091 }-
1092 return getZeroVariant().toDateTime();-
1093 } else if (cachedText == input && !fixup) {-
1094 state = cachedState;-
1095 return cachedValue.toDateTime();-
1096 } else if (!specialValueText.isEmpty()) {-
1097 bool changeCase = false;-
1098 const int max = qMin(specialValueText.size(), input.size());-
1099 int i;-
1100 for (i=0; i<max; ++i) {-
1101 const QChar ic = input.at(i);-
1102 const QChar sc = specialValueText.at(i);-
1103 if (ic != sc) {-
1104 if (sc.toLower() == ic.toLower()) {-
1105 changeCase = true;-
1106 } else {-
1107 break;-
1108 }-
1109 }-
1110 }-
1111 if (i == max) {-
1112 state = specialValueText.size() == input.size() ? QValidator::Acceptable : QValidator::Intermediate;-
1113 if (changeCase) {-
1114 input = specialValueText.left(max);-
1115 }-
1116 return minimum.toDateTime();-
1117 }-
1118 }-
1119 StateNode tmp = parse(input, position, value.toDateTime(), fixup);-
1120 input = tmp.input;-
1121 state = QValidator::State(int(tmp.state));-
1122 if (state == QValidator::Acceptable) {-
1123 if (tmp.conflicts && conflictGuard != tmp.value) {-
1124 conflictGuard = tmp.value;-
1125 clearCache();-
1126 input = textFromValue(tmp.value);-
1127 updateCache(tmp.value, input);-
1128 conflictGuard.clear();-
1129 } else {-
1130 cachedText = input;-
1131 cachedState = state;-
1132 cachedValue = tmp.value;-
1133 }-
1134 } else {-
1135 clearCache();-
1136 }-
1137 return (tmp.value.isNull() ? getZeroVariant().toDateTime() : tmp.value);-
1138}-
1139-
1140-
1141-
1142-
1143-
1144-
1145QString QDateTimeEditPrivate::textFromValue(const QVariant &f) const-
1146{-
1147 const QDateTimeEdit * const q = q_func();-
1148 return q->textFromDateTime(f.toDateTime());-
1149}-
1150QVariant QDateTimeEditPrivate::valueFromText(const QString &f) const-
1151{-
1152 const QDateTimeEdit * const q = q_func();-
1153 return q->dateTimeFromText(f).toTimeSpec(spec);-
1154}-
1155QDateTime QDateTimeEditPrivate::stepBy(int sectionIndex, int steps, bool test) const-
1156{-
1157 const QDateTimeEdit * const q = q_func();-
1158 QDateTime v = value.toDateTime();-
1159 QString str = displayText();-
1160 int pos = edit->cursorPosition();-
1161 const SectionNode sn = sectionNode(sectionIndex);-
1162-
1163 int val;-
1164-
1165 if (!test && pendingEmit) {-
1166 if (q->validate(str, pos) != QValidator::Acceptable) {-
1167 v = value.toDateTime();-
1168 } else {-
1169 v = q->dateTimeFromText(str);-
1170 }-
1171 val = getDigit(v, sectionIndex);-
1172 } else {-
1173 val = getDigit(v, sectionIndex);-
1174 }-
1175-
1176 val += steps;-
1177-
1178 const int min = absoluteMin(sectionIndex);-
1179 const int max = absoluteMax(sectionIndex, value.toDateTime());-
1180-
1181 if (val < min) {-
1182 val = (wrapping ? max - (min - val) + 1 : min);-
1183 } else if (val > max) {-
1184 val = (wrapping ? min + val - max - 1 : max);-
1185 }-
1186-
1187-
1188 const int oldDay = v.date().day();-
1189-
1190 setDigit(v, sectionIndex, val);-
1191-
1192-
1193-
1194 const QDateTime minimumDateTime = minimum.toDateTime();-
1195 const QDateTime maximumDateTime = maximum.toDateTime();-
1196-
1197 if (sn.type != AmPmSection && (v < minimumDateTime || v > maximumDateTime)) {-
1198 const int localmin = getDigit(minimumDateTime, sectionIndex);-
1199 const int localmax = getDigit(maximumDateTime, sectionIndex);-
1200-
1201 if (wrapping) {-
1202-
1203-
1204 if (steps > 0) {-
1205 setDigit(v, sectionIndex, min);-
1206 if (!(sn.type & DaySectionMask) && sections & DateSectionMask) {-
1207 const int daysInMonth = v.date().daysInMonth();-
1208 if (v.date().day() < oldDay && v.date().day() < daysInMonth) {-
1209 const int adds = qMin(oldDay, daysInMonth);-
1210 v = v.addDays(adds - v.date().day());-
1211 }-
1212 }-
1213-
1214 if (v < minimumDateTime) {-
1215 setDigit(v, sectionIndex, localmin);-
1216 if (v < minimumDateTime)-
1217 setDigit(v, sectionIndex, localmin + 1);-
1218 }-
1219 } else {-
1220 setDigit(v, sectionIndex, max);-
1221 if (!(sn.type & DaySectionMask) && sections & DateSectionMask) {-
1222 const int daysInMonth = v.date().daysInMonth();-
1223 if (v.date().day() < oldDay && v.date().day() < daysInMonth) {-
1224 const int adds = qMin(oldDay, daysInMonth);-
1225 v = v.addDays(adds - v.date().day());-
1226 }-
1227 }-
1228-
1229 if (v > maximumDateTime) {-
1230 setDigit(v, sectionIndex, localmax);-
1231 if (v > maximumDateTime)-
1232 setDigit(v, sectionIndex, localmax - 1);-
1233 }-
1234 }-
1235 } else {-
1236 setDigit(v, sectionIndex, (steps > 0 ? localmax : localmin));-
1237 }-
1238 }-
1239 if (!test && oldDay != v.date().day() && !(sn.type & DaySectionMask)) {-
1240-
1241 cachedDay = qMax<int>(oldDay, cachedDay);-
1242 }-
1243-
1244 if (v < minimumDateTime) {-
1245 if (wrapping) {-
1246 QDateTime t = v;-
1247 setDigit(t, sectionIndex, steps < 0 ? max : min);-
1248 bool mincmp = (t >= minimumDateTime);-
1249 bool maxcmp = (t <= maximumDateTime);-
1250 if (!mincmp || !maxcmp) {-
1251 setDigit(t, sectionIndex, getDigit(steps < 0-
1252 ? maximumDateTime-
1253 : minimumDateTime, sectionIndex));-
1254 mincmp = (t >= minimumDateTime);-
1255 maxcmp = (t <= maximumDateTime);-
1256 }-
1257 if (mincmp && maxcmp) {-
1258 v = t;-
1259 }-
1260 } else {-
1261 v = value.toDateTime();-
1262 }-
1263 } else if (v > maximumDateTime) {-
1264 if (wrapping) {-
1265 QDateTime t = v;-
1266 setDigit(t, sectionIndex, steps > 0 ? min : max);-
1267 bool mincmp = (t >= minimumDateTime);-
1268 bool maxcmp = (t <= maximumDateTime);-
1269 if (!mincmp || !maxcmp) {-
1270 setDigit(t, sectionIndex, getDigit(steps > 0 ?-
1271 minimumDateTime :-
1272 maximumDateTime, sectionIndex));-
1273 mincmp = (t >= minimumDateTime);-
1274 maxcmp = (t <= maximumDateTime);-
1275 }-
1276 if (mincmp && maxcmp) {-
1277 v = t;-
1278 }-
1279 } else {-
1280 v = value.toDateTime();-
1281 }-
1282 }-
1283-
1284 const QDateTime ret = bound(v, value, steps).toDateTime().toTimeSpec(spec);-
1285 return ret;-
1286}-
1287-
1288-
1289-
1290-
1291-
1292void QDateTimeEditPrivate::emitSignals(EmitPolicy ep, const QVariant &old)-
1293{-
1294 QDateTimeEdit * const q = q_func();-
1295 if (ep == NeverEmit) {-
1296 return;-
1297 }-
1298 pendingEmit = false;-
1299-
1300 const bool dodate = value.toDate().isValid() && (sections & DateSectionMask);-
1301 const bool datechanged = (ep == AlwaysEmit || old.toDate() != value.toDate());-
1302 const bool dotime = value.toTime().isValid() && (sections & TimeSectionMask);-
1303 const bool timechanged = (ep == AlwaysEmit || old.toTime() != value.toTime());-
1304-
1305 updateCache(value, displayText());-
1306-
1307 syncCalendarWidget();-
1308 if (datechanged || timechanged)-
1309 q->dateTimeChanged(value.toDateTime());-
1310 if (dodate && datechanged)-
1311 q->dateChanged(value.toDate());-
1312 if (dotime && timechanged)-
1313 q->timeChanged(value.toTime());-
1314-
1315}-
1316-
1317-
1318-
1319-
1320-
1321void QDateTimeEditPrivate::_q_editorCursorPositionChanged(int oldpos, int newpos)-
1322{-
1323 if (ignoreCursorPositionChanged || specialValue())-
1324 return;-
1325 const QString oldText = displayText();-
1326 updateCache(value, oldText);-
1327-
1328 const bool allowChange = !edit->hasSelectedText();-
1329 const bool forward = oldpos <= newpos;-
1330 ignoreCursorPositionChanged = true;-
1331 int s = sectionAt(newpos);-
1332 if (s == NoSectionIndex && forward && newpos > 0) {-
1333 s = sectionAt(newpos - 1);-
1334 }-
1335-
1336 int c = newpos;-
1337-
1338 const int selstart = edit->selectionStart();-
1339 const int selSection = sectionAt(selstart);-
1340 const int l = selSection != -1 ? sectionSize(selSection) : 0;-
1341-
1342 if (s == NoSectionIndex) {-
1343 if (l > 0 && selstart == sectionPos(selSection) && edit->selectedText().size() == l) {-
1344 s = selSection;-
1345 if (allowChange)-
1346 setSelected(selSection, true);-
1347 c = -1;-
1348 } else {-
1349 int closest = closestSection(newpos, forward);-
1350 c = sectionPos(closest) + (forward ? 0 : qMax<int>(0, sectionSize(closest)));-
1351-
1352 if (allowChange) {-
1353 edit->setCursorPosition(c);-
1354 if (false) QMessageLogger(__FILE__, 21932199, __PRETTY_FUNCTION__).debug() << c;
dead code: QMessageLogger(__FILE__, 2199, __PRETTY_FUNCTION__).debug() << c;
-
1355 }-
1356 s = closest;-
1357 }-
1358 }-
1359-
1360 if (allowChange && currentSectionIndex != s) {-
1361 interpret(EmitIfChanged);-
1362 }-
1363 if (c == -1) {-
1364 setSelected(s, true);-
1365 } else if (!edit->hasSelectedText()) {-
1366 if (oldpos < newpos) {-
1367 edit->setCursorPosition(displayText().size() - (oldText.size() - c));-
1368 } else {-
1369 edit->setCursorPosition(c);-
1370 }-
1371 }-
1372-
1373 if (false) QMessageLogger(__FILE__, 22122218, __PRETTY_FUNCTION__).debug() << "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();
-
1374 << oldpos << newpos
dead code: QMessageLogger(__FILE__, 2218, __PRETTY_FUNCTION__).debug() << "currentSectionIndex is set to" << sectionNode(s).name() << oldpos << newpos << "was" << sectionNode(currentSectionIndex).name();
-
1375 << "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();
-
1376-
1377 currentSectionIndex = s;-
1378 ((!(currentSectionIndex < sectionNodes.size())) ? qt_assert_x("QDateTimeEditPrivate::_q_editorCursorPositionChanged()", QString(QString::fromLatin1("Internal error (%1 %2)"). arg(currentSectionIndex). arg(sectionNodes.size())).toLocal8Bit().constData(),-
1379-
1380-
1381-
1382 __FILE__-
1383 ,-
1384-
1385-
1386-
1387 22212227-
1388 ) : qt_noop())-
1389-
1390-
1391-
1392 ;-
1393-
1394 ignoreCursorPositionChanged = false;-
1395}-
1396-
1397-
1398-
1399-
1400-
1401-
1402void QDateTimeEditPrivate::readLocaleSettings()-
1403{-
1404 const QLocale loc;-
1405 defaultTimeFormat = loc.timeFormat(QLocale::ShortFormat);-
1406 defaultDateFormat = loc.dateFormat(QLocale::ShortFormat);-
1407 defaultDateTimeFormat = loc.dateTimeFormat(QLocale::ShortFormat);-
1408}-
1409-
1410QDateTimeEdit::Section QDateTimeEditPrivate::convertToPublic(QDateTimeParser::Section s)-
1411{-
1412 switch (s & ~Internal) {-
1413 case AmPmSection: return QDateTimeEdit::AmPmSection;-
1414 case MSecSection: return QDateTimeEdit::MSecSection;-
1415 case SecondSection: return QDateTimeEdit::SecondSection;-
1416 case MinuteSection: return QDateTimeEdit::MinuteSection;-
1417 case DayOfWeekSectionShort:-
1418 case DayOfWeekSectionLong:-
1419 case DaySection: return QDateTimeEdit::DaySection;-
1420 case MonthSection: return QDateTimeEdit::MonthSection;-
1421 case YearSection2Digits:-
1422 case YearSection: return QDateTimeEdit::YearSection;-
1423 case Hour12Section:-
1424 case Hour24Section: return QDateTimeEdit::HourSection;-
1425 case FirstSection:-
1426 case NoSection:-
1427 case LastSection: break;-
1428 }-
1429 return QDateTimeEdit::NoSection;-
1430}-
1431-
1432QDateTimeEdit::Sections QDateTimeEditPrivate::convertSections(QDateTimeParser::Sections s)-
1433{-
1434 QDateTimeEdit::Sections ret = 0;-
1435 if (s & QDateTimeParser::MSecSection)-
1436 ret |= QDateTimeEdit::MSecSection;-
1437 if (s & QDateTimeParser::SecondSection)-
1438 ret |= QDateTimeEdit::SecondSection;-
1439 if (s & QDateTimeParser::MinuteSection)-
1440 ret |= QDateTimeEdit::MinuteSection;-
1441 if (s & (QDateTimeParser::HourSectionMask))-
1442 ret |= QDateTimeEdit::HourSection;-
1443 if (s & QDateTimeParser::AmPmSection)-
1444 ret |= QDateTimeEdit::AmPmSection;-
1445 if (s & (QDateTimeParser::DaySectionMask))-
1446 ret |= QDateTimeEdit::DaySection;-
1447 if (s & QDateTimeParser::MonthSection)-
1448 ret |= QDateTimeEdit::MonthSection;-
1449 if (s & (QDateTimeParser::YearSectionMask))-
1450 ret |= QDateTimeEdit::YearSection;-
1451-
1452 return ret;-
1453}-
1454-
1455-
1456-
1457-
1458-
1459void QDateTimeEdit::paintEvent(QPaintEvent *event)-
1460{-
1461 QDateTimeEditPrivate * const d = d_func();-
1462 if (!d->calendarPopupEnabled()) {-
1463 QAbstractSpinBox::paintEvent(event);-
1464 return;-
1465 }-
1466-
1467 QStyleOptionSpinBox opt;-
1468 initStyleOption(&opt);-
1469-
1470 QStyleOptionComboBox optCombo;-
1471-
1472 optCombo.init(this);-
1473 optCombo.editable = true;-
1474 optCombo.frame = opt.frame;-
1475 optCombo.subControls = opt.subControls;-
1476 optCombo.activeSubControls = opt.activeSubControls;-
1477 optCombo.state = opt.state;-
1478 if (d->readOnly) {-
1479 optCombo.state &= ~QStyle::State_Enabled;-
1480 }-
1481-
1482 QPainter p(this);-
1483 style()->drawComplexControl(QStyle::CC_ComboBox, &optCombo, &p, this);-
1484}-
1485-
1486QString QDateTimeEditPrivate::getAmPmText(AmPm ap, Case cs) const-
1487{-
1488 if (ap == AmText) {-
1489 return (cs == UpperCase ? QDateTimeParser::tr("AM") : QDateTimeParser::tr("am"));-
1490 } else {-
1491 return (cs == UpperCase ? QDateTimeParser::tr("PM") : QDateTimeParser::tr("pm"));-
1492 }-
1493}-
1494-
1495int QDateTimeEditPrivate::absoluteIndex(QDateTimeEdit::Section s, int index) const-
1496{-
1497 for (int i=0; i<sectionNodes.size(); ++i) {-
1498 if (convertToPublic(sectionNodes.at(i).type) == s && index-- == 0) {-
1499 return i;-
1500 }-
1501 }-
1502 return NoSectionIndex;-
1503}-
1504-
1505int QDateTimeEditPrivate::absoluteIndex(const SectionNode &s) const-
1506{-
1507 return sectionNodes.indexOf(s);-
1508}-
1509-
1510void QDateTimeEditPrivate::interpret(EmitPolicy ep)-
1511{-
1512 QDateTimeEdit * const q = q_func();-
1513 QString tmp = displayText();-
1514 int pos = edit->cursorPosition();-
1515 const QValidator::State state = q->validate(tmp, pos);-
1516 if (state != QValidator::Acceptable-
1517 && correctionMode == QAbstractSpinBox::CorrectToPreviousValue-
1518 && (state == QValidator::Invalid-
1519 || currentSectionIndex < 0-
1520 || !(fieldInfo(currentSectionIndex) & AllowPartial))) {-
1521 setValue(value, ep);-
1522 updateTimeSpec();-
1523 } else {-
1524 QAbstractSpinBoxPrivate::interpret(ep);-
1525 }-
1526}-
1527-
1528void QDateTimeEditPrivate::clearCache() const-
1529{-
1530 QAbstractSpinBoxPrivate::clearCache();-
1531 cachedDay = -1;-
1532}-
1533void QDateTimeEdit::initStyleOption(QStyleOptionSpinBox *option) const-
1534{-
1535 if (!option)-
1536 return;-
1537-
1538 const QDateTimeEditPrivate * const d = d_func();-
1539 QAbstractSpinBox::initStyleOption(option);-
1540 if (d->calendarPopupEnabled()) {-
1541 option->subControls = QStyle::SC_ComboBoxFrame | QStyle::SC_ComboBoxEditField-
1542 | QStyle::SC_ComboBoxArrow;-
1543 if (d->arrowState == QStyle::State_Sunken)-
1544 option->state |= QStyle::State_Sunken;-
1545 else-
1546 option->state &= ~QStyle::State_Sunken;-
1547 }-
1548}-
1549-
1550void QDateTimeEditPrivate::init(const QVariant &var)-
1551{-
1552 QDateTimeEdit * const q = q_func();-
1553 switch (var.type()) {-
1554 case QVariant::Date:-
1555 value = QDateTime(var.toDate(), QTime(0, 0, 0, 0));-
1556 updateTimeSpec();-
1557 q->setDisplayFormat(defaultDateFormat);-
1558 if (sectionNodes.isEmpty())-
1559 q->setDisplayFormat(QLatin1String("dd/MM/yyyy"));-
1560 break;-
1561 case QVariant::DateTime:-
1562 value = var;-
1563 updateTimeSpec();-
1564 q->setDisplayFormat(defaultDateTimeFormat);-
1565 if (sectionNodes.isEmpty())-
1566 q->setDisplayFormat(QLatin1String("dd/MM/yyyy hh:mm:ss"));-
1567 break;-
1568 case QVariant::Time:-
1569 value = QDateTime(QDate(2000, 1, 1), var.toTime());-
1570 updateTimeSpec();-
1571 q->setDisplayFormat(defaultTimeFormat);-
1572 if (sectionNodes.isEmpty())-
1573 q->setDisplayFormat(QLatin1String("hh:mm:ss"));-
1574 break;-
1575 default:-
1576 ((!(0)) ? qt_assert_x("QDateTimeEditPrivate::init", "Internal error",__FILE__,24132419) : qt_noop());-
1577 break;-
1578 }-
1579-
1580-
1581-
1582-
1583 q->setInputMethodHints(Qt::ImhPreferNumbers);-
1584 setLayoutItemMargins(QStyle::SE_DateTimeEditLayoutItem);-
1585}-
1586-
1587void QDateTimeEditPrivate::_q_resetButton()-
1588{-
1589 updateArrow(QStyle::State_None);-
1590}-
1591-
1592void QDateTimeEditPrivate::updateArrow(QStyle::StateFlag state)-
1593{-
1594 QDateTimeEdit * const q = q_func();-
1595-
1596 if (arrowState == state)-
1597 return;-
1598 arrowState = state;-
1599 if (arrowState != QStyle::State_None)-
1600 buttonState |= Mouse;-
1601 else {-
1602 buttonState = 0;-
1603 hoverControl = QStyle::SC_ComboBoxFrame;-
1604 }-
1605 q->update();-
1606}-
1607-
1608-
1609-
1610-
1611-
1612-
1613QStyle::SubControl QDateTimeEditPrivate::newHoverControl(const QPoint &pos)-
1614{-
1615 if (!calendarPopupEnabled())-
1616 return QAbstractSpinBoxPrivate::newHoverControl(pos);-
1617-
1618 QDateTimeEdit * const q = q_func();-
1619-
1620 QStyleOptionComboBox optCombo;-
1621 optCombo.init(q);-
1622 optCombo.editable = true;-
1623 optCombo.subControls = QStyle::SC_All;-
1624 hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ComboBox, &optCombo, pos, q);-
1625 return hoverControl;-
1626}-
1627-
1628void QDateTimeEditPrivate::updateEditFieldGeometry()-
1629{-
1630 if (!calendarPopupEnabled()) {-
1631 QAbstractSpinBoxPrivate::updateEditFieldGeometry();-
1632 return;-
1633 }-
1634-
1635 QDateTimeEdit * const q = q_func();-
1636-
1637 QStyleOptionComboBox optCombo;-
1638 optCombo.init(q);-
1639 optCombo.editable = true;-
1640 optCombo.subControls = QStyle::SC_ComboBoxEditField;-
1641 edit->setGeometry(q->style()->subControlRect(QStyle::CC_ComboBox, &optCombo,-
1642 QStyle::SC_ComboBoxEditField, q));-
1643}-
1644-
1645QVariant QDateTimeEditPrivate::getZeroVariant() const-
1646{-
1647 ((!(type == QVariant::DateTime)) ? qt_assert("type == QVariant::DateTime",__FILE__,24842490) : qt_noop());-
1648 return QDateTime(QDate(2000, 1, 1), QTime(), spec);-
1649}-
1650-
1651void QDateTimeEditPrivate::setRange(const QVariant &min, const QVariant &max)-
1652{-
1653 QAbstractSpinBoxPrivate::setRange(min, max);-
1654 syncCalendarWidget();-
1655}-
1656-
1657-
1658bool QDateTimeEditPrivate::isSeparatorKey(const QKeyEvent *ke) const-
1659{-
1660 if (!ke->text().isEmpty() && currentSectionIndex + 1 < sectionNodes.size() && currentSectionIndex >= 0) {-
1661 if (fieldInfo(currentSectionIndex) & Numeric) {-
1662 if (ke->text().at(0).isNumber())-
1663 return false;-
1664 } else if (ke->text().at(0).isLetterOrNumber()) {-
1665 return false;-
1666 }-
1667 return separators.at(currentSectionIndex + 1).contains(ke->text());-
1668 }-
1669 return false;-
1670}-
1671-
1672void QDateTimeEditPrivate::initCalendarPopup(QCalendarWidget *cw)-
1673{-
1674 QDateTimeEdit * const q = q_func();-
1675 if (!monthCalendar) {-
1676 monthCalendar = new QCalendarPopup(q, cw);-
1677 monthCalendar->setObjectName(QLatin1String("qt_datetimedit_calendar"));-
1678 QObject::connect(monthCalendar, qFlagLocation("2""newDateSelected(QDate)" "\0" __FILE__ ":" "2515""2521"), q, qFlagLocation("1""setDate(QDate)" "\0" __FILE__ ":" "2515""2521"));-
1679 QObject::connect(monthCalendar, qFlagLocation("2""hidingCalendar(QDate)" "\0" __FILE__ ":" "2516""2522"), q, qFlagLocation("1""setDate(QDate)" "\0" __FILE__ ":" "2516""2522"));-
1680 QObject::connect(monthCalendar, qFlagLocation("2""activated(QDate)" "\0" __FILE__ ":" "2517""2523"), q, qFlagLocation("1""setDate(QDate)" "\0" __FILE__ ":" "2517""2523"));-
1681 QObject::connect(monthCalendar, qFlagLocation("2""activated(QDate)" "\0" __FILE__ ":" "2518""2524"), monthCalendar, qFlagLocation("1""close()" "\0" __FILE__ ":" "2518""2524"));-
1682 QObject::connect(monthCalendar, qFlagLocation("2""resetButton()" "\0" __FILE__ ":" "2519""2525"), q, qFlagLocation("1""_q_resetButton()" "\0" __FILE__ ":" "2519""2525"));-
1683 } else if (cw) {-
1684 monthCalendar->setCalendarWidget(cw);-
1685 }-
1686 syncCalendarWidget();-
1687}-
1688-
1689void QDateTimeEditPrivate::positionCalendarPopup()-
1690{-
1691 QDateTimeEdit * const q = q_func();-
1692 QPoint pos = (q->layoutDirection() == Qt::RightToLeft) ? q->rect().bottomRight() : q->rect().bottomLeft();-
1693 QPoint pos2 = (q->layoutDirection() == Qt::RightToLeft) ? q->rect().topRight() : q->rect().topLeft();-
1694 pos = q->mapToGlobal(pos);-
1695 pos2 = q->mapToGlobal(pos2);-
1696 QSize size = monthCalendar->sizeHint();-
1697 QRect screen = QApplication::desktop()->availableGeometry(pos);-
1698-
1699 if (q->layoutDirection() == Qt::RightToLeft) {-
1700 pos.setX(pos.x()-size.width());-
1701 pos2.setX(pos2.x()-size.width());-
1702 if (pos.x() < screen.left())-
1703 pos.setX(qMax(pos.x(), screen.left()));-
1704 else if (pos.x()+size.width() > screen.right())-
1705 pos.setX(qMax(pos.x()-size.width(), screen.right()-size.width()));-
1706 } else {-
1707 if (pos.x()+size.width() > screen.right())-
1708 pos.setX(screen.right()-size.width());-
1709 pos.setX(qMax(pos.x(), screen.left()));-
1710 }-
1711 if (pos.y() + size.height() > screen.bottom())-
1712 pos.setY(pos2.y() - size.height());-
1713 else if (pos.y() < screen.top())-
1714 pos.setY(screen.top());-
1715 if (pos.y() < screen.top())-
1716 pos.setY(screen.top());-
1717 if (pos.y()+size.height() > screen.bottom())-
1718 pos.setY(screen.bottom()-size.height());-
1719 monthCalendar->move(pos);-
1720}-
1721-
1722bool QDateTimeEditPrivate::calendarPopupEnabled() const-
1723{-
1724 return (calendarPopup && (sections & (DateSectionMask)));-
1725}-
1726-
1727void QDateTimeEditPrivate::syncCalendarWidget()-
1728{-
1729 QDateTimeEdit * const q = q_func();-
1730 if (monthCalendar) {-
1731 const QSignalBlocker blocker(monthCalendar);-
1732 monthCalendar->setDateRange(q->minimumDate(), q->maximumDate());-
1733 monthCalendar->setDate(q->date());-
1734 }-
1735}-
1736-
1737QCalendarPopup::QCalendarPopup(QWidget * parent, QCalendarWidget *cw)-
1738 : QWidget(parent, Qt::Popup)-
1739{-
1740 setAttribute(Qt::WA_WindowPropagation);-
1741-
1742 dateChanged = false;-
1743 if (!cw) {-
1744 verifyCalendarInstance();-
1745 } else {-
1746 setCalendarWidget(cw);-
1747 }-
1748}-
1749-
1750QCalendarWidget *QCalendarPopup::verifyCalendarInstance()-
1751{-
1752 if (calendar.isNull()) {-
1753 QCalendarWidget *cw = new QCalendarWidget(this);-
1754 cw->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);-
1755-
1756-
1757-
1758-
1759 setCalendarWidget(cw);-
1760 return cw;-
1761 } else {-
1762 return calendar.data();-
1763 }-
1764}-
1765-
1766void QCalendarPopup::setCalendarWidget(QCalendarWidget *cw)-
1767{-
1768 ((!(cw)) ? qt_assert("cw",__FILE__,26052611) : qt_noop());-
1769 QVBoxLayout *widgetLayout = qobject_cast<QVBoxLayout*>(layout());-
1770 if (!widgetLayout) {-
1771 widgetLayout = new QVBoxLayout(this);-
1772 widgetLayout->setMargin(0);-
1773 widgetLayout->setSpacing(0);-
1774 }-
1775 delete calendar.data();-
1776 calendar = QPointer<QCalendarWidget>(cw);-
1777 widgetLayout->addWidget(cw);-
1778-
1779 connect(cw, qFlagLocation("2""activated(QDate)" "\0" __FILE__ ":" "2616""2622"), this, qFlagLocation("1""dateSelected(QDate)" "\0" __FILE__ ":" "2616""2622"));-
1780 connect(cw, qFlagLocation("2""clicked(QDate)" "\0" __FILE__ ":" "2617""2623"), this, qFlagLocation("1""dateSelected(QDate)" "\0" __FILE__ ":" "2617""2623"));-
1781 connect(cw, qFlagLocation("2""selectionChanged()" "\0" __FILE__ ":" "2618""2624"), this, qFlagLocation("1""dateSelectionChanged()" "\0" __FILE__ ":" "2618""2624"));-
1782-
1783 cw->setFocus();-
1784}-
1785-
1786-
1787void QCalendarPopup::setDate(const QDate &date)-
1788{-
1789 oldDate = date;-
1790 verifyCalendarInstance()->setSelectedDate(date);-
1791}-
1792-
1793void QCalendarPopup::setDateRange(const QDate &min, const QDate &max)-
1794{-
1795 QCalendarWidget *cw = verifyCalendarInstance();-
1796 cw->setMinimumDate(min);-
1797 cw->setMaximumDate(max);-
1798}-
1799-
1800void QCalendarPopup::mousePressEvent(QMouseEvent *event)-
1801{-
1802 QDateTimeEdit *dateTime = qobject_cast<QDateTimeEdit *>(parentWidget());-
1803 if (dateTime) {-
1804 QStyleOptionComboBox opt;-
1805 opt.init(dateTime);-
1806 QRect arrowRect = dateTime->style()->subControlRect(QStyle::CC_ComboBox, &opt,-
1807 QStyle::SC_ComboBoxArrow, dateTime);-
1808 arrowRect.moveTo(dateTime->mapToGlobal(arrowRect .topLeft()));-
1809 if (arrowRect.contains(event->globalPos()) || rect().contains(event->pos()))-
1810 setAttribute(Qt::WA_NoMouseReplay);-
1811 }-
1812 QWidget::mousePressEvent(event);-
1813}-
1814-
1815void QCalendarPopup::mouseReleaseEvent(QMouseEvent*)-
1816{-
1817 resetButton();-
1818}-
1819-
1820bool QCalendarPopup::event(QEvent *event)-
1821{-
1822 if (event->type() == QEvent::KeyPress) {-
1823 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);-
1824 if (keyEvent->matches(QKeySequence::Cancel))-
1825 dateChanged = false;-
1826 }-
1827 return QWidget::event(event);-
1828}-
1829-
1830void QCalendarPopup::dateSelectionChanged()-
1831{-
1832 dateChanged = true;-
1833 newDateSelected(verifyCalendarInstance()->selectedDate());-
1834}-
1835void QCalendarPopup::dateSelected(const QDate &date)-
1836{-
1837 dateChanged = true;-
1838 activated(date);-
1839 close();-
1840}-
1841-
1842void QCalendarPopup::hideEvent(QHideEvent *)-
1843{-
1844 resetButton();-
1845 if (!dateChanged)-
1846 hidingCalendar(oldDate);-
1847}-
1848-
1849-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9