summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qcalendarwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/widgets/qcalendarwidget.cpp')
-rw-r--r--src/widgets/widgets/qcalendarwidget.cpp743
1 files changed, 405 insertions, 338 deletions
diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp
index 2ff383d9c7..0495b20422 100644
--- a/src/widgets/widgets/qcalendarwidget.cpp
+++ b/src/widgets/widgets/qcalendarwidget.cpp
@@ -1,46 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWidgets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qcalendarwidget.h"
#include <qabstractitemmodel.h>
-#include <qitemdelegate.h>
+#include <qstyleditemdelegate.h>
#include <qdatetime.h>
#include <qtableview.h>
#include <qlayout.h>
@@ -54,13 +18,17 @@
#include <qspinbox.h>
#include <qmenu.h>
#include <qapplication.h>
+#include <private/qapplication_p.h>
#include <qbasictimer.h>
#include <qstylepainter.h>
+#include <qcalendar.h>
#include <vector>
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
enum {
RowCount = 6,
ColumnCount = 7,
@@ -69,13 +37,13 @@ enum {
MinimumDayOffset = 1
};
-namespace {
-
static QString formatNumber(int number, int fieldWidth)
{
- return QString::number(number).rightJustified(fieldWidth, QLatin1Char('0'));
+ return QString::number(number).rightJustified(fieldWidth, u'0');
}
+namespace QtPrivate {
+
class QCalendarDateSectionValidator
{
public:
@@ -89,24 +57,23 @@ public:
QCalendarDateSectionValidator() {}
virtual ~QCalendarDateSectionValidator() {}
virtual Section handleKey(int key) = 0;
- virtual QDate applyToDate(const QDate &date) const = 0;
- virtual void setDate(const QDate &date) = 0;
+ virtual QDate applyToDate(QDate date, QCalendar cal = QCalendar()) const = 0;
+ virtual void setDate(QDate date, QCalendar cal = QCalendar()) = 0;
virtual QString text() const = 0;
- virtual QString text(const QDate &date, int repeat) const = 0;
+ virtual QString text(QDate date, QCalendar cal, int repeat) const = 0;
QLocale m_locale;
protected:
static QString highlightString(const QString &str, int pos);
-private:
};
QString QCalendarDateSectionValidator::highlightString(const QString &str, int pos)
{
if (pos == 0)
- return QLatin1String("<b>") + str + QLatin1String("</b>");
- int startPos = str.length() - pos;
- return str.midRef(0, startPos) + QLatin1String("<b>") + str.midRef(startPos, pos) + QLatin1String("</b>");
+ return "<b>"_L1 + str + "</b>"_L1;
+ int startPos = str.size() - pos;
+ return QStringView{str}.mid(0, startPos) + "<b>"_L1 + QStringView{str}.mid(startPos, pos) + "</b>"_L1;
}
@@ -116,10 +83,10 @@ class QCalendarDayValidator : public QCalendarDateSectionValidator
public:
QCalendarDayValidator();
virtual Section handleKey(int key) override;
- virtual QDate applyToDate(const QDate &date) const override;
- virtual void setDate(const QDate &date) override;
+ virtual QDate applyToDate(QDate date, QCalendar cal) const override;
+ virtual void setDate(QDate date, QCalendar cal) override;
virtual QString text() const override;
- virtual QString text(const QDate &date, int repeat) const override;
+ virtual QString text(QDate date, QCalendar cal, int repeat) const override;
private:
int m_pos;
int m_day;
@@ -180,21 +147,18 @@ QCalendarDateSectionValidator::Section QCalendarDayValidator::handleKey(int key)
return QCalendarDateSectionValidator::ThisSection;
}
-QDate QCalendarDayValidator::applyToDate(const QDate &date) const
+QDate QCalendarDayValidator::applyToDate(QDate date, QCalendar cal) const
{
- int day = m_day;
- if (day < 1)
- day = 1;
- else if (day > 31)
- day = 31;
- if (day > date.daysInMonth())
- day = date.daysInMonth();
- return QDate(date.year(), date.month(), day);
+ auto parts = cal.partsFromDate(date);
+ if (!parts.isValid())
+ return QDate();
+ parts.day = qMin(qMax(1, m_day), cal.daysInMonth(parts.month, parts.year));
+ return cal.dateFromParts(parts);
}
-void QCalendarDayValidator::setDate(const QDate &date)
+void QCalendarDayValidator::setDate(QDate date, QCalendar cal)
{
- m_day = m_oldDay = date.day();
+ m_day = m_oldDay = date.day(cal);
m_pos = 0;
}
@@ -203,16 +167,16 @@ QString QCalendarDayValidator::text() const
return highlightString(formatNumber(m_day, 2), m_pos);
}
-QString QCalendarDayValidator::text(const QDate &date, int repeat) const
+QString QCalendarDayValidator::text(QDate date, QCalendar cal, int repeat) const
{
if (repeat <= 1) {
- return QString::number(date.day());
+ return QString::number(date.day(cal));
} else if (repeat == 2) {
- return formatNumber(date.day(), 2);
+ return formatNumber(date.day(cal), 2);
} else if (repeat == 3) {
- return m_locale.dayName(date.dayOfWeek(), QLocale::ShortFormat);
+ return m_locale.dayName(date.dayOfWeek(cal), QLocale::ShortFormat);
} else /* repeat >= 4 */ {
- return m_locale.dayName(date.dayOfWeek(), QLocale::LongFormat);
+ return m_locale.dayName(date.dayOfWeek(cal), QLocale::LongFormat);
}
}
@@ -224,10 +188,10 @@ class QCalendarMonthValidator : public QCalendarDateSectionValidator
public:
QCalendarMonthValidator();
virtual Section handleKey(int key) override;
- virtual QDate applyToDate(const QDate &date) const override;
- virtual void setDate(const QDate &date) override;
+ virtual QDate applyToDate(QDate date, QCalendar cal) const override;
+ virtual void setDate(QDate date, QCalendar cal) override;
virtual QString text() const override;
- virtual QString text(const QDate &date, int repeat) const override;
+ virtual QString text(QDate date, QCalendar cal, int repeat) const override;
private:
int m_pos;
int m_month;
@@ -288,23 +252,19 @@ QCalendarDateSectionValidator::Section QCalendarMonthValidator::handleKey(int ke
return QCalendarDateSectionValidator::ThisSection;
}
-QDate QCalendarMonthValidator::applyToDate(const QDate &date) const
+QDate QCalendarMonthValidator::applyToDate(QDate date, QCalendar cal) const
{
- int month = m_month;
- if (month < 1)
- month = 1;
- else if (month > 12)
- month = 12;
- QDate newDate(date.year(), m_month, 1);
- int day = date.day();
- if (day > newDate.daysInMonth())
- day = newDate.daysInMonth();
- return QDate(date.year(), month, day);
+ auto parts = cal.partsFromDate(date);
+ if (!parts.isValid())
+ return QDate();
+ parts.month = qMin(qMax(1, m_month), cal.monthsInYear(parts.year));
+ parts.day = qMin(parts.day, cal.daysInMonth(m_month, parts.year)); // m_month or parts.month ?
+ return cal.dateFromParts(parts);
}
-void QCalendarMonthValidator::setDate(const QDate &date)
+void QCalendarMonthValidator::setDate(QDate date, QCalendar cal)
{
- m_month = m_oldMonth = date.month();
+ m_month = m_oldMonth = date.month(cal);
m_pos = 0;
}
@@ -313,17 +273,19 @@ QString QCalendarMonthValidator::text() const
return highlightString(formatNumber(m_month, 2), m_pos);
}
-QString QCalendarMonthValidator::text(const QDate &date, int repeat) const
+QString QCalendarMonthValidator::text(QDate date, QCalendar cal, int repeat) const
{
- if (repeat <= 1) {
- return QString::number(date.month());
- } else if (repeat == 2) {
- return formatNumber(date.month(), 2);
- } else if (repeat == 3) {
- return m_locale.standaloneMonthName(date.month(), QLocale::ShortFormat);
- } else /*if (repeat >= 4)*/ {
- return m_locale.standaloneMonthName(date.month(), QLocale::LongFormat);
- }
+ const auto parts = cal.partsFromDate(date);
+ // Numeric forms:
+ if (repeat <= 1)
+ return QString::number(parts.month);
+ if (repeat == 2)
+ return formatNumber(parts.month, 2);
+ // Text forms:
+ if (repeat == 3)
+ return cal.standaloneMonthName(m_locale, parts.month, parts.year, QLocale::ShortFormat);
+ /* repeat >= 4 */
+ return cal.standaloneMonthName(m_locale, parts.month, parts.year, QLocale::LongFormat);
}
//////////////////////////////////
@@ -334,10 +296,10 @@ class QCalendarYearValidator : public QCalendarDateSectionValidator
public:
QCalendarYearValidator();
virtual Section handleKey(int key) override;
- virtual QDate applyToDate(const QDate &date) const override;
- virtual void setDate(const QDate &date) override;
+ virtual QDate applyToDate(QDate date, QCalendar cal) const override;
+ virtual void setDate(QDate date, QCalendar cal) override;
virtual QString text() const override;
- virtual QString text(const QDate &date, int repeat) const override;
+ virtual QString text(QDate date, QCalendar cal, int repeat) const override;
private:
int pow10(int n);
int m_pos;
@@ -348,6 +310,8 @@ private:
QCalendarYearValidator::QCalendarYearValidator()
: QCalendarDateSectionValidator(), m_pos(0), m_year(2000), m_oldYear(2000)
{
+ // TODO: What to use (for non-Gregorian calendars) as default year?
+ // Maybe 1360 for Jalali, 1420 for Islamic, etc.
}
int QCalendarYearValidator::pow10(int n)
@@ -396,21 +360,20 @@ QCalendarDateSectionValidator::Section QCalendarYearValidator::handleKey(int key
return QCalendarDateSectionValidator::ThisSection;
}
-QDate QCalendarYearValidator::applyToDate(const QDate &date) const
+QDate QCalendarYearValidator::applyToDate(QDate date, QCalendar cal) const
{
- int year = m_year;
- if (year < 1)
- year = 1;
- QDate newDate(year, date.month(), 1);
- int day = date.day();
- if (day > newDate.daysInMonth())
- day = newDate.daysInMonth();
- return QDate(year, date.month(), day);
+ auto parts = cal.partsFromDate(date);
+ if (!parts.isValid())
+ return QDate();
+ // This widget does not support negative years (some calendars may support)
+ parts.year = qMax(1, m_year);
+ parts.day = qMin(parts.day, cal.daysInMonth(parts.month, parts.year));
+ return cal.dateFromParts(parts);
}
-void QCalendarYearValidator::setDate(const QDate &date)
+void QCalendarYearValidator::setDate(QDate date, QCalendar cal)
{
- m_year = m_oldYear = date.year();
+ m_year = m_oldYear = date.year(cal);
m_pos = 0;
}
@@ -419,25 +382,27 @@ QString QCalendarYearValidator::text() const
return highlightString(formatNumber(m_year, 4), m_pos);
}
-QString QCalendarYearValidator::text(const QDate &date, int repeat) const
+QString QCalendarYearValidator::text(QDate date, QCalendar cal, int repeat) const
{
if (repeat < 4)
- return formatNumber(date.year() % 100, 2);
- return QString::number(date.year());
+ return formatNumber(date.year(cal) % 100, 2);
+ return QString::number(date.year(cal));
}
///////////////////////////////////
struct SectionToken {
- Q_DECL_CONSTEXPR SectionToken(QCalendarDateSectionValidator *v, int rep)
+ constexpr SectionToken(QCalendarDateSectionValidator *v, int rep)
: validator(v), repeat(rep) {}
QCalendarDateSectionValidator *validator;
int repeat;
};
-} // unnamed namespace
-Q_DECLARE_TYPEINFO(SectionToken, Q_PRIMITIVE_TYPE);
-namespace {
+} // namespace QtPrivate
+
+Q_DECLARE_TYPEINFO(QtPrivate::SectionToken, Q_PRIMITIVE_TYPE);
+
+namespace QtPrivate {
class QCalendarDateValidator
{
@@ -445,18 +410,18 @@ public:
QCalendarDateValidator();
~QCalendarDateValidator();
- void handleKeyEvent(QKeyEvent *keyEvent);
- QString currentText() const;
+ void handleKeyEvent(QKeyEvent *keyEvent, QCalendar cal);
+ QString currentText(QCalendar cal) const;
QDate currentDate() const { return m_currentDate; }
void setFormat(const QString &format);
- void setInitialDate(const QDate &date);
+ void setInitialDate(QDate date, QCalendar cal);
void setLocale(const QLocale &locale);
private:
void toNextToken();
void toPreviousToken();
- void applyToDate();
+ void applyToDate(QCalendar cal);
int countRepeat(const QString &str, int index) const;
void clear();
@@ -506,17 +471,17 @@ int QCalendarDateValidator::countRepeat(const QString &str, int index) const
return count;
}
-void QCalendarDateValidator::setInitialDate(const QDate &date)
+void QCalendarDateValidator::setInitialDate(QDate date, QCalendar cal)
{
- m_yearValidator.setDate(date);
- m_monthValidator.setDate(date);
- m_dayValidator.setDate(date);
+ m_yearValidator.setDate(date, cal);
+ m_monthValidator.setDate(date, cal);
+ m_dayValidator.setDate(date, cal);
m_initialDate = date;
m_currentDate = date;
m_lastSectionMove = QCalendarDateSectionValidator::ThisSection;
}
-QString QCalendarDateValidator::currentText() const
+QString QCalendarDateValidator::currentText(QCalendar cal) const
{
QString str;
const int numSeps = m_separators.size();
@@ -528,7 +493,7 @@ QString QCalendarDateValidator::currentText() const
if (i == m_currentToken)
str += token.validator->text();
else
- str += token.validator->text(m_currentDate, token.repeat);
+ str += token.validator->text(m_currentDate, cal, token.repeat);
}
}
return str;
@@ -547,11 +512,11 @@ void QCalendarDateValidator::setFormat(const QString &format)
clear();
int pos = 0;
- const QLatin1Char quote('\'');
+ const auto quote = u'\'';
bool quoting = false;
QString separator;
while (pos < format.size()) {
- const QStringRef mid = format.midRef(pos);
+ const QStringView mid = QStringView{format}.mid(pos);
int offset = 1;
if (mid.startsWith(quote)) {
@@ -562,14 +527,14 @@ void QCalendarDateValidator::setFormat(const QString &format)
separator += nextChar;
quoting = false;
} else {
- QCalendarDateSectionValidator *validator = 0;
- if (nextChar == QLatin1Char('d')) {
+ QCalendarDateSectionValidator *validator = nullptr;
+ if (nextChar == u'd') {
offset = qMin(4, countRepeat(format, pos));
validator = &m_dayValidator;
- } else if (nextChar == QLatin1Char('M')) {
+ } else if (nextChar == u'M') {
offset = qMin(4, countRepeat(format, pos));
validator = &m_monthValidator;
- } else if (nextChar == QLatin1Char('y')) {
+ } else if (nextChar == u'y') {
offset = qMin(4, countRepeat(format, pos));
validator = &m_yearValidator;
} else {
@@ -590,11 +555,11 @@ void QCalendarDateValidator::setFormat(const QString &format)
m_separators += separator;
}
-void QCalendarDateValidator::applyToDate()
+void QCalendarDateValidator::applyToDate(QCalendar cal)
{
- m_currentDate = m_yearValidator.applyToDate(m_currentDate);
- m_currentDate = m_monthValidator.applyToDate(m_currentDate);
- m_currentDate = m_dayValidator.applyToDate(m_currentDate);
+ m_currentDate = m_yearValidator.applyToDate(m_currentDate, cal);
+ m_currentDate = m_monthValidator.applyToDate(m_currentDate, cal);
+ m_currentDate = m_dayValidator.applyToDate(m_currentDate, cal);
}
void QCalendarDateValidator::toNextToken()
@@ -613,7 +578,7 @@ void QCalendarDateValidator::toPreviousToken()
m_currentToken %= m_tokens.size();
}
-void QCalendarDateValidator::handleKeyEvent(QKeyEvent *keyEvent)
+void QCalendarDateValidator::handleKeyEvent(QKeyEvent *keyEvent,QCalendar cal)
{
if (m_currentToken < 0)
return;
@@ -630,7 +595,7 @@ void QCalendarDateValidator::handleKeyEvent(QKeyEvent *keyEvent)
m_lastSectionMove = m_tokens[m_currentToken].validator->handleKey(key);
- applyToDate();
+ applyToDate(cal);
if (m_lastSectionMove == QCalendarDateSectionValidator::NextSection)
toNextToken();
else if (m_lastSectionMove == QCalendarDateSectionValidator::PrevSection)
@@ -643,8 +608,9 @@ class QCalendarTextNavigator: public QObject
{
Q_OBJECT
public:
- QCalendarTextNavigator(QObject *parent = 0)
- : QObject(parent), m_dateText(0), m_dateFrame(0), m_dateValidator(0), m_widget(0), m_editDelay(1500), m_date(QDate::currentDate()) { }
+ QCalendarTextNavigator(QObject *parent = nullptr)
+ : QObject(parent), m_dateText(nullptr), m_dateFrame(nullptr), m_dateValidator(nullptr),
+ m_widget(nullptr), m_editDelay(1500), m_date(QDate::currentDate()) {}
QWidget *widget() const;
void setWidget(QWidget *widget);
@@ -652,13 +618,13 @@ public:
int dateEditAcceptDelay() const;
void setDateEditAcceptDelay(int delay);
- void setDate(const QDate &date);
+ void setDate(QDate date);
bool eventFilter(QObject *o, QEvent *e) override;
void timerEvent(QTimerEvent *e) override;
signals:
- void dateChanged(const QDate &date);
+ void dateChanged(QDate date);
void editingFinished();
private:
@@ -675,6 +641,7 @@ private:
int m_editDelay;
QDate m_date;
+ const QCalendar m_calendar;
};
QWidget *QCalendarTextNavigator::widget() const
@@ -687,7 +654,7 @@ void QCalendarTextNavigator::setWidget(QWidget *widget)
m_widget = widget;
}
-void QCalendarTextNavigator::setDate(const QDate &date)
+void QCalendarTextNavigator::setDate(QDate date)
{
m_date = date;
}
@@ -699,7 +666,7 @@ void QCalendarTextNavigator::updateDateLabel()
m_acceptTimer.start(m_editDelay, this);
- m_dateText->setText(m_dateValidator->currentText());
+ m_dateText->setText(m_dateValidator->currentText(m_calendar));
QSize s = m_dateFrame->sizeHint();
QRect r = m_widget->geometry(); // later, just the table section
@@ -739,7 +706,7 @@ void QCalendarTextNavigator::createDateLabel()
m_dateValidator = new QCalendarDateValidator();
m_dateValidator->setLocale(m_widget->locale());
m_dateValidator->setFormat(m_widget->locale().dateFormat(QLocale::ShortFormat));
- m_dateValidator->setInitialDate(m_date);
+ m_dateValidator->setInitialDate(m_date, m_calendar);
m_dateFrame->setAutoFillBackground(true);
m_dateFrame->setBackgroundRole(QPalette::Window);
@@ -753,17 +720,17 @@ void QCalendarTextNavigator::removeDateLabel()
m_dateFrame->hide();
m_dateFrame->deleteLater();
delete m_dateValidator;
- m_dateFrame = 0;
- m_dateText = 0;
- m_dateValidator = 0;
+ m_dateFrame = nullptr;
+ m_dateText = nullptr;
+ m_dateValidator = nullptr;
}
bool QCalendarTextNavigator::eventFilter(QObject *o, QEvent *e)
{
if (m_widget) {
if (e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease) {
- QKeyEvent* ke = (QKeyEvent*)e;
- if ((ke->text().length() > 0 && ke->text().at(0).isPrint()) || m_dateFrame) {
+ QKeyEvent *ke = static_cast<QKeyEvent *>(e);
+ if ((ke->text().size() > 0 && ke->text().at(0).isPrint()) || m_dateFrame) {
if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Select) {
applyDate();
emit editingFinished();
@@ -774,7 +741,7 @@ bool QCalendarTextNavigator::eventFilter(QObject *o, QEvent *e)
#endif
} else if (e->type() == QEvent::KeyPress) {
createDateLabel();
- m_dateValidator->handleKeyEvent(ke);
+ m_dateValidator->handleKeyEvent(ke, m_calendar);
updateDateLabel();
}
ke->accept();
@@ -827,27 +794,23 @@ class StaticDayOfWeekAssociativeArray {
bool contained[7];
T data[7];
- static Q_DECL_CONSTEXPR int day2idx(Qt::DayOfWeek day) Q_DECL_NOTHROW { return int(day) - 1; } // alt: day % 7
+ static constexpr int day2idx(Qt::DayOfWeek day) noexcept { return int(day) - 1; } // alt: day % 7
public:
- Q_DECL_CONSTEXPR StaticDayOfWeekAssociativeArray() Q_DECL_NOEXCEPT_EXPR(noexcept(T()))
-#ifdef Q_COMPILER_CONSTEXPR
+ constexpr StaticDayOfWeekAssociativeArray() noexcept(noexcept(T()))
: contained{}, data{} // arrays require uniform initialization
-#else
- : contained(), data()
-#endif
{}
- Q_DECL_CONSTEXPR bool contains(Qt::DayOfWeek day) const Q_DECL_NOTHROW { return contained[day2idx(day)]; }
- Q_DECL_CONSTEXPR const T &value(Qt::DayOfWeek day) const Q_DECL_NOTHROW { return data[day2idx(day)]; }
+ constexpr bool contains(Qt::DayOfWeek day) const noexcept { return contained[day2idx(day)]; }
+ constexpr const T &value(Qt::DayOfWeek day) const noexcept { return data[day2idx(day)]; }
- Q_DECL_RELAXED_CONSTEXPR T &operator[](Qt::DayOfWeek day) Q_DECL_NOTHROW
+ constexpr T &operator[](Qt::DayOfWeek day) noexcept
{
const int idx = day2idx(day);
contained[idx] = true;
return data[idx];
}
- Q_DECL_RELAXED_CONSTEXPR void insert(Qt::DayOfWeek day, T v) Q_DECL_NOTHROW
+ constexpr void insert(Qt::DayOfWeek day, T v) noexcept
{
operator[](day).swap(v);
}
@@ -859,47 +822,35 @@ class QCalendarModel : public QAbstractTableModel
{
Q_OBJECT
public:
- QCalendarModel(QObject *parent = 0);
-
- int rowCount(const QModelIndex &) const override
- { return RowCount + m_firstRow; }
- int columnCount(const QModelIndex &) const override
- { return ColumnCount + m_firstColumn; }
- QVariant data(const QModelIndex &index, int role) const override;
- Qt::ItemFlags flags(const QModelIndex &index) const override;
+ QCalendarModel(QObject *parent = nullptr);
- bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override
- {
- beginInsertRows(parent, row, row + count - 1);
- endInsertRows();
- return true;
- }
- bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override
- {
- beginInsertColumns(parent, column, column + count - 1);
- endInsertColumns();
- return true;
- }
- bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override
+ int rowCount(const QModelIndex &parent) const override
{
- beginRemoveRows(parent, row, row + count - 1);
- endRemoveRows();
- return true;
+ if (parent.isValid())
+ return 0;
+ return RowCount + m_firstRow;
}
- bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override
+
+ int columnCount(const QModelIndex &parent) const override
{
- beginRemoveColumns(parent, column, column + count - 1);
- endRemoveColumns();
- return true;
+ if (parent.isValid())
+ return 0;
+ return ColumnCount + m_firstColumn;
}
+ QVariant data(const QModelIndex &index, int role) const override;
+ Qt::ItemFlags flags(const QModelIndex &index) const override;
+
void showMonth(int year, int month);
- void setDate(const QDate &d);
+ void setDate(QDate d);
- void setMinimumDate(const QDate &date);
- void setMaximumDate(const QDate &date);
+ void setCalendar(QCalendar c);
+ QCalendar calendar() const;
- void setRange(const QDate &min, const QDate &max);
+ void setMinimumDate(QDate date);
+ void setMaximumDate(QDate date);
+
+ void setRange(QDate min, QDate max);
void setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat format);
@@ -913,7 +864,7 @@ public:
Qt::DayOfWeek dayOfWeekForColumn(int section) const;
int columnForDayOfWeek(Qt::DayOfWeek day) const;
QDate dateForCell(int row, int column) const;
- void cellForDate(const QDate &date, int *row, int *column) const;
+ void cellForDate(QDate date, int *row, int *column) const;
QString dayName(Qt::DayOfWeek day) const;
void setView(QCalendarView *view)
@@ -921,10 +872,16 @@ public:
void internalUpdate();
QDate referenceDate() const;
- int columnForFirstOfMonth(const QDate &date) const;
+ int columnForFirstOfMonth(QDate date) const;
+
+ QString monthName(const QLocale &locale, int month)
+ {
+ return m_calendar.standaloneMonthName(locale, month, m_shownYear, QLocale::LongFormat);
+ }
int m_firstColumn;
int m_firstRow;
+ QCalendar m_calendar;
QDate m_date;
QDate m_minimumDate;
QDate m_maximumDate;
@@ -943,16 +900,16 @@ class QCalendarView : public QTableView
{
Q_OBJECT
public:
- QCalendarView(QWidget *parent = 0);
+ QCalendarView(QWidget *parent = nullptr);
void internalUpdate() { updateGeometries(); }
void setReadOnly(bool enable);
- virtual void keyboardSearch(const QString & search) override { Q_UNUSED(search) }
+ virtual void keyboardSearch(const QString &) override {}
signals:
- void showDate(const QDate &date);
- void changeDate(const QDate &date, bool changeMonth);
- void clicked(const QDate &date);
+ void showDate(QDate date);
+ void changeDate(QDate date, bool changeMonth);
+ void clicked(QDate date);
void editingFinished();
protected:
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
@@ -983,8 +940,8 @@ QCalendarModel::QCalendarModel(QObject *parent)
m_date(QDate::currentDate()),
m_minimumDate(QDate::fromJulianDay(1)),
m_maximumDate(9999, 12, 31),
- m_shownYear(m_date.year()),
- m_shownMonth(m_date.month()),
+ m_shownYear(m_date.year(m_calendar)),
+ m_shownMonth(m_date.month(m_calendar)),
m_firstDay(QLocale().firstDayOfWeek()),
m_horizontalHeaderFormat(QCalendarWidget::ShortDayNames),
m_weekNumbersShown(true),
@@ -1027,9 +984,10 @@ will be rendered in 2nd or 3rd row, showing more dates from previous month.
*/
QDate QCalendarModel::referenceDate() const
{
+ // TODO: Check this
int refDay = 1;
while (refDay <= 31) {
- QDate refDate(m_shownYear, m_shownMonth, refDay);
+ QDate refDate(m_shownYear, m_shownMonth, refDay, m_calendar);
if (refDate.isValid())
return refDate;
refDay += 1;
@@ -1037,9 +995,10 @@ QDate QCalendarModel::referenceDate() const
return QDate();
}
-int QCalendarModel::columnForFirstOfMonth(const QDate &date) const
+int QCalendarModel::columnForFirstOfMonth(QDate date) const
{
- return (columnForDayOfWeek(static_cast<Qt::DayOfWeek>(date.dayOfWeek())) - (date.day() % 7) + 8) % 7;
+ return (columnForDayOfWeek(static_cast<Qt::DayOfWeek>(m_calendar.dayOfWeek(date)))
+ - (date.day(m_calendar) % 7) + 8) % 7;
}
QDate QCalendarModel::dateForCell(int row, int column) const
@@ -1055,11 +1014,12 @@ QDate QCalendarModel::dateForCell(int row, int column) const
if (columnForFirstOfShownMonth - m_firstColumn < MinimumDayOffset)
row -= 1;
- const int requestedDay = 7 * (row - m_firstRow) + column - columnForFirstOfShownMonth - refDate.day() + 1;
+ const int requestedDay =
+ 7 * (row - m_firstRow) + column - columnForFirstOfShownMonth - refDate.day(m_calendar) + 1;
return refDate.addDays(requestedDay);
}
-void QCalendarModel::cellForDate(const QDate &date, int *row, int *column) const
+void QCalendarModel::cellForDate(QDate date, int *row, int *column) const
{
if (!row && !column)
return;
@@ -1074,7 +1034,8 @@ void QCalendarModel::cellForDate(const QDate &date, int *row, int *column) const
return;
const int columnForFirstOfShownMonth = columnForFirstOfMonth(refDate);
- const int requestedPosition = refDate.daysTo(date) - m_firstColumn + columnForFirstOfShownMonth + refDate.day() - 1;
+ const int requestedPosition = (refDate.daysTo(date) - m_firstColumn +
+ columnForFirstOfShownMonth + refDate.day(m_calendar) - 1);
int c = requestedPosition % 7;
int r = requestedPosition / 7;
@@ -1118,16 +1079,17 @@ QTextCharFormat QCalendarModel::formatForCell(int row, int col) const
{
QPalette pal;
QPalette::ColorGroup cg = QPalette::Active;
+ QTextCharFormat format;
+
if (m_view) {
pal = m_view->palette();
if (!m_view->isEnabled())
cg = QPalette::Disabled;
else if (!m_view->isActiveWindow())
cg = QPalette::Inactive;
+ format.setFont(m_view->font());
}
- QTextCharFormat format;
- format.setFont(m_view->font());
bool header = (m_weekNumbersShown && col == HeaderColumn)
|| (m_horizontalHeaderFormat != QCalendarWidget::NoHorizontalHeader && row == HeaderRow);
format.setBackground(pal.brush(cg, header ? QPalette::AlternateBase : QPalette::Base));
@@ -1145,9 +1107,9 @@ QTextCharFormat QCalendarModel::formatForCell(int row, int col) const
if (!header) {
QDate date = dateForCell(row, col);
format.merge(m_dateFormats.value(date));
- if(date < m_minimumDate || date > m_maximumDate)
+ if (date < m_minimumDate || date > m_maximumDate)
format.setBackground(pal.brush(cg, QPalette::Window));
- if (m_shownMonth != date.month())
+ if (m_shownMonth != date.month(m_calendar))
format.setForeground(pal.brush(QPalette::Disabled, QPalette::Text));
}
return format;
@@ -1161,7 +1123,7 @@ QVariant QCalendarModel::data(const QModelIndex &index, int role) const
int row = index.row();
int column = index.column();
- if(role == Qt::DisplayRole) {
+ if (role == Qt::DisplayRole) {
if (m_weekNumbersShown && column == HeaderColumn
&& row >= m_firstRow && row < m_firstRow + RowCount) {
QDate date = dateForCell(row, columnForDayOfWeek(Qt::Monday));
@@ -1173,14 +1135,14 @@ QVariant QCalendarModel::data(const QModelIndex &index, int role) const
return dayName(dayOfWeekForColumn(column));
QDate date = dateForCell(row, column);
if (date.isValid())
- return date.day();
+ return date.day(m_calendar);
return QString();
}
QTextCharFormat fmt = formatForCell(row, column);
- if (role == Qt::BackgroundColorRole)
+ if (role == Qt::BackgroundRole)
return fmt.background().color();
- if (role == Qt::TextColorRole)
+ if (role == Qt::ForegroundRole)
return fmt.foreground().color();
if (role == Qt::FontRole)
return fmt.font();
@@ -1195,13 +1157,13 @@ Qt::ItemFlags QCalendarModel::flags(const QModelIndex &index) const
if (!date.isValid())
return QAbstractTableModel::flags(index);
if (date < m_minimumDate)
- return 0;
+ return { };
if (date > m_maximumDate)
- return 0;
+ return { };
return QAbstractTableModel::flags(index);
}
-void QCalendarModel::setDate(const QDate &d)
+void QCalendarModel::setDate(QDate d)
{
m_date = d;
if (m_date < m_minimumDate)
@@ -1210,6 +1172,20 @@ void QCalendarModel::setDate(const QDate &d)
m_date = m_maximumDate;
}
+void QCalendarModel::setCalendar(QCalendar c)
+{
+ m_calendar = c;
+ m_shownYear = m_date.year(c);
+ m_shownMonth = m_date.month(c);
+ internalUpdate();
+ m_view->internalUpdate();
+}
+
+QCalendar QCalendarModel::calendar() const
+{
+ return m_calendar;
+}
+
void QCalendarModel::showMonth(int year, int month)
{
if (m_shownYear == year && m_shownMonth == month)
@@ -1221,7 +1197,7 @@ void QCalendarModel::showMonth(int year, int month)
internalUpdate();
}
-void QCalendarModel::setMinimumDate(const QDate &d)
+void QCalendarModel::setMinimumDate(QDate d)
{
if (!d.isValid() || d == m_minimumDate)
return;
@@ -1234,7 +1210,7 @@ void QCalendarModel::setMinimumDate(const QDate &d)
internalUpdate();
}
-void QCalendarModel::setMaximumDate(const QDate &d)
+void QCalendarModel::setMaximumDate(QDate d)
{
if (!d.isValid() || d == m_maximumDate)
return;
@@ -1247,7 +1223,7 @@ void QCalendarModel::setMaximumDate(const QDate &d)
internalUpdate();
}
-void QCalendarModel::setRange(const QDate &min, const QDate &max)
+void QCalendarModel::setRange(QDate min, QDate max)
{
m_minimumDate = min;
m_maximumDate = max;
@@ -1277,11 +1253,13 @@ void QCalendarModel::setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeader
int oldFormat = m_horizontalHeaderFormat;
m_horizontalHeaderFormat = format;
if (oldFormat == QCalendarWidget::NoHorizontalHeader) {
+ beginInsertRows(QModelIndex(), 0, 0);
m_firstRow = 1;
- insertRow(0);
+ endInsertRows();
} else if (m_horizontalHeaderFormat == QCalendarWidget::NoHorizontalHeader) {
+ beginRemoveRows(QModelIndex(), 0, 0);
m_firstRow = 0;
- removeRow(0);
+ endRemoveRows();
}
internalUpdate();
}
@@ -1312,11 +1290,13 @@ void QCalendarModel::setWeekNumbersShown(bool show)
m_weekNumbersShown = show;
if (show) {
+ beginInsertColumns(QModelIndex(), 0, 0);
m_firstColumn = 1;
- insertColumn(0);
+ endInsertColumns();
} else {
+ beginRemoveColumns(QModelIndex(), 0, 0);
m_firstColumn = 0;
- removeColumn(0);
+ endRemoveColumns();
}
internalUpdate();
}
@@ -1340,6 +1320,8 @@ QModelIndex QCalendarView::moveCursor(CursorAction cursorAction, Qt::KeyboardMod
if (!calendarModel)
return QTableView::moveCursor(cursorAction, modifiers);
+ QCalendar cal = calendarModel->calendar();
+
if (readOnly)
return currentIndex();
@@ -1358,17 +1340,27 @@ QModelIndex QCalendarView::moveCursor(CursorAction cursorAction, Qt::KeyboardMod
case QAbstractItemView::MoveRight:
currentDate = currentDate.addDays(isRightToLeft() ? -1 : 1);
break;
- case QAbstractItemView::MoveHome:
- currentDate = QDate(currentDate.year(), currentDate.month(), 1);
+ case QAbstractItemView::MoveHome: {
+ auto parts = cal.partsFromDate(currentDate);
+ if (parts.isValid()) {
+ parts.day = 1;
+ currentDate = cal.dateFromParts(parts);
+ }
+ }
break;
- case QAbstractItemView::MoveEnd:
- currentDate = QDate(currentDate.year(), currentDate.month(), currentDate.daysInMonth());
+ case QAbstractItemView::MoveEnd: {
+ auto parts = cal.partsFromDate(currentDate);
+ if (parts.isValid()) {
+ parts.day = cal.daysInMonth(parts.month, parts.year);
+ currentDate = cal.dateFromParts(parts);
+ }
+ }
break;
case QAbstractItemView::MovePageUp:
- currentDate = currentDate.addMonths(-1);
+ currentDate = currentDate.addMonths(-1, cal);
break;
case QAbstractItemView::MovePageDown:
- currentDate = currentDate.addMonths(1);
+ currentDate = currentDate.addMonths(1, cal);
break;
case QAbstractItemView::MoveNext:
case QAbstractItemView::MovePrevious:
@@ -1384,14 +1376,14 @@ void QCalendarView::keyPressEvent(QKeyEvent *event)
{
#ifdef QT_KEYPAD_NAVIGATION
if (event->key() == Qt::Key_Select) {
- if (QApplication::keypadNavigationEnabled()) {
+ if (QApplicationPrivate::keypadNavigationEnabled()) {
if (!hasEditFocus()) {
setEditFocus(true);
return;
}
}
} else if (event->key() == Qt::Key_Back) {
- if (QApplication::keypadNavigationEnabled() && hasEditFocus()) {
+ if (QApplicationPrivate::keypadNavigationEnabled() && hasEditFocus()) {
if (qobject_cast<QCalendarModel *>(model())) {
emit changeDate(origDate, true); //changes selection back to origDate, but doesn't activate
setEditFocus(false);
@@ -1418,11 +1410,12 @@ void QCalendarView::keyPressEvent(QKeyEvent *event)
#if QT_CONFIG(wheelevent)
void QCalendarView::wheelEvent(QWheelEvent *event)
{
- const int numDegrees = event->delta() / 8;
+ const int numDegrees = event->angleDelta().y() / 8;
const int numSteps = numDegrees / 15;
const QModelIndex index = currentIndex();
- QDate currentDate = static_cast<QCalendarModel*>(model())->dateForCell(index.row(), index.column());
- currentDate = currentDate.addMonths(-numSteps);
+ QCalendarModel *calendarModel = static_cast<QCalendarModel*>(model());
+ QDate currentDate = calendarModel->dateForCell(index.row(), index.column());
+ currentDate = currentDate.addMonths(-numSteps, calendarModel->calendar());
emit showDate(currentDate);
}
#endif
@@ -1446,7 +1439,7 @@ QDate QCalendarView::handleMouseEvent(QMouseEvent *event)
if (!calendarModel)
return QDate();
- QPoint pos = event->pos();
+ QPoint pos = event->position().toPoint();
QModelIndex index = indexAt(pos);
QDate date = calendarModel->dateForCell(index.row(), index.column());
if (date.isValid() && date >= calendarModel->m_minimumDate
@@ -1555,16 +1548,16 @@ void QCalendarView::mouseReleaseEvent(QMouseEvent *event)
}
}
-class QCalendarDelegate : public QItemDelegate
+class QCalendarDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
- QCalendarDelegate(QCalendarWidgetPrivate *w, QObject *parent = 0)
- : QItemDelegate(parent), calendarWidgetPrivate(w)
+ QCalendarDelegate(QCalendarWidgetPrivate *w, QObject *parent = nullptr)
+ : QStyledItemDelegate(parent), calendarWidgetPrivate(w)
{ }
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
- void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const;
+ void paintCell(QPainter *painter, const QRect &rect, QDate date) const;
private:
QCalendarWidgetPrivate *calendarWidgetPrivate;
@@ -1581,9 +1574,8 @@ public:
protected:
void paintEvent(QPaintEvent *e) override
{
- Q_UNUSED(e)
+ Q_UNUSED(e);
-#if 1 // Used to be excluded in Qt4 for Q_WS_MAC
QStyleOptionToolButton opt;
initStyleOption(&opt);
@@ -1596,7 +1588,7 @@ protected:
toolPalette.setColor(QPalette::ButtonText, toolPalette.color(QPalette::HighlightedText));
setPalette(toolPalette);
}
-#endif
+
QToolButton::paintEvent(e);
}
};
@@ -1616,7 +1608,20 @@ protected:
}
};
-} // unnamed namespace
+} // namespace QtPrivate
+
+using QCalendarDateSectionValidator = QtPrivate::QCalendarDateSectionValidator;
+using QCalendarDayValidator = QtPrivate::QCalendarDayValidator;
+using QCalendarMonthValidator = QtPrivate::QCalendarMonthValidator;
+using QCalendarYearValidator = QtPrivate::QCalendarYearValidator;
+using QCalendarDateValidator = QtPrivate::QCalendarDateValidator;
+using QPrevNextCalButton = QtPrivate::QPrevNextCalButton;
+using QCalendarDelegate = QtPrivate::QCalendarDelegate;
+using QCalToolButton = QtPrivate::QCalToolButton;
+using QCalendarDelegate = QtPrivate::QCalendarDelegate;
+using QCalendarModel = QtPrivate::QCalendarModel;
+using QCalendarView = QtPrivate::QCalendarView;
+using QCalendarTextNavigator = QtPrivate::QCalendarTextNavigator;
class QCalendarWidgetPrivate : public QWidgetPrivate
{
@@ -1626,11 +1631,11 @@ public:
void showMonth(int year, int month);
void update();
- void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const;
+ void paintCell(QPainter *painter, const QRect &rect, QDate date) const;
- void _q_slotShowDate(const QDate &date);
- void _q_slotChangeDate(const QDate &date);
- void _q_slotChangeDate(const QDate &date, bool changeMonth);
+ void _q_slotShowDate(QDate date);
+ void _q_slotChangeDate(QDate date);
+ void _q_slotChangeDate(QDate date, bool changeMonth);
void _q_editingFinished();
void _q_monthChanged(QAction*);
void _q_prevMonthClicked();
@@ -1643,7 +1648,7 @@ public:
void updateMonthMenu();
void updateMonthMenuNames();
void updateNavigationBar();
- void updateCurrentPage(const QDate &newDate);
+ void updateCurrentPage(QDate newDate);
inline QDate getCurrentDate();
void setNavigatorEnabled(bool enable);
@@ -1678,28 +1683,28 @@ void QCalendarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt
QRect rect = option.rect;
calendarWidgetPrivate->paintCell(painter, rect, date);
} else {
- QItemDelegate::paint(painter, option, index);
+ QStyledItemDelegate::paint(painter, option, index);
}
}
-void QCalendarDelegate::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const
+void QCalendarDelegate::paintCell(QPainter *painter, const QRect &rect, QDate date) const
{
storedOption.rect = rect;
int row = -1;
int col = -1;
calendarWidgetPrivate->m_model->cellForDate(date, &row, &col);
QModelIndex idx = calendarWidgetPrivate->m_model->index(row, col);
- QItemDelegate::paint(painter, storedOption, idx);
+ QStyledItemDelegate::paint(painter, storedOption, idx);
}
QCalendarWidgetPrivate::QCalendarWidgetPrivate()
: QWidgetPrivate()
{
- m_model = 0;
- m_view = 0;
- m_delegate = 0;
- m_selection = 0;
- m_navigator = 0;
+ m_model = nullptr;
+ m_view = nullptr;
+ m_delegate = nullptr;
+ m_selection = nullptr;
+ m_navigator = nullptr;
m_dateEditEnabled = false;
navBarVisible = true;
oldFocusPolicy = Qt::StrongFocus;
@@ -1709,7 +1714,7 @@ void QCalendarWidgetPrivate::setNavigatorEnabled(bool enable)
{
Q_Q(QCalendarWidget);
- bool navigatorEnabled = (m_navigator->widget() != 0);
+ bool navigatorEnabled = (m_navigator->widget() != nullptr);
if (enable == navigatorEnabled)
return;
@@ -1721,7 +1726,7 @@ void QCalendarWidgetPrivate::setNavigatorEnabled(bool enable)
q, SLOT(_q_editingFinished()));
m_view->installEventFilter(m_navigator);
} else {
- m_navigator->setWidget(0);
+ m_navigator->setWidget(nullptr);
q->disconnect(m_navigator, SIGNAL(dateChanged(QDate)),
q, SLOT(_q_slotChangeDate(QDate)));
q->disconnect(m_navigator, SIGNAL(editingFinished()),
@@ -1734,7 +1739,7 @@ void QCalendarWidgetPrivate::createNavigationBar(QWidget *widget)
{
Q_Q(QCalendarWidget);
navBarBackground = new QWidget(widget);
- navBarBackground->setObjectName(QLatin1String("qt_calendar_navigationbar"));
+ navBarBackground->setObjectName("qt_calendar_navigationbar"_L1);
navBarBackground->setAutoFillBackground(true);
navBarBackground->setBackgroundRole(QPalette::Highlight);
@@ -1754,8 +1759,8 @@ void QCalendarWidgetPrivate::createNavigationBar(QWidget *widget)
monthButton->setAutoRaise(true);
monthButton->setPopupMode(QToolButton::InstantPopup);
monthMenu = new QMenu(monthButton);
- for (int i = 1; i <= 12; i++) {
- QString monthName(q->locale().standaloneMonthName(i, QLocale::LongFormat));
+ for (int i = 1, e = m_model->m_calendar.maximumMonthsInYear(); i <= e; i++) {
+ QString monthName(m_model->monthName(q->locale(), i));
QAction *act = monthMenu->addAction(monthName);
act->setData(i);
monthToAction[i] = act;
@@ -1771,13 +1776,13 @@ void QCalendarWidgetPrivate::createNavigationBar(QWidget *widget)
monthButton->setFont(font);
yearButton->setFont(font);
yearEdit->setFrame(false);
- yearEdit->setMinimum(m_model->m_minimumDate.year());
- yearEdit->setMaximum(m_model->m_maximumDate.year());
+ yearEdit->setMinimum(m_model->m_minimumDate.year(m_model->m_calendar));
+ yearEdit->setMaximum(m_model->m_maximumDate.year(m_model->m_calendar));
yearEdit->hide();
spaceHolder = new QSpacerItem(0,0);
QHBoxLayout *headerLayout = new QHBoxLayout;
- headerLayout->setMargin(0);
+ headerLayout->setContentsMargins(QMargins());
headerLayout->setSpacing(0);
headerLayout->addWidget(prevMonth);
headerLayout->insertStretch(headerLayout->count());
@@ -1795,41 +1800,43 @@ void QCalendarWidgetPrivate::createNavigationBar(QWidget *widget)
monthButton->setFocusPolicy(Qt::NoFocus);
//set names for the header controls.
- prevMonth->setObjectName(QLatin1String("qt_calendar_prevmonth"));
- nextMonth->setObjectName(QLatin1String("qt_calendar_nextmonth"));
- monthButton->setObjectName(QLatin1String("qt_calendar_monthbutton"));
- yearButton->setObjectName(QLatin1String("qt_calendar_yearbutton"));
- yearEdit->setObjectName(QLatin1String("qt_calendar_yearedit"));
+ prevMonth->setObjectName("qt_calendar_prevmonth"_L1);
+ nextMonth->setObjectName("qt_calendar_nextmonth"_L1);
+ monthButton->setObjectName("qt_calendar_monthbutton"_L1);
+ yearButton->setObjectName("qt_calendar_yearbutton"_L1);
+ yearEdit->setObjectName("qt_calendar_yearedit"_L1);
updateMonthMenu();
- showMonth(m_model->m_date.year(), m_model->m_date.month());
+ showMonth(m_model->m_date.year(m_model->m_calendar), m_model->m_date.month(m_model->m_calendar));
}
void QCalendarWidgetPrivate::updateButtonIcons()
{
Q_Q(QCalendarWidget);
- prevMonth->setIcon(q->style()->standardIcon(q->isRightToLeft() ? QStyle::SP_ArrowRight : QStyle::SP_ArrowLeft, 0, q));
- nextMonth->setIcon(q->style()->standardIcon(q->isRightToLeft() ? QStyle::SP_ArrowLeft : QStyle::SP_ArrowRight, 0, q));
+ prevMonth->setIcon(q->style()->standardIcon(q->isRightToLeft() ? QStyle::SP_ArrowRight : QStyle::SP_ArrowLeft, nullptr, q));
+ nextMonth->setIcon(q->style()->standardIcon(q->isRightToLeft() ? QStyle::SP_ArrowLeft : QStyle::SP_ArrowRight, nullptr, q));
}
void QCalendarWidgetPrivate::updateMonthMenu()
{
- int beg = 1, end = 12;
+ int maxMonths = m_model->m_calendar.monthsInYear(m_model->m_shownYear);
+ int beg = 1, end = maxMonths;
bool prevEnabled = true;
bool nextEnabled = true;
- if (m_model->m_shownYear == m_model->m_minimumDate.year()) {
- beg = m_model->m_minimumDate.month();
- if (m_model->m_shownMonth == m_model->m_minimumDate.month())
+ QCalendar cal = m_model->calendar();
+ if (m_model->m_shownYear == m_model->m_minimumDate.year(cal)) {
+ beg = m_model->m_minimumDate.month(cal);
+ if (m_model->m_shownMonth == m_model->m_minimumDate.month(cal))
prevEnabled = false;
}
- if (m_model->m_shownYear == m_model->m_maximumDate.year()) {
- end = m_model->m_maximumDate.month();
- if (m_model->m_shownMonth == m_model->m_maximumDate.month())
+ if (m_model->m_shownYear == m_model->m_maximumDate.year(cal)) {
+ end = m_model->m_maximumDate.month(cal);
+ if (m_model->m_shownMonth == m_model->m_maximumDate.month(cal))
nextEnabled = false;
}
prevMonth->setEnabled(prevEnabled);
nextMonth->setEnabled(nextEnabled);
- for (int i = 1; i <= 12; i++) {
+ for (int i = 1; i <= maxMonths; i++) {
bool monthEnabled = true;
if (i < beg || i > end)
monthEnabled = false;
@@ -1842,14 +1849,15 @@ void QCalendarWidgetPrivate::updateMonthMenuNames()
Q_Q(QCalendarWidget);
for (int i = 1; i <= 12; i++) {
- QString monthName(q->locale().standaloneMonthName(i, QLocale::LongFormat));
+ QString monthName(m_model->monthName(q->locale(), i));
monthToAction[i]->setText(monthName);
}
}
-void QCalendarWidgetPrivate::updateCurrentPage(const QDate &date)
+void QCalendarWidgetPrivate::updateCurrentPage(QDate date)
{
Q_Q(QCalendarWidget);
+ QCalendar cal = m_model->calendar();
QDate newDate = date;
QDate minDate = q->minimumDate();
@@ -1858,7 +1866,7 @@ void QCalendarWidgetPrivate::updateCurrentPage(const QDate &date)
newDate = minDate;
if (maxDate.isValid()&& maxDate.daysTo(newDate) > 0)
newDate = maxDate;
- showMonth(newDate.year(), newDate.month());
+ showMonth(newDate.year(cal), newDate.month(cal));
int row = -1, col = -1;
m_model->cellForDate(newDate, &row, &col);
if (row != -1 && col != -1)
@@ -1872,7 +1880,7 @@ void QCalendarWidgetPrivate::_q_monthChanged(QAction *act)
{
monthButton->setText(act->text());
QDate currentDate = getCurrentDate();
- QDate newDate = currentDate.addMonths(act->data().toInt()-currentDate.month());
+ QDate newDate = currentDate.addMonths(act->data().toInt() - currentDate.month(m_model->m_calendar), m_model->m_calendar);
updateCurrentPage(newDate);
}
@@ -1884,27 +1892,28 @@ QDate QCalendarWidgetPrivate::getCurrentDate()
void QCalendarWidgetPrivate::_q_prevMonthClicked()
{
- QDate currentDate = getCurrentDate().addMonths(-1);
+ QDate currentDate = getCurrentDate().addMonths(-1, m_model->m_calendar);
updateCurrentPage(currentDate);
}
void QCalendarWidgetPrivate::_q_nextMonthClicked()
{
- QDate currentDate = getCurrentDate().addMonths(1);
+ QDate currentDate = getCurrentDate().addMonths(1, m_model->m_calendar);
updateCurrentPage(currentDate);
}
void QCalendarWidgetPrivate::_q_yearEditingFinished()
{
Q_Q(QCalendarWidget);
- yearButton->setText(yearEdit->text());
yearEdit->hide();
q->setFocusPolicy(oldFocusPolicy);
qApp->removeEventFilter(q);
spaceHolder->changeSize(0, 0);
yearButton->show();
QDate currentDate = getCurrentDate();
- currentDate = currentDate.addYears(yearEdit->text().toInt() - currentDate.year());
+ int newYear = q->locale().toInt(yearEdit->text());
+ currentDate = currentDate.addYears(newYear - currentDate.year(m_model->m_calendar), m_model->m_calendar);
+ yearButton->setText(q->locale().toString(currentDate, u"yyyy", m_model->m_calendar));
updateCurrentPage(currentDate);
}
@@ -1943,7 +1952,7 @@ void QCalendarWidgetPrivate::updateNavigationBar()
{
Q_Q(QCalendarWidget);
- QString monthName = q->locale().standaloneMonthName(m_model->m_shownMonth, QLocale::LongFormat);
+ QString monthName = m_model->monthName(q->locale(), m_model->m_shownMonth);
monthButton->setText(monthName);
yearEdit->setValue(m_model->m_shownYear);
@@ -1963,29 +1972,29 @@ void QCalendarWidgetPrivate::update()
}
}
-void QCalendarWidgetPrivate::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const
+void QCalendarWidgetPrivate::paintCell(QPainter *painter, const QRect &rect, QDate date) const
{
Q_Q(const QCalendarWidget);
q->paintCell(painter, rect, date);
}
-void QCalendarWidgetPrivate::_q_slotShowDate(const QDate &date)
+void QCalendarWidgetPrivate::_q_slotShowDate(QDate date)
{
updateCurrentPage(date);
}
-void QCalendarWidgetPrivate::_q_slotChangeDate(const QDate &date)
+void QCalendarWidgetPrivate::_q_slotChangeDate(QDate date)
{
_q_slotChangeDate(date, true);
}
-void QCalendarWidgetPrivate::_q_slotChangeDate(const QDate &date, bool changeMonth)
+void QCalendarWidgetPrivate::_q_slotChangeDate(QDate date, bool changeMonth)
{
QDate oldDate = m_model->m_date;
m_model->setDate(date);
QDate newDate = m_model->m_date;
if (changeMonth)
- showMonth(newDate.year(), newDate.month());
+ showMonth(newDate.year(m_model->m_calendar), newDate.month(m_model->m_calendar));
if (oldDate != newDate) {
update();
Q_Q(QCalendarWidget);
@@ -2092,7 +2101,7 @@ void QCalendarWidgetPrivate::_q_editingFinished()
\sa setCurrentPage()
*/
QCalendarWidget::QCalendarWidget(QWidget *parent)
- : QWidget(*new QCalendarWidgetPrivate, parent, 0)
+ : QWidget(*new QCalendarWidgetPrivate, parent, { })
{
Q_D(QCalendarWidget);
@@ -2100,14 +2109,14 @@ QCalendarWidget::QCalendarWidget(QWidget *parent)
setBackgroundRole(QPalette::Window);
QVBoxLayout *layoutV = new QVBoxLayout(this);
- layoutV->setMargin(0);
+ layoutV->setContentsMargins(QMargins());
d->m_model = new QCalendarModel(this);
QTextCharFormat fmt;
fmt.setForeground(QBrush(Qt::red));
d->m_model->m_dayFormats.insert(Qt::Saturday, fmt);
d->m_model->m_dayFormats.insert(Qt::Sunday, fmt);
d->m_view = new QCalendarView(this);
- d->m_view->setObjectName(QLatin1String("qt_calendar_calendarview"));
+ d->m_view->setObjectName("qt_calendar_calendarview"_L1);
d->m_view->setModel(d->m_model);
d->m_model->setView(d->m_view);
d->m_view->setSelectionBehavior(QAbstractItemView::SelectItems);
@@ -2147,7 +2156,7 @@ QCalendarWidget::QCalendarWidget(QWidget *parent)
connect(d->yearEdit, SIGNAL(editingFinished()),
this, SLOT(_q_yearEditingFinished()));
- layoutV->setMargin(0);
+ layoutV->setContentsMargins(QMargins());
layoutV->setSpacing(0);
layoutV->addWidget(d->navBarBackground);
layoutV->addWidget(d->m_view);
@@ -2189,7 +2198,9 @@ QSize QCalendarWidget::minimumSizeHint() const
int rows = 7;
int cols = 8;
- const int marginH = (style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1) * 2;
+ QStyleOption option;
+ option.initFrom(this);
+ const int marginH = (style()->pixelMetric(QStyle::PM_FocusFrameHMargin, &option, this) + 1) * 2;
if (horizontalHeaderFormat() == QCalendarWidget::NoHorizontalHeader) {
rows = 6;
@@ -2241,14 +2252,14 @@ QSize QCalendarWidget::minimumSizeHint() const
QFontMetrics fm = d->monthButton->fontMetrics();
int monthW = 0;
for (int i = 1; i < 12; i++) {
- QString monthName = locale().standaloneMonthName(i, QLocale::LongFormat);
+ QString monthName = d->m_model->monthName(locale(), i);
monthW = qMax(monthW, fm.boundingRect(monthName).width());
}
const int buttonDecoMargin = d->monthButton->sizeHint().width() - fm.boundingRect(d->monthButton->text()).width();
headerW += monthW + buttonDecoMargin;
fm = d->yearButton->fontMetrics();
- headerW += fm.boundingRect(QLatin1String("5555")).width() + buttonDecoMargin;
+ headerW += fm.boundingRect("5555"_L1).width() + buttonDecoMargin;
headerSize = QSize(headerW, headerH);
}
@@ -2266,7 +2277,7 @@ QSize QCalendarWidget::minimumSizeHint() const
Paints the cell specified by the given \a date, using the given \a painter and \a rect.
*/
-void QCalendarWidget::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const
+void QCalendarWidget::paintCell(QPainter *painter, const QRect &rect, QDate date) const
{
Q_D(const QCalendarWidget);
d->m_delegate->paintCell(painter, rect, date);
@@ -2289,7 +2300,7 @@ QDate QCalendarWidget::selectedDate() const
return d->m_model->m_date;
}
-void QCalendarWidget::setSelectedDate(const QDate &date)
+void QCalendarWidget::setSelectedDate(QDate date)
{
Q_D(QCalendarWidget);
if (d->m_model->m_date == date && date == d->getCurrentDate())
@@ -2301,7 +2312,8 @@ void QCalendarWidget::setSelectedDate(const QDate &date)
d->m_model->setDate(date);
d->update();
QDate newDate = d->m_model->m_date;
- d->showMonth(newDate.year(), newDate.month());
+ QCalendar cal = d->m_model->m_calendar;
+ d->showMonth(newDate.year(cal), newDate.month(cal));
emit selectionChanged();
}
@@ -2347,14 +2359,15 @@ void QCalendarWidget::setCurrentPage(int year, int month)
{
Q_D(QCalendarWidget);
QDate currentDate = d->getCurrentDate();
- int day = currentDate.day();
- int daysInMonths = QDate(year, month, 1).daysInMonth();
+ QCalendar cal = d->m_model->m_calendar;
+ int day = currentDate.day(cal);
+ int daysInMonths = cal.daysInMonth(month, year);
if (day > daysInMonths)
day = daysInMonths;
d->showMonth(year, month);
- QDate newDate(year, month, day);
+ QDate newDate(year, month, day, d->m_model->m_calendar);
int row = -1, col = -1;
d->m_model->cellForDate(newDate, &row, &col);
if (row != -1 && col != -1) {
@@ -2372,9 +2385,10 @@ void QCalendarWidget::setCurrentPage(int year, int month)
void QCalendarWidget::showNextMonth()
{
+ Q_D(const QCalendarWidget);
int year = yearShown();
int month = monthShown();
- if (month == 12) {
+ if (month == d->m_model->m_calendar.maximumMonthsInYear()) {
++year;
month = 1;
} else {
@@ -2392,11 +2406,13 @@ void QCalendarWidget::showNextMonth()
void QCalendarWidget::showPreviousMonth()
{
+ Q_D(const QCalendarWidget);
+
int year = yearShown();
int month = monthShown();
if (month == 1) {
--year;
- month = 12;
+ month = d->m_model->m_calendar.maximumMonthsInYear();
} else {
--month;
}
@@ -2442,8 +2458,10 @@ void QCalendarWidget::showPreviousYear()
*/
void QCalendarWidget::showSelectedDate()
{
+ Q_D(const QCalendarWidget);
+
QDate currentDate = selectedDate();
- setCurrentPage(currentDate.year(), currentDate.month());
+ setCurrentPage(currentDate.year(d->m_model->m_calendar), currentDate.month(d->m_model->m_calendar));
}
/*!
@@ -2453,8 +2471,10 @@ void QCalendarWidget::showSelectedDate()
*/
void QCalendarWidget::showToday()
{
+ Q_D(const QCalendarWidget);
+
QDate currentDate = QDate::currentDate();
- setCurrentPage(currentDate.year(), currentDate.month());
+ setCurrentPage(currentDate.year(d->m_model->m_calendar), currentDate.month(d->m_model->m_calendar));
}
/*!
@@ -2472,14 +2492,14 @@ void QCalendarWidget::showToday()
\snippet code/src_gui_widgets_qcalendarwidget.cpp 1
\endtable
- By default, the minimum date is the earliest date that the QDate
- class can handle.
-
When setting a minimum date, the maximumDate and selectedDate
properties are adjusted if the selection range becomes invalid. If
the provided date is not a valid QDate object, the
setMinimumDate() function does nothing.
+ The default minimum date is November 25, 4714 BCE.
+ You can restore this default by calling clearMinimumDate() (since Qt 6.6).
+
\sa setDateRange()
*/
@@ -2489,7 +2509,7 @@ QDate QCalendarWidget::minimumDate() const
return d->m_model->m_minimumDate;
}
-void QCalendarWidget::setMinimumDate(const QDate &date)
+void QCalendarWidget::setMinimumDate(QDate date)
{
Q_D(QCalendarWidget);
if (!date.isValid() || d->m_model->m_minimumDate == date)
@@ -2497,17 +2517,22 @@ void QCalendarWidget::setMinimumDate(const QDate &date)
QDate oldDate = d->m_model->m_date;
d->m_model->setMinimumDate(date);
- d->yearEdit->setMinimum(d->m_model->m_minimumDate.year());
+ d->yearEdit->setMinimum(d->m_model->m_minimumDate.year(d->m_model->m_calendar));
d->updateMonthMenu();
QDate newDate = d->m_model->m_date;
if (oldDate != newDate) {
d->update();
- d->showMonth(newDate.year(), newDate.month());
+ d->showMonth(newDate.year(d->m_model->m_calendar), newDate.month(d->m_model->m_calendar));
d->m_navigator->setDate(newDate);
emit selectionChanged();
}
}
+void QCalendarWidget::clearMinimumDate()
+{
+ setMinimumDate(QDate::fromJulianDay(1));
+}
+
/*!
\property QCalendarWidget::maximumDate
\brief the maximum date of the currently specified date range.
@@ -2523,14 +2548,14 @@ void QCalendarWidget::setMinimumDate(const QDate &date)
\snippet code/src_gui_widgets_qcalendarwidget.cpp 2
\endtable
- By default, the maximum date is the last day the QDate class can
- handle.
-
When setting a maximum date, the minimumDate and selectedDate
properties are adjusted if the selection range becomes invalid. If
the provided date is not a valid QDate object, the
setMaximumDate() function does nothing.
+ The default maximum date is December 31, 9999 CE.
+ You can restore this default by calling clearMaximumDate() (since Qt 6.6).
+
\sa setDateRange()
*/
@@ -2540,7 +2565,7 @@ QDate QCalendarWidget::maximumDate() const
return d->m_model->m_maximumDate;
}
-void QCalendarWidget::setMaximumDate(const QDate &date)
+void QCalendarWidget::setMaximumDate(QDate date)
{
Q_D(QCalendarWidget);
if (!date.isValid() || d->m_model->m_maximumDate == date)
@@ -2548,17 +2573,22 @@ void QCalendarWidget::setMaximumDate(const QDate &date)
QDate oldDate = d->m_model->m_date;
d->m_model->setMaximumDate(date);
- d->yearEdit->setMaximum(d->m_model->m_maximumDate.year());
+ d->yearEdit->setMaximum(d->m_model->m_maximumDate.year(d->m_model->m_calendar));
d->updateMonthMenu();
QDate newDate = d->m_model->m_date;
if (oldDate != newDate) {
d->update();
- d->showMonth(newDate.year(), newDate.month());
+ d->showMonth(newDate.year(d->m_model->m_calendar), newDate.month(d->m_model->m_calendar));
d->m_navigator->setDate(newDate);
emit selectionChanged();
}
}
+void QCalendarWidget::clearMaximumDate()
+{
+ setMaximumDate(QDate(9999, 12, 31));
+}
+
/*!
Defines a date range by setting the minimumDate and maximumDate
properties.
@@ -2578,7 +2608,7 @@ void QCalendarWidget::setMaximumDate(const QDate &date)
\sa setMinimumDate(), setMaximumDate()
*/
-void QCalendarWidget::setDateRange(const QDate &min, const QDate &max)
+void QCalendarWidget::setDateRange(QDate min, QDate max)
{
Q_D(QCalendarWidget);
if (d->m_model->m_minimumDate == min && d->m_model->m_maximumDate == max)
@@ -2588,13 +2618,13 @@ void QCalendarWidget::setDateRange(const QDate &min, const QDate &max)
QDate oldDate = d->m_model->m_date;
d->m_model->setRange(min, max);
- d->yearEdit->setMinimum(d->m_model->m_minimumDate.year());
- d->yearEdit->setMaximum(d->m_model->m_maximumDate.year());
+ d->yearEdit->setMinimum(d->m_model->m_minimumDate.year(d->m_model->m_calendar));
+ d->yearEdit->setMaximum(d->m_model->m_maximumDate.year(d->m_model->m_calendar));
d->updateMonthMenu();
QDate newDate = d->m_model->m_date;
if (oldDate != newDate) {
d->update();
- d->showMonth(newDate.year(), newDate.month());
+ d->showMonth(newDate.year(d->m_model->m_calendar), newDate.month(d->m_model->m_calendar));
d->m_navigator->setDate(newDate);
emit selectionChanged();
}
@@ -2701,6 +2731,39 @@ bool QCalendarWidget::isGridVisible() const
return d->m_view->showGrid();
}
+/*!
+ \since 5.14
+ Report the calendar system in use by this widget.
+
+ \sa setCalendar()
+*/
+
+QCalendar QCalendarWidget::calendar() const
+{
+ Q_D(const QCalendarWidget);
+ return d->m_model->m_calendar;
+}
+
+/*!
+ \since 5.14
+ Set \a c as the calendar system to be used by this widget.
+
+ The widget can use any supported calendar system.
+ By default, it uses the Gregorian calendar.
+
+ \sa calendar()
+*/
+
+void QCalendarWidget::setCalendar(QCalendar c)
+{
+ Q_D(QCalendarWidget);
+ d->m_model->setCalendar(c);
+ d->updateMonthMenuNames();
+ d->yearEdit->setMinimum(d->m_model->m_minimumDate.year(d->m_model->m_calendar));
+ d->yearEdit->setMaximum(d->m_model->m_maximumDate.year(d->m_model->m_calendar));
+ d->updateNavigationBar();
+}
+
void QCalendarWidget::setGridVisible(bool show)
{
Q_D(QCalendarWidget);
@@ -2827,10 +2890,10 @@ QMap<QDate, QTextCharFormat> QCalendarWidget::dateTextFormat() const
}
/*!
- Returns a QTextCharFormat for \a date. The char format can be be
+ Returns a QTextCharFormat for \a date. The char format can be
empty if the date is not renderd specially.
*/
-QTextCharFormat QCalendarWidget::dateTextFormat(const QDate &date) const
+QTextCharFormat QCalendarWidget::dateTextFormat(QDate date) const
{
Q_D(const QCalendarWidget);
return d->m_model->m_dateFormats.value(date);
@@ -2841,7 +2904,7 @@ QTextCharFormat QCalendarWidget::dateTextFormat(const QDate &date) const
If \a date is null, all date formats are cleared.
*/
-void QCalendarWidget::setDateTextFormat(const QDate &date, const QTextCharFormat &format)
+void QCalendarWidget::setDateTextFormat(QDate date, const QTextCharFormat &format)
{
Q_D(QCalendarWidget);
if (date.isNull())
@@ -2893,7 +2956,7 @@ void QCalendarWidget::setDateEditEnabled(bool enable)
\since 4.3
If the calendar widget's \l{dateEditEnabled}{date edit is enabled}, this
- property specifies the amount of time (in millseconds) that the date edit
+ property specifies the amount of time (in milliseconds) that the date edit
remains open after the most recent user input. Once this time has elapsed,
the date specified in the date edit is accepted and the popup is closed.
@@ -2919,7 +2982,7 @@ void QCalendarWidget::setDateEditAcceptDelay(int delay)
\sa updateCells(), yearShown(), monthShown()
*/
-void QCalendarWidget::updateCell(const QDate &date)
+void QCalendarWidget::updateCell(QDate date)
{
if (Q_UNLIKELY(!date.isValid())) {
qWarning("QCalendarWidget::updateCell: Invalid date");
@@ -2978,7 +3041,7 @@ void QCalendarWidget::updateCells()
*/
/*!
- \fn void QCalendarWidget::activated(const QDate &date)
+ \fn void QCalendarWidget::activated(QDate date)
This signal is emitted whenever the user presses the Return or
Enter key or double-clicks a \a date in the calendar
@@ -2986,7 +3049,7 @@ void QCalendarWidget::updateCells()
*/
/*!
- \fn void QCalendarWidget::clicked(const QDate &date)
+ \fn void QCalendarWidget::clicked(QDate date)
This signal is emitted when a mouse button is clicked. The date
the mouse was clicked on is specified by \a date. The signal is
@@ -3041,6 +3104,9 @@ bool QCalendarWidget::event(QEvent *event)
d->updateMonthMenuNames();
d->updateNavigationBar();
d->m_view->updateGeometry();
+ // TODO: fix this known bug of calendaring API:
+ // Changing locale before calendar works, but reverse order causes
+ // invalid month names (in C Locale apparently).
break;
case QEvent::FontChange:
case QEvent::ApplicationFontChange:
@@ -3050,6 +3116,7 @@ bool QCalendarWidget::event(QEvent *event)
case QEvent::StyleChange:
d->cachedSizeHint = QSize();
d->m_view->updateGeometry();
+ break;
default:
break;
}
@@ -3072,7 +3139,7 @@ bool QCalendarWidget::eventFilter(QObject *watched, QEvent *event)
if (!widget || widget->window() != tlw)
return QWidget::eventFilter(watched, event);
- QPoint mousePos = widget->mapTo(tlw, static_cast<QMouseEvent *>(event)->pos());
+ QPoint mousePos = widget->mapTo(tlw, static_cast<QMouseEvent *>(event)->position().toPoint());
QRect geom = QRect(d->yearEdit->mapTo(tlw, QPoint(0, 0)), d->yearEdit->size());
if (!geom.contains(mousePos)) {
event->accept();
@@ -3104,7 +3171,7 @@ void QCalendarWidget::resizeEvent(QResizeEvent * event)
// XXX Should really use a QWidgetStack for yearEdit and yearButton,
// XXX here we hide the year edit when the layout is likely to break
// XXX the manual positioning of the yearEdit over the yearButton.
- if(d->yearEdit->isVisible() && event->size().width() != event->oldSize().width())
+ if (d->yearEdit->isVisible() && event->size().width() != event->oldSize().width())
d->_q_yearEditingFinished();
QWidget::resizeEvent(event);