diff options
Diffstat (limited to 'src/widgets/widgets')
28 files changed, 338 insertions, 693 deletions
diff --git a/src/widgets/widgets/qabstractscrollarea.cpp b/src/widgets/widgets/qabstractscrollarea.cpp index 55b2dcd662..b295e66574 100644 --- a/src/widgets/widgets/qabstractscrollarea.cpp +++ b/src/widgets/widgets/qabstractscrollarea.cpp @@ -62,10 +62,6 @@ #include <private/qapplication_p.h> -#if 0 // Used to be included in Qt4 for Q_WS_MAC -#include <private/qt_mac_p.h> -#include <private/qt_cocoa_helpers_mac_p.h> -#endif #ifdef Q_OS_WIN # include <qt_windows.h> #endif @@ -169,9 +165,6 @@ QAbstractScrollAreaPrivate::QAbstractScrollAreaPrivate() shownOnce(false), inResize(false), sizeAdjustPolicy(QAbstractScrollArea::AdjustIgnored), viewport(0), cornerWidget(0), left(0), top(0), right(0), bottom(0), xoffset(0), yoffset(0), viewportFilter(0) -#if 0 // Used to be included in Qt4 for Q_WS_WIN - , singleFingerPanEnabled(false) -#endif { } @@ -322,16 +315,6 @@ void QAbstractScrollAreaPrivate::init() #endif } -#if 0 // Used to be included in Qt4 for Q_WS_WIN -void QAbstractScrollAreaPrivate::setSingleFingerPanEnabled(bool on) -{ - singleFingerPanEnabled = on; - QWidgetPrivate *dd = static_cast<QWidgetPrivate *>(QObjectPrivate::get(viewport)); - if (dd) - dd->winSetupGestures(); -} -#endif - void QAbstractScrollAreaPrivate::layoutChildren() { bool needH = false; @@ -362,38 +345,6 @@ void QAbstractScrollAreaPrivate::layoutChildren_helper(bool *needHorizontalScrol const int hscrollOverlap = hbar->style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarOverlap, &opt, hbar); const int vscrollOverlap = vbar->style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarOverlap, &opt, vbar); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - QWidget * const window = q->window(); - - // Use small scroll bars for tool windows, to match the native size grip. - bool hbarIsSmall = hbar->testAttribute(Qt::WA_MacSmallSize); - bool vbarIsSmall = vbar->testAttribute(Qt::WA_MacSmallSize); - const Qt::WindowType windowType = window->windowType(); - if (windowType == Qt::Tool) { - if (!hbarIsSmall) { - hbar->setAttribute(Qt::WA_MacMiniSize, false); - hbar->setAttribute(Qt::WA_MacNormalSize, false); - hbar->setAttribute(Qt::WA_MacSmallSize, true); - } - if (!vbarIsSmall) { - vbar->setAttribute(Qt::WA_MacMiniSize, false); - vbar->setAttribute(Qt::WA_MacNormalSize, false); - vbar->setAttribute(Qt::WA_MacSmallSize, true); - } - } else { - if (hbarIsSmall) { - hbar->setAttribute(Qt::WA_MacMiniSize, false); - hbar->setAttribute(Qt::WA_MacNormalSize, false); - hbar->setAttribute(Qt::WA_MacSmallSize, false); - } - if (vbarIsSmall) { - vbar->setAttribute(Qt::WA_MacMiniSize, false); - vbar->setAttribute(Qt::WA_MacNormalSize, false); - vbar->setAttribute(Qt::WA_MacSmallSize, false); - } - } -#endif - const int hsbExt = hbar->sizeHint().height(); const int vsbExt = vbar->sizeHint().width(); const QPoint extPoint(vsbExt, hsbExt); @@ -403,30 +354,6 @@ void QAbstractScrollAreaPrivate::layoutChildren_helper(bool *needHorizontalScrol const bool hasCornerWidget = (cornerWidget != 0); -// If the scroll bars are at the very right and bottom of the window we -// move their positions to be aligned with the size grip. -#if 0 // Used to be included in Qt4 for Q_WS_MAC - // Check if a native sizegrip is present. - bool hasMacReverseSizeGrip = false; - bool hasMacSizeGrip = false; - bool nativeGripPresent = false; - if (q->testAttribute(Qt::WA_WState_Created)) - nativeGripPresent = qt_mac_checkForNativeSizeGrip(q); - - if (nativeGripPresent) { - // Look for a native size grip at the visual window bottom right and at the - // absolute window bottom right. In reverse mode, the native size grip does not - // swich side, so we need to check if it is on the "wrong side". - const QPoint scrollAreaBottomRight = q->mapTo(window, widgetRect.bottomRight() - QPoint(frameWidth, frameWidth)); - const QPoint windowBottomRight = window->rect().bottomRight(); - const QPoint visualWindowBottomRight = QStyle::visualPos(opt.direction, opt.rect, windowBottomRight); - const QPoint offset = windowBottomRight - scrollAreaBottomRight; - const QPoint visualOffset = visualWindowBottomRight - scrollAreaBottomRight; - hasMacSizeGrip = (visualOffset.manhattanLength() < vsbExt); - hasMacReverseSizeGrip = (hasMacSizeGrip == false && (offset.manhattanLength() < hsbExt)); - } -#endif - QPoint cornerOffset((needv && vscrollOverlap == 0) ? vsbExt : 0, (needh && hscrollOverlap == 0) ? hsbExt : 0); QRect controlsRect; QRect viewportRect; @@ -458,12 +385,6 @@ void QAbstractScrollAreaPrivate::layoutChildren_helper(bool *needHorizontalScrol if (hasCornerWidget && ((needv && vscrollOverlap == 0) || (needh && hscrollOverlap == 0))) cornerOffset = extPoint; -#if 0 // Used to be included in Qt4 for Q_WS_MAC - // Also move the scroll bars if they are covered by the native Mac size grip. - if (hasMacSizeGrip) - cornerOffset = extPoint; -#endif - // The corner point is where the scroll bar rects, the corner widget rect and the // viewport rect meets. const QPoint cornerPoint(controlsRect.bottomRight() + QPoint(1, 1) - cornerOffset); @@ -475,13 +396,6 @@ void QAbstractScrollAreaPrivate::layoutChildren_helper(bool *needHorizontalScrol else cornerPaintingRect = QRect(); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (hasMacReverseSizeGrip) - reverseCornerPaintingRect = QRect(controlsRect.bottomRight() + QPoint(1, 1) - extPoint, extSize); - else - reverseCornerPaintingRect = QRect(); -#endif - // move the scrollbars away from top/left headers int vHeaderRight = 0; int hHeaderBottom = 0; @@ -501,10 +415,7 @@ void QAbstractScrollAreaPrivate::layoutChildren_helper(bool *needHorizontalScrol #endif // QT_CONFIG(itemviews) if (needh) { QRect horizontalScrollBarRect(QPoint(controlsRect.left() + vHeaderRight, cornerPoint.y()), QPoint(cornerPoint.x() - 1, controlsRect.bottom())); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (hasMacReverseSizeGrip) - horizontalScrollBarRect.adjust(vsbExt, 0, 0, 0); -#endif + if (!hasCornerWidget && htransient) horizontalScrollBarRect.adjust(0, 0, cornerOffset.x(), 0); scrollBarContainers[Qt::Horizontal]->setGeometry(QStyle::visualRect(opt.direction, opt.rect, horizontalScrollBarRect)); @@ -617,11 +528,9 @@ void QAbstractScrollArea::setViewport(QWidget *widget) d->viewport->setParent(this); d->viewport->setFocusProxy(this); d->viewport->installEventFilter(d->viewportFilter.data()); -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC #ifndef QT_NO_GESTURES d->viewport->grabGesture(Qt::PanGesture); #endif -#endif d->layoutChildren(); #ifndef QT_NO_OPENGL QWidgetPrivate::get(d->viewport)->initializeViewportFramebuffer(); @@ -1043,13 +952,6 @@ bool QAbstractScrollArea::event(QEvent *e) QPainter p(this); style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, &option, &p, this); } -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (d->reverseCornerPaintingRect.isValid()) { - option.rect = d->reverseCornerPaintingRect; - QPainter p(this); - style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, &option, &p, this); - } -#endif } QFrame::paintEvent((QPaintEvent*)e); break; @@ -1122,38 +1024,10 @@ bool QAbstractScrollArea::event(QEvent *e) hBar->setValue(se->contentPos().x()); vBar->setValue(se->contentPos().y()); -#if 0 // Used to be included in Qt4 for Q_WS_WIN - typedef BOOL (*PtrBeginPanningFeedback)(HWND); - typedef BOOL (*PtrUpdatePanningFeedback)(HWND, LONG, LONG, BOOL); - typedef BOOL (*PtrEndPanningFeedback)(HWND, BOOL); - - static PtrBeginPanningFeedback ptrBeginPanningFeedback = 0; - static PtrUpdatePanningFeedback ptrUpdatePanningFeedback = 0; - static PtrEndPanningFeedback ptrEndPanningFeedback = 0; - - if (!ptrBeginPanningFeedback) - ptrBeginPanningFeedback = (PtrBeginPanningFeedback) QLibrary::resolve(QLatin1String("UxTheme"), "BeginPanningFeedback"); - if (!ptrUpdatePanningFeedback) - ptrUpdatePanningFeedback = (PtrUpdatePanningFeedback) QLibrary::resolve(QLatin1String("UxTheme"), "UpdatePanningFeedback"); - if (!ptrEndPanningFeedback) - ptrEndPanningFeedback = (PtrEndPanningFeedback) QLibrary::resolve(QLatin1String("UxTheme"), "EndPanningFeedback"); - - if (ptrBeginPanningFeedback && ptrUpdatePanningFeedback && ptrEndPanningFeedback) { - WId wid = window()->winId(); - - if (!se->overshootDistance().isNull() && d->overshoot.isNull()) - ptrBeginPanningFeedback(wid); - if (!se->overshootDistance().isNull()) - ptrUpdatePanningFeedback(wid, -se->overshootDistance().x(), -se->overshootDistance().y(), false); - if (se->overshootDistance().isNull() && !d->overshoot.isNull()) - ptrEndPanningFeedback(wid, true); - } else -#endif - { - QPoint delta = d->overshoot - se->overshootDistance().toPoint(); - if (!delta.isNull()) - viewport()->move(viewport()->pos() + delta); - } + QPoint delta = d->overshoot - se->overshootDistance().toPoint(); + if (!delta.isNull()) + viewport()->move(viewport()->pos() + delta); + d->overshoot = se->overshootDistance().toPoint(); return true; @@ -1546,13 +1420,6 @@ void QAbstractScrollAreaPrivate::_q_vslide(int y) void QAbstractScrollAreaPrivate::_q_showOrHideScrollBars() { layoutChildren(); -#if 0 // Used to be included in Qt4 for Q_WS_WIN - // Need to re-subscribe to gestures as the content changes to make sure we - // enable/disable panning when needed. - QWidgetPrivate *dd = static_cast<QWidgetPrivate *>(QObjectPrivate::get(viewport)); - if (dd) - dd->winSetupGestures(); -#endif } QPoint QAbstractScrollAreaPrivate::contentsOffset() const diff --git a/src/widgets/widgets/qabstractscrollarea_p.h b/src/widgets/widgets/qabstractscrollarea_p.h index 732a2ab40d..6d78b9db6d 100644 --- a/src/widgets/widgets/qabstractscrollarea_p.h +++ b/src/widgets/widgets/qabstractscrollarea_p.h @@ -85,9 +85,7 @@ public: QWidget *viewport; QWidget *cornerWidget; QRect cornerPaintingRect; -#if 0 // Used to be included in Qt4 for Q_WS_MAC - QRect reverseCornerPaintingRect; -#endif + int left, top, right, bottom; // viewport margin int xoffset, yoffset; @@ -112,11 +110,6 @@ public: inline bool viewportEvent(QEvent *event) { return q_func()->viewportEvent(event); } QScopedPointer<QObject> viewportFilter; - -#if 0 // Used to be included in Qt4 for Q_WS_WIN - bool singleFingerPanEnabled; - void setSingleFingerPanEnabled(bool on = true); -#endif }; class QAbstractScrollAreaFilter : public QObject diff --git a/src/widgets/widgets/qabstractslider.cpp b/src/widgets/widgets/qabstractslider.cpp index 129d540f50..dc325ab871 100644 --- a/src/widgets/widgets/qabstractslider.cpp +++ b/src/widgets/widgets/qabstractslider.cpp @@ -721,15 +721,10 @@ bool QAbstractSliderPrivate::scrollByDelta(Qt::Orientation orientation, Qt::Keyb offset_accumulated = 0; offset_accumulated += stepsToScrollF; -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC + // Don't scroll more than one page in any case: stepsToScroll = qBound(-pageStep, int(offset_accumulated), pageStep); -#else - // Native UI-elements on Mac can scroll hundreds of lines at a time as - // a result of acceleration. So keep the same behaviour in Qt, and - // don't restrict stepsToScroll to certain maximum (pageStep): - stepsToScroll = int(offset_accumulated); -#endif + offset_accumulated -= int(offset_accumulated); if (stepsToScroll == 0) { // We moved less than a line, but might still have accumulated partial scroll, diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp index f5708788b8..d49d9dbd66 100644 --- a/src/widgets/widgets/qabstractspinbox.cpp +++ b/src/widgets/widgets/qabstractspinbox.cpp @@ -1321,7 +1321,9 @@ void QAbstractSpinBox::contextMenuEvent(QContextMenuEvent *event) d->reset(); QAction *selAll = new QAction(tr("&Select All"), menu); +#if QT_CONFIG(shortcut) selAll->setShortcut(QKeySequence::SelectAll); +#endif menu->insertAction(d->edit->d_func()->selectAllAction, selAll); menu->removeAction(d->edit->d_func()->selectAllAction); diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp index 78706b1854..ec19b64d4a 100644 --- a/src/widgets/widgets/qcalendarwidget.cpp +++ b/src/widgets/widgets/qcalendarwidget.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -57,6 +57,7 @@ #include <private/qapplication_p.h> #include <qbasictimer.h> #include <qstylepainter.h> +#include <qcalendar.h> #include <vector> @@ -90,16 +91,15 @@ 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) @@ -117,10 +117,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; @@ -181,21 +181,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.year, parts.month)); + 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; } @@ -204,16 +201,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); } } @@ -225,10 +222,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; @@ -289,23 +286,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(parts.year, m_month)); // 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; } @@ -314,16 +307,16 @@ 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()); + return QString::number(date.month(cal)); } else if (repeat == 2) { - return formatNumber(date.month(), 2); + return formatNumber(date.month(cal), 2); } else if (repeat == 3) { - return m_locale.standaloneMonthName(date.month(), QLocale::ShortFormat); + return cal.standaloneMonthName(m_locale, date.month(cal), QLocale::ShortFormat); } else /*if (repeat >= 4)*/ { - return m_locale.standaloneMonthName(date.month(), QLocale::LongFormat); + return cal.standaloneMonthName(m_locale, date.month(cal), QLocale::LongFormat); } } @@ -335,10 +328,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; @@ -349,6 +342,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) @@ -397,21 +392,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.year, parts.month)); + 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; } @@ -420,11 +414,11 @@ 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)); } /////////////////////////////////// @@ -446,18 +440,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(); @@ -507,17 +501,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(); @@ -529,7 +523,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; @@ -591,11 +585,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() @@ -614,7 +608,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; @@ -631,7 +625,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) @@ -645,7 +639,8 @@ 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()) { } + : QObject(parent), m_dateText(0), m_dateFrame(0), m_dateValidator(0), + m_widget(0), m_editDelay(1500), m_date(QDate::currentDate()) {} QWidget *widget() const; void setWidget(QWidget *widget); @@ -653,13 +648,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: @@ -676,6 +671,7 @@ private: int m_editDelay; QDate m_date; + const QCalendar m_calendar; }; QWidget *QCalendarTextNavigator::widget() const @@ -688,7 +684,7 @@ void QCalendarTextNavigator::setWidget(QWidget *widget) m_widget = widget; } -void QCalendarTextNavigator::setDate(const QDate &date) +void QCalendarTextNavigator::setDate(QDate date) { m_date = date; } @@ -700,7 +696,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 @@ -740,7 +736,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); @@ -775,7 +771,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(); @@ -895,12 +891,15 @@ public: } 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); @@ -914,7 +913,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) @@ -922,10 +921,11 @@ public: void internalUpdate(); QDate referenceDate() const; - int columnForFirstOfMonth(const QDate &date) const; + int columnForFirstOfMonth(QDate date) const; int m_firstColumn; int m_firstRow; + QCalendar m_calendar; QDate m_date; QDate m_minimumDate; QDate m_maximumDate; @@ -951,9 +951,9 @@ public: virtual void keyboardSearch(const QString & search) override { Q_UNUSED(search) } 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; @@ -984,8 +984,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), @@ -1028,9 +1028,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; @@ -1038,9 +1039,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 @@ -1056,11 +1058,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; @@ -1075,7 +1078,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; @@ -1148,7 +1152,7 @@ QTextCharFormat QCalendarModel::formatForCell(int row, int col) const format.merge(m_dateFormats.value(date)); 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; @@ -1174,7 +1178,7 @@ 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(); } @@ -1202,7 +1206,7 @@ Qt::ItemFlags QCalendarModel::flags(const QModelIndex &index) const return QAbstractTableModel::flags(index); } -void QCalendarModel::setDate(const QDate &d) +void QCalendarModel::setDate(QDate d) { m_date = d; if (m_date < m_minimumDate) @@ -1211,6 +1215,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) @@ -1222,7 +1240,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; @@ -1235,7 +1253,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; @@ -1248,7 +1266,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; @@ -1341,6 +1359,8 @@ QModelIndex QCalendarView::moveCursor(CursorAction cursorAction, Qt::KeyboardMod if (!calendarModel) return QTableView::moveCursor(cursorAction, modifiers); + QCalendar cal = calendarModel->calendar(); + if (readOnly) return currentIndex(); @@ -1359,17 +1379,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.year, parts.month); + 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: @@ -1422,8 +1452,9 @@ void QCalendarView::wheelEvent(QWheelEvent *event) 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 @@ -1566,7 +1597,7 @@ public: { } 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; @@ -1585,7 +1616,6 @@ protected: { Q_UNUSED(e) -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC QStyleOptionToolButton opt; initStyleOption(&opt); @@ -1598,7 +1628,7 @@ protected: toolPalette.setColor(QPalette::ButtonText, toolPalette.color(QPalette::HighlightedText)); setPalette(toolPalette); } -#endif + QToolButton::paintEvent(e); } }; @@ -1628,11 +1658,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(); @@ -1645,7 +1675,7 @@ public: void updateMonthMenu(); void updateMonthMenuNames(); void updateNavigationBar(); - void updateCurrentPage(const QDate &newDate); + void updateCurrentPage(QDate newDate); inline QDate getCurrentDate(); void setNavigatorEnabled(bool enable); @@ -1684,7 +1714,7 @@ void QCalendarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt } } -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; @@ -1757,7 +1787,7 @@ void QCalendarWidgetPrivate::createNavigationBar(QWidget *widget) monthButton->setPopupMode(QToolButton::InstantPopup); monthMenu = new QMenu(monthButton); for (int i = 1; i <= 12; i++) { - QString monthName(q->locale().standaloneMonthName(i, QLocale::LongFormat)); + QString monthName(m_model->m_calendar.standaloneMonthName(q->locale(), i, QLocale::LongFormat)); QAction *act = monthMenu->addAction(monthName); act->setData(i); monthToAction[i] = act; @@ -1773,8 +1803,8 @@ 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); @@ -1804,7 +1834,7 @@ void QCalendarWidgetPrivate::createNavigationBar(QWidget *widget) 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_calendar), m_model->m_date.month(m_model->m_calendar)); } void QCalendarWidgetPrivate::updateButtonIcons() @@ -1816,22 +1846,24 @@ void QCalendarWidgetPrivate::updateButtonIcons() 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; @@ -1844,14 +1876,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->m_calendar.standaloneMonthName(q->locale(), i, QLocale::LongFormat)); 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(); @@ -1860,7 +1893,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) @@ -1874,7 +1907,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); } @@ -1886,27 +1919,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()); + yearButton->setText(q->locale().toString(yearEdit->value())); 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); updateCurrentPage(currentDate); } @@ -1945,7 +1979,7 @@ void QCalendarWidgetPrivate::updateNavigationBar() { Q_Q(QCalendarWidget); - QString monthName = q->locale().standaloneMonthName(m_model->m_shownMonth, QLocale::LongFormat); + QString monthName = m_model->m_calendar.standaloneMonthName(q->locale(), m_model->m_shownMonth, QLocale::LongFormat); monthButton->setText(monthName); yearEdit->setValue(m_model->m_shownYear); @@ -1965,29 +1999,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); @@ -2243,7 +2277,7 @@ 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->m_calendar.standaloneMonthName(locale(), i, QLocale::LongFormat); monthW = qMax(monthW, fm.boundingRect(monthName).width()); } const int buttonDecoMargin = d->monthButton->sizeHint().width() - fm.boundingRect(d->monthButton->text()).width(); @@ -2303,7 +2337,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(); } @@ -2349,14 +2384,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(year, month); 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) { @@ -2374,9 +2410,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.maxMonthsInYear()) { ++year; month = 1; } else { @@ -2394,11 +2431,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.maxMonthsInYear(); } else { --month; } @@ -2444,8 +2483,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)); } /*! @@ -2455,8 +2496,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)); } /*! @@ -2499,12 +2542,12 @@ 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(); } @@ -2550,12 +2593,12 @@ 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(); } @@ -2590,13 +2633,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(); } @@ -2703,6 +2746,22 @@ bool QCalendarWidget::isGridVisible() const return d->m_view->showGrid(); } +QCalendar QCalendarWidget::calendar() const +{ + Q_D(const QCalendarWidget); + return d->m_model->m_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); @@ -3043,6 +3102,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: diff --git a/src/widgets/widgets/qcalendarwidget.h b/src/widgets/widgets/qcalendarwidget.h index 44ba340289..08825a0ff3 100644 --- a/src/widgets/widgets/qcalendarwidget.h +++ b/src/widgets/widgets/qcalendarwidget.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2018 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -112,6 +112,9 @@ public: bool isNavigationBarVisible() const; bool isGridVisible() const; + QCalendar calendar() const; + void setCalendar(QCalendar calendar); + SelectionMode selectionMode() const; void setSelectionMode(SelectionMode mode); diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 8b54d61e8e..e73c63f657 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -64,7 +64,9 @@ #include <qheaderview.h> #include <qmath.h> #include <qmetaobject.h> +#if QT_CONFIG(proxymodel) #include <qabstractproxymodel.h> +#endif #include <qstylehints.h> #include <private/qguiapplication_p.h> #include <private/qhighdpiscaling_p.h> @@ -200,6 +202,7 @@ QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewIt void QComboBoxPrivate::_q_completerActivated(const QModelIndex &index) { Q_Q(QComboBox); +#if QT_CONFIG(proxymodel) if (index.isValid() && q->completer()) { QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(q->completer()->completionModel()); if (proxy) { @@ -221,6 +224,7 @@ void QComboBoxPrivate::_q_completerActivated(const QModelIndex &index) emitActivated(currentIndex); } } +#endif # ifdef QT_KEYPAD_NAVIGATION if ( QApplicationPrivate::keypadNavigationEnabled() @@ -443,13 +447,6 @@ void QComboBoxPrivateContainer::paintEvent(QPaintEvent *e) void QComboBoxPrivateContainer::leaveEvent(QEvent *) { -// On Mac using the Mac style we want to clear the selection -// when the mouse moves outside the popup. -#if 0 // Used to be included in Qt4 for Q_WS_MAC - QStyleOptionComboBox opt = comboStyleOption(); - if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)) - view->clearSelection(); -#endif } QComboBoxPrivateContainer::QComboBoxPrivateContainer(QAbstractItemView *itemView, QComboBox *parent) diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index 3c92d4be0e..e26993fb23 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -312,6 +312,22 @@ void QDateTimeEdit::setTime(const QTime &time) } +QCalendar QDateTimeEdit::calendar() const +{ + Q_D(const QDateTimeEdit); + return d->calendar; +} + +void QDateTimeEdit::setCalendar(QCalendar calendar) +{ + Q_D(QDateTimeEdit); + // Set invalid date time to prevent runtime crashes on calendar change + QDateTime previousValue = d->value.toDateTime(); + setDateTime(QDateTime()); + d->setCalendar(calendar); + setDateTime(previousValue); +} + /*! \property QDateTimeEdit::minimumDateTime \since 4.4 @@ -1125,16 +1141,6 @@ void QDateTimeEdit::keyPressEvent(QKeyEvent *event) select = false; break; } -#if 0 // Used to be included in Qt4 for Q_WS_MAC - else -#ifdef QT_KEYPAD_NAVIGATION - if (!QApplicationPrivate::keypadNavigationEnabled()) -#endif - { - select = (event->modifiers() & Qt::ShiftModifier); - break; - } -#endif } Q_FALLTHROUGH(); case Qt::Key_Backtab: @@ -1354,7 +1360,7 @@ void QDateTimeEdit::stepBy(int steps) QString QDateTimeEdit::textFromDateTime(const QDateTime &dateTime) const { Q_D(const QDateTimeEdit); - return locale().toString(dateTime, d->displayFormat); + return locale().toString(dateTime, d->displayFormat, d->calendar); } @@ -1646,7 +1652,7 @@ QDateEdit::~QDateEdit() QDateTimeEditPrivate::QDateTimeEditPrivate() - : QDateTimeParser(QVariant::DateTime, QDateTimeParser::DateTimeEdit) + : QDateTimeParser(QVariant::DateTime, QDateTimeParser::DateTimeEdit, QCalendar()) { hasHadFocus = false; formatExplicitlySet = false; @@ -1671,10 +1677,6 @@ QDateTimeEditPrivate::QDateTimeEditPrivate() #endif } -QDateTimeEditPrivate::~QDateTimeEditPrivate() -{ -} - void QDateTimeEditPrivate::updateTimeSpec() { minimum = minimum.toDateTime().toTimeSpec(spec); @@ -2018,8 +2020,7 @@ QDateTime QDateTimeEditPrivate::stepBy(int sectionIndex, int steps, bool test) c val = (wrapping ? min + val - max - 1 : max); } - - const int oldDay = v.date().day(); + const int oldDay = v.date().day(calendar); setDigit(v, sectionIndex, val); // if this sets year or month it will make @@ -2038,10 +2039,10 @@ QDateTime QDateTimeEditPrivate::stepBy(int sectionIndex, int steps, bool test) c if (steps > 0) { setDigit(v, sectionIndex, min); if (!(sn.type & DaySectionMask) && sections & DateSectionMask) { - const int daysInMonth = v.date().daysInMonth(); - if (v.date().day() < oldDay && v.date().day() < daysInMonth) { + const int daysInMonth = v.date().daysInMonth(calendar); + if (v.date().day(calendar) < oldDay && v.date().day(calendar) < daysInMonth) { const int adds = qMin(oldDay, daysInMonth); - v = v.addDays(adds - v.date().day()); + v = v.addDays(adds - v.date().day(calendar)); } } @@ -2053,10 +2054,10 @@ QDateTime QDateTimeEditPrivate::stepBy(int sectionIndex, int steps, bool test) c } else { setDigit(v, sectionIndex, max); if (!(sn.type & DaySectionMask) && sections & DateSectionMask) { - const int daysInMonth = v.date().daysInMonth(); - if (v.date().day() < oldDay && v.date().day() < daysInMonth) { + const int daysInMonth = v.date().daysInMonth(calendar); + if (v.date().day(calendar) < oldDay && v.date().day(calendar) < daysInMonth) { const int adds = qMin(oldDay, daysInMonth); - v = v.addDays(adds - v.date().day()); + v = v.addDays(adds - v.date().day(calendar)); } } @@ -2070,7 +2071,7 @@ QDateTime QDateTimeEditPrivate::stepBy(int sectionIndex, int steps, bool test) c setDigit(v, sectionIndex, (steps > 0 ? localmax : localmin)); } } - if (!test && oldDay != v.date().day() && !(sn.type & DaySectionMask)) { + if (!test && oldDay != v.date().day(calendar) && !(sn.type & DaySectionMask)) { // this should not happen when called from stepEnabled cachedDay = qMax<int>(oldDay, cachedDay); } @@ -2523,7 +2524,7 @@ void QDateTimeEditPrivate::initCalendarPopup(QCalendarWidget *cw) { Q_Q(QDateTimeEdit); if (!monthCalendar) { - monthCalendar = new QCalendarPopup(q, cw); + monthCalendar = new QCalendarPopup(q, cw, calendar); monthCalendar->setObjectName(QLatin1String("qt_datetimedit_calendar")); QObject::connect(monthCalendar, SIGNAL(newDateSelected(QDate)), q, SLOT(setDate(QDate))); QObject::connect(monthCalendar, SIGNAL(hidingCalendar(QDate)), q, SLOT(setDate(QDate))); @@ -2584,8 +2585,8 @@ void QDateTimeEditPrivate::syncCalendarWidget() } } -QCalendarPopup::QCalendarPopup(QWidget * parent, QCalendarWidget *cw) - : QWidget(parent, Qt::Popup) +QCalendarPopup::QCalendarPopup(QWidget *parent, QCalendarWidget *cw, QCalendar ca) + : QWidget(parent, Qt::Popup), calendarSystem(ca) { setAttribute(Qt::WA_WindowPropagation); @@ -2601,6 +2602,7 @@ QCalendarWidget *QCalendarPopup::verifyCalendarInstance() { if (calendar.isNull()) { QCalendarWidget *cw = new QCalendarWidget(this); + cw->setCalendar(calendarSystem); cw->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader); #ifdef QT_KEYPAD_NAVIGATION if (QApplicationPrivate::keypadNavigationEnabled()) @@ -2634,13 +2636,13 @@ void QCalendarPopup::setCalendarWidget(QCalendarWidget *cw) } -void QCalendarPopup::setDate(const QDate &date) +void QCalendarPopup::setDate(QDate date) { oldDate = date; verifyCalendarInstance()->setSelectedDate(date); } -void QCalendarPopup::setDateRange(const QDate &min, const QDate &max) +void QCalendarPopup::setDateRange(QDate min, QDate max) { QCalendarWidget *cw = verifyCalendarInstance(); cw->setMinimumDate(min); @@ -2684,7 +2686,7 @@ void QCalendarPopup::dateSelectionChanged() dateChanged = true; emit newDateSelected(verifyCalendarInstance()->selectedDate()); } -void QCalendarPopup::dateSelected(const QDate &date) +void QCalendarPopup::dateSelected(QDate date) { dateChanged = true; emit activated(date); diff --git a/src/widgets/widgets/qdatetimeedit.h b/src/widgets/widgets/qdatetimeedit.h index b6fb35fc71..03994675ae 100644 --- a/src/widgets/widgets/qdatetimeedit.h +++ b/src/widgets/widgets/qdatetimeedit.h @@ -42,6 +42,7 @@ #include <QtWidgets/qtwidgetsglobal.h> #include <QtCore/qdatetime.h> +#include <QtCore/qcalendar.h> #include <QtCore/qvariant.h> #include <QtWidgets/qabstractspinbox.h> @@ -102,6 +103,9 @@ public: QDate date() const; QTime time() const; + QCalendar calendar() const; + void setCalendar(QCalendar calendar); + QDateTime minimumDateTime() const; void clearMinimumDateTime(); void setMinimumDateTime(const QDateTime &dt); diff --git a/src/widgets/widgets/qdatetimeedit_p.h b/src/widgets/widgets/qdatetimeedit_p.h index c05e7d9b48..dcf8863c8b 100644 --- a/src/widgets/widgets/qdatetimeedit_p.h +++ b/src/widgets/widgets/qdatetimeedit_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2018 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -52,6 +52,7 @@ // #include <QtWidgets/private/qtwidgetsglobal_p.h> +#include <QtCore/qcalendar.h> #include "QtWidgets/qcalendarwidget.h" #include "QtWidgets/qspinbox.h" #include "QtWidgets/qtoolbutton.h" @@ -70,7 +71,6 @@ class Q_AUTOTEST_EXPORT QDateTimeEditPrivate : public QAbstractSpinBoxPrivate, p Q_DECLARE_PUBLIC(QDateTimeEdit) public: QDateTimeEditPrivate(); - ~QDateTimeEditPrivate(); void init(const QVariant &var); void readLocaleSettings(); @@ -145,21 +145,22 @@ class QCalendarPopup : public QWidget { Q_OBJECT public: - explicit QCalendarPopup(QWidget *parent = nullptr, QCalendarWidget *cw = nullptr); + explicit QCalendarPopup(QWidget *parent = nullptr, QCalendarWidget *cw = nullptr, + QCalendar ca = QCalendar()); QDate selectedDate() { return verifyCalendarInstance()->selectedDate(); } - void setDate(const QDate &date); - void setDateRange(const QDate &min, const QDate &max); + void setDate(QDate date); + void setDateRange(QDate min, QDate max); void setFirstDayOfWeek(Qt::DayOfWeek dow) { verifyCalendarInstance()->setFirstDayOfWeek(dow); } QCalendarWidget *calendarWidget() const { return const_cast<QCalendarPopup*>(this)->verifyCalendarInstance(); } void setCalendarWidget(QCalendarWidget *cw); Q_SIGNALS: - void activated(const QDate &date); - void newDateSelected(const QDate &newDate); - void hidingCalendar(const QDate &oldDate); + void activated(QDate date); + void newDateSelected(QDate newDate); + void hidingCalendar(QDate oldDate); void resetButton(); private Q_SLOTS: - void dateSelected(const QDate &date); + void dateSelected(QDate date); void dateSelectionChanged(); protected: @@ -174,6 +175,7 @@ private: QPointer<QCalendarWidget> calendar; QDate oldDate; bool dateChanged; + QCalendar calendarSystem; }; QT_END_NAMESPACE diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index 55ae42db04..5900326087 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -138,11 +138,8 @@ bool QDockAreaLayoutItem::skip() const QSize QDockAreaLayoutItem::minimumSize() const { - if (widgetItem != 0) { - int left, top, right, bottom; - widgetItem->widget()->getContentsMargins(&left, &top, &right, &bottom); - return widgetItem->minimumSize() + QSize(left+right, top+bottom); - } + if (widgetItem) + return widgetItem->minimumSize().grownBy(widgetItem->widget()->contentsMargins()); if (subinfo != 0) return subinfo->minimumSize(); return QSize(0, 0); @@ -150,11 +147,8 @@ QSize QDockAreaLayoutItem::minimumSize() const QSize QDockAreaLayoutItem::maximumSize() const { - if (widgetItem != 0) { - int left, top, right, bottom; - widgetItem->widget()->getContentsMargins(&left, &top, &right, &bottom); - return widgetItem->maximumSize()+ QSize(left+right, top+bottom); - } + if (widgetItem) + return widgetItem->maximumSize().grownBy(widgetItem->widget()->contentsMargins()); if (subinfo != 0) return subinfo->maximumSize(); return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); @@ -180,11 +174,8 @@ QSize QDockAreaLayoutItem::sizeHint() const { if (placeHolderItem != 0) return QSize(0, 0); - if (widgetItem != 0) { - int left, top, right, bottom; - widgetItem->widget()->getContentsMargins(&left, &top, &right, &bottom); - return widgetItem->sizeHint() + QSize(left+right, top+bottom); - } + if (widgetItem) + return widgetItem->sizeHint().grownBy(widgetItem->widget()->contentsMargins()); if (subinfo != 0) return subinfo->sizeHint(); return QSize(-1, -1); @@ -1934,11 +1925,6 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*> QDockAreaLayoutItem item(new QDockWidgetItem(widget)); if (flags & StateFlagFloating) { bool drawer = false; -#if 0 // Used to be included in Qt4 for Q_WS_MAC // drawer support - extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp - extern bool qt_mac_set_drawer_preferred_edge(QWidget *, Qt::DockWidgetArea); //qwidget_mac.cpp - drawer = qt_mac_is_macdrawer(widget); -#endif if (!testing) { widget->hide(); @@ -1949,13 +1935,6 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*> int x, y, w, h; stream >> x >> y >> w >> h; -#if 0 // Used to be included in Qt4 for Q_WS_MAC // drawer support - if (drawer) { - mainWindow->window()->createWinId(); - widget->window()->createWinId(); - qt_mac_set_drawer_preferred_edge(widget, toDockWidgetArea(dockPos)); - } else -#endif if (!testing) widget->setGeometry(QDockAreaLayout::constrainedRect(QRect(x, y, w, h), widget)); @@ -2049,9 +2028,8 @@ void QDockAreaLayoutInfo::updateSeparatorWidgets() const } j++; -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC sepWidget->raise(); -#endif + QRect sepRect = separatorRect(i).adjusted(-2, -2, 2, 2); sepWidget->setGeometry(sepRect); sepWidget->setMask( QRegion(separatorRect(i).translated( - sepRect.topLeft()))); @@ -3090,10 +3068,6 @@ bool QDockAreaLayout::restoreDockWidget(QDockWidget *dockWidget) dockWidget->d_func()->setWindowState(true, true, r); } dockWidget->setVisible(!placeHolder->hidden); -#if 0 // Used to be included in Qt4 for Q_WS_X11 - if (placeHolder->window) // gets rid of the X11BypassWindowManager window flag - dockWidget->d_func()->setWindowState(true); -#endif item->placeHolderItem = 0; delete placeHolder; @@ -3340,9 +3314,8 @@ void QDockAreaLayout::updateSeparatorWidgets() const } j++; -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC sepWidget->raise(); -#endif + QRect sepRect = separatorRect(i).adjusted(-2, -2, 2, 2); sepWidget->setGeometry(sepRect); sepWidget->setMask( QRegion(separatorRect(i).translated( - sepRect.topLeft()))); diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp index 28a7cee2a0..05ec3aface 100644 --- a/src/widgets/widgets/qdockwidget.cpp +++ b/src/widgets/widgets/qdockwidget.cpp @@ -381,11 +381,10 @@ QSize QDockWidgetLayout::sizeFromContent(const QSize &content, bool floating) co if (content.height() < 0) result.setHeight(-1); - int left, top, right, bottom; - w->getContentsMargins(&left, &top, &right, &bottom); + const QMargins margins = w->contentsMargins(); //we need to subtract the contents margin (it will be added by the caller) - QSize min = w->minimumSize() - QSize(left + right, top + bottom); - QSize max = w->maximumSize() - QSize(left + right, top + bottom); + QSize min = w->minimumSize().shrunkBy(margins); + QSize max = w->maximumSize().shrunkBy(margins); /* A floating dockwidget will automatically get its minimumSize set to the layout's minimum size + deco. We're *not* interested in this, we only take minimumSize() @@ -977,11 +976,7 @@ bool QDockWidgetPrivate::mouseMoveEvent(QMouseEvent *event) && (event->pos() - state->pressPos).manhattanLength() > QApplication::startDragDistance()) { startDrag(); -#if 0 // Used to be included in Qt4 for Q_WS_WIN - grabMouseWhileInWindow(); -#else q->grabMouse(); -#endif ret = true; } } @@ -1029,13 +1024,6 @@ void QDockWidgetPrivate::nonClientAreaMouseEvent(QMouseEvent *event) QWidget *tl = q->topLevelWidget(); QRect geo = tl->geometry(); QRect titleRect = tl->frameGeometry(); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if ((features & QDockWidget::DockWidgetVerticalTitleBar)) { - titleRect.setTop(geo.top()); - titleRect.setBottom(geo.bottom()); - titleRect.setRight(geo.left() - 1); - } else -#endif { titleRect.setLeft(geo.left()); titleRect.setRight(geo.right()); @@ -1588,17 +1576,6 @@ bool QDockWidget::event(QEvent *event) if (d->mouseMoveEvent(static_cast<QMouseEvent *>(event))) return true; break; -#if 0 // Used to be included in Qt4 for Q_WS_WIN - case QEvent::Leave: - if (d->state != 0 && d->state->dragging && !d->state->nca) { - // This is a workaround for loosing the mouse on Vista. - QPoint pos = QCursor::pos(); - QMouseEvent fake(QEvent::MouseMove, mapFromGlobal(pos), pos, Qt::NoButton, - QGuiApplication::mouseButtons(), QGuiApplication::keyboardModifiers()); - d->mouseMoveEvent(&fake); - } - break; -#endif case QEvent::MouseButtonRelease: if (d->mouseReleaseEvent(static_cast<QMouseEvent *>(event))) return true; diff --git a/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm b/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm index 0b64b2a2bb..88baf0410b 100644 --- a/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm +++ b/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm @@ -82,8 +82,32 @@ The following is a snippet showing how to subclass QMacCocoaViewContainer to wrap an NSSearchField. - \snippet macmainwindow.mm 0 + \code + SearchWidget::SearchWidget(QWidget *parent) + : QMacCocoaViewContainer(0, parent) + { + // Many Cocoa objects create temporary autorelease objects, + // so create a pool to catch them. + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + // Create the NSSearchField, set it on the QCocoaViewContainer. + NSSearchField *search = [[NSSearchField alloc] init]; + setCocoaView(search); + + // Use a Qt menu for the search field menu. + QMenu *qtMenu = createMenu(this); + NSMenu *nsMenu = qtMenu->macMenu(0); + [[search cell] setSearchMenuTemplate:nsMenu]; + + // Release our reference, since our super class takes ownership and we + // don't need it anymore. + [search release]; + + // Clean up our pool as we no longer need it. + [pool release]; + } + \endcode */ QT_BEGIN_NAMESPACE diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp index c7b7e5bf97..6e3de1b1ff 100644 --- a/src/widgets/widgets/qmdiarea.cpp +++ b/src/widgets/widgets/qmdiarea.cpp @@ -2493,13 +2493,6 @@ bool QMdiArea::event(QEvent *event) { Q_D(QMdiArea); switch (event->type()) { -#if 0 // Used to be included in Qt4 for Q_WS_WIN - // QWidgetPrivate::hide_helper activates another sub-window when closing a - // modal dialog on Windows (see activateWindow() inside the ifdef). - case QEvent::WindowUnblocked: - d->activateCurrentWindow(); - break; -#endif case QEvent::WindowActivate: { d->isActivated = true; if (d->childWindows.isEmpty()) @@ -2557,11 +2550,7 @@ bool QMdiArea::eventFilter(QObject *object, QEvent *event) QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); // Ingore key events without a Ctrl modifier (except for press/release on the modifier itself). -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (!(keyEvent->modifiers() & Qt::MetaModifier) && keyEvent->key() != Qt::Key_Meta) -#else if (!(keyEvent->modifiers() & Qt::ControlModifier) && keyEvent->key() != Qt::Key_Control) -#endif return QAbstractScrollArea::eventFilter(object, event); // Find closest mdi area (in case we have a nested workspace). @@ -2576,11 +2565,7 @@ bool QMdiArea::eventFilter(QObject *object, QEvent *event) // 3) Ctrl-Shift-Tab (Tab, Tab, ...) -> iterate through all windows in the opposite // direction (activatePreviousSubWindow()) switch (keyEvent->key()) { -#if 0 // Used to be included in Qt4 for Q_WS_MAC - case Qt::Key_Meta: -#else case Qt::Key_Control: -#endif if (keyPress) area->d_func()->startTabToPreviousTimer(); else diff --git a/src/widgets/widgets/qmdisubwindow.cpp b/src/widgets/widgets/qmdisubwindow.cpp index 474cce983c..d58a1d06db 100644 --- a/src/widgets/widgets/qmdisubwindow.cpp +++ b/src/widgets/widgets/qmdisubwindow.cpp @@ -288,13 +288,6 @@ static inline bool isHoverControl(QStyle::SubControl control) return control != QStyle::SC_None && control != QStyle::SC_TitleBarLabel; } -#if 0 // Used to be included in Qt4 for Q_WS_WIN -static inline QRgb colorref2qrgb(COLORREF col) -{ - return qRgb(GetRValue(col),GetGValue(col),GetBValue(col)); -} -#endif - #ifndef QT_NO_TOOLTIP static void showToolTip(QHelpEvent *helpEvent, QWidget *widget, const QStyleOptionComplex &opt, QStyle::ComplexControl complexControl, QStyle::SubControl subControl) @@ -1926,43 +1919,7 @@ QPalette QMdiSubWindowPrivate::desktopPalette() const QPalette newPalette = q->palette(); bool colorsInitialized = false; -#if 0 // Used to be included in Qt4 for Q_WS_WIN // ask system properties on windows -#ifndef SPI_GETGRADIENTCAPTIONS -#define SPI_GETGRADIENTCAPTIONS 0x1008 -#endif -#ifndef COLOR_GRADIENTACTIVECAPTION -#define COLOR_GRADIENTACTIVECAPTION 27 -#endif -#ifndef COLOR_GRADIENTINACTIVECAPTION -#define COLOR_GRADIENTINACTIVECAPTION 28 -#endif - if (QGuiApplication::desktopSettingsAware()) { - newPalette.setColor(QPalette::Active, QPalette::Highlight, - colorref2qrgb(GetSysColor(COLOR_ACTIVECAPTION))); - newPalette.setColor(QPalette::Inactive, QPalette::Highlight, - colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTION))); - newPalette.setColor(QPalette::Active, QPalette::HighlightedText, - colorref2qrgb(GetSysColor(COLOR_CAPTIONTEXT))); - newPalette.setColor(QPalette::Inactive, QPalette::HighlightedText, - colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT))); - colorsInitialized = true; - BOOL hasGradient = false; - SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &hasGradient, 0); - - if (hasGradient) { - newPalette.setColor(QPalette::Active, QPalette::Base, - colorref2qrgb(GetSysColor(COLOR_GRADIENTACTIVECAPTION))); - newPalette.setColor(QPalette::Inactive, QPalette::Base, - colorref2qrgb(GetSysColor(COLOR_GRADIENTINACTIVECAPTION))); - } else { - newPalette.setColor(QPalette::Active, QPalette::Base, - newPalette.color(QPalette::Active, QPalette::Highlight)); - newPalette.setColor(QPalette::Inactive, QPalette::Base, - newPalette.color(QPalette::Inactive, QPalette::Highlight)); - } - } -#endif if (!colorsInitialized) { newPalette.setColor(QPalette::Active, QPalette::Highlight, newPalette.color(QPalette::Active, QPalette::Highlight)); diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index 8843797430..0a81931b57 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -825,9 +825,6 @@ void QPlainTextEditPrivate::init(const QString &txt) viewport->setCursor(Qt::IBeamCursor); #endif originalOffsetY = 0; -#if 0 // Used to be included in Qt4 for Q_WS_WIN - setSingleFingerPanEnabled(true); -#endif } void QPlainTextEditPrivate::_q_textChanged() diff --git a/src/widgets/widgets/qpushbutton.cpp b/src/widgets/widgets/qpushbutton.cpp index b578aa0b18..f48b5706f7 100644 --- a/src/widgets/widgets/qpushbutton.cpp +++ b/src/widgets/widgets/qpushbutton.cpp @@ -684,38 +684,6 @@ bool QPushButton::event(QEvent *e) return QAbstractButton::event(e); } -#if 0 // Used to be included in Qt4 for Q_WS_MAC -/* \reimp */ -bool QPushButton::hitButton(const QPoint &pos) const -{ - QStyleOptionButton opt; - initStyleOption(&opt); - if (qt_mac_buttonIsRenderedFlat(this, &opt)) - return QAbstractButton::hitButton(pos); - - // Now that we know we are using the native style, let's proceed. - Q_D(const QPushButton); - QPushButtonPrivate *nonConst = const_cast<QPushButtonPrivate *>(d); - // In OSX buttons are round, which causes the hit method to be special. - // We cannot simply relay on detecting if something is inside the rect or not, - // we need to check if it is inside the "rounded area" or not. A point might - // be inside the rect but not inside the rounded area. - // Notice this method is only reimplemented for OSX. - return nonConst->hitButton(pos); -} - -bool QPushButtonPrivate::hitButton(const QPoint &pos) -{ - Q_Q(QPushButton); - QRect roundedRect(q->rect().left() + QMacStylePrivate::PushButtonLeftOffset, - q->rect().top() + QMacStylePrivate::PushButtonContentPadding, - q->rect().width() - QMacStylePrivate::PushButtonRightOffset, - q->rect().height() - QMacStylePrivate::PushButtonBottomOffset); - return roundedRect.contains(pos); -} -#endif - - QT_END_NAMESPACE #include "moc_qpushbutton.cpp" diff --git a/src/widgets/widgets/qpushbutton_p.h b/src/widgets/widgets/qpushbutton_p.h index a58675fe64..439b6e35d6 100644 --- a/src/widgets/widgets/qpushbutton_p.h +++ b/src/widgets/widgets/qpushbutton_p.h @@ -73,9 +73,6 @@ public: inline void init() { resetLayoutItemMargins(); } static QPushButtonPrivate* get(QPushButton *b) { return b->d_func(); } -#if 0 // Used to be included in Qt4 for Q_WS_MAC - bool hitButton(const QPoint &pos); -#endif #if QT_CONFIG(menu) QPoint adjustedMenuPosition(); #endif diff --git a/src/widgets/widgets/qrubberband.cpp b/src/widgets/widgets/qrubberband.cpp index ade8675db8..af730f8023 100644 --- a/src/widgets/widgets/qrubberband.cpp +++ b/src/widgets/widgets/qrubberband.cpp @@ -45,10 +45,6 @@ #include "qstyle.h" #include "qstyleoption.h" -#if 0 // Used to be included in Qt4 for Q_WS_MAC -# include <private/qt_mac_p.h> -# include <private/qt_cocoa_helpers_mac_p.h> -#endif #include <qdebug.h> @@ -140,18 +136,9 @@ QRubberBand::QRubberBand(Shape s, QWidget *p) Q_D(QRubberBand); d->shape = s; setAttribute(Qt::WA_TransparentForMouseEvents); -#if 1 // Used to be excluded in Qt4 for Q_WS_WIN setAttribute(Qt::WA_NoSystemBackground); -#endif setAttribute(Qt::WA_WState_ExplicitShowHide); setVisible(false); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (isWindow()) { - createWinId(); - extern OSWindowRef qt_mac_window_for(const QWidget *); //qwidget_mac.cpp - macWindowSetHasShadow(qt_mac_window_for(this), false); - } -#endif } /*! diff --git a/src/widgets/widgets/qsizegrip.cpp b/src/widgets/widgets/qsizegrip.cpp index dc5a7158dd..835af9c7b8 100644 --- a/src/widgets/widgets/qsizegrip.cpp +++ b/src/widgets/widgets/qsizegrip.cpp @@ -50,10 +50,6 @@ #include "qdebug.h" #include <QDesktopWidget> -#if 0 // Used to be included in Qt4 for Q_WS_MAC -#include <private/qt_mac_p.h> -#endif - #include <private/qwidget_p.h> #include <private/qdesktopwidget_p.h> #include <QtWidgets/qabstractscrollarea.h> @@ -81,9 +77,7 @@ public: Qt::Corner m_corner; bool gotMousePress; QPointer<QWidget> tlw; -#if 0 // Used to be included in Qt4 for Q_WS_MAC - void updateMacSizer(bool hide) const; -#endif + Qt::Corner corner() const; inline bool atBottom() const { @@ -119,9 +113,7 @@ public: updateTopLevelWidget(); if (tlw && showSizeGrip) { Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen; -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC sizeGripNotVisibleState |= Qt::WindowMaximized; -#endif // Don't show the size grip if the tlw is maximized or in full screen mode. showSizeGrip = !(tlw->windowState() & sizeGripNotVisibleState); } @@ -141,18 +133,6 @@ QSizeGripPrivate::QSizeGripPrivate() { } -#if 0 // Used to be included in Qt4 for Q_WS_MAC -void QSizeGripPrivate::updateMacSizer(bool hide) const -{ - Q_Q(const QSizeGrip); - if (QApplication::closingDown() || !parent) - return; - QWidget *topLevelWindow = qt_sizegrip_topLevelWidget(const_cast<QSizeGrip *>(q)); - if(topLevelWindow && topLevelWindow->isWindow()) - QWidgetPrivate::qt_mac_update_sizer(topLevelWindow, hide ? -1 : 1); -} -#endif - Qt::Corner QSizeGripPrivate::corner() const { Q_Q(const QSizeGrip); @@ -227,7 +207,7 @@ void QSizeGripPrivate::init() Q_Q(QSizeGrip); m_corner = q->isLeftToRight() ? Qt::BottomRightCorner : Qt::BottomLeftCorner; -#if !defined(QT_NO_CURSOR) && !0 /* Used to be included in Qt4 for Q_WS_MAC */ +#if !defined(QT_NO_CURSOR) q->setCursor(m_corner == Qt::TopLeftCorner || m_corner == Qt::BottomRightCorner ? Qt::SizeFDiagCursor : Qt::SizeBDiagCursor); #endif @@ -440,7 +420,7 @@ void QSizeGrip::moveEvent(QMoveEvent * /*moveEvent*/) return; d->m_corner = d->corner(); -#if !defined(QT_NO_CURSOR) && !0 /* Used to be included in Qt4 for Q_WS_MAC */ +#if !defined(QT_NO_CURSOR) setCursor(d->m_corner == Qt::TopLeftCorner || d->m_corner == Qt::BottomRightCorner ? Qt::SizeFDiagCursor : Qt::SizeBDiagCursor); #endif @@ -451,9 +431,6 @@ void QSizeGrip::moveEvent(QMoveEvent * /*moveEvent*/) */ void QSizeGrip::showEvent(QShowEvent *showEvent) { -#if 0 // Used to be included in Qt4 for Q_WS_MAC - d_func()->updateMacSizer(false); -#endif QWidget::showEvent(showEvent); } @@ -462,9 +439,6 @@ void QSizeGrip::showEvent(QShowEvent *showEvent) */ void QSizeGrip::hideEvent(QHideEvent *hideEvent) { -#if 0 // Used to be included in Qt4 for Q_WS_MAC - d_func()->updateMacSizer(true); -#endif QWidget::hideEvent(hideEvent); } @@ -486,9 +460,7 @@ bool QSizeGrip::eventFilter(QObject *o, QEvent *e) return QWidget::eventFilter(o, e); } Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen; -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC sizeGripNotVisibleState |= Qt::WindowMaximized; -#endif // Don't show the size grip if the tlw is maximized or in full screen mode. setVisible(!(d->tlw->windowState() & sizeGripNotVisibleState)); setAttribute(Qt::WA_WState_ExplicitShowHide, false); diff --git a/src/widgets/widgets/qstatusbar.cpp b/src/widgets/widgets/qstatusbar.cpp index e9044e6cad..39f0f11daf 100644 --- a/src/widgets/widgets/qstatusbar.cpp +++ b/src/widgets/widgets/qstatusbar.cpp @@ -90,10 +90,6 @@ public: int savedStrut; -#if 0 // Used to be included in Qt4 for Q_WS_MAC - QPoint dragStart; -#endif - int indexToLastNonPermanentWidget() const { int i = items.size() - 1; @@ -747,44 +743,7 @@ bool QStatusBar::event(QEvent *e) } } -// On Mac OS X Leopard it is possible to drag the window by clicking -// on the tool bar on most applications. -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC return QWidget::event(e); -#else - // Enable drag-click only if the status bar is the status bar for a - // QMainWindow with a unifed toolbar. - if (parent() == 0 || qobject_cast<QMainWindow *>(parent()) == 0 || - qobject_cast<QMainWindow *>(parent())->unifiedTitleAndToolBarOnMac() == false ) - return QWidget::event(e); - - // Check for mouse events. - QMouseEvent *mouseEvent; - if (e->type() == QEvent::MouseButtonPress || - e->type() == QEvent::MouseMove || - e->type() == QEvent::MouseButtonRelease) { - mouseEvent = static_cast <QMouseEvent*>(e); - } else { - return QWidget::event(e); - } - - // The following is a standard mouse drag handler. - if (e->type() == QEvent::MouseButtonPress && (mouseEvent->button() == Qt::LeftButton)) { - d->dragStart = mouseEvent->pos(); - } else if (e->type() == QEvent::MouseMove){ - if (d->dragStart == QPoint()) - return QWidget::event(e); - QPoint pos = mouseEvent->pos(); - QPoint delta = (pos - d->dragStart); - window()->move(window()->pos() + delta); - } else if (e->type() == QEvent::MouseButtonRelease && (mouseEvent->button() == Qt::LeftButton)){ - d->dragStart = QPoint(); - } else { - return QWidget::event(e); - } - - return true; -#endif } QT_END_NAMESPACE diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index 18fda11ddf..7e1794efef 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -68,11 +68,6 @@ #include "private/qapplication_p.h" #include "private/qtabbar_p.h" -#if 0 // Used to be included in Qt4 for Q_WS_MAC -#include <private/qt_mac_p.h> -#include <private/qt_cocoa_helpers_mac_p.h> -#endif - QT_BEGIN_NAMESPACE namespace { @@ -1976,9 +1971,7 @@ void QTabBar::mousePressEvent(QMouseEvent *event) d->moveTabFinished(d->pressedIndex); d->pressedIndex = d->indexAtPos(event->pos()); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - d->previousPressedIndex = d->pressedIndex; -#endif + if (d->validIndex(d->pressedIndex)) { QStyleOptionTabBarBase optTabBase; optTabBase.init(this); @@ -2058,17 +2051,6 @@ void QTabBar::mouseMoveEvent(QMouseEvent *event) update(); } -#if 0 // Used to be included in Qt4 for Q_WS_MAC - } else if (!d->documentMode && event->buttons() == Qt::LeftButton && d->previousPressedIndex != -1) { - int newPressedIndex = d->indexAtPos(event->pos()); - if (d->pressedIndex == -1 && d->previousPressedIndex == newPressedIndex) { - d->pressedIndex = d->previousPressedIndex; - update(tabRect(d->pressedIndex)); - } else if(d->pressedIndex != newPressedIndex) { - d->pressedIndex = -1; - update(tabRect(d->previousPressedIndex)); - } -#endif } if (event->buttons() != Qt::LeftButton) { @@ -2162,9 +2144,7 @@ void QTabBar::mouseReleaseEvent(QMouseEvent *event) event->ignore(); return; } -#if 0 // Used to be included in Qt4 for Q_WS_MAC - d->previousPressedIndex = -1; -#endif + if (d->movable && d->dragInProgress && d->validIndex(d->pressedIndex)) { int length = d->tabList[d->pressedIndex].dragOffset; int width = verticalTabs(d->shape) diff --git a/src/widgets/widgets/qtabbar_p.h b/src/widgets/widgets/qtabbar_p.h index 458d486b10..5552c43548 100644 --- a/src/widgets/widgets/qtabbar_p.h +++ b/src/widgets/widgets/qtabbar_p.h @@ -93,9 +93,6 @@ public: selectionBehaviorOnRemove(QTabBar::SelectRightTab), paintWithOffsets(true), movable(false), dragInProgress(false), documentMode(false), autoHide(false), changeCurrentOnDrag(false), switchTabCurrentIndex(-1), switchTabTimerId(0), movingTab(nullptr) -#if 0 // Used to be included in Qt4 for Q_WS_MAC - , previousPressedIndex(-1) -#endif {} int currentIndex; @@ -232,9 +229,6 @@ public: int switchTabTimerId; QMovableTabWidget *movingTab; -#if 0 // Used to be included in Qt4 for Q_WS_MAC - int previousPressedIndex; -#endif // shared by tabwidget and qtabbar static void initStyleBaseOption(QStyleOptionTabBarBase *optTabBase, QTabBar *tabbar, QSize size) { diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp index bd9e5f8159..0ccbad7eaa 100644 --- a/src/widgets/widgets/qtextedit.cpp +++ b/src/widgets/widgets/qtextedit.cpp @@ -200,9 +200,6 @@ void QTextEditPrivate::init(const QString &html) #ifndef QT_NO_CURSOR viewport->setCursor(Qt::IBeamCursor); #endif -#if 0 // Used to be included in Qt4 for Q_WS_WIN - setSingleFingerPanEnabled(true); -#endif } void QTextEditPrivate::_q_repaintContents(const QRectF &contentsRect) diff --git a/src/widgets/widgets/qtoolbar.cpp b/src/widgets/widgets/qtoolbar.cpp index d1a0f5ea78..58e9c4fd87 100644 --- a/src/widgets/widgets/qtoolbar.cpp +++ b/src/widgets/widgets/qtoolbar.cpp @@ -324,13 +324,8 @@ bool QToolBarPrivate::mouseMoveEvent(QMouseEvent *event) event->y() >= 0 && event->y() < q->height()); startDrag(moving); - if (!moving && !wasDragging) { -#if 0 // Used to be included in Qt4 for Q_WS_WIN - grabMouseWhileInWindow(); -#else + if (!moving && !wasDragging) q->grabMouse(); -#endif - } } if (state->dragging) { diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index 46bc29eed7..9cdae4f28f 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -78,11 +78,6 @@ int QWidgetLineControl::redoTextLayout() const QTextLine l = m_textLayout.createLine(); m_textLayout.endLayout(); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (m_threadChecks) - m_textLayoutThread = QThread::currentThread(); -#endif - return qRound(l.ascent()); } diff --git a/src/widgets/widgets/qwidgetlinecontrol_p.h b/src/widgets/widgets/qwidgetlinecontrol_p.h index 940a17714f..8ebed25084 100644 --- a/src/widgets/widgets/qwidgetlinecontrol_p.h +++ b/src/widgets/widgets/qwidgetlinecontrol_p.h @@ -95,10 +95,6 @@ public: m_selstart(0), m_selend(0), m_passwordEchoEditing(false) , m_passwordEchoTimer(0) , m_passwordMaskDelay(-1) -#if 0 // Used to be included in Qt4 for Q_WS_MAC - , m_threadChecks(false) - , m_textLayoutThread(0) - #endif #if defined(QT_BUILD_INTERNAL) , m_passwordMaskDelayOverride(-1) #endif @@ -404,25 +400,9 @@ public: QTextLayout *textLayout() const { -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (m_threadChecks && QThread::currentThread() != m_textLayoutThread) - redoTextLayout(); -#endif return &m_textLayout; } -#if 0 // Used to be included in Qt4 for Q_WS_MAC - void setThreadChecks(bool threadChecks) - { - m_threadChecks = threadChecks; - } - - bool threadChecks() const - { - return m_threadChecks; - } -#endif - private: void init(const QString &txt); void removeSelectedText(); @@ -534,10 +514,6 @@ private: } int redoTextLayout() const; -#if 0 // Used to be included in Qt4 for Q_WS_MAC - bool m_threadChecks; - mutable QThread *m_textLayoutThread; -#endif public: #if defined(QT_BUILD_INTERNAL) diff --git a/src/widgets/widgets/qwidgetresizehandler.cpp b/src/widgets/widgets/qwidgetresizehandler.cpp index e8d435429f..9dbba12aba 100644 --- a/src/widgets/widgets/qwidgetresizehandler.cpp +++ b/src/widgets/widgets/qwidgetresizehandler.cpp @@ -124,21 +124,6 @@ bool QWidgetResizeHandler::eventFilter(QObject *o, QEvent *ee) if (!widgetRect.contains(cursorPoint)) return false; if (e->button() == Qt::LeftButton) { -#if 0 // Used to be included in Qt4 for Q_WS_X11 - /* - Implicit grabs do not stop the X server from changing - the cursor in children, which looks *really* bad when - doing resizingk, so we grab the cursor. Note that we do - not do this on Windows since double clicks are lost due - to the grab (see change 198463). - */ - if (e->spontaneous()) -# if !defined(QT_NO_CURSOR) - widget->grabMouse(widget->cursor()); -# else - widget->grabMouse(); -# endif // QT_NO_CURSOR -#endif buttonDown = false; emit activate(); bool me = movingEnabled; |