930void QDateTimeEdit::setDisplayFormat(
const QString &format)
933 if (d->parseFormat(format)) {
934 d->unreversedFormat.clear();
935 if (isRightToLeft()) {
936 d->unreversedFormat = format;
937 d->displayFormat.clear();
938 for (
int i=d->sectionNodes.size() - 1; i>=0; --i) {
939 d->displayFormat += d->separators.at(i + 1);
940 d->displayFormat += d->sectionNode(i).format();
942 d->displayFormat += d->separators.at(0);
943 std::reverse(d->separators.begin(), d->separators.end());
944 std::reverse(d->sectionNodes.begin(), d->sectionNodes.end());
947 d->formatExplicitlySet =
true;
948 d->sections = QDateTimeEditPrivate::convertSections(d->display);
951 d->currentSectionIndex = qMin(d->currentSectionIndex, d->sectionNodes.size() - 1);
952 const bool timeShown = (d->sections & TimeSections_Mask);
953 const bool dateShown = (d->sections & DateSections_Mask);
954 Q_ASSERT(dateShown || timeShown);
955 if (timeShown && !dateShown) {
956 QTime time = d->value.toTime();
957 setDateRange(d->value.toDate(), d->value.toDate());
958 if (d->minimum.toTime() >= d->maximum.toTime()) {
959 setTimeRange(QDATETIMEEDIT_TIME_MIN, QDATETIMEEDIT_TIME_MAX);
963 }
else if (dateShown && !timeShown) {
964 setTimeRange(QDATETIMEEDIT_TIME_MIN, QDATETIMEEDIT_TIME_MAX);
965 d->value = d->value.toDate().startOfDay(d->timeZone);
968 d->editorCursorPositionChanged(-1, 0);
1075QSize QDateTimeEdit::sizeHint()
const
1077 Q_D(
const QDateTimeEdit);
1078 if (d->cachedSizeHint.isEmpty()) {
1081 const QFontMetrics fm(fontMetrics());
1082 int h = d->edit->sizeHint().height();
1085 s = d->textFromValue(d->minimum) + u' ';
1086 w = qMax<
int>(w, fm.horizontalAdvance(s));
1087 s = d->textFromValue(d->maximum) + u' ';
1088 w = qMax<
int>(w, fm.horizontalAdvance(s));
1089 if (d->specialValueText.size()) {
1090 s = d->specialValueText;
1091 w = qMax<
int>(w, fm.horizontalAdvance(s));
1096 QStyleOptionSpinBox opt;
1097 initStyleOption(&opt);
1098 d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint,
this);
1099 if (d->calendarPopupEnabled()) {
1100 QStyleOptionComboBox optCbx;
1101 optCbx.initFrom(
this);
1102 optCbx.frame = d->frame;
1103 d->cachedSizeHint.rwidth() =
1104 style()->sizeFromContents(QStyle::CT_ComboBox, &optCbx, hint,
this).width();
1107 d->cachedMinimumSizeHint = d->cachedSizeHint;
1110 return d->cachedSizeHint;
1157void QDateTimeEdit::keyPressEvent(QKeyEvent *event)
1160 int oldCurrent = d->currentSectionIndex;
1162 bool inserted =
false;
1164 switch (event->key()) {
1165#ifdef QT_KEYPAD_NAVIGATION
1166 case Qt::Key_NumberSign:
1167 if (QApplicationPrivate::keypadNavigationEnabled() && d->calendarPopupEnabled()) {
1168 d->initCalendarPopup();
1169 d->positionCalendarPopup();
1170 d->monthCalendar->show();
1174 case Qt::Key_Select:
1175 if (QApplicationPrivate::keypadNavigationEnabled()) {
1176 if (hasEditFocus()) {
1177 if (d->focusOnButton) {
1178 d->initCalendarPopup();
1179 d->positionCalendarPopup();
1180 d->monthCalendar->show();
1181 d->focusOnButton =
false;
1184 setEditFocus(
false);
1190 d->edit->d_func()->setCursorVisible(
false);
1191 d->edit->d_func()->control->setBlinkingCursorEnabled(
false);
1198 case Qt::Key_Return:
1199 d->interpret(AlwaysEmit);
1200 d->setSelected(d->currentSectionIndex,
true);
1202 emit editingFinished();
1203 emit d->edit->returnPressed();
1206#ifdef QT_KEYPAD_NAVIGATION
1207 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()
1208 && !event->text().isEmpty() && event->text().at(0).isLetterOrNumber()) {
1212 d->edit->d_func()->setCursorVisible(
false);
1213 d->edit->d_func()->control->setBlinkingCursorEnabled(
false);
1218 if (!d->isSeparatorKey(event)) {
1219 inserted = select = !event->text().isEmpty() && event->text().at(0).isPrint()
1220 && !(event->modifiers() & ~(Qt::ShiftModifier|Qt::KeypadModifier));
1226 if (event->key() == Qt::Key_Left || event->key() == Qt::Key_Right) {
1228#ifdef QT_KEYPAD_NAVIGATION
1229 QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()
1230 || !QApplicationPrivate::keypadNavigationEnabled() &&
1232 !(event->modifiers() & Qt::ControlModifier)) {
1238 case Qt::Key_Backtab:
1241 if (d->specialValue()) {
1242 d->edit->setSelection(d->edit->cursorPosition(), 0);
1245 const bool forward = event->key() != Qt::Key_Left && event->key() != Qt::Key_Backtab
1246 && (event->key() != Qt::Key_Tab || !(event->modifiers() & Qt::ShiftModifier));
1247#ifdef QT_KEYPAD_NAVIGATION
1248 int newSection = d->nextPrevSection(d->currentSectionIndex, forward);
1249 if (QApplicationPrivate::keypadNavigationEnabled()) {
1250 if (d->focusOnButton) {
1251 newSection = forward ? 0 : d->sectionNodes.size() - 1;
1252 d->focusOnButton =
false;
1254 }
else if (newSection < 0 && select && d->calendarPopupEnabled()) {
1255 setSelectedSection(NoSection);
1256 d->focusOnButton =
true;
1262 if (newSection & ~(QDateTimeParser::TimeSectionMask | QDateTimeParser::DateSectionMask))
1266 if (event->key() != Qt::Key_Backtab && event->key() != Qt::Key_Tab)
1267 focusNextPrevChild(forward);
1271 QAbstractSpinBox::keyPressEvent(event);
1272 if (select && !d->edit->hasSelectedText()) {
1273 if (inserted && d->sectionAt(d->edit->cursorPosition()) == QDateTimeParser::NoSectionIndex) {
1274 QString str = d->displayText();
1275 int pos = d->edit->cursorPosition();
1276 if (validate(str, pos) == QValidator::Acceptable
1277 && (d->sectionNodes.at(oldCurrent).count != 1
1278 || d->sectionMaxSize(oldCurrent) == d->sectionSize(oldCurrent)
1279 || d->skipToNextSection(oldCurrent, d->value.toDateTime(), d->sectionText(oldCurrent)))) {
1280 QDTEDEBUG <<
"Setting currentsection to"
1281 << d->closestSection(d->edit->cursorPosition(),
true) << event->key()
1282 << oldCurrent << str;
1283 const int tmp = d->closestSection(d->edit->cursorPosition(),
true);
1285 d->currentSectionIndex = tmp;
1288 if (d->currentSectionIndex != oldCurrent) {
1289 d->setSelected(d->currentSectionIndex);
1292 if (d->specialValue()) {
1293 d->edit->setSelection(d->edit->cursorPosition(), 0);
1312void QDateTimeEdit::focusInEvent(QFocusEvent *event)
1315 QAbstractSpinBox::focusInEvent(event);
1316 const int oldPos = d->edit->cursorPosition();
1317 if (!d->formatExplicitlySet) {
1318 QString *frm =
nullptr;
1319 if (d->displayFormat == d->defaultTimeFormat) {
1320 frm = &d->defaultTimeFormat;
1321 }
else if (d->displayFormat == d->defaultDateFormat) {
1322 frm = &d->defaultDateFormat;
1323 }
else if (d->displayFormat == d->defaultDateTimeFormat) {
1324 frm = &d->defaultDateTimeFormat;
1328 d->readLocaleSettings();
1329 if (d->displayFormat != *frm) {
1330 setDisplayFormat(*frm);
1331 d->formatExplicitlySet =
false;
1332 d->edit->setCursorPosition(oldPos);
1336 const bool oldHasHadFocus = d->hasHadFocus;
1337 d->hasHadFocus =
true;
1339 switch (event->reason()) {
1340 case Qt::BacktabFocusReason:
1343 case Qt::MouseFocusReason:
1344 case Qt::PopupFocusReason:
1346 case Qt::ActiveWindowFocusReason:
1350 case Qt::ShortcutFocusReason:
1351 case Qt::TabFocusReason:
1355 if (isRightToLeft())
1359 d->setSelected(first ? 0 : d->sectionNodes.size() - 1);
1388void QDateTimeEdit::stepBy(
int steps)
1391#ifdef QT_KEYPAD_NAVIGATION
1393 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
1395 if (d->sections & DateSections_Mask) {
1396 setDateTime(dateTime().addDays(steps));
1398 int minutes = time().hour()*60 + time().minute();
1399 int blocks = minutes/15;
1408 minutes = blocks * 15;
1412 int max_minutes = d->maximum.toTime().hour()*60 + d->maximum.toTime().minute();
1413 int min_minutes = d->minimum.toTime().hour()*60 + d->minimum.toTime().minute();
1415 if (minutes >= max_minutes) {
1416 setTime(maximumTime());
1418 }
else if (minutes <= min_minutes) {
1419 setTime(minimumTime());
1423 setTime(QTime(minutes/60, minutes%60));
1430 if (d->specialValue() && displayedSections() != AmPmSection) {
1431 for (
int i=0; i<d->sectionNodes.size(); ++i) {
1432 if (d->sectionType(i) != QDateTimeParser::AmPmSection) {
1433 d->currentSectionIndex = i;
1438 d->setValue(d->stepBy(d->currentSectionIndex, steps,
false), EmitIfChanged);
1439 d->updateCache(d->value, d->displayText());
1441 d->setSelected(d->currentSectionIndex);
1442 d->updateTimeZone();
1513QDateTimeEdit::StepEnabled QDateTimeEdit::stepEnabled()
const
1515 Q_D(
const QDateTimeEdit);
1518 if (d->specialValue()) {
1519 return (d->minimum == d->maximum ? StepEnabled{} : StepEnabled(StepUpEnabled));
1522 QAbstractSpinBox::StepEnabled ret = { };
1524#ifdef QT_KEYPAD_NAVIGATION
1525 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
1527 return StepEnabled(StepUpEnabled | StepDownEnabled);
1530 QVariant max, min, val;
1531 if (!(d->sections & DateSections_Mask)) {
1533 max = d->maximum.toTime();
1534 min = d->minimum.toTime();
1535 val = d->value.toTime();
1536 }
else if (!(d->sections & TimeSections_Mask)) {
1538 max = d->maximum.toDate();
1539 min = d->minimum.toDate();
1540 val = d->value.toDate();
1548 ret |= QAbstractSpinBox::StepDownEnabled;
1550 ret |= QAbstractSpinBox::StepUpEnabled;
1554 switch (d->sectionType(d->currentSectionIndex)) {
1555 case QDateTimeParser::NoSection:
1556 case QDateTimeParser::FirstSection:
1557 case QDateTimeParser::LastSection:
return { };
1561 return StepEnabled(StepDownEnabled|StepUpEnabled);
1563 QVariant v = d->stepBy(d->currentSectionIndex, 1,
true);
1564 if (v != d->value) {
1565 ret |= QAbstractSpinBox::StepUpEnabled;
1567 v = d->stepBy(d->currentSectionIndex, -1,
true);
1568 if (v != d->value) {
1569 ret |= QAbstractSpinBox::StepDownEnabled;
1913int QDateTimeEditPrivate::closestSection(
int pos,
bool forward)
const
1916 if (pos < separators.first().size())
1917 return forward ? 0 : FirstSectionIndex;
1919 const QString text = displayText();
1920 if (text.size() - pos < separators.last().size() + 1)
1921 return forward ? LastSectionIndex :
int(sectionNodes.size() - 1);
1923 updateCache(value, text);
1924 for (
int i=0; i<sectionNodes.size(); ++i) {
1925 const int tmp = sectionPos(sectionNodes.at(i));
1926 if (pos < tmp + sectionSize(i)) {
1927 if (pos < tmp && !forward) {
1931 }
else if (i == sectionNodes.size() - 1 && pos > tmp) {
1935 qWarning(
"QDateTimeEdit: Internal Error: closestSection returned NoSection");
1936 return NoSectionIndex;
2018QDateTime QDateTimeEditPrivate::validateAndInterpret(QString &input,
int &position,
2019 QValidator::State &state,
bool fixup)
const
2021 if (input.isEmpty()) {
2022 if (sectionNodes.size() == 1 || !specialValueText.isEmpty()) {
2023 state = QValidator::Intermediate;
2025 state = QValidator::Invalid;
2027 return getZeroVariant().toDateTime();
2028 }
else if (cachedText == input && !fixup) {
2029 state = cachedState;
2030 return cachedValue.toDateTime();
2031 }
else if (!specialValueText.isEmpty()) {
2032 bool changeCase =
false;
2033 const int max = qMin(specialValueText.size(), input.size());
2035 for (i=0; i<max; ++i) {
2036 const QChar ic = input.at(i);
2037 const QChar sc = specialValueText.at(i);
2039 if (sc.toLower() == ic.toLower()) {
2047 state = specialValueText.size() == input.size() ? QValidator::Acceptable : QValidator::Intermediate;
2049 input = specialValueText.left(max);
2051 return minimum.toDateTime();
2055 StateNode tmp = parse(input, position, value.toDateTime(), fixup);
2061 tmp.value = tmp.value.toTimeZone(timeZone);
2063 if (!tmp.value.isValid() && tmp.state == Acceptable)
2064 tmp.state = Intermediate;
2066 position += tmp.padded;
2067 state = QValidator::State(
int(tmp.state));
2068 if (state == QValidator::Acceptable) {
2069 if (tmp.conflicts && conflictGuard != tmp.value) {
2070 conflictGuard = tmp.value;
2072 input = textFromValue(tmp.value);
2073 updateCache(tmp.value, input);
2074 conflictGuard.clear();
2077 cachedState = state;
2078 cachedValue = tmp.value;
2083 return (tmp.value.isNull() ? getZeroVariant().toDateTime() : tmp.value);
2121QDateTime QDateTimeEditPrivate::stepBy(
int sectionIndex,
int steps,
bool test)
const
2123 Q_Q(
const QDateTimeEdit);
2124 QDateTime v = value.toDateTime();
2125 QString str = displayText();
2126 int pos = edit->cursorPosition();
2127 const SectionNode sn = sectionNode(sectionIndex);
2130 if (!test && pendingEmit && q->validate(str, pos) == QValidator::Acceptable)
2131 v = q->dateTimeFromText(str);
2132 int val = getDigit(v, sectionIndex);
2134 const int min = absoluteMin(sectionIndex);
2135 const int max = absoluteMax(sectionIndex, value.toDateTime());
2137 if (sn.type & DayOfWeekSectionMask) {
2140#ifndef QT_ALWAYS_WRAP_WEEKDAY
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152 const int first =
int(locale().firstDayOfWeek());
2153 val = qBound(val < first ? first - 7 : first,
2155 val < first ? first - 1 : first + 6);
2168 const int span = max - min + 1;
2170 val = wrapping ? val + span : min;
2172 val = wrapping ? val - span : max;
2175 const int oldDay = v.date().day(calendar);
2178
2179
2180
2181
2182 if (setDigit(v, sectionIndex, val) && getDigit(v, sectionIndex) != val
2183 && sn.type & HourSectionMask && steps < 0) {
2185 auto msecsSinceEpoch = v.toMSecsSinceEpoch() - 3600 * 1000;
2186 v = QDateTime::fromMSecsSinceEpoch(msecsSinceEpoch, v.timeRepresentation());
2191 const QDateTime minimumDateTime = minimum.toDateTime();
2192 const QDateTime maximumDateTime = maximum.toDateTime();
2194 if (sn.type != AmPmSection && !(sn.type & DayOfWeekSectionMask)
2195 && (v < minimumDateTime || v > maximumDateTime)) {
2196 const int localmin = getDigit(minimumDateTime, sectionIndex);
2197 const int localmax = getDigit(maximumDateTime, sectionIndex);
2203 setDigit(v, sectionIndex, min);
2204 if (!(sn.type & DaySectionMask) && sections & DateSectionMask) {
2205 const int daysInMonth = v.date().daysInMonth(calendar);
2206 if (v.date().day(calendar) < oldDay && v.date().day(calendar) < daysInMonth) {
2207 const int adds = qMin(oldDay, daysInMonth);
2208 v = v.addDays(adds - v.date().day(calendar));
2212 if (v < minimumDateTime) {
2213 setDigit(v, sectionIndex, localmin);
2214 if (v < minimumDateTime)
2215 setDigit(v, sectionIndex, localmin + 1);
2218 setDigit(v, sectionIndex, max);
2219 if (!(sn.type & DaySectionMask) && sections & DateSectionMask) {
2220 const int daysInMonth = v.date().daysInMonth(calendar);
2221 if (v.date().day(calendar) < oldDay && v.date().day(calendar) < daysInMonth) {
2222 const int adds = qMin(oldDay, daysInMonth);
2223 v = v.addDays(adds - v.date().day(calendar));
2227 if (v > maximumDateTime) {
2228 setDigit(v, sectionIndex, localmax);
2229 if (v > maximumDateTime)
2230 setDigit(v, sectionIndex, localmax - 1);
2234 setDigit(v, sectionIndex, (steps > 0 ? localmax : localmin));
2237 if (!test && oldDay != v.date().day(calendar) && !(sn.type & DaySectionMask)) {
2239 cachedDay = qMax<
int>(oldDay, cachedDay);
2242 if (v < minimumDateTime) {
2245 setDigit(t, sectionIndex, steps < 0 ? max : min);
2246 bool mincmp = (t >= minimumDateTime);
2247 bool maxcmp = (t <= maximumDateTime);
2248 if (!mincmp || !maxcmp) {
2249 setDigit(t, sectionIndex, getDigit(steps < 0
2251 : minimumDateTime, sectionIndex));
2252 mincmp = (t >= minimumDateTime);
2253 maxcmp = (t <= maximumDateTime);
2255 if (mincmp && maxcmp) {
2259 v = value.toDateTime();
2261 }
else if (v > maximumDateTime) {
2264 setDigit(t, sectionIndex, steps > 0 ? min : max);
2265 bool mincmp = (t >= minimumDateTime);
2266 bool maxcmp = (t <= maximumDateTime);
2267 if (!mincmp || !maxcmp) {
2268 setDigit(t, sectionIndex, getDigit(steps > 0 ?
2270 maximumDateTime, sectionIndex));
2271 mincmp = (t >= minimumDateTime);
2272 maxcmp = (t <= maximumDateTime);
2274 if (mincmp && maxcmp) {
2278 v = value.toDateTime();
2282 return bound(v, value, steps).toDateTime().toTimeZone(timeZone);
2318void QDateTimeEditPrivate::editorCursorPositionChanged(
int oldpos,
int newpos)
2320 if (ignoreCursorPositionChanged || specialValue())
2322 const QString oldText = displayText();
2323 updateCache(value, oldText);
2325 const bool allowChange = !edit->hasSelectedText();
2326 const bool forward = oldpos <= newpos;
2327 ignoreCursorPositionChanged =
true;
2328 int s = sectionAt(newpos);
2329 if (s == NoSectionIndex && forward && newpos > 0) {
2330 s = sectionAt(newpos - 1);
2335 const int selstart = edit->selectionStart();
2336 const int selSection = sectionAt(selstart);
2337 const int l = selSection != -1 ? sectionSize(selSection) : 0;
2339 if (s == NoSectionIndex) {
2340 if (l > 0 && selstart == sectionPos(selSection) && edit->selectedText().size() == l) {
2343 setSelected(selSection,
true);
2346 int closest = closestSection(newpos, forward);
2347 c = sectionPos(closest) + (forward ? 0 : qMax<
int>(0, sectionSize(closest)));
2350 edit->setCursorPosition(c);
2357 if (allowChange && currentSectionIndex != s) {
2358 interpret(EmitIfChanged);
2361 setSelected(s,
true);
2362 }
else if (!edit->hasSelectedText()) {
2363 if (oldpos < newpos) {
2364 edit->setCursorPosition(displayText().size() - (oldText.size() - c));
2366 edit->setCursorPosition(c);
2370 QDTEDEBUG <<
"currentSectionIndex is set to" << sectionNode(s).name()
2372 <<
"was" << sectionNode(currentSectionIndex).name();
2374 currentSectionIndex = s;
2375 Q_ASSERT_X(currentSectionIndex < sectionNodes.size(),
2376 "QDateTimeEditPrivate::editorCursorPositionChanged()",
2377 qPrintable(QString::fromLatin1(
"Internal error (%1 %2)").
2378 arg(currentSectionIndex).
2379 arg(sectionNodes.size())));
2381 ignoreCursorPositionChanged =
false;
2419QDateTimeEdit::Sections QDateTimeEditPrivate::convertSections(QDateTimeParser::Sections s)
2421 QDateTimeEdit::Sections ret;
2422 if (s & QDateTimeParser::MSecSection)
2423 ret |= QDateTimeEdit::MSecSection;
2424 if (s & QDateTimeParser::SecondSection)
2425 ret |= QDateTimeEdit::SecondSection;
2426 if (s & QDateTimeParser::MinuteSection)
2427 ret |= QDateTimeEdit::MinuteSection;
2428 if (s & (QDateTimeParser::HourSectionMask))
2429 ret |= QDateTimeEdit::HourSection;
2430 if (s & QDateTimeParser::AmPmSection)
2431 ret |= QDateTimeEdit::AmPmSection;
2432 if (s & (QDateTimeParser::DaySectionMask))
2433 ret |= QDateTimeEdit::DaySection;
2434 if (s & QDateTimeParser::MonthSection)
2435 ret |= QDateTimeEdit::MonthSection;
2436 if (s & (QDateTimeParser::YearSectionMask))
2437 ret |= QDateTimeEdit::YearSection;
2659void QDateTimeEditPrivate::initCalendarPopup(QCalendarWidget *cw)
2662 if (!monthCalendar) {
2663 monthCalendar =
new QCalendarPopup(q, cw, calendar);
2664 monthCalendar->setObjectName(
"qt_datetimedit_calendar"_L1);
2665 QObject::connect(monthCalendar, SIGNAL(newDateSelected(QDate)), q, SLOT(setDate(QDate)));
2666 QObject::connect(monthCalendar, SIGNAL(hidingCalendar(QDate)), q, SLOT(setDate(QDate)));
2667 QObject::connect(monthCalendar, SIGNAL(activated(QDate)), q, SLOT(setDate(QDate)));
2668 QObject::connect(monthCalendar, SIGNAL(activated(QDate)), monthCalendar, SLOT(close()));
2669 QObject::connect(monthCalendar, SIGNAL(resetButton()), q, SLOT(_q_resetButton()));
2671 monthCalendar->setCalendarWidget(cw);
2673 syncCalendarWidget();
2676void QDateTimeEditPrivate::positionCalendarPopup()
2679 QPoint pos = (q->layoutDirection() == Qt::RightToLeft) ? q->rect().bottomRight() : q->rect().bottomLeft();
2680 QPoint pos2 = (q->layoutDirection() == Qt::RightToLeft) ? q->rect().topRight() : q->rect().topLeft();
2681 pos = q->mapToGlobal(pos);
2682 pos2 = q->mapToGlobal(pos2);
2683 QSize size = monthCalendar->sizeHint();
2684 QScreen *screen = QGuiApplication::screenAt(pos);
2686 screen = QGuiApplication::primaryScreen();
2687 const QRect screenRect = screen->availableGeometry();
2689 if (q->layoutDirection() == Qt::RightToLeft) {
2690 pos.setX(pos.x()-size.width());
2691 pos2.setX(pos2.x()-size.width());
2692 if (pos.x() < screenRect.left())
2693 pos.setX(qMax(pos.x(), screenRect.left()));
2694 else if (pos.x()+size.width() > screenRect.right())
2695 pos.setX(qMax(pos.x()-size.width(), screenRect.right()-size.width()));
2697 if (pos.x()+size.width() > screenRect.right())
2698 pos.setX(screenRect.right()-size.width());
2699 pos.setX(qMax(pos.x(), screenRect.left()));
2701 if (pos.y() + size.height() > screenRect.bottom())
2702 pos.setY(pos2.y() - size.height());
2703 else if (pos.y() < screenRect.top())
2704 pos.setY(screenRect.top());
2705 if (pos.y() < screenRect.top())
2706 pos.setY(screenRect.top());
2707 if (pos.y()+size.height() > screenRect.bottom())
2708 pos.setY(screenRect.bottom()-size.height());
2709 monthCalendar->move(pos);
2757void QCalendarPopup::setCalendarWidget(QCalendarWidget *cw)
2760 QVBoxLayout *widgetLayout = qobject_cast<QVBoxLayout*>(layout());
2761 if (!widgetLayout) {
2762 widgetLayout =
new QVBoxLayout(
this);
2763 widgetLayout->setContentsMargins(QMargins());
2764 widgetLayout->setSpacing(0);
2766 delete calendar.data();
2767 calendar = QPointer<QCalendarWidget>(cw);
2768 widgetLayout->addWidget(cw);
2770 connect(cw, SIGNAL(activated(QDate)),
this, SLOT(dateSelected(QDate)));
2771 connect(cw, SIGNAL(clicked(QDate)),
this, SLOT(dateSelected(QDate)));
2772 connect(cw, SIGNAL(selectionChanged()),
this, SLOT(dateSelectionChanged()));