SelectDatePopupWidget::SelectDatePopupWidget(QWidget *parent) : QWidget(parent) { layout = new QGridLayout; auto calendar = new QCalendarWidget(this); auto ok = new QPushButton("ОК", this); auto cancel = new QPushButton("Cancel", this); QObject::connect(ok, &QPushButton::clicked, [&]() { close(); emit onOk(selectedDate()); }); QObject::connect(cancel, &QPushButton::clicked, [&]() { close(); }); layout->addWidget(calendar, 0, 0, 1, 2); layout->addWidget(ok, 1, 0); layout->addWidget(cancel, 1, 1); setLayout(layout); setWindowFlags(Qt::Popup); setFocus(Qt::PopupFocusReason); resize(150, 150); }
wxQtCalendarWidget::wxQtCalendarWidget( wxWindow *parent, wxCalendarCtrl *handler ) : wxQtEventSignalHandler< QCalendarWidget, wxCalendarCtrl >( parent, handler ) { m_date = selectedDate(); connect(this, &QCalendarWidget::selectionChanged, this, &wxQtCalendarWidget::selectionChanged); connect(this, &QCalendarWidget::activated, this, &wxQtCalendarWidget::activated); }
void wxQtCalendarWidget::selectionChanged() { wxCalendarCtrl *win = GetHandler(); if ( win ) { GetHandler()->GenerateAllChangeEvents(wxQtConvertDate(m_date)); m_date = selectedDate(); } }
void tst_QCalendarWidget::buttonClickCheck() { QCalendarWidget object; QSize size = object.sizeHint(); object.setGeometry(0,0,size.width(), size.height()); object.show(); object.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&object)); QDate selectedDate(2005, 1, 1); //click on the month buttons int month = object.monthShown(); QToolButton *button = object.findChild<QToolButton *>("qt_calendar_prevmonth"); QTest::mouseClick(button, Qt::LeftButton); QCOMPARE(month > 1 ? month-1 : 12, object.monthShown()); button = object.findChild<QToolButton *>("qt_calendar_nextmonth"); QTest::mouseClick(button, Qt::LeftButton); QCOMPARE(month, object.monthShown()); button = object.findChild<QToolButton *>("qt_calendar_yearbutton"); QTest::mouseClick(button, Qt::LeftButton, Qt::NoModifier, button->rect().center(), 2); QVERIFY(!button->isVisible()); QSpinBox *spinbox = object.findChild<QSpinBox *>("qt_calendar_yearedit"); QTest::qWait(500); QTest::keyClick(spinbox, '2'); QTest::keyClick(spinbox, '0'); QTest::keyClick(spinbox, '0'); QTest::keyClick(spinbox, '6'); QTest::qWait(500); QWidget *widget = object.findChild<QWidget *>("qt_calendar_calendarview"); QTest::mouseMove(widget); QTest::mouseClick(widget, Qt::LeftButton); QCOMPARE(2006, object.yearShown()); object.setSelectedDate(selectedDate); object.showSelectedDate(); QTest::keyClick(widget, Qt::Key_Down); QVERIFY(selectedDate != object.selectedDate()); object.setDateRange(QDate(2006,1,1), QDate(2006,2,28)); object.setSelectedDate(QDate(2006,1,1)); object.showSelectedDate(); button = object.findChild<QToolButton *>("qt_calendar_prevmonth"); QTest::mouseClick(button, Qt::LeftButton); QCOMPARE(1, object.monthShown()); button = object.findChild<QToolButton *>("qt_calendar_nextmonth"); QTest::mouseClick(button, Qt::LeftButton); QCOMPARE(2, object.monthShown()); QTest::mouseClick(button, Qt::LeftButton); QCOMPARE(2, object.monthShown()); }
// Testing get/set functions void tst_QCalendarWidget::getSetCheck() { QWidget topLevel; QCalendarWidget object(&topLevel); //horizontal header formats object.setHorizontalHeaderFormat(QCalendarWidget::NoHorizontalHeader); QCOMPARE(QCalendarWidget::NoHorizontalHeader, object.horizontalHeaderFormat()); object.setHorizontalHeaderFormat(QCalendarWidget::SingleLetterDayNames); QCOMPARE(QCalendarWidget::SingleLetterDayNames, object.horizontalHeaderFormat()); object.setHorizontalHeaderFormat(QCalendarWidget::ShortDayNames); QCOMPARE(QCalendarWidget::ShortDayNames, object.horizontalHeaderFormat()); object.setHorizontalHeaderFormat(QCalendarWidget::LongDayNames); QCOMPARE(QCalendarWidget::LongDayNames, object.horizontalHeaderFormat()); //vertical header formats object.setVerticalHeaderFormat(QCalendarWidget::ISOWeekNumbers); QCOMPARE(QCalendarWidget::ISOWeekNumbers, object.verticalHeaderFormat()); object.setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader); QCOMPARE(QCalendarWidget::NoVerticalHeader, object.verticalHeaderFormat()); //maximum Date QDate maxDate(2006, 7, 3); object.setMaximumDate(maxDate); QCOMPARE(maxDate, object.maximumDate()); //minimum date QDate minDate(2004, 7, 3); object.setMinimumDate(minDate); QCOMPARE(minDate, object.minimumDate()); //day of week object.setFirstDayOfWeek(Qt::Thursday); QCOMPARE(Qt::Thursday, object.firstDayOfWeek()); //grid visible object.setGridVisible(true); QVERIFY(object.isGridVisible()); object.setGridVisible(false); QVERIFY(!object.isGridVisible()); //header visible object.setNavigationBarVisible(true); QVERIFY(object.isNavigationBarVisible()); object.setNavigationBarVisible(false); QVERIFY(!object.isNavigationBarVisible()); //selection mode QCOMPARE(QCalendarWidget::SingleSelection, object.selectionMode()); object.setSelectionMode(QCalendarWidget::NoSelection); QCOMPARE(QCalendarWidget::NoSelection, object.selectionMode()); object.setSelectionMode(QCalendarWidget::SingleSelection); QCOMPARE(QCalendarWidget::SingleSelection, object.selectionMode()); //selected date QDate selectedDate(2005, 7, 3); QSignalSpy spy(&object, SIGNAL(selectionChanged())); object.setSelectedDate(selectedDate); QCOMPARE(spy.count(), 1); QCOMPARE(selectedDate, object.selectedDate()); //month and year object.setCurrentPage(2004, 1); QCOMPARE(1, object.monthShown()); QCOMPARE(2004, object.yearShown()); object.showNextMonth(); QCOMPARE(2, object.monthShown()); object.showPreviousMonth(); QCOMPARE(1, object.monthShown()); object.showNextYear(); QCOMPARE(2005, object.yearShown()); object.showPreviousYear(); QCOMPARE(2004, object.yearShown()); //date range minDate = QDate(2006,1,1); maxDate = QDate(2010,12,31); object.setDateRange(minDate, maxDate); QCOMPARE(maxDate, object.maximumDate()); QCOMPARE(minDate, object.minimumDate()); //date should not go beyond the minimum. selectedDate = minDate.addDays(-10); object.setSelectedDate(selectedDate); QCOMPARE(minDate, object.selectedDate()); QVERIFY(selectedDate != object.selectedDate()); //date should not go beyond the maximum. selectedDate = maxDate.addDays(10); object.setSelectedDate(selectedDate); QCOMPARE(maxDate, object.selectedDate()); QVERIFY(selectedDate != object.selectedDate()); //show today QDate today = QDate::currentDate(); object.showToday(); QCOMPARE(today.month(), object.monthShown()); QCOMPARE(today.year(), object.yearShown()); //slect a different date and move. object.setSelectedDate(minDate); object.showSelectedDate(); QCOMPARE(minDate.month(), object.monthShown()); QCOMPARE(minDate.year(), object.yearShown()); }
int QCalendarWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: selectionChanged(); break; case 1: clicked((*reinterpret_cast< const QDate(*)>(_a[1]))); break; case 2: activated((*reinterpret_cast< const QDate(*)>(_a[1]))); break; case 3: currentPageChanged((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; case 4: setSelectedDate((*reinterpret_cast< const QDate(*)>(_a[1]))); break; case 5: setDateRange((*reinterpret_cast< const QDate(*)>(_a[1])),(*reinterpret_cast< const QDate(*)>(_a[2]))); break; case 6: setCurrentPage((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; case 7: setGridVisible((*reinterpret_cast< bool(*)>(_a[1]))); break; case 8: setNavigationBarVisible((*reinterpret_cast< bool(*)>(_a[1]))); break; case 9: showNextMonth(); break; case 10: showPreviousMonth(); break; case 11: showNextYear(); break; case 12: showPreviousYear(); break; case 13: showSelectedDate(); break; case 14: showToday(); break; case 15: d_func()->_q_slotShowDate((*reinterpret_cast< const QDate(*)>(_a[1]))); break; case 16: d_func()->_q_slotChangeDate((*reinterpret_cast< const QDate(*)>(_a[1]))); break; case 17: d_func()->_q_slotChangeDate((*reinterpret_cast< const QDate(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2]))); break; case 18: d_func()->_q_editingFinished(); break; case 19: d_func()->_q_prevMonthClicked(); break; case 20: d_func()->_q_nextMonthClicked(); break; case 21: d_func()->_q_yearEditingFinished(); break; case 22: d_func()->_q_yearClicked(); break; case 23: d_func()->_q_monthChanged((*reinterpret_cast< QAction*(*)>(_a[1]))); break; default: ; } _id -= 24; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QDate*>(_v) = selectedDate(); break; case 1: *reinterpret_cast< QDate*>(_v) = minimumDate(); break; case 2: *reinterpret_cast< QDate*>(_v) = maximumDate(); break; case 3: *reinterpret_cast< Qt::DayOfWeek*>(_v) = firstDayOfWeek(); break; case 4: *reinterpret_cast< bool*>(_v) = isGridVisible(); break; case 5: *reinterpret_cast< SelectionMode*>(_v) = selectionMode(); break; case 6: *reinterpret_cast< HorizontalHeaderFormat*>(_v) = horizontalHeaderFormat(); break; case 7: *reinterpret_cast< VerticalHeaderFormat*>(_v) = verticalHeaderFormat(); break; case 8: *reinterpret_cast< bool*>(_v) = isHeaderVisible(); break; case 9: *reinterpret_cast< bool*>(_v) = isNavigationBarVisible(); break; case 10: *reinterpret_cast< bool*>(_v) = isDateEditEnabled(); break; case 11: *reinterpret_cast< int*>(_v) = dateEditAcceptDelay(); break; } _id -= 12; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setSelectedDate(*reinterpret_cast< QDate*>(_v)); break; case 1: setMinimumDate(*reinterpret_cast< QDate*>(_v)); break; case 2: setMaximumDate(*reinterpret_cast< QDate*>(_v)); break; case 3: setFirstDayOfWeek(*reinterpret_cast< Qt::DayOfWeek*>(_v)); break; case 4: setGridVisible(*reinterpret_cast< bool*>(_v)); break; case 5: setSelectionMode(*reinterpret_cast< SelectionMode*>(_v)); break; case 6: setHorizontalHeaderFormat(*reinterpret_cast< HorizontalHeaderFormat*>(_v)); break; case 7: setVerticalHeaderFormat(*reinterpret_cast< VerticalHeaderFormat*>(_v)); break; case 8: setHeaderVisible(*reinterpret_cast< bool*>(_v)); break; case 9: setNavigationBarVisible(*reinterpret_cast< bool*>(_v)); break; case 10: setDateEditEnabled(*reinterpret_cast< bool*>(_v)); break; case 11: setDateEditAcceptDelay(*reinterpret_cast< int*>(_v)); break; } _id -= 12; } else if (_c == QMetaObject::ResetProperty) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 12; } #endif // QT_NO_PROPERTIES return _id; }
void CCalendarWidget::paintCell (QPainter *painter, const QRect &rect, const QDate &date) const { QSize fsize = fontMetrics().size (Qt::TextSingleLine, "A"); if (moon_mode) { int moon_day = moon_phase_by_algo (moon_phase_algo, date.year(), date.month(), date.day()); bool has_image = true; if (moon_day == 0 || moon_day == 30 || moon_day == 1) has_image = false; //вычисляем ряд и колонку //правильно //int row = moon_day / 8; int cursorOffset = moon_day; int off = 0; int row = 0; while (cursorOffset >= (off + 8)) { off += 7; row++; } int col = cursorOffset - off; // qDebug() << "moon day: " << moon_day << "| date:" << date.toString("dd") << " | row = " << row << " col = " << col; //вычисляем, откуда копировать int pad = 3; int x = (col - 1) * 73 + (pad * col) - pad; int y = row * 73 + (pad * row); QRect r (x, y, 66, 73); QImage tile = moon_tiles.copy (r); QColor bg_color (Qt::black); painter->fillRect (rect, bg_color); if (has_image) { if (northern_hemisphere) painter->drawImage (rect.x(), rect.y(), tile); else painter->drawImage (rect.x(), rect.y(), tile.mirrored (true, false)); } painter->setPen (QPen (Qt::yellow)); QTextCharFormat tcf = dateTextFormat (date); if (tcf.fontStrikeOut()) painter->setPen (QPen (Qt::magenta)); else if (tcf.fontUnderline()) painter->setPen (QPen (Qt::red)); painter->drawText (QPoint (rect.x() + 5, rect.y() + fsize.height()), date.toString("dd") + " / " + QString::number (moon_day)); if (selectedDate() == date) { QPen dpen (Qt::yellow); dpen.setWidth (5); painter->setPen (dpen); painter->drawRect (rect); } } else QCalendarWidget::paintCell (painter, rect, date); }
void SelectDatePopupWidget::closeEvent(QCloseEvent *) { qDebug("SelectDateWidget::closeEvent"); qDebug() << selectedDate(); }
QDate SelectDatePopupWidget::selectedDate() const { auto calendar = static_cast<QCalendarWidget*>( layout->itemAt(0)->widget()); return calendar->selectedDate(); }
int QCalendarWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 24) qt_static_metacall(this, _c, _id, _a); _id -= 24; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QDate*>(_v) = selectedDate(); break; case 1: *reinterpret_cast< QDate*>(_v) = minimumDate(); break; case 2: *reinterpret_cast< QDate*>(_v) = maximumDate(); break; case 3: *reinterpret_cast< Qt::DayOfWeek*>(_v) = firstDayOfWeek(); break; case 4: *reinterpret_cast< bool*>(_v) = isGridVisible(); break; case 5: *reinterpret_cast< SelectionMode*>(_v) = selectionMode(); break; case 6: *reinterpret_cast< HorizontalHeaderFormat*>(_v) = horizontalHeaderFormat(); break; case 7: *reinterpret_cast< VerticalHeaderFormat*>(_v) = verticalHeaderFormat(); break; case 8: *reinterpret_cast< bool*>(_v) = isHeaderVisible(); break; case 9: *reinterpret_cast< bool*>(_v) = isNavigationBarVisible(); break; case 10: *reinterpret_cast< bool*>(_v) = isDateEditEnabled(); break; case 11: *reinterpret_cast< int*>(_v) = dateEditAcceptDelay(); break; } _id -= 12; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setSelectedDate(*reinterpret_cast< QDate*>(_v)); break; case 1: setMinimumDate(*reinterpret_cast< QDate*>(_v)); break; case 2: setMaximumDate(*reinterpret_cast< QDate*>(_v)); break; case 3: setFirstDayOfWeek(*reinterpret_cast< Qt::DayOfWeek*>(_v)); break; case 4: setGridVisible(*reinterpret_cast< bool*>(_v)); break; case 5: setSelectionMode(*reinterpret_cast< SelectionMode*>(_v)); break; case 6: setHorizontalHeaderFormat(*reinterpret_cast< HorizontalHeaderFormat*>(_v)); break; case 7: setVerticalHeaderFormat(*reinterpret_cast< VerticalHeaderFormat*>(_v)); break; case 8: setHeaderVisible(*reinterpret_cast< bool*>(_v)); break; case 9: setNavigationBarVisible(*reinterpret_cast< bool*>(_v)); break; case 10: setDateEditEnabled(*reinterpret_cast< bool*>(_v)); break; case 11: setDateEditAcceptDelay(*reinterpret_cast< int*>(_v)); break; } _id -= 12; } else if (_c == QMetaObject::ResetProperty) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 12; } #endif // QT_NO_PROPERTIES return _id; }