Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/widgets/qabstractscrollarea.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5252#include "qboxlayout.h"
    5353#include "qpainter.h"
     54#include "qmargins.h"
    5455
    5556#include "qabstractscrollarea_p.h"
    5657#include <qwidget.h>
     58
     59#include <private/qapplication_p.h>
    5760
    5861#ifdef Q_WS_MAC
     
    158161     viewport(0), cornerWidget(0), left(0), top(0), right(0), bottom(0),
    159162     xoffset(0), yoffset(0), viewportFilter(0)
     163#ifdef Q_WS_WIN
     164     , singleFingerPanEnabled(false)
     165#endif
    160166{
    161167}
     
    282288    QObject::connect(vbar, SIGNAL(valueChanged(int)), q, SLOT(_q_vslide(int)));
    283289    QObject::connect(vbar, SIGNAL(rangeChanged(int,int)), q, SLOT(_q_showOrHideScrollBars()), Qt::QueuedConnection);
    284     viewportFilter = new QAbstractScrollAreaFilter(this);
    285     viewport->installEventFilter(viewportFilter);
     290    viewportFilter.reset(new QAbstractScrollAreaFilter(this));
     291    viewport->installEventFilter(viewportFilter.data());
    286292    viewport->setFocusProxy(q);
    287293    q->setFocusPolicy(Qt::WheelFocus);
     
    289295    q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    290296    layoutChildren();
    291 }
     297#ifndef Q_WS_MAC
     298    viewport->grabGesture(Qt::PanGesture);
     299#endif
     300}
     301
     302#ifdef Q_WS_WIN
     303void QAbstractScrollAreaPrivate::setSingleFingerPanEnabled(bool on)
     304{
     305    singleFingerPanEnabled = on;
     306    QWidgetPrivate *dd = static_cast<QWidgetPrivate *>(QObjectPrivate::get(viewport));
     307    if (dd)
     308        dd->winSetupGestures();
     309}
     310#endif // Q_WS_WIN
    292311
    293312void QAbstractScrollAreaPrivate::layoutChildren()
     
    460479}
    461480
    462 // ### Fix for 4.4, talk to Bjoern E or Girish.
    463 void QAbstractScrollAreaPrivate::scrollBarPolicyChanged(Qt::Orientation, Qt::ScrollBarPolicy) {}
    464 
    465481/*!
    466482    \internal
     
    472488{
    473489    Q_D(QAbstractScrollArea);
    474     d->init();
     490    QT_TRY {
     491        d->init();
     492    } QT_CATCH(...) {
     493        d->viewportFilter.reset();
     494        QT_RETHROW;
     495    }
    475496}
    476497
     
    484505{
    485506    Q_D(QAbstractScrollArea);
    486     d->init();
     507    QT_TRY {
     508        d->init();
     509    } QT_CATCH(...) {
     510        d->viewportFilter.reset();
     511        QT_RETHROW;
     512    }
    487513}
    488514
     
    494520{
    495521    Q_D(QAbstractScrollArea);
    496     delete d->viewportFilter;
     522    // reset it here, otherwise we'll have a dangling pointer in ~QWidget
     523    d->viewportFilter.reset();
    497524}
    498525
     
    518545        d->viewport->setParent(this);
    519546        d->viewport->setFocusProxy(this);
    520         d->viewport->installEventFilter(d->viewportFilter);
     547        d->viewport->installEventFilter(d->viewportFilter.data());
     548#ifndef Q_WS_MAC
     549        d->viewport->grabGesture(Qt::PanGesture);
     550#endif
    521551        d->layoutChildren();
    522552        if (isVisible())
     
    841871    d->bottom = bottom;
    842872    d->layoutChildren();
     873}
     874
     875/*!
     876    \since 4.6
     877    Sets \a margins around the scrolling area. This is useful for
     878    applications such as spreadsheets with "locked" rows and columns.
     879    The marginal space is is left blank; put widgets in the unused
     880    area.
     881
     882    By default all margins are zero.
     883
     884*/
     885void QAbstractScrollArea::setViewportMargins(const QMargins &margins)
     886{
     887    setViewportMargins(margins.left(), margins.top(),
     888                       margins.right(), margins.bottom());
    843889}
    844890
     
    874920            d->layoutChildren();
    875921            break;
    876     case QEvent::Paint:
     922    case QEvent::Paint: {
     923        QStyleOption option;
     924        option.initFrom(this);
    877925        if (d->cornerPaintingRect.isValid()) {
    878             QStyleOption option;
    879926            option.rect = d->cornerPaintingRect;
    880927            QPainter p(this);
     
    883930#ifdef Q_WS_MAC
    884931        if (d->reverseCornerPaintingRect.isValid()) {
    885             QStyleOption option;
    886932            option.rect = d->reverseCornerPaintingRect;
    887933            QPainter p(this);
     
    889935        }
    890936#endif
     937        }
    891938        QFrame::paintEvent((QPaintEvent*)e);
    892939        break;
     
    909956    case QEvent::DragLeave:
    910957#endif
     958        // ignore touch events in case they have been propagated from the viewport
     959    case QEvent::TouchBegin:
     960    case QEvent::TouchUpdate:
     961    case QEvent::TouchEnd:
    911962        return false;
     963    case QEvent::Gesture:
     964    {
     965        QGestureEvent *ge = static_cast<QGestureEvent *>(e);
     966        QPanGesture *g = static_cast<QPanGesture *>(ge->gesture(Qt::PanGesture));
     967        if (g) {
     968            QScrollBar *hBar = horizontalScrollBar();
     969            QScrollBar *vBar = verticalScrollBar();
     970            QPointF delta = g->delta();
     971            if (!delta.isNull()) {
     972                if (QApplication::isRightToLeft())
     973                    delta.rx() *= -1;
     974                int newX = hBar->value() - delta.x();
     975                int newY = vBar->value() - delta.y();
     976                hBar->setValue(newX);
     977                vBar->setValue(newY);
     978            }
     979            return true;
     980        }
     981        return false;
     982    }
    912983    case QEvent::StyleChange:
    913984    case QEvent::LayoutDirectionChange:
     
    9491020    case QEvent::MouseButtonRelease:
    9501021    case QEvent::MouseButtonDblClick:
     1022    case QEvent::TouchBegin:
     1023    case QEvent::TouchUpdate:
     1024    case QEvent::TouchEnd:
    9511025    case QEvent::MouseMove:
    9521026    case QEvent::ContextMenu:
     
    9621036        return QFrame::event(e);
    9631037    case QEvent::LayoutRequest:
     1038    case QEvent::Gesture:
     1039    case QEvent::GestureOverride:
    9641040        return event(e);
    9651041    default:
     
    10591135{
    10601136    Q_D(QAbstractScrollArea);
    1061     if (static_cast<QWheelEvent*>(e)->orientation() == Qt::Horizontal)
    1062         QApplication::sendEvent(d->hbar, e);
    1063     else
    1064         QApplication::sendEvent(d->vbar, e);
     1137    QScrollBar *const bars[2] = { d->hbar, d->vbar };
     1138    int idx = (e->orientation() == Qt::Vertical) ? 1 : 0;
     1139    int other = (idx + 1) % 2;
     1140    if (!bars[idx]->isVisible() && bars[other]->isVisible())
     1141        idx = other;   // If the scrollbar of the event orientation is hidden, fallback to the other.
     1142
     1143    QApplication::sendEvent(bars[idx], e);
    10651144}
    10661145#endif
     
    12381317{
    12391318    layoutChildren();
     1319#ifdef Q_WS_WIN
     1320    // Need to re-subscribe to gestures as the content changes to make sure we
     1321    // enable/disable panning when needed.
     1322    QWidgetPrivate *dd = static_cast<QWidgetPrivate *>(QObjectPrivate::get(viewport));
     1323    if (dd)
     1324        dd->winSetupGestures();
     1325#endif // Q_WS_WIN
    12401326}
    12411327
     
    12651351    int vsbExt = d->vbar->sizeHint().width();
    12661352    int extra = 2 * d->frameWidth;
     1353    QStyleOption opt;
     1354    opt.initFrom(this);
     1355    if ((d->frameStyle != QFrame::NoFrame)
     1356        && style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, &opt, this)) {
     1357        extra += style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarSpacing, &opt, this);
     1358    }
    12671359    return QSize(d->scrollBarContainers[Qt::Horizontal]->sizeHint().width() + vsbExt + extra,
    12681360                 d->scrollBarContainers[Qt::Vertical]->sizeHint().height() + hsbExt + extra);
Note: See TracChangeset for help on using the changeset viewer.