widgets/qabstractscrollarea.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/****************************************************************************-
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtGui 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/****************************************************************************
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qabstractscrollarea.h" -
43 -
44#ifndef QT_NO_SCROLLAREA -
45 -
46#include "qscrollbar.h" -
47#include "qapplication.h" -
48#include "qstyle.h" -
49#include "qstyleoption.h" -
50#include "qevent.h" -
51#include "qdebug.h" -
52#include "qboxlayout.h" -
53#include "qpainter.h" -
54#include "qmargins.h" -
55#include "qheaderview.h" -
56 -
57#include <QDebug> -
58 -
59#include "qabstractscrollarea_p.h" -
60#include "qscrollbar_p.h" -
61#include <qwidget.h> -
62 -
63#include <private/qapplication_p.h> -
64 -
65#ifdef Q_WS_MAC -
66#include <private/qt_mac_p.h> -
67#include <private/qt_cocoa_helpers_mac_p.h> -
68#endif -
69#ifdef Q_OS_WIN -
70# include <qlibrary.h> -
71# include <qt_windows.h> -
72#endif -
73 -
74QT_BEGIN_NAMESPACE -
75 -
76/*! -
77 \class QAbstractScrollArea -
78 \brief The QAbstractScrollArea widget provides a scrolling area with -
79 on-demand scroll bars. -
80 -
81 \ingroup abstractwidgets -
82 \inmodule QtWidgets -
83 -
84 QAbstractScrollArea is a low-level abstraction of a scrolling -
85 area. The area provides a central widget called the viewport, in -
86 which the contents of the area is to be scrolled (i.e, the -
87 visible parts of the contents are rendered in the viewport). -
88 -
89 Next to the viewport is a vertical scroll bar, and below is a -
90 horizontal scroll bar. When all of the area contents fits in the -
91 viewport, each scroll bar can be either visible or hidden -
92 depending on the scroll bar's Qt::ScrollBarPolicy. When a scroll -
93 bar is hidden, the viewport expands in order to cover all -
94 available space. When a scroll bar becomes visible again, the -
95 viewport shrinks in order to make room for the scroll bar. -
96 -
97 It is possible to reserve a margin area around the viewport, see -
98 setViewportMargins(). The feature is mostly used to place a -
99 QHeaderView widget above or beside the scrolling area. Subclasses -
100 of QAbstractScrollArea should implement margins. -
101 -
102 When inheriting QAbstractScrollArea, you need to do the -
103 following: -
104 -
105 \list -
106 \li Control the scroll bars by setting their -
107 range, value, page step, and tracking their -
108 movements. -
109 \li Draw the contents of the area in the viewport according -
110 to the values of the scroll bars. -
111 \li Handle events received by the viewport in -
112 viewportEvent() - notably resize events. -
113 \li Use \c{viewport->update()} to update the contents of the -
114 viewport instead of \l{QWidget::update()}{update()} -
115 as all painting operations take place on the viewport. -
116 \endlist -
117 -
118 With a scroll bar policy of Qt::ScrollBarAsNeeded (the default), -
119 QAbstractScrollArea shows scroll bars when they provide a non-zero -
120 scrolling range, and hides them otherwise. -
121 -
122 The scroll bars and viewport should be updated whenever the viewport -
123 receives a resize event or the size of the contents changes. -
124 The viewport also needs to be updated when the scroll bars -
125 values change. The initial values of the scroll bars are often -
126 set when the area receives new contents. -
127 -
128 We give a simple example, in which we have implemented a scroll area -
129 that can scroll any QWidget. We make the widget a child of the -
130 viewport; this way, we do not have to calculate which part of -
131 the widget to draw but can simply move the widget with -
132 QWidget::move(). When the area contents or the viewport size -
133 changes, we do the following: -
134 -
135 \snippet myscrollarea.cpp 1 -
136 -
137 When the scroll bars change value, we need to update the widget -
138 position, i.e., find the part of the widget that is to be drawn in -
139 the viewport: -
140 -
141 \snippet myscrollarea.cpp 0 -
142 -
143 In order to track scroll bar movements, reimplement the virtual -
144 function scrollContentsBy(). In order to fine-tune scrolling -
145 behavior, connect to a scroll bar's -
146 QAbstractSlider::actionTriggered() signal and adjust the \l -
147 QAbstractSlider::sliderPosition as you wish. -
148 -
149 For convenience, QAbstractScrollArea makes all viewport events -
150 available in the virtual viewportEvent() handler. QWidget's -
151 specialized handlers are remapped to viewport events in the cases -
152 where this makes sense. The remapped specialized handlers are: -
153 paintEvent(), mousePressEvent(), mouseReleaseEvent(), -
154 mouseDoubleClickEvent(), mouseMoveEvent(), wheelEvent(), -
155 dragEnterEvent(), dragMoveEvent(), dragLeaveEvent(), dropEvent(), -
156 contextMenuEvent(), and resizeEvent(). -
157 -
158 QScrollArea, which inherits QAbstractScrollArea, provides smooth -
159 scrolling for any QWidget (i.e., the widget is scrolled pixel by -
160 pixel). You only need to subclass QAbstractScrollArea if you need -
161 more specialized behavior. This is, for instance, true if the -
162 entire contents of the area is not suitable for being drawn on a -
163 QWidget or if you do not want smooth scrolling. -
164 -
165 \sa QScrollArea -
166*/ -
167 -
168QAbstractScrollAreaPrivate::QAbstractScrollAreaPrivate() -
169 :hbar(0), vbar(0), vbarpolicy(Qt::ScrollBarAsNeeded), hbarpolicy(Qt::ScrollBarAsNeeded), -
170 viewport(0), cornerWidget(0), left(0), top(0), right(0), bottom(0), -
171 xoffset(0), yoffset(0), viewportFilter(0) -
172#ifdef Q_WS_WIN -
173 , singleFingerPanEnabled(false) -
174#endif -
175{ -
176} -
177 -
178QAbstractScrollAreaScrollBarContainer::QAbstractScrollAreaScrollBarContainer(Qt::Orientation orientation, QWidget *parent) -
179 :QWidget(parent), scrollBar(new QScrollBar(orientation, this)), -
180 layout(new QBoxLayout(orientation == Qt::Horizontal ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom)), -
181 orientation(orientation) -
182{ -
183 setLayout(layout); -
184 layout->setMargin(0); -
185 layout->setSpacing(0); -
186 layout->addWidget(scrollBar); -
187 layout->setSizeConstraint(QLayout::SetMaximumSize); -
188} -
189 -
190/*! \internal -
191 Adds a widget to the scroll bar container. -
192*/ -
193void QAbstractScrollAreaScrollBarContainer::addWidget(QWidget *widget, LogicalPosition position) -
194{ -
195 QSizePolicy policy = widget->sizePolicy(); -
196 if (orientation == Qt::Vertical) -
197 policy.setHorizontalPolicy(QSizePolicy::Ignored); -
198 else -
199 policy.setVerticalPolicy(QSizePolicy::Ignored); -
200 widget->setSizePolicy(policy); -
201 widget->setParent(this); -
202 -
203 const int insertIndex = (position & LogicalLeft) ? 0 : scrollBarLayoutIndex() + 1; -
204 layout->insertWidget(insertIndex, widget); -
205} -
206 -
207/*! \internal -
208 Retuns a list of scroll bar widgets for the given position. The scroll bar -
209 itself is not returned. -
210*/ -
211QWidgetList QAbstractScrollAreaScrollBarContainer::widgets(LogicalPosition position) -
212{ -
213 QWidgetList list; -
214 const int scrollBarIndex = scrollBarLayoutIndex(); -
215 if (position == LogicalLeft) { -
216 for (int i = 0; i < scrollBarIndex; ++i) -
217 list.append(layout->itemAt(i)->widget()); -
218 } else if (position == LogicalRight) { -
219 const int layoutItemCount = layout->count(); -
220 for (int i = scrollBarIndex + 1; i < layoutItemCount; ++i) -
221 list.append(layout->itemAt(i)->widget()); -
222 } -
223 return list; -
224} -
225 -
226/*! \internal -
227 Returns the layout index for the scroll bar. This needs to be -
228 recalculated by a linear search for each use, since items in -
229 the layout can be removed at any time (i.e. when a widget is -
230 deleted or re-parented). -
231*/ -
232int QAbstractScrollAreaScrollBarContainer::scrollBarLayoutIndex() const -
233{ -
234 const int layoutItemCount = layout->count(); -
235 for (int i = 0; i < layoutItemCount; ++i) { -
236 if (qobject_cast<QScrollBar *>(layout->itemAt(i)->widget())) -
237 return i; -
238 } -
239 return -1; -
240} -
241 -
242/*! \internal -
243*/ -
244void QAbstractScrollAreaPrivate::replaceScrollBar(QScrollBar *scrollBar, -
245 Qt::Orientation orientation) -
246{ -
247 Q_Q(QAbstractScrollArea); -
248 -
249 QAbstractScrollAreaScrollBarContainer *container = scrollBarContainers[orientation]; -
250 bool horizontal = (orientation == Qt::Horizontal); -
251 QScrollBar *oldBar = horizontal ? hbar : vbar; -
252 if (horizontal) -
253 hbar = scrollBar; -
254 else -
255 vbar = scrollBar; -
256 scrollBar->setParent(container); -
257 container->scrollBar = scrollBar; -
258 container->layout->removeWidget(oldBar); -
259 container->layout->insertWidget(0, scrollBar); -
260 scrollBar->setVisible(oldBar->isVisibleTo(container)); -
261 scrollBar->setInvertedAppearance(oldBar->invertedAppearance()); -
262 scrollBar->setInvertedControls(oldBar->invertedControls()); -
263 scrollBar->setRange(oldBar->minimum(), oldBar->maximum()); -
264 scrollBar->setOrientation(oldBar->orientation()); -
265 scrollBar->setPageStep(oldBar->pageStep()); -
266 scrollBar->setSingleStep(oldBar->singleStep()); -
267 scrollBar->setSliderDown(oldBar->isSliderDown()); -
268 scrollBar->setSliderPosition(oldBar->sliderPosition()); -
269 scrollBar->setTracking(oldBar->hasTracking()); -
270 scrollBar->setValue(oldBar->value()); -
271 scrollBar->installEventFilter(q); -
272 oldBar->removeEventFilter(q); -
273 delete oldBar; -
274 -
275 QObject::connect(scrollBar, SIGNAL(valueChanged(int)), -
276 q, horizontal ? SLOT(_q_hslide(int)) : SLOT(_q_vslide(int))); -
277 QObject::connect(scrollBar, SIGNAL(rangeChanged(int,int)), -
278 q, SLOT(_q_showOrHideScrollBars()), Qt::QueuedConnection); -
279} -
280 -
281void QAbstractScrollAreaPrivate::init() -
282{ -
283 Q_Q(QAbstractScrollArea); -
284 viewport = new QWidget(q); -
285 viewport->setObjectName(QLatin1String("qt_scrollarea_viewport")); -
286 viewport->setBackgroundRole(QPalette::Base); -
287 viewport->setAutoFillBackground(true); -
288 scrollBarContainers[Qt::Horizontal] = new QAbstractScrollAreaScrollBarContainer(Qt::Horizontal, q); -
289 scrollBarContainers[Qt::Horizontal]->setObjectName(QLatin1String("qt_scrollarea_hcontainer")); -
290 hbar = scrollBarContainers[Qt::Horizontal]->scrollBar; -
291 hbar->setRange(0,0); -
292 scrollBarContainers[Qt::Horizontal]->setVisible(false); -
293 hbar->installEventFilter(q); -
294 QObject::connect(hbar, SIGNAL(valueChanged(int)), q, SLOT(_q_hslide(int))); -
295 QObject::connect(hbar, SIGNAL(rangeChanged(int,int)), q, SLOT(_q_showOrHideScrollBars()), Qt::QueuedConnection); -
296 scrollBarContainers[Qt::Vertical] = new QAbstractScrollAreaScrollBarContainer(Qt::Vertical, q); -
297 scrollBarContainers[Qt::Vertical]->setObjectName(QLatin1String("qt_scrollarea_vcontainer")); -
298 vbar = scrollBarContainers[Qt::Vertical]->scrollBar; -
299 vbar->setRange(0,0); -
300 scrollBarContainers[Qt::Vertical]->setVisible(false); -
301 vbar->installEventFilter(q); -
302 QObject::connect(vbar, SIGNAL(valueChanged(int)), q, SLOT(_q_vslide(int))); -
303 QObject::connect(vbar, SIGNAL(rangeChanged(int,int)), q, SLOT(_q_showOrHideScrollBars()), Qt::QueuedConnection); -
304 viewportFilter.reset(new QAbstractScrollAreaFilter(this)); -
305 viewport->installEventFilter(viewportFilter.data()); -
306 viewport->setFocusProxy(q); -
307 q->setFocusPolicy(Qt::WheelFocus); -
308 q->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); -
309 q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); -
310 layoutChildren(); -
311#ifndef Q_WS_MAC -
312# ifndef QT_NO_GESTURES -
313 viewport->grabGesture(Qt::PanGesture); -
314# endif -
315#endif -
316} -
317 -
318#ifdef Q_WS_WIN -
319void QAbstractScrollAreaPrivate::setSingleFingerPanEnabled(bool on) -
320{ -
321 singleFingerPanEnabled = on; -
322 QWidgetPrivate *dd = static_cast<QWidgetPrivate *>(QObjectPrivate::get(viewport)); -
323 if (dd) -
324 dd->winSetupGestures(); -
325} -
326#endif // Q_WS_WIN -
327 -
328void QAbstractScrollAreaPrivate::layoutChildren() -
329{ -
330 Q_Q(QAbstractScrollArea);
executed (the execution status of this line is deduced): QAbstractScrollArea * const q = q_func();
-
331 bool transient = q->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, vbar ? vbar : hbar);
executed (the execution status of this line is deduced): bool transient = q->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, vbar ? vbar : hbar);
-
332 bool needh = (hbarpolicy != Qt::ScrollBarAlwaysOff) && ((hbarpolicy == Qt::ScrollBarAlwaysOn && !transient)
evaluated: (hbarpolicy != Qt::ScrollBarAlwaysOff)
TRUEFALSE
yes
Evaluation Count:15161
yes
Evaluation Count:13037
evaluated: hbarpolicy == Qt::ScrollBarAlwaysOn
TRUEFALSE
yes
Evaluation Count:225
yes
Evaluation Count:14936
partially evaluated: !transient
TRUEFALSE
yes
Evaluation Count:225
no
Evaluation Count:0
0-15161
333 || ((hbarpolicy == Qt::ScrollBarAsNeeded || transient)
partially evaluated: hbarpolicy == Qt::ScrollBarAsNeeded
TRUEFALSE
yes
Evaluation Count:14936
no
Evaluation Count:0
never evaluated: transient
0-14936
334 && hbar->minimum() < hbar->maximum() && !hbar->sizeHint().isEmpty());()));
evaluated: hbar->minimum() < hbar->maximum()
TRUEFALSE
yes
Evaluation Count:2334
yes
Evaluation Count:12602
partially evaluated: !hbar->sizeHint().isEmpty()
TRUEFALSE
yes
Evaluation Count:2334
no
Evaluation Count:0
0-12602
335 -
336 bool needv = (vbarpolicy != Qt::ScrollBarAlwaysOff) && ((vbarpolicy == Qt::ScrollBarAlwaysOn && !transient)
evaluated: (vbarpolicy != Qt::ScrollBarAlwaysOff)
TRUEFALSE
yes
Evaluation Count:15463
yes
Evaluation Count:12735
evaluated: vbarpolicy == Qt::ScrollBarAlwaysOn
TRUEFALSE
yes
Evaluation Count:411
yes
Evaluation Count:15052
partially evaluated: !transient
TRUEFALSE
yes
Evaluation Count:411
no
Evaluation Count:0
0-15463
337 || ((vbarpolicy == Qt::ScrollBarAsNeeded || transient)
partially evaluated: vbarpolicy == Qt::ScrollBarAsNeeded
TRUEFALSE
yes
Evaluation Count:15052
no
Evaluation Count:0
never evaluated: transient
0-15052
338 && vbar->minimum() < vbar->maximum() && !vbar->sizeHint().isEmpty());()));
evaluated: vbar->minimum() < vbar->maximum()
TRUEFALSE
yes
Evaluation Count:3031
yes
Evaluation Count:12021
partially evaluated: !vbar->sizeHint().isEmpty()
TRUEFALSE
yes
Evaluation Count:3031
no
Evaluation Count:0
0-12021
339 -
340 QStyleOption opt(0);
executed (the execution status of this line is deduced): QStyleOption opt(0);
-
341 opt.init(q);
executed (the execution status of this line is deduced): opt.init(q);
-
342 const int scrollOverlap = q->style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarOverlap,
executed (the execution status of this line is deduced): const int scrollOverlap = q->style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarOverlap,
-
343 &opt, q);
executed (the execution status of this line is deduced): &opt, q);
-
344 -
345#ifdef Q_WS_MAC -
346 QWidget * const window = q->window(); -
347 -
348 // Use small scroll bars for tool windows, to match the native size grip. -
349 bool hbarIsSmall = hbar->testAttribute(Qt::WA_MacSmallSize); -
350 bool vbarIsSmall = vbar->testAttribute(Qt::WA_MacSmallSize); -
351 const Qt::WindowType windowType = window->windowType(); -
352 if (windowType == Qt::Tool) { -
353 if (!hbarIsSmall) { -
354 hbar->setAttribute(Qt::WA_MacMiniSize, false); -
355 hbar->setAttribute(Qt::WA_MacNormalSize, false); -
356 hbar->setAttribute(Qt::WA_MacSmallSize, true); -
357 } -
358 if (!vbarIsSmall) { -
359 vbar->setAttribute(Qt::WA_MacMiniSize, false); -
360 vbar->setAttribute(Qt::WA_MacNormalSize, false); -
361 vbar->setAttribute(Qt::WA_MacSmallSize, true); -
362 } -
363 } else { -
364 if (hbarIsSmall) { -
365 hbar->setAttribute(Qt::WA_MacMiniSize, false); -
366 hbar->setAttribute(Qt::WA_MacNormalSize, false); -
367 hbar->setAttribute(Qt::WA_MacSmallSize, false); -
368 } -
369 if (vbarIsSmall) { -
370 vbar->setAttribute(Qt::WA_MacMiniSize, false); -
371 vbar->setAttribute(Qt::WA_MacNormalSize, false); -
372 vbar->setAttribute(Qt::WA_MacSmallSize, false); -
373 } -
374 } -
375#endif -
376 -
377 const int hsbExt = hbar->sizeHint().height();
executed (the execution status of this line is deduced): const int hsbExt = hbar->sizeHint().height();
-
378 const int vsbExt = vbar->sizeHint().width();
executed (the execution status of this line is deduced): const int vsbExt = vbar->sizeHint().width();
-
379 const QPoint extPoint(vsbExt, hsbExt);
executed (the execution status of this line is deduced): const QPoint extPoint(vsbExt, hsbExt);
-
380 const QSize extSize(vsbExt, hsbExt);
executed (the execution status of this line is deduced): const QSize extSize(vsbExt, hsbExt);
-
381 -
382 const QRect widgetRect = q->rect();
executed (the execution status of this line is deduced): const QRect widgetRect = q->rect();
-
383 -
384 const bool hasCornerWidget = (cornerWidget != 0);
executed (the execution status of this line is deduced): const bool hasCornerWidget = (cornerWidget != 0);
-
385 -
386// If the scroll bars are at the very right and bottom of the window we -
387// move their positions to be aligned with the size grip. -
388#ifdef Q_WS_MAC -
389 // Check if a native sizegrip is present. -
390 bool hasMacReverseSizeGrip = false; -
391 bool hasMacSizeGrip = false; -
392 bool nativeGripPresent = false; -
393 if (q->testAttribute(Qt::WA_WState_Created)) -
394 nativeGripPresent = qt_mac_checkForNativeSizeGrip(q); -
395 -
396 if (nativeGripPresent) { -
397 // Look for a native size grip at the visual window bottom right and at the -
398 // absolute window bottom right. In reverse mode, the native size grip does not -
399 // swich side, so we need to check if it is on the "wrong side". -
400 const QPoint scrollAreaBottomRight = q->mapTo(window, widgetRect.bottomRight() - QPoint(frameWidth, frameWidth)); -
401 const QPoint windowBottomRight = window->rect().bottomRight(); -
402 const QPoint visualWindowBottomRight = QStyle::visualPos(opt.direction, opt.rect, windowBottomRight); -
403 const QPoint offset = windowBottomRight - scrollAreaBottomRight; -
404 const QPoint visualOffset = visualWindowBottomRight - scrollAreaBottomRight; -
405 hasMacSizeGrip = (visualOffset.manhattanLength() < vsbExt); -
406 hasMacReverseSizeGrip = (hasMacSizeGrip == false && (offset.manhattanLength() < hsbExt)); -
407 } -
408#endif -
409 -
410 QPoint cornerOffset((needv && scrollOverlap == 0) ? vsbExt : 0, (needh && scrollOverlap == 0) ? hsbExt : 0);
executed (the execution status of this line is deduced): QPoint cornerOffset((needv && scrollOverlap == 0) ? vsbExt : 0, (needh && scrollOverlap == 0) ? hsbExt : 0);
-
411 QRect controlsRect;
executed (the execution status of this line is deduced): QRect controlsRect;
-
412 QRect viewportRect;
executed (the execution status of this line is deduced): QRect viewportRect;
-
413 -
414 // In FrameOnlyAroundContents mode the frame is drawn between the controls and -
415 // the viewport, else the frame rect is equal to the widget rect. -
416 if ((frameStyle != QFrame::NoFrame) &&
evaluated: (frameStyle != QFrame::NoFrame)
TRUEFALSE
yes
Evaluation Count:14796
yes
Evaluation Count:13402
13402-14796
417 q->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, &opt, q)) {
evaluated: q->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, &opt, q)
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:14794
2-14794
418 controlsRect = widgetRect;
executed (the execution status of this line is deduced): controlsRect = widgetRect;
-
419 const int extra = scrollOverlap + q->style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarSpacing, &opt, q);
executed (the execution status of this line is deduced): const int extra = scrollOverlap + q->style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarSpacing, &opt, q);
-
420 const QPoint cornerExtra(needv ? extra : 0, needh ? extra : 0);
executed (the execution status of this line is deduced): const QPoint cornerExtra(needv ? extra : 0, needh ? extra : 0);
-
421 QRect frameRect = widgetRect;
executed (the execution status of this line is deduced): QRect frameRect = widgetRect;
-
422 frameRect.adjust(0, 0, -cornerOffset.x() - cornerExtra.x(), -cornerOffset.y() - cornerExtra.y());
executed (the execution status of this line is deduced): frameRect.adjust(0, 0, -cornerOffset.x() - cornerExtra.x(), -cornerOffset.y() - cornerExtra.y());
-
423 q->setFrameRect(QStyle::visualRect(opt.direction, opt.rect, frameRect));
executed (the execution status of this line is deduced): q->setFrameRect(QStyle::visualRect(opt.direction, opt.rect, frameRect));
-
424 // The frame rect needs to be in logical coords, however we need to flip -
425 // the contentsRect back before passing it on to the viewportRect -
426 // since the viewportRect has its logical coords calculated later. -
427 viewportRect = QStyle::visualRect(opt.direction, opt.rect, q->contentsRect());
executed (the execution status of this line is deduced): viewportRect = QStyle::visualRect(opt.direction, opt.rect, q->contentsRect());
-
428 } else {
executed: }
Execution Count:2
2
429 q->setFrameRect(QStyle::visualRect(opt.direction, opt.rect, widgetRect));
executed (the execution status of this line is deduced): q->setFrameRect(QStyle::visualRect(opt.direction, opt.rect, widgetRect));
-
430 controlsRect = q->contentsRect();
executed (the execution status of this line is deduced): controlsRect = q->contentsRect();
-
431 viewportRect = QRect(controlsRect.topLeft(), controlsRect.bottomRight() - cornerOffset);
executed (the execution status of this line is deduced): viewportRect = QRect(controlsRect.topLeft(), controlsRect.bottomRight() - cornerOffset);
-
432 }
executed: }
Execution Count:28196
28196
433 -
434 cornerOffset = QPoint(needv ? vsbExt : 0, needh ? hsbExt : 0);
executed (the execution status of this line is deduced): cornerOffset = QPoint(needv ? vsbExt : 0, needh ? hsbExt : 0);
-
435 -
436 // If we have a corner widget and are only showing one scroll bar, we need to move it -
437 // to make room for the corner widget. -
438 if (hasCornerWidget && (needv || needh) && scrollOverlap == 0)
evaluated: hasCornerWidget
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:28196
evaluated: needv
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
partially evaluated: needh
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
partially evaluated: scrollOverlap == 0
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-28196
439 cornerOffset = extPoint;
executed: cornerOffset = extPoint;
Execution Count:1
1
440 -
441#ifdef Q_WS_MAC -
442 // Also move the scroll bars if they are covered by the native Mac size grip. -
443 if (hasMacSizeGrip) -
444 cornerOffset = extPoint; -
445#endif -
446 -
447 // The corner point is where the scroll bar rects, the corner widget rect and the -
448 // viewport rect meets. -
449 const QPoint cornerPoint(controlsRect.bottomRight() + QPoint(1, 1) - cornerOffset);
executed (the execution status of this line is deduced): const QPoint cornerPoint(controlsRect.bottomRight() + QPoint(1, 1) - cornerOffset);
-
450 -
451 // Some styles paints the corner if both scorllbars are showing and there is -
452 // no corner widget. Also, on the Mac we paint if there is a native -
453 // (transparent) sizegrip in the area where a corner widget would be. -
454 if ((needv && needh && hasCornerWidget == false && scrollOverlap == 0)
evaluated: needv
TRUEFALSE
yes
Evaluation Count:3442
yes
Evaluation Count:24756
evaluated: needh
TRUEFALSE
yes
Evaluation Count:1733
yes
Evaluation Count:1709
evaluated: hasCornerWidget == false
TRUEFALSE
yes
Evaluation Count:1732
yes
Evaluation Count:1
partially evaluated: scrollOverlap == 0
TRUEFALSE
yes
Evaluation Count:1732
no
Evaluation Count:0
0-24756
455 || ((needv || needh)
evaluated: needv
TRUEFALSE
yes
Evaluation Count:1710
yes
Evaluation Count:24756
evaluated: needh
TRUEFALSE
yes
Evaluation Count:826
yes
Evaluation Count:23930
826-24756
456#ifdef Q_WS_MAC
executed (the execution status of this line is deduced):
-
457 && hasMacSizeGrip
executed (the execution status of this line is deduced):
-
458#endif
executed (the execution status of this line is deduced):
-
459 )
executed (the execution status of this line is deduced): )
-
460 ) { -
461 cornerPaintingRect = QStyle::visualRect(opt.direction, opt.rect, QRect(cornerPoint, extSize));
executed (the execution status of this line is deduced): cornerPaintingRect = QStyle::visualRect(opt.direction, opt.rect, QRect(cornerPoint, extSize));
-
462 } else {
executed: }
Execution Count:4268
4268
463 cornerPaintingRect = QRect();
executed (the execution status of this line is deduced): cornerPaintingRect = QRect();
-
464 }
executed: }
Execution Count:23930
23930
465 -
466#ifdef Q_WS_MAC -
467 if (hasMacReverseSizeGrip) -
468 reverseCornerPaintingRect = QRect(controlsRect.bottomRight() + QPoint(1, 1) - extPoint, extSize); -
469 else -
470 reverseCornerPaintingRect = QRect(); -
471#endif -
472 -
473 // move the scrollbars away from top/left headers -
474 int vHeaderRight = 0;
executed (the execution status of this line is deduced): int vHeaderRight = 0;
-
475 int hHeaderBottom = 0;
executed (the execution status of this line is deduced): int hHeaderBottom = 0;
-
476 if (scrollOverlap > 0 && (needv || needh)) {
partially evaluated: scrollOverlap > 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:28198
never evaluated: needv
never evaluated: needh
0-28198
477 const QList<QHeaderView *> headers = q->findChildren<QHeaderView*>();
never executed (the execution status of this line is deduced): const QList<QHeaderView *> headers = q->findChildren<QHeaderView*>();
-
478 if (headers.count() <= 2) {
never evaluated: headers.count() <= 2
0
479 Q_FOREACH (const QHeaderView *header, headers) {
never executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(headers)> _container_(headers); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QHeaderView *header = *_container_.i;; __extension__ ({--_container_.brk; break;})) {
-
480 const QRect geo = header->geometry();
never executed (the execution status of this line is deduced): const QRect geo = header->geometry();
-
481 if (header->orientation() == Qt::Vertical && header->isVisible() && QStyle::visualRect(opt.direction, opt.rect, geo).left() <= opt.rect.width() / 2)
never evaluated: header->orientation() == Qt::Vertical
never evaluated: header->isVisible()
never evaluated: QStyle::visualRect(opt.direction, opt.rect, geo).left() <= opt.rect.width() / 2
0
482 vHeaderRight = QStyle::visualRect(opt.direction, opt.rect, geo).right();
never executed: vHeaderRight = QStyle::visualRect(opt.direction, opt.rect, geo).right();
0
483 else if (header->orientation() == Qt::Horizontal && header->isVisible() && geo.top() <= q->frameWidth())
never evaluated: header->orientation() == Qt::Horizontal
never evaluated: header->isVisible()
never evaluated: geo.top() <= q->frameWidth()
0
484 hHeaderBottom = geo.bottom();
never executed: hHeaderBottom = geo.bottom();
0
485 } -
486 }
never executed: }
0
487 }
never executed: }
0
488 -
489 if (needh) {
evaluated: needh
TRUEFALSE
yes
Evaluation Count:2559
yes
Evaluation Count:25639
2559-25639
490 QRect horizontalScrollBarRect(QPoint(controlsRect.left() + vHeaderRight, cornerPoint.y()), QPoint(cornerPoint.x() - 1, controlsRect.bottom()));
executed (the execution status of this line is deduced): QRect horizontalScrollBarRect(QPoint(controlsRect.left() + vHeaderRight, cornerPoint.y()), QPoint(cornerPoint.x() - 1, controlsRect.bottom()));
-
491#ifdef Q_WS_MAC -
492 if (hasMacReverseSizeGrip) -
493 horizontalScrollBarRect.adjust(vsbExt, 0, 0, 0); -
494#endif -
495#ifdef Q_OS_MAC -
496 if (!hasCornerWidget && QSysInfo::macVersion() >= QSysInfo::MV_10_8 && transient) -
497 horizontalScrollBarRect.adjust(0, 0, cornerOffset.x(), 0); -
498#endif -
499 scrollBarContainers[Qt::Horizontal]->setGeometry(QStyle::visualRect(opt.direction, opt.rect, horizontalScrollBarRect));
executed (the execution status of this line is deduced): scrollBarContainers[Qt::Horizontal]->setGeometry(QStyle::visualRect(opt.direction, opt.rect, horizontalScrollBarRect));
-
500 scrollBarContainers[Qt::Horizontal]->raise();
executed (the execution status of this line is deduced): scrollBarContainers[Qt::Horizontal]->raise();
-
501 }
executed: }
Execution Count:2559
2559
502 -
503 if (needv) {
evaluated: needv
TRUEFALSE
yes
Evaluation Count:3442
yes
Evaluation Count:24756
3442-24756
504 QRect verticalScrollBarRect (QPoint(cornerPoint.x(), controlsRect.top() + hHeaderBottom), QPoint(controlsRect.right(), cornerPoint.y() - 1));
executed (the execution status of this line is deduced): QRect verticalScrollBarRect (QPoint(cornerPoint.x(), controlsRect.top() + hHeaderBottom), QPoint(controlsRect.right(), cornerPoint.y() - 1));
-
505#ifdef Q_OS_MAC -
506 if (!hasCornerWidget && QSysInfo::macVersion() >= QSysInfo::MV_10_8 && transient) -
507 verticalScrollBarRect.adjust(0, 0, 0, cornerOffset.y()); -
508#endif -
509 scrollBarContainers[Qt::Vertical]->setGeometry(QStyle::visualRect(opt.direction, opt.rect, verticalScrollBarRect));
executed (the execution status of this line is deduced): scrollBarContainers[Qt::Vertical]->setGeometry(QStyle::visualRect(opt.direction, opt.rect, verticalScrollBarRect));
-
510 scrollBarContainers[Qt::Vertical]->raise();
executed (the execution status of this line is deduced): scrollBarContainers[Qt::Vertical]->raise();
-
511 }
executed: }
Execution Count:3442
3442
512 -
513 if (cornerWidget) {
evaluated: cornerWidget
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:28196
2-28196
514 const QRect cornerWidgetRect(cornerPoint, controlsRect.bottomRight());
executed (the execution status of this line is deduced): const QRect cornerWidgetRect(cornerPoint, controlsRect.bottomRight());
-
515 cornerWidget->setGeometry(QStyle::visualRect(opt.direction, opt.rect, cornerWidgetRect));
executed (the execution status of this line is deduced): cornerWidget->setGeometry(QStyle::visualRect(opt.direction, opt.rect, cornerWidgetRect));
-
516 }
executed: }
Execution Count:2
2
517 -
518 scrollBarContainers[Qt::Horizontal]->setVisible(needh);
executed (the execution status of this line is deduced): scrollBarContainers[Qt::Horizontal]->setVisible(needh);
-
519 scrollBarContainers[Qt::Vertical]->setVisible(needv);
executed (the execution status of this line is deduced): scrollBarContainers[Qt::Vertical]->setVisible(needv);
-
520 -
521 if (q->isRightToLeft())
evaluated: q->isRightToLeft()
TRUEFALSE
yes
Evaluation Count:96
yes
Evaluation Count:28102
96-28102
522 viewportRect.adjust(right, top, -left, -bottom);
executed: viewportRect.adjust(right, top, -left, -bottom);
Execution Count:96
96
523 else -
524 viewportRect.adjust(left, top, -right, -bottom);
executed: viewportRect.adjust(left, top, -right, -bottom);
Execution Count:28102
28102
525 -
526 viewport->setGeometry(QStyle::visualRect(opt.direction, opt.rect, viewportRect)); // resize the viewport last
executed (the execution status of this line is deduced): viewport->setGeometry(QStyle::visualRect(opt.direction, opt.rect, viewportRect));
-
527}
executed: }
Execution Count:28198
28198
528 -
529/*! -
530 \internal -
531 -
532 Creates a new QAbstractScrollAreaPrivate, \a dd with the given \a parent. -
533*/ -
534QAbstractScrollArea::QAbstractScrollArea(QAbstractScrollAreaPrivate &dd, QWidget *parent) -
535 :QFrame(dd, parent) -
536{ -
537 Q_D(QAbstractScrollArea); -
538 QT_TRY { -
539 d->init(); -
540 } QT_CATCH(...) { -
541 d->viewportFilter.reset(); -
542 QT_RETHROW; -
543 } -
544} -
545 -
546/*! -
547 Constructs a viewport. -
548 -
549 The \a parent argument is sent to the QWidget constructor. -
550*/ -
551QAbstractScrollArea::QAbstractScrollArea(QWidget *parent) -
552 :QFrame(*new QAbstractScrollAreaPrivate, parent) -
553{ -
554 Q_D(QAbstractScrollArea); -
555 QT_TRY { -
556 d->init(); -
557 } QT_CATCH(...) { -
558 d->viewportFilter.reset(); -
559 QT_RETHROW; -
560 } -
561} -
562 -
563 -
564/*! -
565 Destroys the viewport. -
566 */ -
567QAbstractScrollArea::~QAbstractScrollArea() -
568{ -
569 Q_D(QAbstractScrollArea); -
570 // reset it here, otherwise we'll have a dangling pointer in ~QWidget -
571 d->viewportFilter.reset(); -
572} -
573 -
574 -
575/*! -
576 \since 4.2 -
577 Sets the viewport to be the given \a widget. -
578 The QAbstractScrollArea will take ownership of the given \a widget. -
579 -
580 If \a widget is 0, QAbstractScrollArea will assign a new QWidget instance -
581 for the viewport. -
582 -
583 \sa viewport() -
584*/ -
585void QAbstractScrollArea::setViewport(QWidget *widget) -
586{ -
587 Q_D(QAbstractScrollArea); -
588 if (widget != d->viewport) { -
589 QWidget *oldViewport = d->viewport; -
590 if (!widget) -
591 widget = new QWidget; -
592 d->viewport = widget; -
593 d->viewport->setParent(this); -
594 d->viewport->setFocusProxy(this); -
595 d->viewport->installEventFilter(d->viewportFilter.data()); -
596#ifndef Q_WS_MAC -
597#ifndef QT_NO_GESTURES -
598 d->viewport->grabGesture(Qt::PanGesture); -
599#endif -
600#endif -
601 d->layoutChildren(); -
602 if (isVisible()) -
603 d->viewport->show(); -
604 setupViewport(widget); -
605 delete oldViewport; -
606 } -
607} -
608 -
609/*! -
610 Returns the viewport widget. -
611 -
612 Use the QScrollArea::widget() function to retrieve the contents of -
613 the viewport widget. -
614 -
615 \sa QScrollArea::widget() -
616*/ -
617QWidget *QAbstractScrollArea::viewport() const -
618{ -
619 Q_D(const QAbstractScrollArea); -
620 return d->viewport; -
621} -
622 -
623 -
624/*! -
625Returns the size of the viewport as if the scroll bars had no valid -
626scrolling range. -
627*/ -
628// ### still thinking about the name -
629QSize QAbstractScrollArea::maximumViewportSize() const -
630{ -
631 Q_D(const QAbstractScrollArea); -
632 int hsbExt = d->hbar->sizeHint().height(); -
633 int vsbExt = d->vbar->sizeHint().width(); -
634 -
635 int f = 2 * d->frameWidth; -
636 QSize max = size() - QSize(f + d->left + d->right, f + d->top + d->bottom); -
637 if (d->vbarpolicy == Qt::ScrollBarAlwaysOn) -
638 max.rwidth() -= vsbExt; -
639 if (d->hbarpolicy == Qt::ScrollBarAlwaysOn) -
640 max.rheight() -= hsbExt; -
641 return max; -
642} -
643 -
644/*! -
645 \property QAbstractScrollArea::verticalScrollBarPolicy -
646 \brief the policy for the vertical scroll bar -
647 -
648 The default policy is Qt::ScrollBarAsNeeded. -
649 -
650 \sa horizontalScrollBarPolicy -
651*/ -
652 -
653Qt::ScrollBarPolicy QAbstractScrollArea::verticalScrollBarPolicy() const -
654{ -
655 Q_D(const QAbstractScrollArea); -
656 return d->vbarpolicy; -
657} -
658 -
659void QAbstractScrollArea::setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy) -
660{ -
661 Q_D(QAbstractScrollArea); -
662 const Qt::ScrollBarPolicy oldPolicy = d->vbarpolicy; -
663 d->vbarpolicy = policy; -
664 if (isVisible()) -
665 d->layoutChildren(); -
666 if (oldPolicy != d->vbarpolicy) -
667 d->scrollBarPolicyChanged(Qt::Vertical, d->vbarpolicy); -
668} -
669 -
670 -
671/*! -
672 Returns the vertical scroll bar. -
673 -
674 \sa verticalScrollBarPolicy, horizontalScrollBar() -
675 */ -
676QScrollBar *QAbstractScrollArea::verticalScrollBar() const -
677{ -
678 Q_D(const QAbstractScrollArea); -
679 return d->vbar; -
680} -
681 -
682/*! -
683 \since 4.2 -
684 Replaces the existing vertical scroll bar with \a scrollBar, and sets all -
685 the former scroll bar's slider properties on the new scroll bar. The former -
686 scroll bar is then deleted. -
687 -
688 QAbstractScrollArea already provides vertical and horizontal scroll bars by -
689 default. You can call this function to replace the default vertical -
690 scroll bar with your own custom scroll bar. -
691 -
692 \sa verticalScrollBar(), setHorizontalScrollBar() -
693*/ -
694void QAbstractScrollArea::setVerticalScrollBar(QScrollBar *scrollBar) -
695{ -
696 Q_D(QAbstractScrollArea); -
697 if (!scrollBar) { -
698 qWarning("QAbstractScrollArea::setVerticalScrollBar: Cannot set a null scroll bar"); -
699 return; -
700 } -
701 -
702 d->replaceScrollBar(scrollBar, Qt::Vertical); -
703} -
704 -
705/*! -
706 \property QAbstractScrollArea::horizontalScrollBarPolicy -
707 \brief the policy for the horizontal scroll bar -
708 -
709 The default policy is Qt::ScrollBarAsNeeded. -
710 -
711 \sa verticalScrollBarPolicy -
712*/ -
713 -
714Qt::ScrollBarPolicy QAbstractScrollArea::horizontalScrollBarPolicy() const -
715{ -
716 Q_D(const QAbstractScrollArea); -
717 return d->hbarpolicy; -
718} -
719 -
720void QAbstractScrollArea::setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy policy) -
721{ -
722 Q_D(QAbstractScrollArea); -
723 const Qt::ScrollBarPolicy oldPolicy = d->hbarpolicy; -
724 d->hbarpolicy = policy; -
725 if (isVisible()) -
726 d->layoutChildren(); -
727 if (oldPolicy != d->hbarpolicy) -
728 d->scrollBarPolicyChanged(Qt::Horizontal, d->hbarpolicy); -
729} -
730 -
731/*! -
732 Returns the horizontal scroll bar. -
733 -
734 \sa horizontalScrollBarPolicy, verticalScrollBar() -
735 */ -
736QScrollBar *QAbstractScrollArea::horizontalScrollBar() const -
737{ -
738 Q_D(const QAbstractScrollArea); -
739 return d->hbar; -
740} -
741 -
742/*! -
743 \since 4.2 -
744 -
745 Replaces the existing horizontal scroll bar with \a scrollBar, and sets all -
746 the former scroll bar's slider properties on the new scroll bar. The former -
747 scroll bar is then deleted. -
748 -
749 QAbstractScrollArea already provides horizontal and vertical scroll bars by -
750 default. You can call this function to replace the default horizontal -
751 scroll bar with your own custom scroll bar. -
752 -
753 \sa horizontalScrollBar(), setVerticalScrollBar() -
754*/ -
755void QAbstractScrollArea::setHorizontalScrollBar(QScrollBar *scrollBar) -
756{ -
757 Q_D(QAbstractScrollArea); -
758 if (!scrollBar) { -
759 qWarning("QAbstractScrollArea::setHorizontalScrollBar: Cannot set a null scroll bar"); -
760 return; -
761 } -
762 -
763 d->replaceScrollBar(scrollBar, Qt::Horizontal); -
764} -
765 -
766/*! -
767 \since 4.2 -
768 -
769 Returns the widget in the corner between the two scroll bars. -
770 -
771 By default, no corner widget is present. -
772*/ -
773QWidget *QAbstractScrollArea::cornerWidget() const -
774{ -
775 Q_D(const QAbstractScrollArea); -
776 return d->cornerWidget; -
777} -
778 -
779/*! -
780 \since 4.2 -
781 -
782 Sets the widget in the corner between the two scroll bars to be -
783 \a widget. -
784 -
785 You will probably also want to set at least one of the scroll bar -
786 modes to \c AlwaysOn. -
787 -
788 Passing 0 shows no widget in the corner. -
789 -
790 Any previous corner widget is hidden. -
791 -
792 You may call setCornerWidget() with the same widget at different -
793 times. -
794 -
795 All widgets set here will be deleted by the scroll area when it is -
796 destroyed unless you separately reparent the widget after setting -
797 some other corner widget (or 0). -
798 -
799 Any \e newly set widget should have no current parent. -
800 -
801 By default, no corner widget is present. -
802 -
803 \sa horizontalScrollBarPolicy, horizontalScrollBarPolicy -
804*/ -
805void QAbstractScrollArea::setCornerWidget(QWidget *widget) -
806{ -
807 Q_D(QAbstractScrollArea); -
808 QWidget* oldWidget = d->cornerWidget; -
809 if (oldWidget != widget) { -
810 if (oldWidget) -
811 oldWidget->hide(); -
812 d->cornerWidget = widget; -
813 -
814 if (widget && widget->parentWidget() != this) -
815 widget->setParent(this); -
816 -
817 d->layoutChildren(); -
818 if (widget) -
819 widget->show(); -
820 } else { -
821 d->cornerWidget = widget; -
822 d->layoutChildren(); -
823 } -
824} -
825 -
826/*! -
827 \since 4.2 -
828 Adds \a widget as a scroll bar widget in the location specified -
829 by \a alignment. -
830 -
831 Scroll bar widgets are shown next to the horizontal or vertical -
832 scroll bar, and can be placed on either side of it. If you want -
833 the scroll bar widgets to be always visible, set the -
834 scrollBarPolicy for the corresponding scroll bar to \c AlwaysOn. -
835 -
836 \a alignment must be one of Qt::Alignleft and Qt::AlignRight, -
837 which maps to the horizontal scroll bar, or Qt::AlignTop and -
838 Qt::AlignBottom, which maps to the vertical scroll bar. -
839 -
840 A scroll bar widget can be removed by either re-parenting the -
841 widget or deleting it. It's also possible to hide a widget with -
842 QWidget::hide() -
843 -
844 The scroll bar widget will be resized to fit the scroll bar -
845 geometry for the current style. The following describes the case -
846 for scroll bar widgets on the horizontal scroll bar: -
847 -
848 The height of the widget will be set to match the height of the -
849 scroll bar. To control the width of the widget, use -
850 QWidget::setMinimumWidth and QWidget::setMaximumWidth, or -
851 implement QWidget::sizeHint() and set a horizontal size policy. -
852 If you want a square widget, call -
853 QStyle::pixelMetric(QStyle::PM_ScrollBarExtent) and set the -
854 width to this value. -
855 -
856 \sa scrollBarWidgets() -
857*/ -
858void QAbstractScrollArea::addScrollBarWidget(QWidget *widget, Qt::Alignment alignment) -
859{ -
860 Q_D(QAbstractScrollArea); -
861 -
862 if (widget == 0) -
863 return; -
864 -
865 const Qt::Orientation scrollBarOrientation -
866 = ((alignment & Qt::AlignLeft) || (alignment & Qt::AlignRight)) ? Qt::Horizontal : Qt::Vertical; -
867 const QAbstractScrollAreaScrollBarContainer::LogicalPosition position -
868 = ((alignment & Qt::AlignRight) || (alignment & Qt::AlignBottom)) -
869 ? QAbstractScrollAreaScrollBarContainer::LogicalRight : QAbstractScrollAreaScrollBarContainer::LogicalLeft; -
870 d->scrollBarContainers[scrollBarOrientation]->addWidget(widget, position); -
871 d->layoutChildren(); -
872 if (isHidden() == false) -
873 widget->show(); -
874} -
875 -
876/*! -
877 \since 4.2 -
878 Returns a list of the currently set scroll bar widgets. \a alignment -
879 can be any combination of the four location flags. -
880 -
881 \sa addScrollBarWidget() -
882*/ -
883QWidgetList QAbstractScrollArea::scrollBarWidgets(Qt::Alignment alignment) -
884{ -
885 Q_D(QAbstractScrollArea); -
886 -
887 QWidgetList list; -
888 -
889 if (alignment & Qt::AlignLeft) -
890 list += d->scrollBarContainers[Qt::Horizontal]->widgets(QAbstractScrollAreaScrollBarContainer::LogicalLeft); -
891 if (alignment & Qt::AlignRight) -
892 list += d->scrollBarContainers[Qt::Horizontal]->widgets(QAbstractScrollAreaScrollBarContainer::LogicalRight); -
893 if (alignment & Qt::AlignTop) -
894 list += d->scrollBarContainers[Qt::Vertical]->widgets(QAbstractScrollAreaScrollBarContainer::LogicalLeft); -
895 if (alignment & Qt::AlignBottom) -
896 list += d->scrollBarContainers[Qt::Vertical]->widgets(QAbstractScrollAreaScrollBarContainer::LogicalRight); -
897 -
898 return list; -
899} -
900 -
901/*! -
902 Sets the margins around the scrolling area to \a left, \a top, \a -
903 right and \a bottom. This is useful for applications such as -
904 spreadsheets with "locked" rows and columns. The marginal space is -
905 is left blank; put widgets in the unused area. -
906 -
907 Note that this function is frequently called by QTreeView and -
908 QTableView, so margins must be implemented by QAbstractScrollArea -
909 subclasses. Also, if the subclasses are to be used in item views, -
910 they should not call this function. -
911 -
912 By default all margins are zero. -
913 -
914*/ -
915void QAbstractScrollArea::setViewportMargins(int left, int top, int right, int bottom) -
916{ -
917 Q_D(QAbstractScrollArea); -
918 d->left = left; -
919 d->top = top; -
920 d->right = right; -
921 d->bottom = bottom; -
922 d->layoutChildren(); -
923} -
924 -
925/*! -
926 \since 4.6 -
927 Sets \a margins around the scrolling area. This is useful for -
928 applications such as spreadsheets with "locked" rows and columns. -
929 The marginal space is is left blank; put widgets in the unused -
930 area. -
931 -
932 By default all margins are zero. -
933 -
934*/ -
935void QAbstractScrollArea::setViewportMargins(const QMargins &margins) -
936{ -
937 setViewportMargins(margins.left(), margins.top(), -
938 margins.right(), margins.bottom()); -
939} -
940 -
941/*! \internal */ -
942bool QAbstractScrollArea::eventFilter(QObject *o, QEvent *e) -
943{ -
944 Q_D(QAbstractScrollArea); -
945 if ((o == d->hbar || o == d->vbar) && (e->type() == QEvent::HoverEnter || e->type() == QEvent::HoverLeave)) { -
946 Qt::ScrollBarPolicy policy = o == d->hbar ? d->vbarpolicy : d->hbarpolicy; -
947 if (policy == Qt::ScrollBarAsNeeded || style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, d->vbar ? d->vbar : d->hbar)) { -
948 QScrollBar *sibling = o == d->hbar ? d->vbar : d->hbar; -
949 d->setScrollBarTransient(sibling, e->type() == QEvent::HoverLeave); -
950 } -
951 } -
952 return QFrame::eventFilter(o, e); -
953} -
954 -
955/*! -
956 \fn bool QAbstractScrollArea::event(QEvent *event) -
957 -
958 \reimp -
959 -
960 This is the main event handler for the QAbstractScrollArea widget (\e not -
961 the scrolling area viewport()). The specified \a event is a general event -
962 object that may need to be cast to the appropriate class depending on its -
963 type. -
964 -
965 \sa QEvent::type() -
966*/ -
967bool QAbstractScrollArea::event(QEvent *e) -
968{ -
969 Q_D(QAbstractScrollArea); -
970 switch (e->type()) { -
971 case QEvent::AcceptDropsChange: -
972 // There was a chance that with accessibility client we get an -
973 // event before the viewport was created. -
974 // Also, in some cases we might get here from QWidget::event() virtual function which is (indirectly) called -
975 // from the viewport constructor at the time when the d->viewport is not yet initialized even without any -
976 // accessibility client. See qabstractscrollarea autotest for a test case. -
977 if (d->viewport) -
978 d->viewport->setAcceptDrops(acceptDrops()); -
979 break; -
980 case QEvent::MouseTrackingChange: -
981 d->viewport->setMouseTracking(hasMouseTracking()); -
982 break; -
983 case QEvent::Resize: -
984 d->layoutChildren(); -
985 break; -
986 case QEvent::Paint: { -
987 QStyleOption option; -
988 option.initFrom(this); -
989 if (d->cornerPaintingRect.isValid()) { -
990 option.rect = d->cornerPaintingRect; -
991 QPainter p(this); -
992 style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, &option, &p, this); -
993 } -
994#ifdef Q_WS_MAC -
995 if (d->reverseCornerPaintingRect.isValid()) { -
996 option.rect = d->reverseCornerPaintingRect; -
997 QPainter p(this); -
998 style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, &option, &p, this); -
999 } -
1000#endif -
1001 } -
1002 QFrame::paintEvent((QPaintEvent*)e); -
1003 break; -
1004#ifndef QT_NO_CONTEXTMENU -
1005 case QEvent::ContextMenu: -
1006 if (static_cast<QContextMenuEvent *>(e)->reason() == QContextMenuEvent::Keyboard) -
1007 return QFrame::event(e); -
1008 e->ignore(); -
1009 break; -
1010#endif // QT_NO_CONTEXTMENU -
1011 case QEvent::MouseButtonPress: -
1012 case QEvent::MouseButtonRelease: -
1013 case QEvent::MouseButtonDblClick: -
1014 case QEvent::MouseMove: -
1015 case QEvent::Wheel: -
1016#ifndef QT_NO_DRAGANDDROP -
1017 case QEvent::Drop: -
1018 case QEvent::DragEnter: -
1019 case QEvent::DragMove: -
1020 case QEvent::DragLeave: -
1021#endif -
1022 // ignore touch events in case they have been propagated from the viewport -
1023 case QEvent::TouchBegin: -
1024 case QEvent::TouchUpdate: -
1025 case QEvent::TouchEnd: -
1026 return false; -
1027#ifndef QT_NO_GESTURES -
1028 case QEvent::Gesture: -
1029 { -
1030 QGestureEvent *ge = static_cast<QGestureEvent *>(e); -
1031 QPanGesture *g = static_cast<QPanGesture *>(ge->gesture(Qt::PanGesture)); -
1032 if (g) { -
1033 QScrollBar *hBar = horizontalScrollBar(); -
1034 QScrollBar *vBar = verticalScrollBar(); -
1035 QPointF delta = g->delta(); -
1036 if (!delta.isNull()) { -
1037 if (QApplication::isRightToLeft()) -
1038 delta.rx() *= -1; -
1039 int newX = hBar->value() - delta.x(); -
1040 int newY = vBar->value() - delta.y(); -
1041 hBar->setValue(newX); -
1042 vBar->setValue(newY); -
1043 } -
1044 return true; -
1045 } -
1046 return false; -
1047 } -
1048#endif // QT_NO_GESTURES -
1049 case QEvent::ScrollPrepare: -
1050 { -
1051 QScrollPrepareEvent *se = static_cast<QScrollPrepareEvent *>(e); -
1052 if (d->canStartScrollingAt(se->startPos().toPoint())) { -
1053 QScrollBar *hBar = horizontalScrollBar(); -
1054 QScrollBar *vBar = verticalScrollBar(); -
1055 -
1056 se->setViewportSize(QSizeF(viewport()->size())); -
1057 se->setContentPosRange(QRectF(0, 0, hBar->maximum(), vBar->maximum())); -
1058 se->setContentPos(QPointF(hBar->value(), vBar->value())); -
1059 se->accept(); -
1060 return true; -
1061 } -
1062 return false; -
1063 } -
1064 case QEvent::Scroll: -
1065 { -
1066 QScrollEvent *se = static_cast<QScrollEvent *>(e); -
1067 -
1068 QScrollBar *hBar = horizontalScrollBar(); -
1069 QScrollBar *vBar = verticalScrollBar(); -
1070 hBar->setValue(se->contentPos().x()); -
1071 vBar->setValue(se->contentPos().y()); -
1072 -
1073#ifdef Q_WS_WIN -
1074 typedef BOOL (*PtrBeginPanningFeedback)(HWND); -
1075 typedef BOOL (*PtrUpdatePanningFeedback)(HWND, LONG, LONG, BOOL); -
1076 typedef BOOL (*PtrEndPanningFeedback)(HWND, BOOL); -
1077 -
1078 static PtrBeginPanningFeedback ptrBeginPanningFeedback = 0; -
1079 static PtrUpdatePanningFeedback ptrUpdatePanningFeedback = 0; -
1080 static PtrEndPanningFeedback ptrEndPanningFeedback = 0; -
1081 -
1082 if (!ptrBeginPanningFeedback) -
1083 ptrBeginPanningFeedback = (PtrBeginPanningFeedback) QLibrary::resolve(QLatin1String("UxTheme"), "BeginPanningFeedback"); -
1084 if (!ptrUpdatePanningFeedback) -
1085 ptrUpdatePanningFeedback = (PtrUpdatePanningFeedback) QLibrary::resolve(QLatin1String("UxTheme"), "UpdatePanningFeedback"); -
1086 if (!ptrEndPanningFeedback) -
1087 ptrEndPanningFeedback = (PtrEndPanningFeedback) QLibrary::resolve(QLatin1String("UxTheme"), "EndPanningFeedback"); -
1088 -
1089 if (ptrBeginPanningFeedback && ptrUpdatePanningFeedback && ptrEndPanningFeedback) { -
1090 WId wid = window()->winId(); -
1091 -
1092 if (!se->overshootDistance().isNull() && d->overshoot.isNull()) -
1093 ptrBeginPanningFeedback(wid); -
1094 if (!se->overshootDistance().isNull()) -
1095 ptrUpdatePanningFeedback(wid, -se->overshootDistance().x(), -se->overshootDistance().y(), false); -
1096 if (se->overshootDistance().isNull() && !d->overshoot.isNull()) -
1097 ptrEndPanningFeedback(wid, true); -
1098 } else -
1099#endif -
1100 { -
1101 QPoint delta = d->overshoot - se->overshootDistance().toPoint(); -
1102 if (!delta.isNull()) -
1103 viewport()->move(viewport()->pos() + delta); -
1104 } -
1105 d->overshoot = se->overshootDistance().toPoint(); -
1106 -
1107 return true; -
1108 } -
1109 case QEvent::StyleChange: -
1110 case QEvent::LayoutDirectionChange: -
1111 case QEvent::ApplicationLayoutDirectionChange: -
1112 case QEvent::LayoutRequest: -
1113 d->layoutChildren(); -
1114 // fall through -
1115 default: -
1116 return QFrame::event(e); -
1117 } -
1118 return true; -
1119} -
1120 -
1121/*! -
1122 \fn bool QAbstractScrollArea::viewportEvent(QEvent *event) -
1123 -
1124 The main event handler for the scrolling area (the viewport() widget). -
1125 It handles the \a event specified, and can be called by subclasses to -
1126 provide reasonable default behavior. -
1127 -
1128 Returns true to indicate to the event system that the event has been -
1129 handled, and needs no further processing; otherwise returns false to -
1130 indicate that the event should be propagated further. -
1131 -
1132 You can reimplement this function in a subclass, but we recommend -
1133 using one of the specialized event handlers instead. -
1134 -
1135 Specialized handlers for viewport events are: paintEvent(), -
1136 mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), -
1137 mouseMoveEvent(), wheelEvent(), dragEnterEvent(), dragMoveEvent(), -
1138 dragLeaveEvent(), dropEvent(), contextMenuEvent(), and -
1139 resizeEvent(). -
1140*/ -
1141bool QAbstractScrollArea::viewportEvent(QEvent *e) -
1142{ -
1143 switch (e->type()) { -
1144 case QEvent::Resize: -
1145 case QEvent::Paint: -
1146 case QEvent::MouseButtonPress: -
1147 case QEvent::MouseButtonRelease: -
1148 case QEvent::MouseButtonDblClick: -
1149 case QEvent::TouchBegin: -
1150 case QEvent::TouchUpdate: -
1151 case QEvent::TouchEnd: -
1152 case QEvent::MouseMove: -
1153 case QEvent::ContextMenu: -
1154#ifndef QT_NO_WHEELEVENT -
1155 case QEvent::Wheel: -
1156#endif -
1157#ifndef QT_NO_DRAGANDDROP -
1158 case QEvent::Drop: -
1159 case QEvent::DragEnter: -
1160 case QEvent::DragMove: -
1161 case QEvent::DragLeave: -
1162#endif -
1163 return QFrame::event(e); -
1164 case QEvent::LayoutRequest: -
1165#ifndef QT_NO_GESTURES -
1166 case QEvent::Gesture: -
1167 case QEvent::GestureOverride: -
1168 return event(e); -
1169#endif -
1170 case QEvent::ScrollPrepare: -
1171 case QEvent::Scroll: -
1172 return event(e); -
1173 default: -
1174 break; -
1175 } -
1176 return false; // let the viewport widget handle the event -
1177} -
1178 -
1179/*! -
1180 \fn void QAbstractScrollArea::resizeEvent(QResizeEvent *event) -
1181 -
1182 This event handler can be reimplemented in a subclass to receive -
1183 resize events (passed in \a event), for the viewport() widget. -
1184 -
1185 When resizeEvent() is called, the viewport already has its new -
1186 geometry: Its new size is accessible through the -
1187 QResizeEvent::size() function, and the old size through -
1188 QResizeEvent::oldSize(). -
1189 -
1190 \sa QWidget::resizeEvent() -
1191 */ -
1192void QAbstractScrollArea::resizeEvent(QResizeEvent *) -
1193{ -
1194} -
1195 -
1196/*! -
1197 \fn void QAbstractScrollArea::paintEvent(QPaintEvent *event) -
1198 -
1199 This event handler can be reimplemented in a subclass to receive -
1200 paint events (passed in \a event), for the viewport() widget. -
1201 -
1202 \note If you open a painter, make sure to open it on the viewport(). -
1203 -
1204 \sa QWidget::paintEvent() -
1205*/ -
1206void QAbstractScrollArea::paintEvent(QPaintEvent*) -
1207{ -
1208} -
1209 -
1210/*! -
1211 This event handler can be reimplemented in a subclass to receive -
1212 mouse press events for the viewport() widget. The event is passed -
1213 in \a e. -
1214 -
1215 \sa QWidget::mousePressEvent() -
1216*/ -
1217void QAbstractScrollArea::mousePressEvent(QMouseEvent *e) -
1218{ -
1219 e->ignore(); -
1220} -
1221 -
1222/*! -
1223 This event handler can be reimplemented in a subclass to receive -
1224 mouse release events for the viewport() widget. The event is -
1225 passed in \a e. -
1226 -
1227 \sa QWidget::mouseReleaseEvent() -
1228*/ -
1229void QAbstractScrollArea::mouseReleaseEvent(QMouseEvent *e) -
1230{ -
1231 e->ignore(); -
1232} -
1233 -
1234/*! -
1235 This event handler can be reimplemented in a subclass to receive -
1236 mouse double click events for the viewport() widget. The event is -
1237 passed in \a e. -
1238 -
1239 \sa QWidget::mouseDoubleClickEvent() -
1240*/ -
1241void QAbstractScrollArea::mouseDoubleClickEvent(QMouseEvent *e) -
1242{ -
1243 e->ignore(); -
1244} -
1245 -
1246/*! -
1247 This event handler can be reimplemented in a subclass to receive -
1248 mouse move events for the viewport() widget. The event is passed -
1249 in \a e. -
1250 -
1251 \sa QWidget::mouseMoveEvent() -
1252*/ -
1253void QAbstractScrollArea::mouseMoveEvent(QMouseEvent *e) -
1254{ -
1255 e->ignore(); -
1256} -
1257 -
1258/*! -
1259 This event handler can be reimplemented in a subclass to receive -
1260 wheel events for the viewport() widget. The event is passed in \a -
1261 e. -
1262 -
1263 \sa QWidget::wheelEvent() -
1264*/ -
1265#ifndef QT_NO_WHEELEVENT -
1266void QAbstractScrollArea::wheelEvent(QWheelEvent *e) -
1267{ -
1268 Q_D(QAbstractScrollArea); -
1269 if (static_cast<QWheelEvent*>(e)->orientation() == Qt::Horizontal) -
1270 QApplication::sendEvent(d->hbar, e); -
1271 else -
1272 QApplication::sendEvent(d->vbar, e); -
1273} -
1274#endif -
1275 -
1276#ifndef QT_NO_CONTEXTMENU -
1277/*! -
1278 This event handler can be reimplemented in a subclass to receive -
1279 context menu events for the viewport() widget. The event is passed -
1280 in \a e. -
1281 -
1282 \sa QWidget::contextMenuEvent() -
1283*/ -
1284void QAbstractScrollArea::contextMenuEvent(QContextMenuEvent *e) -
1285{ -
1286 e->ignore(); -
1287} -
1288#endif // QT_NO_CONTEXTMENU -
1289 -
1290/*! -
1291 This function is called with key event \a e when key presses -
1292 occur. It handles PageUp, PageDown, Up, Down, Left, and Right, and -
1293 ignores all other key presses. -
1294*/ -
1295void QAbstractScrollArea::keyPressEvent(QKeyEvent * e) -
1296{ -
1297 Q_D(QAbstractScrollArea); -
1298 if (false){ -
1299#ifndef QT_NO_SHORTCUT -
1300 } else if (e == QKeySequence::MoveToPreviousPage) { -
1301 d->vbar->triggerAction(QScrollBar::SliderPageStepSub); -
1302 } else if (e == QKeySequence::MoveToNextPage) { -
1303 d->vbar->triggerAction(QScrollBar::SliderPageStepAdd); -
1304#endif -
1305 } else { -
1306#ifdef QT_KEYPAD_NAVIGATION -
1307 if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { -
1308 e->ignore(); -
1309 return; -
1310 } -
1311#endif -
1312 switch (e->key()) { -
1313 case Qt::Key_Up: -
1314 d->vbar->triggerAction(QScrollBar::SliderSingleStepSub); -
1315 break; -
1316 case Qt::Key_Down: -
1317 d->vbar->triggerAction(QScrollBar::SliderSingleStepAdd); -
1318 break; -
1319 case Qt::Key_Left: -
1320#ifdef QT_KEYPAD_NAVIGATION -
1321 if (QApplication::keypadNavigationEnabled() && hasEditFocus() -
1322 && (!d->hbar->isVisible() || d->hbar->value() == d->hbar->minimum())) { -
1323 //if we aren't using the hbar or we are already at the leftmost point ignore -
1324 e->ignore(); -
1325 return; -
1326 } -
1327#endif -
1328 d->hbar->triggerAction( -
1329 layoutDirection() == Qt::LeftToRight -
1330 ? QScrollBar::SliderSingleStepSub : QScrollBar::SliderSingleStepAdd); -
1331 break; -
1332 case Qt::Key_Right: -
1333#ifdef QT_KEYPAD_NAVIGATION -
1334 if (QApplication::keypadNavigationEnabled() && hasEditFocus() -
1335 && (!d->hbar->isVisible() || d->hbar->value() == d->hbar->maximum())) { -
1336 //if we aren't using the hbar or we are already at the rightmost point ignore -
1337 e->ignore(); -
1338 return; -
1339 } -
1340#endif -
1341 d->hbar->triggerAction( -
1342 layoutDirection() == Qt::LeftToRight -
1343 ? QScrollBar::SliderSingleStepAdd : QScrollBar::SliderSingleStepSub); -
1344 break; -
1345 default: -
1346 e->ignore(); -
1347 return; -
1348 } -
1349 } -
1350 e->accept(); -
1351} -
1352 -
1353 -
1354#ifndef QT_NO_DRAGANDDROP -
1355/*! -
1356 \fn void QAbstractScrollArea::dragEnterEvent(QDragEnterEvent *event) -
1357 -
1358 This event handler can be reimplemented in a subclass to receive -
1359 drag enter events (passed in \a event), for the viewport() widget. -
1360 -
1361 \sa QWidget::dragEnterEvent() -
1362*/ -
1363void QAbstractScrollArea::dragEnterEvent(QDragEnterEvent *) -
1364{ -
1365} -
1366 -
1367/*! -
1368 \fn void QAbstractScrollArea::dragMoveEvent(QDragMoveEvent *event) -
1369 -
1370 This event handler can be reimplemented in a subclass to receive -
1371 drag move events (passed in \a event), for the viewport() widget. -
1372 -
1373 \sa QWidget::dragMoveEvent() -
1374*/ -
1375void QAbstractScrollArea::dragMoveEvent(QDragMoveEvent *) -
1376{ -
1377} -
1378 -
1379/*! -
1380 \fn void QAbstractScrollArea::dragLeaveEvent(QDragLeaveEvent *event) -
1381 -
1382 This event handler can be reimplemented in a subclass to receive -
1383 drag leave events (passed in \a event), for the viewport() widget. -
1384 -
1385 \sa QWidget::dragLeaveEvent() -
1386*/ -
1387void QAbstractScrollArea::dragLeaveEvent(QDragLeaveEvent *) -
1388{ -
1389} -
1390 -
1391/*! -
1392 \fn void QAbstractScrollArea::dropEvent(QDropEvent *event) -
1393 -
1394 This event handler can be reimplemented in a subclass to receive -
1395 drop events (passed in \a event), for the viewport() widget. -
1396 -
1397 \sa QWidget::dropEvent() -
1398*/ -
1399void QAbstractScrollArea::dropEvent(QDropEvent *) -
1400{ -
1401} -
1402 -
1403 -
1404#endif -
1405 -
1406/*! -
1407 This virtual handler is called when the scroll bars are moved by -
1408 \a dx, \a dy, and consequently the viewport's contents should be -
1409 scrolled accordingly. -
1410 -
1411 The default implementation simply calls update() on the entire -
1412 viewport(), subclasses can reimplement this handler for -
1413 optimization purposes, or - like QScrollArea - to move a contents -
1414 widget. The parameters \a dx and \a dy are there for convenience, -
1415 so that the class knows how much should be scrolled (useful -
1416 e.g. when doing pixel-shifts). You may just as well ignore these -
1417 values and scroll directly to the position the scroll bars -
1418 indicate. -
1419 -
1420 Calling this function in order to scroll programmatically is an -
1421 error, use the scroll bars instead (e.g. by calling -
1422 QScrollBar::setValue() directly). -
1423*/ -
1424void QAbstractScrollArea::scrollContentsBy(int, int) -
1425{ -
1426 viewport()->update(); -
1427} -
1428 -
1429bool QAbstractScrollAreaPrivate::canStartScrollingAt( const QPoint &startPos ) -
1430{ -
1431 Q_Q(QAbstractScrollArea); -
1432 -
1433#ifndef QT_NO_GRAPHICSVIEW -
1434 // don't start scrolling when a drag mode has been set. -
1435 // don't start scrolling on a movable item. -
1436 if (QGraphicsView *view = qobject_cast<QGraphicsView *>(q)) { -
1437 if (view->dragMode() != QGraphicsView::NoDrag) -
1438 return false; -
1439 -
1440 QGraphicsItem *childItem = view->itemAt(startPos); -
1441 -
1442 if (childItem && (childItem->flags() & QGraphicsItem::ItemIsMovable)) -
1443 return false; -
1444 } -
1445#endif -
1446 -
1447 // don't start scrolling on a QAbstractSlider -
1448 if (qobject_cast<QAbstractSlider *>(q->viewport()->childAt(startPos))) { -
1449 return false; -
1450 } -
1451 -
1452 return true; -
1453} -
1454 -
1455void QAbstractScrollAreaPrivate::flashScrollBars() -
1456{ -
1457 Q_Q(QAbstractScrollArea);
executed (the execution status of this line is deduced): QAbstractScrollArea * const q = q_func();
-
1458 bool transient = q->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, vbar ? vbar : hbar);
executed (the execution status of this line is deduced): bool transient = q->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, vbar ? vbar : hbar);
-
1459 if ((hbarpolicy != Qt::ScrollBarAlwaysOff) && (hbarpolicy == Qt::ScrollBarAsNeeded || transient)))
evaluated: (hbarpolicy != Qt::ScrollBarAlwaysOff)
TRUEFALSE
yes
Evaluation Count:9080
yes
Evaluation Count:122
evaluated: hbarpolicy == Qt::ScrollBarAsNeeded
TRUEFALSE
yes
Evaluation Count:9012
yes
Evaluation Count:68
partially evaluated: transient
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:68
0-9080
1460 hbar->d_func()->flash();
executed: hbar->d_func()->flash();
Execution Count:9012
9012
1461 if ((vbarpolicy != Qt::ScrollBarAlwaysOff) && (vbarpolicy == Qt::ScrollBarAsNeeded || transient)))
evaluated: (vbarpolicy != Qt::ScrollBarAlwaysOff)
TRUEFALSE
yes
Evaluation Count:9142
yes
Evaluation Count:60
evaluated: vbarpolicy == Qt::ScrollBarAsNeeded
TRUEFALSE
yes
Evaluation Count:9014
yes
Evaluation Count:128
partially evaluated: transient
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:128
0-9142
1462 vbar->d_func()->flash();
executed: vbar->d_func()->flash();
Execution Count:9014
9014
1463}
executed: }
Execution Count:9202
9202
1464 -
1465void QAbstractScrollAreaPrivate::setScrollBarTransient(QScrollBar *scrollBar, bool transient) -
1466{ -
1467 scrollBar->d_func()->setTransient(transient); -
1468} -
1469 -
1470void QAbstractScrollAreaPrivate::_q_hslide(int x) -
1471{ -
1472 Q_Q(QAbstractScrollArea); -
1473 int dx = xoffset - x; -
1474 xoffset = x; -
1475 q->scrollContentsBy(dx, 0); -
1476 flashScrollBars(); -
1477} -
1478 -
1479void QAbstractScrollAreaPrivate::_q_vslide(int y) -
1480{ -
1481 Q_Q(QAbstractScrollArea); -
1482 int dy = yoffset - y; -
1483 yoffset = y; -
1484 q->scrollContentsBy(0, dy); -
1485 flashScrollBars(); -
1486} -
1487 -
1488void QAbstractScrollAreaPrivate::_q_showOrHideScrollBars() -
1489{ -
1490 layoutChildren(); -
1491#ifdef Q_WS_WIN -
1492 // Need to re-subscribe to gestures as the content changes to make sure we -
1493 // enable/disable panning when needed. -
1494 QWidgetPrivate *dd = static_cast<QWidgetPrivate *>(QObjectPrivate::get(viewport)); -
1495 if (dd) -
1496 dd->winSetupGestures(); -
1497#endif // Q_WS_WIN -
1498} -
1499 -
1500QPoint QAbstractScrollAreaPrivate::contentsOffset() const -
1501{ -
1502 Q_Q(const QAbstractScrollArea); -
1503 QPoint offset; -
1504 if (vbar->isVisible()) -
1505 offset.setY(vbar->value()); -
1506 if (hbar->isVisible()) { -
1507 if (q->isRightToLeft()) -
1508 offset.setX(hbar->maximum() - hbar->value()); -
1509 else -
1510 offset.setX(hbar->value()); -
1511 } -
1512 return offset; -
1513} -
1514 -
1515/*! -
1516 \reimp -
1517 -
1518*/ -
1519QSize QAbstractScrollArea::minimumSizeHint() const -
1520{ -
1521 Q_D(const QAbstractScrollArea); -
1522 int hsbExt = d->hbar->sizeHint().height(); -
1523 int vsbExt = d->vbar->sizeHint().width(); -
1524 int extra = 2 * d->frameWidth; -
1525 QStyleOption opt; -
1526 opt.initFrom(this); -
1527 if ((d->frameStyle != QFrame::NoFrame) -
1528 && style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, &opt, this)) { -
1529 extra += style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarSpacing, &opt, this); -
1530 } -
1531 return QSize(d->scrollBarContainers[Qt::Horizontal]->sizeHint().width() + vsbExt + extra, -
1532 d->scrollBarContainers[Qt::Vertical]->sizeHint().height() + hsbExt + extra); -
1533} -
1534 -
1535/*! -
1536 \reimp -
1537*/ -
1538QSize QAbstractScrollArea::sizeHint() const -
1539{ -
1540 return QSize(256, 192); -
1541#if 0 -
1542 Q_D(const QAbstractScrollArea); -
1543 int h = qMax(10, fontMetrics().height()); -
1544 int f = 2 * d->frameWidth; -
1545 return QSize((6 * h) + f, (4 * h) + f); -
1546#endif -
1547} -
1548 -
1549/*! -
1550 This slot is called by QAbstractScrollArea after setViewport(\a -
1551 viewport) has been called. Reimplement this function in a -
1552 subclass of QAbstractScrollArea to initialize the new \a viewport -
1553 before it is used. -
1554 -
1555 \sa setViewport() -
1556*/ -
1557void QAbstractScrollArea::setupViewport(QWidget *viewport) -
1558{ -
1559 Q_UNUSED(viewport); -
1560} -
1561 -
1562/*! -
1563 \internal -
1564 -
1565 This method is reserved for future use. -
1566*/ -
1567QSize QAbstractScrollArea::viewportSizeHint() const -
1568{ -
1569 return QSize(); -
1570} -
1571 -
1572QT_END_NAMESPACE -
1573 -
1574#include "moc_qabstractscrollarea.cpp" -
1575#include "moc_qabstractscrollarea_p.cpp" -
1576 -
1577#endif // QT_NO_SCROLLAREA -
1578 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial