Changeset 561 for trunk/src/gui/widgets/qabstractscrollarea.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/widgets/qabstractscrollarea.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 52 52 #include "qboxlayout.h" 53 53 #include "qpainter.h" 54 #include "qmargins.h" 54 55 55 56 #include "qabstractscrollarea_p.h" 56 57 #include <qwidget.h> 58 59 #include <private/qapplication_p.h> 57 60 58 61 #ifdef Q_WS_MAC … … 158 161 viewport(0), cornerWidget(0), left(0), top(0), right(0), bottom(0), 159 162 xoffset(0), yoffset(0), viewportFilter(0) 163 #ifdef Q_WS_WIN 164 , singleFingerPanEnabled(false) 165 #endif 160 166 { 161 167 } … … 282 288 QObject::connect(vbar, SIGNAL(valueChanged(int)), q, SLOT(_q_vslide(int))); 283 289 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()); 286 292 viewport->setFocusProxy(q); 287 293 q->setFocusPolicy(Qt::WheelFocus); … … 289 295 q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 290 296 layoutChildren(); 291 } 297 #ifndef Q_WS_MAC 298 viewport->grabGesture(Qt::PanGesture); 299 #endif 300 } 301 302 #ifdef Q_WS_WIN 303 void 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 292 311 293 312 void QAbstractScrollAreaPrivate::layoutChildren() … … 460 479 } 461 480 462 // ### Fix for 4.4, talk to Bjoern E or Girish.463 void QAbstractScrollAreaPrivate::scrollBarPolicyChanged(Qt::Orientation, Qt::ScrollBarPolicy) {}464 465 481 /*! 466 482 \internal … … 472 488 { 473 489 Q_D(QAbstractScrollArea); 474 d->init(); 490 QT_TRY { 491 d->init(); 492 } QT_CATCH(...) { 493 d->viewportFilter.reset(); 494 QT_RETHROW; 495 } 475 496 } 476 497 … … 484 505 { 485 506 Q_D(QAbstractScrollArea); 486 d->init(); 507 QT_TRY { 508 d->init(); 509 } QT_CATCH(...) { 510 d->viewportFilter.reset(); 511 QT_RETHROW; 512 } 487 513 } 488 514 … … 494 520 { 495 521 Q_D(QAbstractScrollArea); 496 delete d->viewportFilter; 522 // reset it here, otherwise we'll have a dangling pointer in ~QWidget 523 d->viewportFilter.reset(); 497 524 } 498 525 … … 518 545 d->viewport->setParent(this); 519 546 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 521 551 d->layoutChildren(); 522 552 if (isVisible()) … … 841 871 d->bottom = bottom; 842 872 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 */ 885 void QAbstractScrollArea::setViewportMargins(const QMargins &margins) 886 { 887 setViewportMargins(margins.left(), margins.top(), 888 margins.right(), margins.bottom()); 843 889 } 844 890 … … 874 920 d->layoutChildren(); 875 921 break; 876 case QEvent::Paint: 922 case QEvent::Paint: { 923 QStyleOption option; 924 option.initFrom(this); 877 925 if (d->cornerPaintingRect.isValid()) { 878 QStyleOption option;879 926 option.rect = d->cornerPaintingRect; 880 927 QPainter p(this); … … 883 930 #ifdef Q_WS_MAC 884 931 if (d->reverseCornerPaintingRect.isValid()) { 885 QStyleOption option;886 932 option.rect = d->reverseCornerPaintingRect; 887 933 QPainter p(this); … … 889 935 } 890 936 #endif 937 } 891 938 QFrame::paintEvent((QPaintEvent*)e); 892 939 break; … … 909 956 case QEvent::DragLeave: 910 957 #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: 911 962 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 } 912 983 case QEvent::StyleChange: 913 984 case QEvent::LayoutDirectionChange: … … 949 1020 case QEvent::MouseButtonRelease: 950 1021 case QEvent::MouseButtonDblClick: 1022 case QEvent::TouchBegin: 1023 case QEvent::TouchUpdate: 1024 case QEvent::TouchEnd: 951 1025 case QEvent::MouseMove: 952 1026 case QEvent::ContextMenu: … … 962 1036 return QFrame::event(e); 963 1037 case QEvent::LayoutRequest: 1038 case QEvent::Gesture: 1039 case QEvent::GestureOverride: 964 1040 return event(e); 965 1041 default: … … 1059 1135 { 1060 1136 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); 1065 1144 } 1066 1145 #endif … … 1238 1317 { 1239 1318 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 1240 1326 } 1241 1327 … … 1265 1351 int vsbExt = d->vbar->sizeHint().width(); 1266 1352 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 } 1267 1359 return QSize(d->scrollBarContainers[Qt::Horizontal]->sizeHint().width() + vsbExt + extra, 1268 1360 d->scrollBarContainers[Qt::Vertical]->sizeHint().height() + hsbExt + extra);
Note:
See TracChangeset
for help on using the changeset viewer.