diff options
Diffstat (limited to 'src/widgets/widgets/qabstractscrollarea.cpp')
-rw-r--r-- | src/widgets/widgets/qabstractscrollarea.cpp | 314 |
1 files changed, 72 insertions, 242 deletions
diff --git a/src/widgets/widgets/qabstractscrollarea.cpp b/src/widgets/widgets/qabstractscrollarea.cpp index 598d173144..f6f8e8b795 100644 --- a/src/widgets/widgets/qabstractscrollarea.cpp +++ b/src/widgets/widgets/qabstractscrollarea.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** 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) 2016 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 "qabstractscrollarea.h" @@ -62,16 +26,14 @@ #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 QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + /*! \class QAbstractScrollArea \brief The QAbstractScrollArea widget provides a scrolling area with @@ -131,13 +93,13 @@ QT_BEGIN_NAMESPACE QWidget::move(). When the area contents or the viewport size changes, we do the following: - \snippet myscrollarea.cpp 1 + \snippet myscrollarea/myscrollarea.cpp 1 When the scroll bars change value, we need to update the widget position, i.e., find the part of the widget that is to be drawn in the viewport: - \snippet myscrollarea.cpp 0 + \snippet myscrollarea/myscrollarea.cpp 0 In order to track scroll bar movements, reimplement the virtual function scrollContentsBy(). In order to fine-tune scrolling @@ -165,13 +127,10 @@ QT_BEGIN_NAMESPACE */ QAbstractScrollAreaPrivate::QAbstractScrollAreaPrivate() - :hbar(0), vbar(0), vbarpolicy(Qt::ScrollBarAsNeeded), hbarpolicy(Qt::ScrollBarAsNeeded), + :hbar(nullptr), vbar(nullptr), vbarpolicy(Qt::ScrollBarAsNeeded), hbarpolicy(Qt::ScrollBarAsNeeded), 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 + viewport(nullptr), cornerWidget(nullptr), left(0), top(0), right(0), bottom(0), + xoffset(0), yoffset(0), viewportFilter(nullptr) { } @@ -185,7 +144,7 @@ QAbstractScrollAreaScrollBarContainer::QAbstractScrollAreaScrollBarContainer(Qt: orientation(orientation) { setLayout(layout); - layout->setMargin(0); + layout->setContentsMargins(QMargins()); layout->setSpacing(0); layout->addWidget(scrollBar); layout->setSizeConstraint(QLayout::SetMaximumSize); @@ -209,7 +168,7 @@ void QAbstractScrollAreaScrollBarContainer::addWidget(QWidget *widget, LogicalPo } /*! \internal - Retuns a list of scroll bar widgets for the given position. The scroll bar + Returns a list of scroll-bar widgets for the given position. The scroll bar itself is not returned. */ QWidgetList QAbstractScrollAreaScrollBarContainer::widgets(LogicalPosition position) @@ -289,11 +248,11 @@ void QAbstractScrollAreaPrivate::init() { Q_Q(QAbstractScrollArea); viewport = new QWidget(q); - viewport->setObjectName(QLatin1String("qt_scrollarea_viewport")); + viewport->setObjectName("qt_scrollarea_viewport"_L1); viewport->setBackgroundRole(QPalette::Base); viewport->setAutoFillBackground(true); scrollBarContainers[Qt::Horizontal] = new QAbstractScrollAreaScrollBarContainer(Qt::Horizontal, q); - scrollBarContainers[Qt::Horizontal]->setObjectName(QLatin1String("qt_scrollarea_hcontainer")); + scrollBarContainers[Qt::Horizontal]->setObjectName("qt_scrollarea_hcontainer"_L1); hbar = scrollBarContainers[Qt::Horizontal]->scrollBar; hbar->setRange(0,0); scrollBarContainers[Qt::Horizontal]->setVisible(false); @@ -301,7 +260,7 @@ void QAbstractScrollAreaPrivate::init() QObject::connect(hbar, SIGNAL(valueChanged(int)), q, SLOT(_q_hslide(int))); QObject::connect(hbar, SIGNAL(rangeChanged(int,int)), q, SLOT(_q_showOrHideScrollBars()), Qt::QueuedConnection); scrollBarContainers[Qt::Vertical] = new QAbstractScrollAreaScrollBarContainer(Qt::Vertical, q); - scrollBarContainers[Qt::Vertical]->setObjectName(QLatin1String("qt_scrollarea_vcontainer")); + scrollBarContainers[Qt::Vertical]->setObjectName("qt_scrollarea_vcontainer"_L1); vbar = scrollBarContainers[Qt::Vertical]->scrollBar; vbar->setRange(0,0); scrollBarContainers[Qt::Vertical]->setVisible(false); @@ -315,23 +274,13 @@ void QAbstractScrollAreaPrivate::init() q->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); layoutChildren(); -#ifndef Q_OS_OSX +#ifndef Q_OS_MACOS # ifndef QT_NO_GESTURES viewport->grabGesture(Qt::PanGesture); # endif #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; @@ -346,53 +295,24 @@ void QAbstractScrollAreaPrivate::layoutChildren() void QAbstractScrollAreaPrivate::layoutChildren_helper(bool *needHorizontalScrollbar, bool *needVerticalScrollbar) { Q_Q(QAbstractScrollArea); - bool htransient = hbar->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, hbar); + QStyleOptionSlider barOpt; + + hbar->initStyleOption(&barOpt); + bool htransient = hbar->style()->styleHint(QStyle::SH_ScrollBar_Transient, &barOpt, hbar); bool needh = *needHorizontalScrollbar || ((hbarpolicy != Qt::ScrollBarAlwaysOff) && ((hbarpolicy == Qt::ScrollBarAlwaysOn && !htransient) || ((hbarpolicy == Qt::ScrollBarAsNeeded || htransient) && hbar->minimum() < hbar->maximum() && !hbar->sizeHint().isEmpty()))); + const int hscrollOverlap = hbar->style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarOverlap, &barOpt, hbar); - bool vtransient = vbar->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, vbar); + vbar->initStyleOption(&barOpt); + bool vtransient = vbar->style()->styleHint(QStyle::SH_ScrollBar_Transient, &barOpt, vbar); bool needv = *needVerticalScrollbar || ((vbarpolicy != Qt::ScrollBarAlwaysOff) && ((vbarpolicy == Qt::ScrollBarAlwaysOn && !vtransient) || ((vbarpolicy == Qt::ScrollBarAsNeeded || vtransient) && vbar->minimum() < vbar->maximum() && !vbar->sizeHint().isEmpty()))); + const int vscrollOverlap = vbar->style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarOverlap, &barOpt, vbar); QStyleOption opt(0); - opt.init(q); - - 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 + opt.initFrom(q); const int hsbExt = hbar->sizeHint().height(); const int vsbExt = vbar->sizeHint().width(); @@ -401,31 +321,7 @@ void QAbstractScrollAreaPrivate::layoutChildren_helper(bool *needHorizontalScrol const QRect widgetRect = q->rect(); - 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 + const bool hasCornerWidget = (cornerWidget != nullptr); QPoint cornerOffset((needv && vscrollOverlap == 0) ? vsbExt : 0, (needh && hscrollOverlap == 0) ? hsbExt : 0); QRect controlsRect; @@ -458,12 +354,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,20 +365,13 @@ 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; #if QT_CONFIG(itemviews) if ((vscrollOverlap > 0 && needv) || (hscrollOverlap > 0 && needh)) { const QList<QHeaderView *> headers = q->findChildren<QHeaderView*>(); - if (headers.count() <= 2) { + if (headers.size() <= 2) { for (const QHeaderView *header : headers) { const QRect geo = header->geometry(); if (header->orientation() == Qt::Vertical && header->isVisible() && QStyle::visualRect(opt.direction, opt.rect, geo).left() <= opt.rect.width() / 2) @@ -501,10 +384,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)); @@ -531,8 +411,10 @@ void QAbstractScrollAreaPrivate::layoutChildren_helper(bool *needHorizontalScrol viewportRect.adjust(right, top, -left, -bottom); else viewportRect.adjust(left, top, -right, -bottom); + viewportRect = QStyle::visualRect(opt.direction, opt.rect, viewportRect); + viewportRect.translate(-overshoot); + viewport->setGeometry(viewportRect); // resize the viewport last - viewport->setGeometry(QStyle::visualRect(opt.direction, opt.rect, viewportRect)); // resize the viewport last *needHorizontalScrollbar = needh; *needVerticalScrollbar = needv; } @@ -601,8 +483,8 @@ QAbstractScrollArea::~QAbstractScrollArea() Sets the viewport to be the given \a widget. The QAbstractScrollArea will take ownership of the given \a widget. - If \a widget is 0, QAbstractScrollArea will assign a new QWidget instance - for the viewport. + If \a widget is \nullptr, QAbstractScrollArea will assign a new QWidget + instance for the viewport. \sa viewport() */ @@ -617,11 +499,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(); @@ -655,15 +535,13 @@ scrolling range. QSize QAbstractScrollArea::maximumViewportSize() const { Q_D(const QAbstractScrollArea); - int hsbExt = d->hbar->sizeHint().height(); - int vsbExt = d->vbar->sizeHint().width(); - int f = 2 * d->frameWidth; QSize max = size() - QSize(f + d->left + d->right, f + d->top + d->bottom); + // Count the sizeHint of the bar only if it is displayed. if (d->vbarpolicy == Qt::ScrollBarAlwaysOn) - max.rwidth() -= vsbExt; + max.rwidth() -= d->vbar->sizeHint().width(); if (d->hbarpolicy == Qt::ScrollBarAlwaysOn) - max.rheight() -= hsbExt; + max.rheight() -= d->hbar->sizeHint().height(); return max; } @@ -811,7 +689,7 @@ QWidget *QAbstractScrollArea::cornerWidget() const You will probably also want to set at least one of the scroll bar modes to \c AlwaysOn. - Passing 0 shows no widget in the corner. + Passing \nullptr shows no widget in the corner. Any previous corner widget is hidden. @@ -820,7 +698,7 @@ QWidget *QAbstractScrollArea::cornerWidget() const All widgets set here will be deleted by the scroll area when it is destroyed unless you separately reparent the widget after setting - some other corner widget (or 0). + some other corner widget (or \nullptr). Any \e newly set widget should have no current parent. @@ -885,7 +763,7 @@ void QAbstractScrollArea::addScrollBarWidget(QWidget *widget, Qt::Alignment alig { Q_D(QAbstractScrollArea); - if (widget == 0) + if (widget == nullptr) return; const Qt::Orientation scrollBarOrientation @@ -927,7 +805,7 @@ QWidgetList QAbstractScrollArea::scrollBarWidgets(Qt::Alignment alignment) /*! Sets the margins around the scrolling area to \a left, \a top, \a right and \a bottom. This is useful for applications such as - spreadsheets with "locked" rows and columns. The marginal space is + spreadsheets with "locked" rows and columns. The marginal space is left blank; put widgets in the unused area. Note that this function is frequently called by QTreeView and @@ -985,8 +863,8 @@ bool QAbstractScrollArea::eventFilter(QObject *o, QEvent *e) if (d->hbarpolicy == Qt::ScrollBarAsNeeded && d->vbarpolicy == Qt::ScrollBarAsNeeded) { QScrollBar *sbar = static_cast<QScrollBar*>(o); QScrollBar *sibling = sbar == d->hbar ? d->vbar : d->hbar; - if (sbar->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, sbar) && - sibling->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, sibling)) + if (sbar->style()->styleHint(QStyle::SH_ScrollBar_Transient, nullptr, sbar) && + sibling->style()->styleHint(QStyle::SH_ScrollBar_Transient, nullptr, sibling)) d->setScrollBarTransient(sibling, e->type() == QEvent::HoverLeave); } } @@ -1043,13 +921,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; @@ -1086,7 +957,7 @@ bool QAbstractScrollArea::event(QEvent *e) QScrollBar *vBar = verticalScrollBar(); QPointF delta = g->delta(); if (!delta.isNull()) { - if (QApplication::isRightToLeft()) + if (QGuiApplication::isRightToLeft()) delta.rx() *= -1; int newX = hBar->value() - delta.x(); int newY = vBar->value() - delta.y(); @@ -1122,38 +993,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; @@ -1257,7 +1100,7 @@ void QAbstractScrollArea::resizeEvent(QResizeEvent *) This event handler can be reimplemented in a subclass to receive paint events (passed in \a event), for the viewport() widget. - \note If you open a painter, make sure to open it on the viewport(). + \note If you create a QPainter, it must operate on the viewport(). \sa QWidget::paintEvent() */ @@ -1270,11 +1113,14 @@ void QAbstractScrollArea::paintEvent(QPaintEvent*) mouse press events for the viewport() widget. The event is passed in \a e. + The default implementation calls QWidget::mousePressEvent() for + default popup handling. + \sa QWidget::mousePressEvent() */ void QAbstractScrollArea::mousePressEvent(QMouseEvent *e) { - e->ignore(); + QWidget::mousePressEvent(e); } /*! @@ -1324,10 +1170,10 @@ void QAbstractScrollArea::mouseMoveEvent(QMouseEvent *e) void QAbstractScrollArea::wheelEvent(QWheelEvent *e) { Q_D(QAbstractScrollArea); - if (e->orientation() == Qt::Horizontal) - QApplication::sendEvent(d->hbar, e); + if (qAbs(e->angleDelta().x()) > qAbs(e->angleDelta().y())) + QCoreApplication::sendEvent(d->hbar, e); else - QApplication::sendEvent(d->vbar, e); + QCoreApplication::sendEvent(d->vbar, e); } #endif @@ -1362,7 +1208,7 @@ void QAbstractScrollArea::keyPressEvent(QKeyEvent * e) #endif } else { #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { + if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) { e->ignore(); return; } @@ -1376,7 +1222,7 @@ void QAbstractScrollArea::keyPressEvent(QKeyEvent * e) break; case Qt::Key_Left: #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && hasEditFocus() + if (QApplicationPrivate::keypadNavigationEnabled() && hasEditFocus() && (!d->hbar->isVisible() || d->hbar->value() == d->hbar->minimum())) { //if we aren't using the hbar or we are already at the leftmost point ignore e->ignore(); @@ -1389,7 +1235,7 @@ void QAbstractScrollArea::keyPressEvent(QKeyEvent * e) break; case Qt::Key_Right: #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && hasEditFocus() + if (QApplicationPrivate::keypadNavigationEnabled() && hasEditFocus() && (!d->hbar->isVisible() || d->hbar->value() == d->hbar->maximum())) { //if we aren't using the hbar or we are already at the rightmost point ignore e->ignore(); @@ -1484,38 +1330,27 @@ void QAbstractScrollArea::scrollContentsBy(int, int) viewport()->update(); } -bool QAbstractScrollAreaPrivate::canStartScrollingAt( const QPoint &startPos ) +bool QAbstractScrollAreaPrivate::canStartScrollingAt(const QPoint &startPos) const { - Q_Q(QAbstractScrollArea); - -#if QT_CONFIG(graphicsview) - // don't start scrolling when a drag mode has been set. - // don't start scrolling on a movable item. - if (QGraphicsView *view = qobject_cast<QGraphicsView *>(q)) { - if (view->dragMode() != QGraphicsView::NoDrag) - return false; - - QGraphicsItem *childItem = view->itemAt(startPos); - - if (childItem && (childItem->flags() & QGraphicsItem::ItemIsMovable)) - return false; - } -#endif + Q_Q(const QAbstractScrollArea); // don't start scrolling on a QAbstractSlider - if (qobject_cast<QAbstractSlider *>(q->viewport()->childAt(startPos))) { + if (qobject_cast<QAbstractSlider *>(q->viewport()->childAt(startPos))) return false; - } return true; } void QAbstractScrollAreaPrivate::flashScrollBars() { - bool htransient = hbar->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, hbar); + QStyleOptionSlider opt; + hbar->initStyleOption(&opt); + + bool htransient = hbar->style()->styleHint(QStyle::SH_ScrollBar_Transient, &opt, hbar); if ((hbarpolicy != Qt::ScrollBarAlwaysOff) && (hbarpolicy == Qt::ScrollBarAsNeeded || htransient)) hbar->d_func()->flash(); - bool vtransient = vbar->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, vbar); + vbar->initStyleOption(&opt); + bool vtransient = vbar->style()->styleHint(QStyle::SH_ScrollBar_Transient, &opt, vbar); if ((vbarpolicy != Qt::ScrollBarAlwaysOff) && (vbarpolicy == Qt::ScrollBarAsNeeded || vtransient)) vbar->d_func()->flash(); } @@ -1546,13 +1381,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 @@ -1603,9 +1431,11 @@ QSize QAbstractScrollArea::sizeHint() const if (!d->sizeHint.isValid() || d->sizeAdjustPolicy == QAbstractScrollArea::AdjustToContents) { const int f = 2 * d->frameWidth; - const QSize frame( f, f ); - const QSize scrollbars(d->vbarpolicy == Qt::ScrollBarAlwaysOn ? d->vbar->sizeHint().width() : 0, - d->hbarpolicy == Qt::ScrollBarAlwaysOn ? d->hbar->sizeHint().height() : 0); + const QSize frame(f, f); + const bool vbarHidden = !d->vbar->isVisibleTo(this) || d->vbarpolicy == Qt::ScrollBarAlwaysOff; + const bool hbarHidden = !d->vbar->isVisibleTo(this) || d->hbarpolicy == Qt::ScrollBarAlwaysOff; + const QSize scrollbars(vbarHidden ? 0 : d->vbar->sizeHint().width(), + hbarHidden ? 0 : d->hbar->sizeHint().height()); d->sizeHint = frame + scrollbars + viewportSizeHint(); } return d->sizeHint; @@ -1633,7 +1463,7 @@ QSize QAbstractScrollArea::viewportSizeHint() const /*! \since 5.2 \property QAbstractScrollArea::sizeAdjustPolicy - This property holds the policy describing how the size of the scroll area changes when the + \brief the policy describing how the size of the scroll area changes when the size of the viewport changes. The default policy is QAbstractScrollArea::AdjustIgnored. |