--- qt-all-opensource-src-4.4.2/src/gui/widgets/qcalendarwidget.cpp~ 2008-09-11 15:35:45 +0000 +++ qt-all-opensource-src-4.4.2/src/gui/widgets/qcalendarwidget.cpp 2008-09-25 11:22:16 +0000 @@ -853,7 +853,7 @@ public: return true; } - void showMonth(int year, int month); + void showMonth(int year, int month, int monthday); void setDate(const QDate &d); void setMinimumDate(const QDate &date); @@ -890,6 +890,7 @@ public: QDate m_maximumDate; int m_shownYear; int m_shownMonth; + int m_shownMonthDay; Qt::DayOfWeek m_firstDay; QCalendarWidget::HorizontalHeaderFormat m_horizontalHeaderFormat; bool m_weekNumbersShown; @@ -940,6 +941,7 @@ QCalendarModel::QCalendarModel(QObject * m_maximumDate = QDate(7999, 12, 31); m_shownYear = m_date.year(); m_shownMonth = m_date.month(); + m_shownMonth = m_date.day(); m_firstDay = Qt::Sunday; m_horizontalHeaderFormat = QCalendarWidget::ShortDayNames; m_weekNumbersShown = true; @@ -1170,12 +1172,13 @@ void QCalendarModel::setDate(const QDate m_date = m_maximumDate; } -void QCalendarModel::showMonth(int year, int month) +void QCalendarModel::showMonth(int year, int month, int monthday) { - if (m_shownYear == year && m_shownMonth == month) + if (m_shownYear == year && m_shownMonth == month && m_shownMonthDay == monthday) return; m_shownYear = year; + m_shownMonthDay = monthday; m_shownMonth = month; internalUpdate(); @@ -1570,7 +1573,7 @@ class QCalendarWidgetPrivate : public QW public: QCalendarWidgetPrivate(); - void showMonth(int year, int month); + void showMonth(int year, int month, int monthday); void update(); void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const; @@ -1601,6 +1604,7 @@ public: QToolButton *nextMonth; QToolButton *prevMonth; + QCalToolButton *monthDayButton; QCalToolButton *monthButton; QMenu *monthMenu; QMap monthToAction; @@ -1694,6 +1698,9 @@ void QCalendarWidgetPrivate::createNavig prevMonth->setFocusProxy(m_view); nextMonth->setFocusProxy(m_view); + monthDayButton = new QCalToolButton(navBarBackground); + monthDayButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); + monthDayButton->setAutoRaise(true); monthButton = new QCalToolButton(navBarBackground); monthButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); @@ -1714,6 +1721,7 @@ void QCalendarWidgetPrivate::createNavig QFont font = q->font(); font.setBold(true); + monthDayButton->setFont(font); monthButton->setFont(font); yearButton->setFont(font); yearEdit->setFrame(false); @@ -1727,6 +1735,7 @@ void QCalendarWidgetPrivate::createNavig headerLayout->setSpacing(0); headerLayout->addWidget(prevMonth); headerLayout->insertStretch(headerLayout->count()); + headerLayout->addWidget(monthDayButton); headerLayout->addWidget(monthButton); headerLayout->addItem(spaceHolder); headerLayout->addWidget(yearButton); @@ -1738,17 +1747,19 @@ void QCalendarWidgetPrivate::createNavig prevMonth->setFocusPolicy(Qt::NoFocus); nextMonth->setFocusPolicy(Qt::NoFocus); yearButton->setFocusPolicy(Qt::NoFocus); + monthDayButton->setFocusPolicy(Qt::NoFocus); monthButton->setFocusPolicy(Qt::NoFocus); //set names for the header controls. prevMonth->setObjectName(QLatin1String("qt_calendar_prevmonth")); nextMonth->setObjectName(QLatin1String("qt_calendar_nextmonth")); + monthDayButton->setObjectName(QLatin1String("qt_calendar_monthdaybutton")); monthButton->setObjectName(QLatin1String("qt_calendar_monthbutton")); yearButton->setObjectName(QLatin1String("qt_calendar_yearbutton")); yearEdit->setObjectName(QLatin1String("qt_calendar_yearedit")); updateMonthMenu(); - showMonth(m_model->m_date.year(), m_model->m_date.month()); + showMonth(m_model->m_date.year(), m_model->m_date.month(), m_model->m_date.day()); } void QCalendarWidgetPrivate::updateButtonIcons() @@ -1803,7 +1814,7 @@ void QCalendarWidgetPrivate::updateCurre newDate = minDate; if (maxDate.isValid()&& maxDate.daysTo(newDate) > 0) newDate = maxDate; - showMonth(newDate.year(), newDate.month()); + showMonth(newDate.year(), newDate.month(), newDate.day()); int row = -1, col = -1; m_model->cellForDate(newDate, &row, &col); if (row != -1 && col != -1) @@ -1863,12 +1874,12 @@ void QCalendarWidgetPrivate::_q_yearClic yearEdit->setFocus(Qt::MouseFocusReason); } -void QCalendarWidgetPrivate::showMonth(int year, int month) +void QCalendarWidgetPrivate::showMonth(int year, int month, int monthday) { - if (m_model->m_shownYear == year && m_model->m_shownMonth == month) + if (m_model->m_shownYear == year && m_model->m_shownMonth == month && m_model->m_shownMonthDay == monthday) return; Q_Q(QCalendarWidget); - m_model->showMonth(year, month); + m_model->showMonth(year, month, monthday); updateNavigationBar(); emit q->currentPageChanged(year, month); m_view->internalUpdate(); @@ -1883,6 +1894,7 @@ void QCalendarWidgetPrivate::updateNavig QString monthName = q->locale().monthName(m_model->m_shownMonth, QLocale::LongFormat); + monthDayButton->setText(QString::number(m_model->m_shownMonthDay)); monthButton->setText(monthName); yearButton->setText(QString::number(m_model->m_shownYear)); yearEdit->setValue(m_model->m_shownYear); @@ -1917,9 +1929,8 @@ void QCalendarWidgetPrivate::_q_slotChan QDate oldDate = m_model->m_date; m_model->setDate(date); QDate newDate = m_model->m_date; - if (changeMonth) - showMonth(newDate.year(), newDate.month()); if (oldDate != newDate) { + showMonth(newDate.year(), newDate.month(), newDate.day()); update(); Q_Q(QCalendarWidget); m_navigator->setDate(newDate); @@ -2173,6 +2184,9 @@ QSize QCalendarWidget::minimumSizeHint() const int buttonDecoMargin = d->monthButton->sizeHint().width() - fm.boundingRect(d->monthButton->text()).width(); headerW += monthW + buttonDecoMargin; + fm = d->monthDayButton->fontMetrics(); + headerW += fm.boundingRect(QLatin1String("55")).width() + buttonDecoMargin; + fm = d->yearButton->fontMetrics(); headerW += fm.boundingRect(QLatin1String("5555")).width() + buttonDecoMargin; @@ -2224,7 +2238,7 @@ void QCalendarWidget::setSelectedDate(co d->m_model->setDate(date); d->update(); QDate newDate = d->m_model->m_date; - d->showMonth(newDate.year(), newDate.month()); + d->showMonth(newDate.year(), newDate.month(), newDate.day()); emit selectionChanged(); } @@ -2269,7 +2283,7 @@ int QCalendarWidget::monthShown() const void QCalendarWidget::setCurrentPage(int year, int month) { Q_D(QCalendarWidget); - d->showMonth(year, month); + d->showMonth(year, month, 15); } /*! @@ -2411,7 +2425,7 @@ void QCalendarWidget::setMinimumDate(con QDate newDate = d->m_model->m_date; if (oldDate != newDate) { d->update(); - d->showMonth(newDate.year(), newDate.month()); + d->showMonth(newDate.year(), newDate.month(), newDate.day()); d->m_navigator->setDate(newDate); emit selectionChanged(); } @@ -2462,7 +2476,7 @@ void QCalendarWidget::setMaximumDate(con QDate newDate = d->m_model->m_date; if (oldDate != newDate) { d->update(); - d->showMonth(newDate.year(), newDate.month()); + d->showMonth(newDate.year(), newDate.month(), newDate.day()); d->m_navigator->setDate(newDate); emit selectionChanged(); } @@ -2510,7 +2524,7 @@ void QCalendarWidget::setDateRange(const QDate newDate = d->m_model->m_date; if (oldDate != newDate) { d->update(); - d->showMonth(newDate.year(), newDate.month()); + d->showMonth(newDate.year(), newDate.month(), newDate.day()); d->m_navigator->setDate(newDate); emit selectionChanged(); }