Qt 4.8
qdatetimeedit.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui 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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <math.h>
43 #include <private/qdatetimeedit_p.h>
44 #include <qabstractspinbox.h>
45 #include <qapplication.h>
46 #include <qdatetimeedit.h>
47 #include <qdesktopwidget.h>
48 #include <qdebug.h>
49 #include <qevent.h>
50 #include <qlineedit.h>
51 #include <private/qlineedit_p.h>
52 #include <qlocale.h>
53 #include <qpainter.h>
54 #include <qlayout.h>
55 #include <qset.h>
56 #include <qstyle.h>
57 
58 #ifndef QT_NO_DATETIMEEDIT
59 
60 //#define QDATETIMEEDIT_QDTEDEBUG
61 #ifdef QDATETIMEEDIT_QDTEDEBUG
62 # define QDTEDEBUG qDebug() << QString::fromLatin1("%1:%2").arg(__FILE__).arg(__LINE__)
63 # define QDTEDEBUGN qDebug
64 #else
65 # define QDTEDEBUG if (false) qDebug()
66 # define QDTEDEBUGN if (false) qDebug
67 #endif
68 
70 
71 // --- QDateTimeEdit ---
72 
172  : QAbstractSpinBox(*new QDateTimeEditPrivate, parent)
173 {
176 }
177 
184  : QAbstractSpinBox(*new QDateTimeEditPrivate, parent)
185 {
187  d->init(datetime.isValid() ? datetime : QDateTime(QDATETIMEEDIT_DATE_INITIAL,
189 }
190 
199  : QAbstractSpinBox(*new QDateTimeEditPrivate, parent)
200 {
202  d->init(date.isValid() ? date : QDATETIMEEDIT_DATE_INITIAL);
203 }
204 
213  : QAbstractSpinBox(*new QDateTimeEditPrivate, parent)
214 {
216  d->init(time.isValid() ? time : QDATETIMEEDIT_TIME_MIN);
217 }
218 
224  : QAbstractSpinBox(*new QDateTimeEditPrivate, parent)
225 {
227  d->parserType = parserType;
228  d->init(var);
229 }
230 
248 {
249  Q_D(const QDateTimeEdit);
250  return d->value.toDateTime();
251 }
252 
254 {
256  if (datetime.isValid()) {
257  d->clearCache();
258  if (!(d->sections & DateSections_Mask))
259  setDateRange(datetime.date(), datetime.date());
260  d->setValue(QDateTime(datetime.date(), datetime.time(), d->spec), EmitIfChanged);
261  }
262 }
263 
280 {
281  Q_D(const QDateTimeEdit);
282  return d->value.toDate();
283 }
284 
286 {
288  if (date.isValid()) {
289  if (!(d->sections & DateSections_Mask))
290  setDateRange(date, date);
291 
292  d->clearCache();
293  d->setValue(QDateTime(date, d->value.toTime(), d->spec), EmitIfChanged);
294  d->updateTimeSpec();
295  }
296 }
297 
314 {
315  Q_D(const QDateTimeEdit);
316  return d->value.toTime();
317 }
318 
320 {
322  if (time.isValid()) {
323  d->clearCache();
324  d->setValue(QDateTime(d->value.toDate(), time, d->spec), EmitIfChanged);
325  }
326 }
327 
328 
355 {
356  Q_D(const QDateTimeEdit);
357  return d->minimum.toDateTime();
358 }
359 
361 {
363 }
364 
366 {
368  if (dt.isValid() && dt.date() >= QDATETIMEEDIT_DATE_MIN) {
369  const QDateTime m = dt.toTimeSpec(d->spec);
370  const QDateTime max = d->maximum.toDateTime();
371  d->setRange(m, (max > m ? max : m));
372  }
373 }
374 
401 {
402  Q_D(const QDateTimeEdit);
403  return d->maximum.toDateTime();
404 }
405 
407 {
409 }
410 
412 {
414  if (dt.isValid() && dt.date() <= QDATETIMEEDIT_DATE_MAX) {
415  const QDateTime m = dt.toTimeSpec(d->spec);
416  const QDateTime min = d->minimum.toDateTime();
417  d->setRange((min < m ? min : m), m);
418  }
419 }
420 
421 
442 {
444  const QDateTime minimum = min.toTimeSpec(d->spec);
445  QDateTime maximum = max.toTimeSpec(d->spec);
446  if (min > max)
447  maximum = minimum;
448  d->setRange(minimum, maximum);
449 }
450 
471 {
472  Q_D(const QDateTimeEdit);
473  return d->minimum.toDate();
474 }
475 
477 {
479  if (min.isValid() && min >= QDATETIMEEDIT_DATE_MIN) {
480  setMinimumDateTime(QDateTime(min, d->minimum.toTime(), d->spec));
481  }
482 }
483 
485 {
487 }
488 
507 {
508  Q_D(const QDateTimeEdit);
509  return d->maximum.toDate();
510 }
511 
513 {
515  if (max.isValid()) {
516  setMaximumDateTime(QDateTime(max, d->maximum.toTime(), d->spec));
517  }
518 }
519 
521 {
523 }
524 
543 {
544  Q_D(const QDateTimeEdit);
545  return d->minimum.toTime();
546 }
547 
549 {
551  if (min.isValid()) {
552  const QDateTime m(d->minimum.toDate(), min, d->spec);
554  }
555 }
556 
558 {
560 }
561 
579 {
580  Q_D(const QDateTimeEdit);
581  return d->maximum.toTime();
582 }
583 
585 {
587  if (max.isValid()) {
588  const QDateTime m(d->maximum.toDate(), max);
590  }
591 }
592 
594 {
596 }
597 
616 void QDateTimeEdit::setDateRange(const QDate &min, const QDate &max)
617 {
619  if (min.isValid() && max.isValid()) {
620  setDateTimeRange(QDateTime(min, d->minimum.toTime(), d->spec),
621  QDateTime(max, d->maximum.toTime(), d->spec));
622  }
623 }
624 
643 void QDateTimeEdit::setTimeRange(const QTime &min, const QTime &max)
644 {
646  if (min.isValid() && max.isValid()) {
647  setDateTimeRange(QDateTime(d->minimum.toDate(), min, d->spec),
648  QDateTime(d->maximum.toDate(), max, d->spec));
649  }
650 }
651 
664 QDateTimeEdit::Sections QDateTimeEdit::displayedSections() const
665 {
666  Q_D(const QDateTimeEdit);
667  return d->sections;
668 }
669 
681 {
682  Q_D(const QDateTimeEdit);
683 #ifdef QT_KEYPAD_NAVIGATION
684  if (QApplication::keypadNavigationEnabled() && d->focusOnButton)
685  return NoSection;
686 #endif
687  return d->convertToPublic(d->sectionType(d->currentSectionIndex));
688 }
689 
691 {
693  if (section == NoSection || !(section & d->sections))
694  return;
695 
696  d->updateCache(d->value, d->displayText());
697  const int size = d->sectionNodes.size();
698  int index = d->currentSectionIndex + 1;
699  for (int i=0; i<2; ++i) {
700  while (index < size) {
701  if (d->convertToPublic(d->sectionType(index)) == section) {
702  d->edit->setCursorPosition(d->sectionPos(index));
703  QDTEDEBUG << d->sectionPos(index);
704  return;
705  }
706  ++index;
707  }
708  index = 0;
709  }
710 }
711 
726 {
727  Q_D(const QDateTimeEdit);
728  if (index < 0 || index >= d->sectionNodes.size())
729  return NoSection;
730  return d->convertToPublic(d->sectionType(index));
731 }
732 
745 int QDateTimeEdit::sectionCount() const
746 {
747  Q_D(const QDateTimeEdit);
748  return d->sectionNodes.size();
749 }
750 
751 
771 {
772  Q_D(const QDateTimeEdit);
773  return d->currentSectionIndex;
774 }
775 
777 {
779  if (index < 0 || index >= d->sectionNodes.size())
780  return;
781  d->edit->setCursorPosition(d->sectionPos(index));
782 }
783 
798 {
799  Q_D(const QDateTimeEdit);
800  if (!d->calendarPopup || !(d->sections & QDateTimeParser::DateSectionMask))
801  return 0;
802  if (!d->monthCalendar) {
803  const_cast<QDateTimeEditPrivate*>(d)->initCalendarPopup();
804  }
805  return d->monthCalendar->calendarWidget();
806 }
807 
821 {
823  if (!calendarWidget) {
824  qWarning("QDateTimeEdit::setCalendarWidget: Cannot set a null calendar widget");
825  return;
826  }
827 
828  if (!d->calendarPopup) {
829  qWarning("QDateTimeEdit::setCalendarWidget: calendarPopup is set to false");
830  return;
831  }
832 
833  if (!(d->display & QDateTimeParser::DateSectionMask)) {
834  qWarning("QDateTimeEdit::setCalendarWidget: no date sections specified");
835  return;
836  }
837  d->initCalendarPopup(calendarWidget);
838 }
839 
840 
857 {
859  if (section == NoSection) {
860  d->edit->setSelection(d->edit->cursorPosition(), 0);
861  } else if (section & d->sections) {
862  if (currentSection() != section)
863  setCurrentSection(section);
864  d->setSelected(d->currentSectionIndex);
865  }
866 }
867 
868 
869 
882 {
883  Q_D(const QDateTimeEdit);
884  if (section == QDateTimeEdit::NoSection || !(section & d->sections)) {
885  return QString();
886  }
887 
888  d->updateCache(d->value, d->displayText());
889  const int sectionIndex = d->absoluteIndex(section, 0);
890  return d->sectionText(sectionIndex);
891 }
892 
923 {
924  Q_D(const QDateTimeEdit);
925  return isRightToLeft() ? d->unreversedFormat : d->displayFormat;
926 }
927 
928 template<typename C> static inline C reverse(const C &l)
929 {
930  C ret;
931  for (int i=l.size() - 1; i>=0; --i)
932  ret.append(l.at(i));
933  return ret;
934 }
935 
937 {
939  if (d->parseFormat(format)) {
940  d->unreversedFormat.clear();
941  if (isRightToLeft()) {
942  d->unreversedFormat = format;
943  d->displayFormat.clear();
944  for (int i=d->sectionNodes.size() - 1; i>=0; --i) {
945  d->displayFormat += d->separators.at(i + 1);
946  d->displayFormat += d->sectionFormat(i);
947  }
948  d->displayFormat += d->separators.at(0);
949  d->separators = reverse(d->separators);
950  d->sectionNodes = reverse(d->sectionNodes);
951  }
952 
953  d->formatExplicitlySet = true;
954  d->sections = d->convertSections(d->display);
955  d->clearCache();
956 
957  d->currentSectionIndex = qMin(d->currentSectionIndex, d->sectionNodes.size() - 1);
958  const bool timeShown = (d->sections & TimeSections_Mask);
959  const bool dateShown = (d->sections & DateSections_Mask);
960  Q_ASSERT(dateShown || timeShown);
961  if (timeShown && !dateShown) {
962  QTime time = d->value.toTime();
963  setDateRange(d->value.toDate(), d->value.toDate());
964  if (d->minimum.toTime() >= d->maximum.toTime()) {
966  // if the time range became invalid during the adjustment, the time would have been reset
967  setTime(time);
968  }
969  } else if (dateShown && !timeShown) {
971  d->value = QDateTime(d->value.toDate(), QTime(), d->spec);
972  }
973  d->updateEdit();
974  d->_q_editorCursorPositionChanged(-1, 0);
975  }
976 }
977 
992 bool QDateTimeEdit::calendarPopup() const
993 {
994  Q_D(const QDateTimeEdit);
995  return d->calendarPopup;
996 }
997 
999 {
1000  Q_D(QDateTimeEdit);
1001  if (enable == d->calendarPopup)
1002  return;
1004  d->calendarPopup = enable;
1005 #ifdef QT_KEYPAD_NAVIGATION
1006  if (!enable)
1007  d->focusOnButton = false;
1008 #endif
1009  d->updateEditFieldGeometry();
1010  update();
1011 }
1012 
1023 {
1024  Q_D(const QDateTimeEdit);
1025  return d->spec;
1026 }
1027 
1029 {
1030  Q_D(QDateTimeEdit);
1031  if (spec != d->spec) {
1032  d->spec = spec;
1033  d->updateTimeSpec();
1034  }
1035 }
1036 
1042 {
1043  Q_D(const QDateTimeEdit);
1044  if (d->cachedSizeHint.isEmpty()) {
1045  ensurePolished();
1046 
1047  const QFontMetrics fm(fontMetrics());
1048  int h = d->edit->sizeHint().height();
1049  int w = 0;
1050  QString s;
1051  s = d->textFromValue(d->minimum) + QLatin1String(" ");
1052  w = qMax<int>(w, fm.width(s));
1053  s = d->textFromValue(d->maximum) + QLatin1String(" ");
1054  w = qMax<int>(w, fm.width(s));
1055  if (d->specialValueText.size()) {
1056  s = d->specialValueText;
1057  w = qMax<int>(w, fm.width(s));
1058  }
1059  w += 2; // cursor blinking space
1060 
1061  QSize hint(w, h);
1062 
1063 #ifdef Q_WS_MAC
1064  if (d->calendarPopupEnabled()) {
1066  d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_ComboBox, &opt, hint, this);
1067  } else {
1068 #else
1069  {
1070 #endif
1071  QSize extra(35, 6);
1072  QStyleOptionSpinBox opt;
1073  initStyleOption(&opt);
1074  opt.rect.setSize(hint + extra);
1075  extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt,
1077  // get closer to final result by repeating the calculation
1078  opt.rect.setSize(hint + extra);
1079  extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt,
1081  hint += extra;
1082 
1083  opt.rect = rect();
1084  d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this)
1086  }
1087 
1088  d->cachedMinimumSizeHint = d->cachedSizeHint;
1089  // essentially make minimumSizeHint return the same as sizeHint for datetimeedits
1090  }
1091  return d->cachedSizeHint;
1092 }
1093 
1099 {
1100  Q_D(QDateTimeEdit);
1101  switch (event->type()) {
1103  const bool was = d->formatExplicitlySet;
1104  const QString oldFormat = d->displayFormat;
1105  d->displayFormat.clear();
1106  setDisplayFormat(oldFormat);
1107  d->formatExplicitlySet = was;
1108  break; }
1109  case QEvent::LocaleChange:
1110  d->updateEdit();
1111  break;
1112  case QEvent::StyleChange:
1113 #ifdef Q_WS_MAC
1114  case QEvent::MacSizeChange:
1115 #endif
1116  d->setLayoutItemMargins(QStyle::SE_DateTimeEditLayoutItem);
1117  break;
1118  default:
1119  break;
1120  }
1121  return QAbstractSpinBox::event(event);
1122 }
1123 
1129 {
1130  Q_D(QDateTimeEdit);
1131  d->clearSection(d->currentSectionIndex);
1132 }
1138 {
1139  Q_D(QDateTimeEdit);
1140  int oldCurrent = d->currentSectionIndex;
1141  bool select = true;
1142  bool inserted = false;
1143 
1144  switch (event->key()) {
1145 #ifdef QT_KEYPAD_NAVIGATION
1146  case Qt::Key_NumberSign: //shortcut to popup calendar
1147  if (QApplication::keypadNavigationEnabled() && d->calendarPopupEnabled()) {
1148  d->initCalendarPopup();
1149  d->positionCalendarPopup();
1150  d->monthCalendar->show();
1151  return;
1152  }
1153  break;
1154  case Qt::Key_Select:
1155  if (QApplication::keypadNavigationEnabled()) {
1156  if (hasEditFocus()) {
1157  if (d->focusOnButton) {
1158  d->initCalendarPopup();
1159  d->positionCalendarPopup();
1160  d->monthCalendar->show();
1161  d->focusOnButton = false;
1162  return;
1163  }
1164  setEditFocus(false);
1165  selectAll();
1166  } else {
1167  setEditFocus(true);
1168 
1169  //hide cursor
1170  d->edit->d_func()->setCursorVisible(false);
1171  d->edit->d_func()->control->setCursorBlinkPeriod(0);
1172  d->setSelected(0);
1173  }
1174  }
1175  return;
1176 #endif
1177  case Qt::Key_Enter:
1178  case Qt::Key_Return:
1179  d->interpret(AlwaysEmit);
1180  d->setSelected(d->currentSectionIndex, true);
1181  event->ignore();
1183  return;
1184  default:
1185 #ifdef QT_KEYPAD_NAVIGATION
1186  if (QApplication::keypadNavigationEnabled() && !hasEditFocus()
1187  && !event->text().isEmpty() && event->text().at(0).isLetterOrNumber()) {
1188  setEditFocus(true);
1189 
1190  //hide cursor
1191  d->edit->d_func()->setCursorVisible(false);
1192  d->edit->d_func()->control->setCursorBlinkPeriod(0);
1193  d->setSelected(0);
1194  oldCurrent = 0;
1195  }
1196 #endif
1197  if (!d->isSeparatorKey(event)) {
1198  inserted = select = !event->text().isEmpty() && event->text().at(0).isPrint()
1199  && !(event->modifiers() & ~(Qt::ShiftModifier|Qt::KeypadModifier));
1200  break;
1201  }
1202  case Qt::Key_Left:
1203  case Qt::Key_Right:
1204  if (event->key() == Qt::Key_Left || event->key() == Qt::Key_Right) {
1205  if (
1206 #ifdef QT_KEYPAD_NAVIGATION
1207  QApplication::keypadNavigationEnabled() && !hasEditFocus()
1208  || !QApplication::keypadNavigationEnabled() &&
1209 #endif
1210  !(event->modifiers() & Qt::ControlModifier)) {
1211  select = false;
1212  break;
1213  }
1214 #ifdef Q_WS_MAC
1215  else
1216 #ifdef QT_KEYPAD_NAVIGATION
1217  if (!QApplication::keypadNavigationEnabled())
1218 #endif
1219  {
1220  select = (event->modifiers() & Qt::ShiftModifier);
1221  break;
1222  }
1223 #endif
1224  }
1225  // else fall through
1226  case Qt::Key_Backtab:
1227  case Qt::Key_Tab: {
1228  event->accept();
1229  if (d->specialValue()) {
1230  d->edit->setSelection(d->edit->cursorPosition(), 0);
1231  return;
1232  }
1233  const bool forward = event->key() != Qt::Key_Left && event->key() != Qt::Key_Backtab
1234  && (event->key() != Qt::Key_Tab || !(event->modifiers() & Qt::ShiftModifier));
1235 #ifdef QT_KEYPAD_NAVIGATION
1236  int newSection = d->nextPrevSection(d->currentSectionIndex, forward);
1237  if (QApplication::keypadNavigationEnabled()) {
1238  if (d->focusOnButton) {
1239  newSection = forward ? 0 : d->sectionNodes.size() - 1;
1240  d->focusOnButton = false;
1241  update();
1242  } else if (newSection < 0 && select && d->calendarPopupEnabled()) {
1244  d->focusOnButton = true;
1245  update();
1246  return;
1247  }
1248  }
1249  // only allow date/time sections to be selected.
1251  return;
1252 #endif
1253  //key tab and backtab will be managed thrgout QWidget::event
1254  if (event->key() != Qt::Key_Backtab && event->key() != Qt::Key_Tab)
1255  focusNextPrevChild(forward);
1256 
1257  return; }
1258  }
1260  if (select && !d->edit->hasSelectedText()) {
1261  if (inserted && d->sectionAt(d->edit->cursorPosition()) == QDateTimeParser::NoSectionIndex) {
1262  QString str = d->displayText();
1263  int pos = d->edit->cursorPosition();
1264  if (validate(str, pos) == QValidator::Acceptable
1265  && (d->sectionNodes.at(oldCurrent).count != 1
1266  || d->sectionMaxSize(oldCurrent) == d->sectionSize(oldCurrent)
1267  || d->skipToNextSection(oldCurrent, d->value.toDateTime(), d->sectionText(oldCurrent)))) {
1268  QDTEDEBUG << "Setting currentsection to"
1269  << d->closestSection(d->edit->cursorPosition(), true) << event->key()
1270  << oldCurrent << str;
1271  const int tmp = d->closestSection(d->edit->cursorPosition(), true);
1272  if (tmp >= 0)
1273  d->currentSectionIndex = tmp;
1274  }
1275  }
1276  if (d->currentSectionIndex != oldCurrent) {
1277  d->setSelected(d->currentSectionIndex);
1278  }
1279  }
1280  if (d->specialValue()) {
1281  d->edit->setSelection(d->edit->cursorPosition(), 0);
1282  }
1283 }
1284 
1289 #ifndef QT_NO_WHEELEVENT
1291 {
1293 }
1294 #endif
1295 
1301 {
1302  Q_D(QDateTimeEdit);
1304  QString *frm = 0;
1305  const int oldPos = d->edit->cursorPosition();
1306  if (!d->formatExplicitlySet) {
1307  if (d->displayFormat == d->defaultTimeFormat) {
1308  frm = &d->defaultTimeFormat;
1309  } else if (d->displayFormat == d->defaultDateFormat) {
1310  frm = &d->defaultDateFormat;
1311  } else if (d->displayFormat == d->defaultDateTimeFormat) {
1312  frm = &d->defaultDateTimeFormat;
1313  }
1314 
1315  if (frm) {
1316  d->readLocaleSettings();
1317  if (d->displayFormat != *frm) {
1318  setDisplayFormat(*frm);
1319  d->formatExplicitlySet = false;
1320  d->edit->setCursorPosition(oldPos);
1321  }
1322  }
1323  }
1324  const bool oldHasHadFocus = d->hasHadFocus;
1325  d->hasHadFocus = true;
1326  bool first = true;
1327  switch (event->reason()) {
1329  first = false;
1330  break;
1331  case Qt::MouseFocusReason:
1332  case Qt::PopupFocusReason:
1333  return;
1335  if (oldHasHadFocus)
1336  return;
1338  case Qt::TabFocusReason:
1339  default:
1340  break;
1341  }
1342  if (isRightToLeft())
1343  first = !first;
1344  d->updateEdit(); // needed to make it update specialValueText
1345 
1346  d->setSelected(first ? 0 : d->sectionNodes.size() - 1);
1347 }
1348 
1354 {
1355  Q_D(QDateTimeEdit);
1356  const int newSection = d->nextPrevSection(d->currentSectionIndex, next);
1357  switch (d->sectionType(newSection)) {
1362  default:
1363  d->edit->deselect();
1364  d->edit->setCursorPosition(d->sectionPos(newSection));
1365  QDTEDEBUG << d->sectionPos(newSection);
1366  d->setSelected(newSection, true);
1367  return false;
1368  }
1369 }
1370 
1375 void QDateTimeEdit::stepBy(int steps)
1376 {
1377  Q_D(QDateTimeEdit);
1378 #ifdef QT_KEYPAD_NAVIGATION
1379  // with keypad navigation and not editFocus, left right change the date/time by a fixed amount.
1380  if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
1381  // if date based, shift by day. else shift by 15min
1382  if (d->sections & DateSections_Mask) {
1383  setDateTime(dateTime().addDays(steps));
1384  } else {
1385  int minutes = time().hour()*60 + time().minute();
1386  int blocks = minutes/15;
1387  blocks += steps;
1388  /* rounding involved */
1389  if (minutes % 15) {
1390  if (steps < 0) {
1391  blocks += 1; // do one less step;
1392  }
1393  }
1394 
1395  minutes = blocks * 15;
1396 
1397  /* need to take wrapping into account */
1398  if (!d->wrapping) {
1399  int max_minutes = d->maximum.toTime().hour()*60 + d->maximum.toTime().minute();
1400  int min_minutes = d->minimum.toTime().hour()*60 + d->minimum.toTime().minute();
1401 
1402  if (minutes >= max_minutes) {
1403  setTime(maximumTime());
1404  return;
1405  } else if (minutes <= min_minutes) {
1406  setTime(minimumTime());
1407  return;
1408  }
1409  }
1410  setTime(QTime(minutes/60, minutes%60));
1411  }
1412  return;
1413  }
1414 #endif
1415  // don't optimize away steps == 0. This is the only way to select
1416  // the currentSection in Qt 4.1.x
1417  if (d->specialValue() && displayedSections() != AmPmSection) {
1418  for (int i=0; i<d->sectionNodes.size(); ++i) {
1419  if (d->sectionType(i) != QDateTimeParser::AmPmSection) {
1420  d->currentSectionIndex = i;
1421  break;
1422  }
1423  }
1424  }
1425  d->setValue(d->stepBy(d->currentSectionIndex, steps, false), EmitIfChanged);
1426  d->updateCache(d->value, d->displayText());
1427 
1428  d->setSelected(d->currentSectionIndex);
1429  d->updateTimeSpec();
1430 }
1431 
1441 {
1442  Q_D(const QDateTimeEdit);
1443  return locale().toString(dateTime, d->displayFormat);
1444 }
1445 
1446 
1456 {
1457  Q_D(const QDateTimeEdit);
1458  QString copy = text;
1459  int pos = d->edit->cursorPosition();
1461  return d->validateAndInterpret(copy, pos, state);
1462 }
1463 
1469 {
1470  Q_D(const QDateTimeEdit);
1471  QValidator::State state;
1472  d->validateAndInterpret(text, pos, state);
1473  return state;
1474 }
1475 
1481 void QDateTimeEdit::fixup(QString &input) const
1482 {
1483  Q_D(const QDateTimeEdit);
1484  QValidator::State state;
1485  int copy = d->edit->cursorPosition();
1486 
1487  d->validateAndInterpret(input, copy, state, true);
1488 }
1489 
1490 
1495 QDateTimeEdit::StepEnabled QDateTimeEdit::stepEnabled() const
1496 {
1497  Q_D(const QDateTimeEdit);
1498  if (d->readOnly)
1499  return StepEnabled(0);
1500  if (d->specialValue()) {
1501  return (d->minimum == d->maximum ? StepEnabled(0) : StepEnabled(StepUpEnabled));
1502  }
1503 
1504  QAbstractSpinBox::StepEnabled ret = 0;
1505 
1506 #ifdef QT_KEYPAD_NAVIGATION
1507  if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
1508  if (d->wrapping)
1509  return StepEnabled(StepUpEnabled | StepDownEnabled);
1510  // 3 cases. date, time, datetime. each case look
1511  // at just the relavant component.
1512  QVariant max, min, val;
1513  if (!(d->sections & DateSections_Mask)) {
1514  // time only, no date
1515  max = d->maximum.toTime();
1516  min = d->minimum.toTime();
1517  val = d->value.toTime();
1518  } else if (!(d->sections & TimeSections_Mask)) {
1519  // date only, no time
1520  max = d->maximum.toDate();
1521  min = d->minimum.toDate();
1522  val = d->value.toDate();
1523  } else {
1524  // both
1525  max = d->maximum;
1526  min = d->minimum;
1527  val = d->value;
1528  }
1529  if (val != min)
1531  if (val != max)
1533  return ret;
1534  }
1535 #endif
1536  switch (d->sectionType(d->currentSectionIndex)) {
1539  case QDateTimeParser::LastSection: return 0;
1540  default: break;
1541  }
1542  if (d->wrapping)
1543  return StepEnabled(StepDownEnabled|StepUpEnabled);
1544 
1545  QVariant v = d->stepBy(d->currentSectionIndex, 1, true);
1546  if (v != d->value) {
1548  }
1549  v = d->stepBy(d->currentSectionIndex, -1, true);
1550  if (v != d->value) {
1552  }
1553 
1554  return ret;
1555 }
1556 
1557 
1563 {
1564  Q_D(QDateTimeEdit);
1565  if (!d->calendarPopupEnabled()) {
1567  return;
1568  }
1569  d->updateHoverControl(event->pos());
1570  if (d->hoverControl == QStyle::SC_ComboBoxArrow) {
1571  event->accept();
1572  if (d->readOnly) {
1573  return;
1574  }
1575  d->updateArrow(QStyle::State_Sunken);
1576  d->initCalendarPopup();
1577  d->positionCalendarPopup();
1578  //Show the calendar
1579  d->monthCalendar->show();
1580  } else {
1582  }
1583 }
1584 
1629 {
1630 }
1631 
1638  : QDateTimeEdit(time, QVariant::Time, parent)
1639 {
1640 }
1641 
1642 
1686 {
1687 }
1688 
1695  : QDateTimeEdit(date, QVariant::Date, parent)
1696 {
1697 }
1698 
1699 
1700 // --- QDateTimeEditPrivate ---
1701 
1709  : QDateTimeParser(QVariant::DateTime, QDateTimeParser::DateTimeEdit)
1710 {
1711  hasHadFocus = false;
1712  formatExplicitlySet = false;
1713  cacheGuard = false;
1714  fixday = true;
1716  sections = 0;
1717  cachedDay = -1;
1719 
1721  last.type = LastSection;
1722  none.type = NoSection;
1723  first.pos = 0;
1724  last.pos = -1;
1725  none.pos = -1;
1726  sections = 0;
1727  calendarPopup = false;
1731  monthCalendar = 0;
1733 
1734 #ifdef QT_KEYPAD_NAVIGATION
1735  focusOnButton = false;
1736 #endif
1737 }
1738 
1740 {
1744 
1745  // time zone changes can lead to 00:00:00 becomes 01:00:00 and 23:59:59 becomes 00:59:59 (invalid range)
1746  const bool dateShown = (sections & QDateTimeEdit::DateSections_Mask);
1747  if (!dateShown) {
1748  if (minimum.toTime() >= maximum.toTime()){
1751  }
1752  }
1753 }
1754 
1756 {
1757  const QString newText = (specialValue() ? specialValueText : textFromValue(value));
1758  if (newText == displayText())
1759  return;
1760  int selsize = edit->selectedText().size();
1761  const bool sb = edit->blockSignals(true);
1762 
1763  edit->setText(newText);
1764 
1765  if (!specialValue()
1766 #ifdef QT_KEYPAD_NAVIGATION
1767  && !(QApplication::keypadNavigationEnabled() && !edit->hasEditFocus())
1768 #endif
1769  ) {
1770  int cursor = sectionPos(currentSectionIndex);
1771  QDTEDEBUG << "cursor is " << cursor << currentSectionIndex;
1772  cursor = qBound(0, cursor, displayText().size());
1773  QDTEDEBUG << cursor;
1774  if (selsize > 0) {
1775  edit->setSelection(cursor, selsize);
1776  QDTEDEBUG << cursor << selsize;
1777  } else {
1778  edit->setCursorPosition(cursor);
1779  QDTEDEBUG << cursor;
1780 
1781  }
1782  }
1783  edit->blockSignals(sb);
1784 }
1785 
1786 
1796 void QDateTimeEditPrivate::setSelected(int sectionIndex, bool forward)
1797 {
1798  if (specialValue()
1799 #ifdef QT_KEYPAD_NAVIGATION
1800  || (QApplication::keypadNavigationEnabled() && !edit->hasEditFocus())
1801 #endif
1802  ) {
1803  edit->selectAll();
1804  } else {
1805  const SectionNode &node = sectionNode(sectionIndex);
1806  if (node.type == NoSection || node.type == LastSection || node.type == FirstSection)
1807  return;
1808 
1810  const int size = sectionSize(sectionIndex);
1811  if (forward) {
1812  edit->setSelection(sectionPos(node), size);
1813  } else {
1814  edit->setSelection(sectionPos(node) + size, -size);
1815  }
1816  }
1817 }
1818 
1829 {
1830  if (pos < separators.first().size()) {
1831  return (pos == 0 ? FirstSectionIndex : NoSectionIndex);
1832  } else if (displayText().size() - pos < separators.last().size() + 1) {
1833  if (separators.last().size() == 0) {
1834  return sectionNodes.count() - 1;
1835  }
1836  return (pos == displayText().size() ? LastSectionIndex : NoSectionIndex);
1837  }
1839 
1840  for (int i=0; i<sectionNodes.size(); ++i) {
1841  const int tmp = sectionPos(i);
1842  if (pos < tmp + sectionSize(i)) {
1843  return (pos < tmp ? -1 : i);
1844  }
1845  }
1846  return -1;
1847 }
1848 
1859 int QDateTimeEditPrivate::closestSection(int pos, bool forward) const
1860 {
1861  Q_ASSERT(pos >= 0);
1862  if (pos < separators.first().size()) {
1863  return forward ? 0 : FirstSectionIndex;
1864  } else if (displayText().size() - pos < separators.last().size() + 1) {
1865  return forward ? LastSectionIndex : sectionNodes.size() - 1;
1866  }
1868  for (int i=0; i<sectionNodes.size(); ++i) {
1869  const int tmp = sectionPos(sectionNodes.at(i));
1870  if (pos < tmp + sectionSize(i)) {
1871  if (pos < tmp && !forward) {
1872  return i-1;
1873  }
1874  return i;
1875  } else if (i == sectionNodes.size() - 1 && pos > tmp) {
1876  return i;
1877  }
1878  }
1879  qWarning("QDateTimeEdit: Internal Error: closestSection returned NoSection");
1880  return NoSectionIndex;
1881 }
1882 
1892 int QDateTimeEditPrivate::nextPrevSection(int current, bool forward) const
1893 {
1894  Q_Q(const QDateTimeEdit);
1895  if (q->isRightToLeft())
1896  forward = !forward;
1897 
1898  switch (current) {
1899  case FirstSectionIndex: return forward ? 0 : FirstSectionIndex;
1900  case LastSectionIndex: return (forward ? LastSectionIndex : sectionNodes.size() - 1);
1901  case NoSectionIndex: return FirstSectionIndex;
1902  default: break;
1903  }
1904  Q_ASSERT(current >= 0 && current < sectionNodes.size());
1905 
1906  current += (forward ? 1 : -1);
1907  if (current >= sectionNodes.size()) {
1908  return LastSectionIndex;
1909  } else if (current < 0) {
1910  return FirstSectionIndex;
1911  }
1912 
1913  return current;
1914 }
1915 
1926 {
1927  const QLatin1Char space(' ');
1928  int cursorPos = edit->cursorPosition();
1929  bool blocked = edit->blockSignals(true);
1930  QString t = edit->text();
1931  const int pos = sectionPos(index);
1932  if (pos == -1) {
1933  qWarning("QDateTimeEdit: Internal error (%s:%d)", __FILE__, __LINE__);
1934  return;
1935  }
1936  const int size = sectionSize(index);
1937  t.replace(pos, size, QString().fill(space, size));
1938  edit->setText(t);
1939  edit->setCursorPosition(cursorPos);
1940  QDTEDEBUG << cursorPos;
1941 
1942  edit->blockSignals(blocked);
1943 }
1944 
1945 
1952 void QDateTimeEditPrivate::updateCache(const QVariant &val, const QString &str) const
1953 {
1954  if (val != cachedValue || str != cachedText || cacheGuard) {
1955  cacheGuard = true;
1956  QString copy = str;
1957  int unused = edit->cursorPosition();
1958  QValidator::State unusedState;
1959  validateAndInterpret(copy, unused, unusedState);
1960  cacheGuard = false;
1961  }
1962 }
1963 
1971  QValidator::State &state, bool fixup) const
1972 {
1973  if (input.isEmpty()) {
1974  if (sectionNodes.size() == 1 || !specialValueText.isEmpty()) {
1975  state = QValidator::Intermediate;
1976  } else {
1977  state = QValidator::Invalid;
1978  }
1979  return getZeroVariant().toDateTime();
1980  } else if (cachedText == input && !fixup) {
1981  state = cachedState;
1982  return cachedValue.toDateTime();
1983  } else if (!specialValueText.isEmpty()) {
1984  bool changeCase = false;
1985  const int max = qMin(specialValueText.size(), input.size());
1986  int i;
1987  for (i=0; i<max; ++i) {
1988  const QChar ic = input.at(i);
1989  const QChar sc = specialValueText.at(i);
1990  if (ic != sc) {
1991  if (sc.toLower() == ic.toLower()) {
1992  changeCase = true;
1993  } else {
1994  break;
1995  }
1996  }
1997  }
1998  if (i == max) {
2000  if (changeCase) {
2001  input = specialValueText.left(max);
2002  }
2003  return minimum.toDateTime();
2004  }
2005  }
2006  StateNode tmp = parse(input, position, value.toDateTime(), fixup);
2007  input = tmp.input;
2008  state = QValidator::State(int(tmp.state));
2009  if (state == QValidator::Acceptable) {
2010  if (tmp.conflicts && conflictGuard != tmp.value) {
2011  conflictGuard = tmp.value;
2012  clearCache();
2013  input = textFromValue(tmp.value);
2014  updateCache(tmp.value, input);
2015  conflictGuard.clear();
2016  } else {
2017  cachedText = input;
2018  cachedState = state;
2019  cachedValue = tmp.value;
2020  }
2021  } else {
2022  clearCache();
2023  }
2024  return (tmp.value.isNull() ? getZeroVariant().toDateTime() : tmp.value);
2025 }
2026 
2027 
2033 {
2034  Q_Q(const QDateTimeEdit);
2035  return q->textFromDateTime(f.toDateTime());
2036 }
2037 
2049 {
2050  Q_Q(const QDateTimeEdit);
2051  return q->dateTimeFromText(f).toTimeSpec(spec);
2052 }
2053 
2054 
2068 QDateTime QDateTimeEditPrivate::stepBy(int sectionIndex, int steps, bool test) const
2069 {
2070  Q_Q(const QDateTimeEdit);
2071  QDateTime v = value.toDateTime();
2072  QString str = displayText();
2073  int pos = edit->cursorPosition();
2074  const SectionNode sn = sectionNode(sectionIndex);
2075 
2076  int val;
2077  // to make sure it behaves reasonably when typing something and then stepping in non-tracking mode
2078  if (!test && pendingEmit) {
2079  if (q->validate(str, pos) != QValidator::Acceptable) {
2080  v = value.toDateTime();
2081  } else {
2082  v = q->dateTimeFromText(str);
2083  }
2084  val = getDigit(v, sectionIndex);
2085  } else {
2086  val = getDigit(v, sectionIndex);
2087  }
2088 
2089  val += steps;
2090 
2091  const int min = absoluteMin(sectionIndex);
2092  const int max = absoluteMax(sectionIndex, value.toDateTime());
2093 
2094  if (val < min) {
2095  val = (wrapping ? max - (min - val) + 1 : min);
2096  } else if (val > max) {
2097  val = (wrapping ? min + val - max - 1 : max);
2098  }
2099 
2100 
2101  const int oldDay = v.date().day();
2102 
2103  setDigit(v, sectionIndex, val);
2104  // if this sets year or month it will make
2105  // sure that days are lowered if needed.
2106 
2107  const QDateTime minimumDateTime = minimum.toDateTime();
2108  const QDateTime maximumDateTime = maximum.toDateTime();
2109  // changing one section should only modify that section, if possible
2110  if (sn.type != AmPmSection && (v < minimumDateTime || v > maximumDateTime)) {
2111  const int localmin = getDigit(minimumDateTime, sectionIndex);
2112  const int localmax = getDigit(maximumDateTime, sectionIndex);
2113 
2114  if (wrapping) {
2115  // just because we hit the roof in one direction, it
2116  // doesn't mean that we hit the floor in the other
2117  if (steps > 0) {
2118  setDigit(v, sectionIndex, min);
2120  const int daysInMonth = v.date().daysInMonth();
2121  if (v.date().day() < oldDay && v.date().day() < daysInMonth) {
2122  const int adds = qMin(oldDay, daysInMonth);
2123  v = v.addDays(adds - v.date().day());
2124  }
2125  }
2126 
2127  if (v < minimumDateTime) {
2128  setDigit(v, sectionIndex, localmin);
2129  if (v < minimumDateTime)
2130  setDigit(v, sectionIndex, localmin + 1);
2131  }
2132  } else {
2133  setDigit(v, sectionIndex, max);
2135  const int daysInMonth = v.date().daysInMonth();
2136  if (v.date().day() < oldDay && v.date().day() < daysInMonth) {
2137  const int adds = qMin(oldDay, daysInMonth);
2138  v = v.addDays(adds - v.date().day());
2139  }
2140  }
2141 
2142  if (v > maximumDateTime) {
2143  setDigit(v, sectionIndex, localmax);
2144  if (v > maximumDateTime)
2145  setDigit(v, sectionIndex, localmax - 1);
2146  }
2147  }
2148  } else {
2149  setDigit(v, sectionIndex, (steps > 0 ? localmax : localmin));
2150  }
2151  }
2152  if (!test && oldDay != v.date().day() && !(sn.type & (DaySection|DayOfWeekSection))) {
2153  // this should not happen when called from stepEnabled
2154  cachedDay = qMax<int>(oldDay, cachedDay);
2155  }
2156 
2157  if (v < minimumDateTime) {
2158  if (wrapping) {
2159  QDateTime t = v;
2160  setDigit(t, sectionIndex, steps < 0 ? max : min);
2161  bool mincmp = (t >= minimumDateTime);
2162  bool maxcmp = (t <= maximumDateTime);
2163  if (!mincmp || !maxcmp) {
2164  setDigit(t, sectionIndex, getDigit(steps < 0
2165  ? maximumDateTime
2166  : minimumDateTime, sectionIndex));
2167  mincmp = (t >= minimumDateTime);
2168  maxcmp = (t <= maximumDateTime);
2169  }
2170  if (mincmp && maxcmp) {
2171  v = t;
2172  }
2173  } else {
2174  v = value.toDateTime();
2175  }
2176  } else if (v > maximumDateTime) {
2177  if (wrapping) {
2178  QDateTime t = v;
2179  setDigit(t, sectionIndex, steps > 0 ? min : max);
2180  bool mincmp = (t >= minimumDateTime);
2181  bool maxcmp = (t <= maximumDateTime);
2182  if (!mincmp || !maxcmp) {
2183  setDigit(t, sectionIndex, getDigit(steps > 0 ?
2184  minimumDateTime :
2185  maximumDateTime, sectionIndex));
2186  mincmp = (t >= minimumDateTime);
2187  maxcmp = (t <= maximumDateTime);
2188  }
2189  if (mincmp && maxcmp) {
2190  v = t;
2191  }
2192  } else {
2193  v = value.toDateTime();
2194  }
2195  }
2196 
2197  const QDateTime ret = bound(v, value, steps).toDateTime().toTimeSpec(spec);
2198  return ret;
2199 }
2200 
2206 {
2207  Q_Q(QDateTimeEdit);
2208  if (ep == NeverEmit) {
2209  return;
2210  }
2211  pendingEmit = false;
2212 
2213  const bool dodate = value.toDate().isValid() && (sections & DateSectionMask);
2214  const bool datechanged = (ep == AlwaysEmit || old.toDate() != value.toDate());
2215  const bool dotime = value.toTime().isValid() && (sections & TimeSectionMask);
2216  const bool timechanged = (ep == AlwaysEmit || old.toTime() != value.toTime());
2217 
2219 
2221  if (datechanged || timechanged)
2222  emit q->dateTimeChanged(value.toDateTime());
2223  if (dodate && datechanged)
2224  emit q->dateChanged(value.toDate());
2225  if (dotime && timechanged)
2226  emit q->timeChanged(value.toTime());
2227 
2228 }
2229 
2235 {
2237  return;
2238  const QString oldText = displayText();
2239  updateCache(value, oldText);
2240 
2241  const bool allowChange = !edit->hasSelectedText();
2242  const bool forward = oldpos <= newpos;
2244  int s = sectionAt(newpos);
2245  if (s == NoSectionIndex && forward && newpos > 0) {
2246  s = sectionAt(newpos - 1);
2247  }
2248 
2249  int c = newpos;
2250 
2251  const int selstart = edit->selectionStart();
2252  const int selSection = sectionAt(selstart);
2253  const int l = selSection != -1 ? sectionSize(selSection) : 0;
2254 
2255  if (s == NoSectionIndex) {
2256  if (l > 0 && selstart == sectionPos(selSection) && edit->selectedText().size() == l) {
2257  s = selSection;
2258  if (allowChange)
2259  setSelected(selSection, true);
2260  c = -1;
2261  } else {
2262  int closest = closestSection(newpos, forward);
2263  c = sectionPos(closest) + (forward ? 0 : qMax<int>(0, sectionSize(closest)));
2264 
2265  if (allowChange) {
2266  edit->setCursorPosition(c);
2267  QDTEDEBUG << c;
2268  }
2269  s = closest;
2270  }
2271  }
2272 
2273  if (allowChange && currentSectionIndex != s) {
2275  }
2276  if (c == -1) {
2277  setSelected(s, true);
2278  } else if (!edit->hasSelectedText()) {
2279  if (oldpos < newpos) {
2280  edit->setCursorPosition(displayText().size() - (oldText.size() - c));
2281  } else {
2282  edit->setCursorPosition(c);
2283  }
2284  }
2285 
2286  QDTEDEBUG << "currentSectionIndex is set to" << sectionName(sectionType(s))
2287  << oldpos << newpos
2289 
2290  currentSectionIndex = s;
2292  "QDateTimeEditPrivate::_q_editorCursorPositionChanged()",
2293  qPrintable(QString::fromAscii("Internal error (%1 %2)").
2294  arg(currentSectionIndex).
2295  arg(sectionNodes.size())));
2296 
2298 }
2299 
2306 {
2307  const QLocale loc;
2311 }
2312 
2314 {
2315  switch (s & ~Internal) {
2320  case DayOfWeekSection:
2323  case YearSection2Digits:
2325  case Hour12Section:
2327  case FirstSection:
2328  case NoSection:
2329  case LastSection: break;
2330  }
2331  return QDateTimeEdit::NoSection;
2332 }
2333 
2334 QDateTimeEdit::Sections QDateTimeEditPrivate::convertSections(QDateTimeParser::Sections s)
2335 {
2336  QDateTimeEdit::Sections ret = 0;
2353 
2354  return ret;
2355 }
2356 
2362 {
2363  Q_D(QDateTimeEdit);
2364  if (!d->calendarPopupEnabled()) {
2366  return;
2367  }
2368 
2369  QStyleOptionSpinBox opt;
2370  initStyleOption(&opt);
2371 
2372  QStyleOptionComboBox optCombo;
2373 
2374  optCombo.init(this);
2375  optCombo.editable = true;
2376  optCombo.frame = opt.frame;
2377  optCombo.subControls = opt.subControls;
2378  optCombo.activeSubControls = opt.activeSubControls;
2379  optCombo.state = opt.state;
2380  if (d->readOnly) {
2381  optCombo.state &= ~QStyle::State_Enabled;
2382  }
2383 
2384  QPainter p(this);
2385  style()->drawComplexControl(QStyle::CC_ComboBox, &optCombo, &p, this);
2386 }
2387 
2389 {
2390  if (ap == AmText) {
2391  return (cs == UpperCase ? QDateTimeEdit::tr("AM") : QDateTimeEdit::tr("am"));
2392  } else {
2393  return (cs == UpperCase ? QDateTimeEdit::tr("PM") : QDateTimeEdit::tr("pm"));
2394  }
2395 }
2396 
2398 {
2399  for (int i=0; i<sectionNodes.size(); ++i) {
2400  if (convertToPublic(sectionNodes.at(i).type) == s && index-- == 0) {
2401  return i;
2402  }
2403  }
2404  return NoSectionIndex;
2405 }
2406 
2408 {
2409  return sectionNodes.indexOf(s);
2410 }
2411 
2413 {
2414  Q_Q(QDateTimeEdit);
2415  QString tmp = displayText();
2416  int pos = edit->cursorPosition();
2417  const QValidator::State state = q->validate(tmp, pos);
2418  if (state != QValidator::Acceptable
2421  setValue(value, ep);
2422  updateTimeSpec();
2423  } else {
2425  }
2426 }
2427 
2429 {
2431  cachedDay = -1;
2432 }
2433 
2442 {
2443  if (!option)
2444  return;
2445 
2446  Q_D(const QDateTimeEdit);
2448  if (d->calendarPopupEnabled()) {
2451  if (d->arrowState == QStyle::State_Sunken)
2452  option->state |= QStyle::State_Sunken;
2453  else
2454  option->state &= ~QStyle::State_Sunken;
2455  }
2456 }
2457 
2459 {
2460  Q_Q(QDateTimeEdit);
2461  switch (var.type()) {
2462  case QVariant::Date:
2464  q->setDisplayFormat(defaultDateFormat);
2465  if (sectionNodes.isEmpty()) // ### safeguard for broken locale
2466  q->setDisplayFormat(QLatin1String("dd/MM/yyyy"));
2467  break;
2468  case QVariant::DateTime:
2469  value = var;
2470  q->setDisplayFormat(defaultDateTimeFormat);
2471  if (sectionNodes.isEmpty()) // ### safeguard for broken locale
2472  q->setDisplayFormat(QLatin1String("dd/MM/yyyy hh:mm:ss"));
2473  break;
2474  case QVariant::Time:
2476  q->setDisplayFormat(defaultTimeFormat);
2477  if (sectionNodes.isEmpty()) // ### safeguard for broken locale
2478  q->setDisplayFormat(QLatin1String("hh:mm:ss"));
2479  break;
2480  default:
2481  Q_ASSERT_X(0, "QDateTimeEditPrivate::init", "Internal error");
2482  break;
2483  }
2484 #ifdef QT_KEYPAD_NAVIGATION
2485  if (QApplication::keypadNavigationEnabled())
2486  q->setCalendarPopup(true);
2487 #endif
2488  updateTimeSpec();
2489  q->setInputMethodHints(Qt::ImhPreferNumbers);
2491 }
2492 
2494 {
2496 }
2497 
2499 {
2500  Q_Q(QDateTimeEdit);
2501 
2502  if (arrowState == state)
2503  return;
2504  arrowState = state;
2506  buttonState |= Mouse;
2507  else {
2508  buttonState = 0;
2510  }
2511  q->update();
2512 }
2513 
2523 {
2524  if (!calendarPopupEnabled())
2526 
2527  Q_Q(QDateTimeEdit);
2528 
2529  QStyleOptionComboBox optCombo;
2530  optCombo.init(q);
2531  optCombo.editable = true;
2532  optCombo.subControls = QStyle::SC_All;
2533  hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ComboBox, &optCombo, pos, q);
2534  return hoverControl;
2535 }
2536 
2538 {
2539  if (!calendarPopupEnabled()) {
2541  return;
2542  }
2543 
2544  Q_Q(QDateTimeEdit);
2545 
2546  QStyleOptionComboBox optCombo;
2547  optCombo.init(q);
2548  optCombo.editable = true;
2550  edit->setGeometry(q->style()->subControlRect(QStyle::CC_ComboBox, &optCombo,
2552 }
2553 
2555 {
2558 }
2559 
2561 {
2564 }
2565 
2566 
2568 {
2569  if (!ke->text().isEmpty() && currentSectionIndex + 1 < sectionNodes.size() && currentSectionIndex >= 0) {
2571  if (ke->text().at(0).isNumber())
2572  return false;
2573  } else if (ke->text().at(0).isLetterOrNumber()) {
2574  return false;
2575  }
2576  return separators.at(currentSectionIndex + 1).contains(ke->text());
2577  }
2578  return false;
2579 }
2580 
2582 {
2583  Q_Q(QDateTimeEdit);
2584  if (!monthCalendar) {
2585  monthCalendar = new QCalendarPopup(q, cw);
2586  monthCalendar->setObjectName(QLatin1String("qt_datetimedit_calendar"));
2587  QObject::connect(monthCalendar, SIGNAL(newDateSelected(QDate)), q, SLOT(setDate(QDate)));
2588  QObject::connect(monthCalendar, SIGNAL(hidingCalendar(QDate)), q, SLOT(setDate(QDate)));
2589  QObject::connect(monthCalendar, SIGNAL(activated(QDate)), q, SLOT(setDate(QDate)));
2590  QObject::connect(monthCalendar, SIGNAL(activated(QDate)), monthCalendar, SLOT(close()));
2591  QObject::connect(monthCalendar, SIGNAL(resetButton()), q, SLOT(_q_resetButton()));
2592  } else if (cw) {
2594  }
2596 }
2597 
2599 {
2600  Q_Q(QDateTimeEdit);
2601  QPoint pos = (q->layoutDirection() == Qt::RightToLeft) ? q->rect().bottomRight() : q->rect().bottomLeft();
2602  QPoint pos2 = (q->layoutDirection() == Qt::RightToLeft) ? q->rect().topRight() : q->rect().topLeft();
2603  pos = q->mapToGlobal(pos);
2604  pos2 = q->mapToGlobal(pos2);
2605  QSize size = monthCalendar->sizeHint();
2607  //handle popup falling "off screen"
2608  if (q->layoutDirection() == Qt::RightToLeft) {
2609  pos.setX(pos.x()-size.width());
2610  pos2.setX(pos2.x()-size.width());
2611  if (pos.x() < screen.left())
2612  pos.setX(qMax(pos.x(), screen.left()));
2613  else if (pos.x()+size.width() > screen.right())
2614  pos.setX(qMax(pos.x()-size.width(), screen.right()-size.width()));
2615  } else {
2616  if (pos.x()+size.width() > screen.right())
2617  pos.setX(screen.right()-size.width());
2618  pos.setX(qMax(pos.x(), screen.left()));
2619  }
2620  if (pos.y() + size.height() > screen.bottom())
2621  pos.setY(pos2.y() - size.height());
2622  else if (pos.y() < screen.top())
2623  pos.setY(screen.top());
2624  if (pos.y() < screen.top())
2625  pos.setY(screen.top());
2626  if (pos.y()+size.height() > screen.bottom())
2627  pos.setY(screen.bottom()-size.height());
2628  monthCalendar->move(pos);
2629 }
2630 
2632 {
2633  return (calendarPopup && (sections & (DateSectionMask)));
2634 }
2635 
2637 {
2638  Q_Q(QDateTimeEdit);
2639  if (monthCalendar) {
2640  const bool sb = monthCalendar->blockSignals(true);
2641  monthCalendar->setDateRange(q->minimumDate(), q->maximumDate());
2642  monthCalendar->setDate(q->date());
2644  }
2645 }
2646 
2648  : QWidget(parent, Qt::Popup)
2649 {
2651 
2652  dateChanged = false;
2653  if (!cw) {
2655  } else {
2656  setCalendarWidget(cw);
2657  }
2658 }
2659 
2661 {
2662  if (calendar.isNull()) {
2663  QCalendarWidget *cw = new QCalendarWidget(this);
2665 #ifdef QT_KEYPAD_NAVIGATION
2666  if (QApplication::keypadNavigationEnabled())
2668 #endif
2669  setCalendarWidget(cw);
2670  return cw;
2671  } else {
2672  return calendar.data();
2673  }
2674 }
2675 
2677 {
2678  Q_ASSERT(cw);
2679  QVBoxLayout *widgetLayout = qobject_cast<QVBoxLayout*>(layout());
2680  if (!widgetLayout) {
2681  widgetLayout = new QVBoxLayout(this);
2682  widgetLayout->setMargin(0);
2683  widgetLayout->setSpacing(0);
2684  }
2685  delete calendar.data();
2687  widgetLayout->addWidget(cw);
2688 
2690  connect(cw, SIGNAL(clicked(QDate)), this, SLOT(dateSelected(QDate)));
2691  connect(cw, SIGNAL(selectionChanged()), this, SLOT(dateSelectionChanged()));
2692 
2693  cw->setFocus();
2694 }
2695 
2696 
2698 {
2699  oldDate = date;
2701 }
2702 
2703 void QCalendarPopup::setDateRange(const QDate &min, const QDate &max)
2704 {
2706  cw->setMinimumDate(min);
2707  cw->setMaximumDate(max);
2708 }
2709 
2711 {
2713  if (dateTime) {
2715  opt.init(dateTime);
2716  QRect arrowRect = dateTime->style()->subControlRect(QStyle::CC_ComboBox, &opt,
2717  QStyle::SC_ComboBoxArrow, dateTime);
2718  arrowRect.moveTo(dateTime->mapToGlobal(arrowRect .topLeft()));
2719  if (arrowRect.contains(event->globalPos()) || rect().contains(event->pos()))
2721  }
2722  QWidget::mousePressEvent(event);
2723 }
2724 
2726 {
2727  emit resetButton();
2728 }
2729 
2731 {
2732  if (event->type() == QEvent::KeyPress) {
2733  QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
2734  if (keyEvent->key()== Qt::Key_Escape)
2735  dateChanged = false;
2736  }
2737  return QWidget::event(event);
2738 }
2739 
2741 {
2742  dateChanged = true;
2744 }
2746 {
2747  dateChanged = true;
2748  emit activated(date);
2749  close();
2750 }
2751 
2753 {
2754  emit resetButton();
2755  if (!dateChanged)
2757 }
2758 
2760 #include "moc_qdatetimeedit.cpp"
2761 
2762 #endif // QT_NO_DATETIMEEDIT
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QPoint pos() const
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define QDATETIMEEDIT_DATE_MAX
Definition: qdatetime_p.h:71
void focusInEvent(QFocusEvent *event)
Reimplemented Function
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
QString getAmPmText(AmPm ap, Case cs) const
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
int selectionStart() const
selectionStart() returns the index of the first selected character in the line edit or -1 if no text ...
Definition: qlineedit.cpp:1039
bool blockSignals(bool b)
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke...
Definition: qobject.cpp:1406
The QKeyEvent class describes a key event.
Definition: qevent.h:224
SectionNode first
Definition: qdatetime_p.h:264
int absoluteMin(int index) const
Definition: qdatetime.cpp:4623
virtual void updateEditFieldGeometry()
void setDateTimeRange(const QDateTime &min, const QDateTime &max)
Convenience function to set minimum and maximum date time with one function call. ...
virtual void focusInEvent(QFocusEvent *event)
Reimplemented Function
virtual QStyle::SubControl newHoverControl(const QPoint &pos)
Returns the hover control at pos.
SubControl
This enum describes the available sub controls.
Definition: qstyle.h:402
bool isNull() const
Returns true if both the date and the time are null; otherwise returns false.
Definition: qdatetime.cpp:2334
virtual void keyPressEvent(QKeyEvent *event)
Reimplemented Function
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
StateNode parse(QString &input, int &cursorPosition, const QDateTime &currentValue, bool fixup) const
Definition: qdatetime.cpp:5271
QDateTime validateAndInterpret(QString &input, int &, QValidator::State &state, bool fixup=false) const
EventRef event
QSize size() const
QStyle::StateFlag arrowState
QDateTime stepBy(int index, int steps, bool test=false) const
Internal function called by QDateTimeEdit::stepBy().
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
#define QDATETIMEEDIT_DATE_INITIAL
Definition: qdatetime_p.h:75
void setMinimumDate(const QDate &date)
QLocale locale() const
#define QDATETIMEEDIT_COMPAT_DATETIME_MIN
Definition: qdatetime_p.h:73
bool calendarPopup() const
bool frame
whether the combo box has a frame
Definition: qstyleoption.h:804
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
static void keyEvent(KeyAction action, QWidget *widget, char ascii, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)
void initStyleOption(QStyleOptionSpinBox *option) const
Initialize option with the values from this QSpinBox.
bool isValid() const
Returns true if this date is valid; otherwise returns false.
Definition: qdatetime.cpp:340
void setMaximumTime(const QTime &max)
void setSelected(int index, bool forward=false)
Selects the section s.
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
QString timeFormat(FormatType format=LongFormat) const
Returns the time format used for the current locale.
Definition: qlocale.cpp:1535
void setCalendarWidget(QCalendarWidget *cw)
void init()
Initialises the QAbstractSpinBoxPrivate object.
The QWheelEvent class contains parameters that describe a wheel event.
Definition: qevent.h:139
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget=0) const =0
Returns the rectangle containing the specified subControl of the given complex control (with the styl...
void hideEvent(QHideEvent *)
This event handler can be reimplemented in a subclass to receive widget hide events.
static QSize globalStrut()
QVector< SectionNode > sectionNodes
Definition: qdatetime_p.h:263
The QCalendarWidget class provides a monthly based calendar widget allowing the user to select a date...
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
EmitPolicy
static C reverse(const C &l)
void setHorizontalHeaderFormat(HorizontalHeaderFormat format)
#define SLOT(a)
Definition: qobjectdefs.h:226
virtual void mousePressEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition: qwidget.cpp:9261
virtual void fixup(QString &input) const
Reimplemented Function
int absoluteMax(int index, const QDateTime &value=QDateTime()) const
\
Definition: qdatetime.cpp:4590
void clearMaximumDateTime()
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
void clearSection(int index)
Clears the text of section s.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
Definition: qvariant.cpp:2349
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:187
QDateTimeEdit::Sections sections
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
void keyPressEvent(QKeyEvent *event)
This function handles keyboard input.
void updateArrow(QStyle::StateFlag state)
int day() const
Returns the day of the month (1 to 31) of this date.
Definition: qdatetime.cpp:395
void setDateTime(const QDateTime &dateTime)
void init(const QWidget *w)
Use initFrom(widget) instead.
bool isValid() const
Returns true if both the date and the time are valid; otherwise returns false.
Definition: qdatetime.cpp:2346
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
void wheelEvent(QWheelEvent *event)
Reimplemented Function
The QDate class provides date functions.
Definition: qdatetime.h:55
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void clearMaximumDate()
virtual QString displayText() const
virtual void updateEditFieldGeometry()
QString textFromValue(const QVariant &f) const
void moveTo(int x, int t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
Definition: qrect.h:334
QStyle::SubControls activeSubControls
This variable holds a bitwise OR of the sub-controls that are active for the complex control...
Definition: qstyleoption.h:694
bool isSeparatorKey(const QKeyEvent *k) const
void setMinimumDate(const QDate &min)
bool editable
whether or not the combobox is editable or not
Definition: qstyleoption.h:802
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
void setMaximumDate(const QDate &date)
void setMaximumDateTime(const QDateTime &dt)
#define QDATETIMEEDIT_TIME_MIN
Definition: qdatetime_p.h:67
void mousePressEvent(QMouseEvent *event)
Reimplemented Function
void initStyleOption(QStyleOptionSpinBox *option) const
Initialize option with the values from this QDataTimeEdit.
bool isNull() const
Returns true if this object is holding a reference to a null pointer.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QDateTimeEdit::Sections convertSections(QDateTimeParser::Sections s)
void setLayoutItemMargins(int left, int top, int right, int bottom)
Definition: qwidget.cpp:12860
SectionNode last
Definition: qdatetime_p.h:264
#define Q_D(Class)
Definition: qglobal.h:2482
Section currentSection() const
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=0)
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment...
T * data() const
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
virtual void wheelEvent(QWheelEvent *event)
Reimplemented Function
QString toString(qlonglong i) const
Returns a localized string representation of i.
Definition: qlocale.cpp:1295
bool frame
whether the spin box has a frame
Definition: qstyleoption.h:737
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int nextPrevSection(int index, bool forward) const
Returns a copy of the section that is before or after current, depending on forward.
void dateSelectionChanged()
virtual QSize sizeHint() const
void dateSelected(const QDate &date)
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
void resetButton()
QStyle * style() const
Definition: qwidget.cpp:2742
The QDateTimeEdit class provides a widget for editing dates and times.
Definition: qdatetimeedit.h:61
void setMaximumDate(const QDate &max)
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
QString sectionText(Section section) const
Returns the text from the given section.
void setCurrentSection(Section section)
QCalendarWidget * verifyCalendarInstance()
TimeSpec
Definition: qnamespace.h:1404
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
void newDateSelected(const QDate &newDate)
virtual void stepBy(int steps)
Reimplemented Function
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void emitSignals(EmitPolicy ep, const QVariant &old)
bool event(QEvent *event)
Reimplemented Function
int width() const
Returns the width.
Definition: qsize.h:126
QCalendarPopup(QWidget *parent=0, QCalendarWidget *cw=0)
void clearMinimumDate()
#define QDTEDEBUG
static QDateTimeEdit::Section convertToPublic(QDateTimeParser::Section s)
The QTime class provides clock time functions.
Definition: qdatetime.h:148
void setDateRange(const QDate &min, const QDate &max)
Convenience function to set minimum and maximum date with one function call.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual void paintEvent(QPaintEvent *event)
Reimplemented Function
void setDateRange(const QDate &min, const QDate &max)
virtual QVariant getZeroVariant() const
Convenience function to get a variant of the right type.
virtual void interpret(EmitPolicy ep)
Interprets text and emits signals.
QString sectionName(int s) const
For debugging.
Definition: qdatetime.cpp:6044
QStyle::SubControl hoverControl
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
QValidator::State cachedState
QDateTimeEdit(QWidget *parent=0)
Constructs an empty date time editor with a parent.
void setCalendarPopup(bool enable)
QString dateTimeFormat(FormatType format=LongFormat) const
Returns the date time format used for the current locale.
Definition: qlocale.cpp:1575
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int sectionSize(int index) const
Returns the size of section s.
Definition: qdatetime.cpp:4943
void initCalendarPopup(QCalendarWidget *cw=0)
void setDate(const QDate &date)
virtual QValidator::State validate(QString &input, int &pos) const
Reimplemented Function
QString text
the line edit&#39;s text
Definition: qlineedit.h:72
The QStyleOptionSpinBox class is used to describe the parameters necessary for drawing a spin box...
Definition: qstyleoption.h:729
virtual QDateTime dateTimeFromText(const QString &text) const
Returns an appropriate datetime for the given text.
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
void setSelection(int, int)
Selects text from position start and for length characters.
Definition: qlineedit.cpp:1106
virtual void setRange(const QVariant &min, const QVariant &max)
Convenience function to set min/max values.
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition: qevent.h:388
void setSelectedSection(Section section)
Selects section.
void * unused
Definition: qobject_p.h:208
void selectAll()
Selects all the text in the spinbox except the prefix and suffix.
QFontMetrics fontMetrics() const
Returns the font metrics for the widget&#39;s current font.
Definition: qwidget.h:984
const SectionNode & sectionNode(int index) const
Returns the sectionNode for the Section s.
Definition: qdatetime.cpp:4654
Q_CORE_EXPORT void qWarning(const char *,...)
void setSize(const QSize &s)
Sets the size of the rectangle to the given size.
Definition: qrect.h:448
void clearMaximumTime()
void editingFinished()
This signal is emitted editing is finished.
bool calendarPopupEnabled() const
Section sectionAt(int index) const
Returns the Section at index.
int absoluteIndex(QDateTimeEdit::Section s, int index) const
void setCalendarWidget(QCalendarWidget *calendarWidget)
Sets the given calendarWidget as the widget to be used for the calendar pop-up.
void activated(const QDate &date)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
void mouseReleaseEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
virtual void interpret(EmitPolicy ep)
Interprets text and emits signals.
void setDisplayFormat(const QString &format)
void clearMinimumDateTime()
QTime minimumTime() const
void setTimeSpec(Qt::TimeSpec spec)
int getDigit(const QDateTime &dt, int index) const
Gets the digit from a datetime.
Definition: qdatetime.cpp:4469
The QAbstractSpinBox class provides a spinbox and a line edit to display values.
int minute() const
Returns the minute part (0 to 59) of the time.
Definition: qdatetime.cpp:1589
virtual void _q_editorCursorPositionChanged(int oldpos, int newpos)
#define QDATETIMEEDIT_TIME_MAX
Definition: qdatetime_p.h:68
virtual void setRange(const QVariant &min, const QVariant &max)
Convenience function to set min/max values.
virtual void mousePressEvent(QMouseEvent *event)
Reimplemented Function
QStringList separators
Definition: qdatetime_p.h:265
int sectionCount() const
QRect rect() const
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
QString text() const
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
void setTime(const QTime &time)
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=0) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
virtual QStyle::SubControl newHoverControl(const QPoint &pos)
Returns the hover control at pos.
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
void setText(const QString &)
Definition: qlineedit.cpp:401
#define QDATETIMEEDIT_DATE_MIN
Definition: qdatetime_p.h:69
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
QTimeEdit(QWidget *parent=0)
Constructs an empty time editor with a parent.
int daysInMonth() const
Returns the number of days in the month (28 to 31) for this date.
Definition: qdatetime.cpp:431
QTime time() const
void setFocus()
Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its paren...
Definition: qwidget.h:432
Qt::TimeSpec spec
Definition: qdatetime_p.h:272
QDate toDate() const
Returns the variant as a QDate if the variant has type() Date , DateTime , or String ; otherwise retu...
Definition: qvariant.cpp:2311
QDate maximumDate() const
QSize sizeHint() const
Reimplemented Function
QString selectedText
the selected text
Definition: qlineedit.h:81
void clear()
Convert this variant to type Invalid and free up any resources used.
Definition: qvariant.cpp:1993
void setY(int y)
Sets the y coordinate of this point to the given y coordinate.
Definition: qpoint.h:137
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
QDateTime addDays(int days) const
Returns a QDateTime object containing a datetime ndays days later than the datetime of this object (o...
Definition: qdatetime.cpp:2783
void mousePressEvent(QMouseEvent *e)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
#define QDATETIMEEDIT_COMPAT_DATE_MIN
Definition: qdatetime_p.h:70
void updateEdit()
Updates the line edit to reflect the current value of the spin box.
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
virtual bool focusNextPrevChild(bool next)
Reimplemented Function
virtual QVariant bound(const QVariant &val, const QVariant &old=QVariant(), int steps=0) const
Bounds val to be within minimum and maximum.
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
QDateTime maximumDateTime() const
bool hasSelectedText
whether there is any text selected
Definition: qlineedit.h:80
QDate date() const
Qt::TimeSpec timeSpec() const
QString text() const
Returns the Unicode text that this key generated.
Definition: qevent.h:236
void setSelectedDate(const QDate &date)
Section sectionType(int index) const
Definition: qdatetime.cpp:4674
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
bool setDigit(QDateTime &t, int index, int newval) const
Sets a digit in a datetime.
Definition: qdatetime.cpp:4520
QAbstractSpinBox::CorrectionMode correctionMode
void setSpacing(int spacing)
Reimplements QLayout::setSpacing().
Definition: qboxlayout.cpp:667
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
virtual void clearCache() const
bool event(QEvent *e)
This is the main event handler; it handles event event.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void setVerticalHeaderFormat(VerticalHeaderFormat format)
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
virtual bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can&#39;t.
Definition: qwidget.cpp:6836
QString displayFormat() const
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
QCalendarWidget * calendarWidget() const
Returns the calendar widget for the editor if calendarPopup is set to true and (sections() & DateSect...
The QStyleOptionComboBox class is used to describe the parameter for drawing a combobox.
Definition: qstyleoption.h:796
void setMinimumDateTime(const QDateTime &dt)
State
This enum type defines the states in which a validated string can exist.
Definition: qvalidator.h:67
QDate minimumDate() const
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
QFactoryLoader * l
Qt::FocusReason reason()
Definition: qevent.cpp:1197
QTime maximumTime() const
void setValue(const QVariant &val, EmitPolicy ep, bool updateEdit=true)
Sets the value of the spin box to val.
virtual void clearCache() const
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
Sections displayedSections() const
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
quint16 index
int currentSectionIndex() const
QObject * parent
Definition: qobject.h:92
virtual void clear()
Reimplemented Function
void setTimeRange(const QTime &min, const QTime &max)
Convenience function to set minimum and maximum time with one function call.
QCalendarPopup * monthCalendar
SectionNode none
Definition: qdatetime_p.h:264
QDateTime minimumDateTime() const
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
void paintEvent(QPaintEvent *event)
Reimplemented Function
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool isRightToLeft() const
Definition: qwidget.h:428
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368
QDateTime toTimeSpec(Qt::TimeSpec spec) const
Returns a copy of this datetime configured to use the given time specification.
Definition: qdatetime.cpp:2969
bool close()
Closes this widget.
Definition: qwidget.cpp:8305
QTime toTime() const
Returns the variant as a QTime if the variant has type() Time , DateTime , or String ; otherwise retu...
Definition: qvariant.cpp:2330
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
void setCurrentSectionIndex(int index)
bool event(QEvent *event)
Reimplemented Function
const QRect availableGeometry(int screen=-1) const
The QVBoxLayout class lines up widgets vertically.
Definition: qboxlayout.h:149
void setCursorPosition(int)
Definition: qlineedit.cpp:758
QPointer< QInputContext > ic
Definition: qwidget_p.h:717
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
int sectionAt(int pos) const
Returns the section at index index or NoSection if there are no sections there.
virtual QString textFromDateTime(const QDateTime &dt) const
This virtual function is used by the date time edit whenever it needs to display dateTime.
void selectAll()
Selects all the text (i.e.
Definition: qlineedit.cpp:1405
void setMinimumTime(const QTime &min)
QWeakPointer< QCalendarWidget > calendar
QString dateFormat(FormatType format=LongFormat) const
Returns the date format used for the current locale.
Definition: qlocale.cpp:1495
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
FieldInfo fieldInfo(int index) const
Definition: qdatetime.cpp:5868
void setMargin(int)
Definition: qlayout.cpp:464
void clearMinimumTime()
QDateTime dateTime() const
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define qPrintable(string)
Definition: qglobal.h:1750
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
const QPoint & globalPos() const
Returns the global position of the mouse cursor at the time of the event.
Definition: qevent.h:96
void setX(int x)
Sets the x coordinate of this point to the given x coordinate.
Definition: qpoint.h:134
int sectionPos(int index) const
Returns the starting position for section s.
Definition: qdatetime.cpp:4689
void setDate(const QDate &date)
virtual StepEnabled stepEnabled() const
Reimplemented Function
StateFlag
This enum describes flags that are used when drawing primitive elements.
Definition: qstyle.h:103
QChar toLower() const
Returns the lowercase equivalent if the character is uppercase or titlecase; otherwise returns the ch...
Definition: qchar.cpp:1239
QVariant valueFromText(const QString &f) const
This function&#39;s name is slightly confusing; it is not to be confused with QAbstractSpinBox::valueFrom...
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool specialValue() const
Returns true if a specialValueText has been set and the current value is minimum. ...
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
bool isNumber() const
Returns true if the character is a number (Number_* categories, not just 0-9); otherwise returns fals...
Definition: qchar.cpp:669
QStyle::SubControls subControls
This variable holds a bitwise OR of the sub-controls to be drawn for the complex control.
Definition: qstyleoption.h:693
void hidingCalendar(const QDate &oldDate)
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
int cursorPosition
the current cursor position for this line edit
Definition: qlineedit.h:77
#define QDATETIMEEDIT_DATETIME_MAX
Definition: qdatetime_p.h:74
QDateEdit(QWidget *parent=0)
Constructs an empty date editor with a parent.
void move(int x, int y)
This corresponds to move(QPoint(x, y)).
Definition: qwidget.h:1011
bool isValid() const
Returns true if the time is valid; otherwise returns false.
Definition: qdatetime.cpp:1566
int hour() const
Returns the hour part (0 to 23) of the time.
Definition: qdatetime.cpp:1578
bool isLetterOrNumber() const
Returns true if the character is a letter or number (Letter_* or Number_* categories); otherwise retu...
Definition: qchar.cpp:681
void updateCache(const QVariant &val, const QString &str) const
int closestSection(int index, bool forward) const
Returns the closest section of index index.
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288