widgets/qscrollarea.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
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 "qscrollarea.h" -
43#include "private/qscrollarea_p.h" -
44 -
45#ifndef QT_NO_SCROLLAREA -
46 -
47#include "qscrollbar.h" -
48#include "qlayout.h" -
49#include "qstyle.h" -
50#include "qapplication.h" -
51#include "qvariant.h" -
52#include "qdebug.h" -
53#include "private/qlayoutengine_p.h" -
54 -
55QT_BEGIN_NAMESPACE -
56 -
57/*! -
58 \class QScrollArea -
59 -
60 \brief The QScrollArea class provides a scrolling view onto -
61 another widget. -
62 -
63 \ingroup basicwidgets -
64 \inmodule QtWidgets -
65 -
66 A scroll area is used to display the contents of a child widget -
67 within a frame. If the widget exceeds the size of the frame, the -
68 view can provide scroll bars so that the entire area of the child -
69 widget can be viewed. The child widget must be specified with -
70 setWidget(). For example: -
71 -
72 \snippet code/src_gui_widgets_qscrollarea.cpp 0 -
73 -
74 The code above creates a scroll area (shown in the images below) -
75 containing an image label. When scaling the image, the scroll area -
76 can provide the necessary scroll bars: -
77 -
78 \table -
79 \row -
80 \li \inlineimage qscrollarea-noscrollbars.png -
81 \li \inlineimage qscrollarea-onescrollbar.png -
82 \li \inlineimage qscrollarea-twoscrollbars.png -
83 \endtable -
84 -
85 The scroll bars appearance depends on the currently set \l -
86 {Qt::ScrollBarPolicy}{scroll bar policies}. You can control the -
87 appearance of the scroll bars using the inherited functionality -
88 from QAbstractScrollArea. -
89 -
90 For example, you can set the -
91 QAbstractScrollArea::horizontalScrollBarPolicy and -
92 QAbstractScrollArea::verticalScrollBarPolicy properties. Or if you -
93 want the scroll bars to adjust dynamically when the contents of -
94 the scroll area changes, you can use the \l -
95 {QAbstractScrollArea::horizontalScrollBar()}{horizontalScrollBar()} -
96 and \l -
97 {QAbstractScrollArea::verticalScrollBar()}{verticalScrollBar()} -
98 functions (which enable you to access the scroll bars) and set the -
99 scroll bars' values whenever the scroll area's contents change, -
100 using the QScrollBar::setValue() function. -
101 -
102 You can retrieve the child widget using the widget() function. The -
103 view can be made to be resizable with the setWidgetResizable() -
104 function. The alignment of the widget can be specified with -
105 setAlignment(). -
106 -
107 Two convenience functions ensureVisible() and -
108 ensureWidgetVisible() ensure a certain region of the contents is -
109 visible inside the viewport, by scrolling the contents if -
110 necessary. -
111 -
112 \section1 Size Hints and Layouts -
113 -
114 When using a scroll area to display the contents of a custom -
115 widget, it is important to ensure that the -
116 \l{QWidget::sizeHint}{size hint} of the child widget is set to a -
117 suitable value. If a standard QWidget is used for the child -
118 widget, it may be necessary to call QWidget::setMinimumSize() to -
119 ensure that the contents of the widget are shown correctly within -
120 the scroll area. -
121 -
122 If a scroll area is used to display the contents of a widget that -
123 contains child widgets arranged in a layout, it is important to -
124 realize that the size policy of the layout will also determine the -
125 size of the widget. This is especially useful to know if you intend -
126 to dynamically change the contents of the layout. In such cases, -
127 setting the layout's \l{QLayout::sizeConstraint}{size constraint} -
128 property to one which provides constraints on the minimum and/or -
129 maximum size of the layout (e.g., QLayout::SetMinAndMaxSize) will -
130 cause the size of the scroll area to be updated whenever the -
131 contents of the layout changes. -
132 -
133 For a complete example using the QScrollArea class, see the \l -
134 {widgets/imageviewer}{Image Viewer} example. The example shows how -
135 to combine QLabel and QScrollArea to display an image. -
136 -
137 \sa QAbstractScrollArea, QScrollBar, {Image Viewer Example} -
138*/ -
139 -
140 -
141/*! -
142 Constructs an empty scroll area with the given \a parent. -
143 -
144 \sa setWidget() -
145*/ -
146QScrollArea::QScrollArea(QWidget *parent) -
147 : QAbstractScrollArea(*new QScrollAreaPrivate,parent) -
148{ -
149 Q_D(QScrollArea);
executed (the execution status of this line is deduced): QScrollAreaPrivate * const d = d_func();
-
150 d->viewport->setBackgroundRole(QPalette::NoRole);
executed (the execution status of this line is deduced): d->viewport->setBackgroundRole(QPalette::NoRole);
-
151 d->vbar->setSingleStep(20);
executed (the execution status of this line is deduced): d->vbar->setSingleStep(20);
-
152 d->hbar->setSingleStep(20);
executed (the execution status of this line is deduced): d->hbar->setSingleStep(20);
-
153 d->layoutChildren();
executed (the execution status of this line is deduced): d->layoutChildren();
-
154}
executed: }
Execution Count:39
39
155 -
156/*! -
157 \internal -
158*/ -
159QScrollArea::QScrollArea(QScrollAreaPrivate &dd, QWidget *parent) -
160 : QAbstractScrollArea(dd, parent) -
161{ -
162 Q_D(QScrollArea);
never executed (the execution status of this line is deduced): QScrollAreaPrivate * const d = d_func();
-
163 d->viewport->setBackgroundRole(QPalette::NoRole);
never executed (the execution status of this line is deduced): d->viewport->setBackgroundRole(QPalette::NoRole);
-
164 d->vbar->setSingleStep(20);
never executed (the execution status of this line is deduced): d->vbar->setSingleStep(20);
-
165 d->hbar->setSingleStep(20);
never executed (the execution status of this line is deduced): d->hbar->setSingleStep(20);
-
166 d->layoutChildren();
never executed (the execution status of this line is deduced): d->layoutChildren();
-
167}
never executed: }
0
168 -
169/*! -
170 Destroys the scroll area and its child widget. -
171 -
172 \sa setWidget() -
173*/ -
174QScrollArea::~QScrollArea() -
175{ -
176} -
177 -
178void QScrollAreaPrivate::updateWidgetPosition() -
179{ -
180 Q_Q(QScrollArea);
executed (the execution status of this line is deduced): QScrollArea * const q = q_func();
-
181 Qt::LayoutDirection dir = q->layoutDirection();
executed (the execution status of this line is deduced): Qt::LayoutDirection dir = q->layoutDirection();
-
182 QRect scrolled = QStyle::visualRect(dir, viewport->rect(), QRect(QPoint(-hbar->value(), -vbar->value()), widget->size()));
executed (the execution status of this line is deduced): QRect scrolled = QStyle::visualRect(dir, viewport->rect(), QRect(QPoint(-hbar->value(), -vbar->value()), widget->size()));
-
183 QRect aligned = QStyle::alignedRect(dir, alignment, widget->size(), viewport->rect());
executed (the execution status of this line is deduced): QRect aligned = QStyle::alignedRect(dir, alignment, widget->size(), viewport->rect());
-
184 widget->move(widget->width() < viewport->width() ? aligned.x() : scrolled.x(),
executed (the execution status of this line is deduced): widget->move(widget->width() < viewport->width() ? aligned.x() : scrolled.x(),
-
185 widget->height() < viewport->height() ? aligned.y() : scrolled.y());
executed (the execution status of this line is deduced): widget->height() < viewport->height() ? aligned.y() : scrolled.y());
-
186}
executed: }
Execution Count:90
90
187 -
188void QScrollAreaPrivate::updateScrollBars() -
189{ -
190 Q_Q(QScrollArea);
executed (the execution status of this line is deduced): QScrollArea * const q = q_func();
-
191 if (!widget)
evaluated: !widget
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:78
15-78
192 return;
executed: return;
Execution Count:15
15
193 QSize p = viewport->size();
executed (the execution status of this line is deduced): QSize p = viewport->size();
-
194 QSize m = q->maximumViewportSize();
executed (the execution status of this line is deduced): QSize m = q->maximumViewportSize();
-
195 -
196 QSize min = qSmartMinSize(widget);
executed (the execution status of this line is deduced): QSize min = qSmartMinSize(widget);
-
197 QSize max = qSmartMaxSize(widget);
executed (the execution status of this line is deduced): QSize max = qSmartMaxSize(widget);
-
198 -
199 if (resizable) {
evaluated: resizable
TRUEFALSE
yes
Evaluation Count:27
yes
Evaluation Count:51
27-51
200 if ((widget->layout() ? widget->layout()->hasHeightForWidth() : widget->sizePolicy().hasHeightForWidth())) {
partially evaluated: widget->layout()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:27
0-27
201 QSize p_hfw = p.expandedTo(min).boundedTo(max);
executed (the execution status of this line is deduced): QSize p_hfw = p.expandedTo(min).boundedTo(max);
-
202 int h = widget->heightForWidth( p_hfw.width() );
executed (the execution status of this line is deduced): int h = widget->heightForWidth( p_hfw.width() );
-
203 min = QSize(p_hfw.width(), qMax(p_hfw.height(), h));
executed (the execution status of this line is deduced): min = QSize(p_hfw.width(), qMax(p_hfw.height(), h));
-
204 }
executed: }
Execution Count:4
4
205 }
executed: }
Execution Count:27
27
206 -
207 if ((resizable && m.expandedTo(min) == m && m.boundedTo(max) == m)
evaluated: resizable
TRUEFALSE
yes
Evaluation Count:27
yes
Evaluation Count:51
evaluated: m.expandedTo(min) == m
TRUEFALSE
yes
Evaluation Count:25
yes
Evaluation Count:2
partially evaluated: m.boundedTo(max) == m
TRUEFALSE
yes
Evaluation Count:25
no
Evaluation Count:0
0-51
208 || (!resizable && m.expandedTo(widget->size()) == m))
evaluated: !resizable
TRUEFALSE
yes
Evaluation Count:51
yes
Evaluation Count:2
evaluated: m.expandedTo(widget->size()) == m
TRUEFALSE
yes
Evaluation Count:25
yes
Evaluation Count:26
2-51
209 p = m; // no scroll bars needed
executed: p = m;
Execution Count:50
50
210 -
211 if (resizable)
evaluated: resizable
TRUEFALSE
yes
Evaluation Count:27
yes
Evaluation Count:51
27-51
212 widget->resize(p.expandedTo(min).boundedTo(max));
executed: widget->resize(p.expandedTo(min).boundedTo(max));
Execution Count:27
27
213 QSize v = widget->size();
executed (the execution status of this line is deduced): QSize v = widget->size();
-
214 -
215 hbar->setRange(0, v.width() - p.width());
executed (the execution status of this line is deduced): hbar->setRange(0, v.width() - p.width());
-
216 hbar->setPageStep(p.width());
executed (the execution status of this line is deduced): hbar->setPageStep(p.width());
-
217 vbar->setRange(0, v.height() - p.height());
executed (the execution status of this line is deduced): vbar->setRange(0, v.height() - p.height());
-
218 vbar->setPageStep(p.height());
executed (the execution status of this line is deduced): vbar->setPageStep(p.height());
-
219 updateWidgetPosition();
executed (the execution status of this line is deduced): updateWidgetPosition();
-
220 -
221}
executed: }
Execution Count:78
78
222 -
223/*! -
224 Returns the scroll area's widget, or 0 if there is none. -
225 -
226 \sa setWidget() -
227*/ -
228 -
229QWidget *QScrollArea::widget() const -
230{ -
231 Q_D(const QScrollArea);
executed (the execution status of this line is deduced): const QScrollAreaPrivate * const d = d_func();
-
232 return d->widget;
executed: return d->widget;
Execution Count:2
2
233} -
234 -
235/*! -
236 \fn void QScrollArea::setWidget(QWidget *widget) -
237 -
238 Sets the scroll area's \a widget. -
239 -
240 The \a widget becomes a child of the scroll area, and will be -
241 destroyed when the scroll area is deleted or when a new widget is -
242 set. -
243 -
244 The widget's \l{QWidget::setAutoFillBackground()}{autoFillBackground} -
245 property will be set to \c{true}. -
246 -
247 If the scroll area is visible when the \a widget is -
248 added, you must \l{QWidget::}{show()} it explicitly. -
249 -
250 Note that You must add the layout of \a widget before you call -
251 this function; if you add it later, the \a widget will not be -
252 visible - regardless of when you \l{QWidget::}{show()} the scroll -
253 area. In this case, you can also not \l{QWidget::}{show()} the \a -
254 widget later. -
255 -
256 \sa widget() -
257*/ -
258void QScrollArea::setWidget(QWidget *widget) -
259{ -
260 Q_D(QScrollArea);
executed (the execution status of this line is deduced): QScrollAreaPrivate * const d = d_func();
-
261 if (widget == d->widget || !widget)
partially evaluated: widget == d->widget
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:32
evaluated: !widget
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:31
0-32
262 return;
executed: return;
Execution Count:1
1
263 -
264 delete d->widget;
executed (the execution status of this line is deduced): delete d->widget;
-
265 d->widget = 0;
executed (the execution status of this line is deduced): d->widget = 0;
-
266 d->hbar->setValue(0);
executed (the execution status of this line is deduced): d->hbar->setValue(0);
-
267 d->vbar->setValue(0);
executed (the execution status of this line is deduced): d->vbar->setValue(0);
-
268 if (widget->parentWidget() != d->viewport)
partially evaluated: widget->parentWidget() != d->viewport
TRUEFALSE
yes
Evaluation Count:31
no
Evaluation Count:0
0-31
269 widget->setParent(d->viewport);
executed: widget->setParent(d->viewport);
Execution Count:31
31
270 if (!widget->testAttribute(Qt::WA_Resized))
evaluated: !widget->testAttribute(Qt::WA_Resized)
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:7
7-24
271 widget->resize(widget->sizeHint());
executed: widget->resize(widget->sizeHint());
Execution Count:24
24
272 d->widget = widget;
executed (the execution status of this line is deduced): d->widget = widget;
-
273 d->widget->setAutoFillBackground(true);
executed (the execution status of this line is deduced): d->widget->setAutoFillBackground(true);
-
274 widget->installEventFilter(this);
executed (the execution status of this line is deduced): widget->installEventFilter(this);
-
275 d->widgetSize = QSize();
executed (the execution status of this line is deduced): d->widgetSize = QSize();
-
276 d->updateScrollBars();
executed (the execution status of this line is deduced): d->updateScrollBars();
-
277 d->widget->show();
executed (the execution status of this line is deduced): d->widget->show();
-
278 -
279}
executed: }
Execution Count:31
31
280 -
281/*! -
282 Removes the scroll area's widget, and passes ownership of the -
283 widget to the caller. -
284 -
285 \sa widget() -
286 */ -
287QWidget *QScrollArea::takeWidget() -
288{ -
289 Q_D(QScrollArea);
never executed (the execution status of this line is deduced): QScrollAreaPrivate * const d = d_func();
-
290 QWidget *w = d->widget;
never executed (the execution status of this line is deduced): QWidget *w = d->widget;
-
291 d->widget = 0;
never executed (the execution status of this line is deduced): d->widget = 0;
-
292 if (w)
never evaluated: w
0
293 w->setParent(0);
never executed: w->setParent(0);
0
294 return w;
never executed: return w;
0
295} -
296 -
297/*! -
298 \reimp -
299 */ -
300bool QScrollArea::event(QEvent *e) -
301{ -
302 Q_D(QScrollArea);
executed (the execution status of this line is deduced): QScrollAreaPrivate * const d = d_func();
-
303 if (e->type() == QEvent::StyleChange || e->type() == QEvent::LayoutRequest) {
evaluated: e->type() == QEvent::StyleChange
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:358
evaluated: e->type() == QEvent::LayoutRequest
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:357
1-358
304 d->updateScrollBars();
executed (the execution status of this line is deduced): d->updateScrollBars();
-
305 }
executed: }
Execution Count:3
3
306#ifdef QT_KEYPAD_NAVIGATION -
307 else if (QApplication::keypadNavigationEnabled()) { -
308 if (e->type() == QEvent::Show) -
309 QApplication::instance()->installEventFilter(this); -
310 else if (e->type() == QEvent::Hide) -
311 QApplication::instance()->removeEventFilter(this); -
312 } -
313#endif -
314 return QAbstractScrollArea::event(e);
executed: return QAbstractScrollArea::event(e);
Execution Count:360
360
315} -
316 -
317 -
318/*! -
319 \reimp -
320 */ -
321bool QScrollArea::eventFilter(QObject *o, QEvent *e) -
322{ -
323 Q_D(QScrollArea);
executed (the execution status of this line is deduced): QScrollAreaPrivate * const d = d_func();
-
324#ifdef QT_KEYPAD_NAVIGATION -
325 if (d->widget && o != d->widget && e->type() == QEvent::FocusIn -
326 && QApplication::keypadNavigationEnabled()) { -
327 if (o->isWidgetType()) -
328 ensureWidgetVisible(static_cast<QWidget *>(o)); -
329 } -
330#endif -
331 if (o == d->widget && e->type() == QEvent::Resize)
evaluated: o == d->widget
TRUEFALSE
yes
Evaluation Count:121
yes
Evaluation Count:106
evaluated: e->type() == QEvent::Resize
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:111
10-121
332 d->updateScrollBars();
executed: d->updateScrollBars();
Execution Count:10
10
333 -
334 return QAbstractScrollArea::eventFilter(o, e);
executed: return QAbstractScrollArea::eventFilter(o, e);
Execution Count:227
227
335} -
336 -
337/*! -
338 \reimp -
339 */ -
340void QScrollArea::resizeEvent(QResizeEvent *) -
341{ -
342 Q_D(QScrollArea);
executed (the execution status of this line is deduced): QScrollAreaPrivate * const d = d_func();
-
343 d->updateScrollBars();
executed (the execution status of this line is deduced): d->updateScrollBars();
-
344 -
345}
executed: }
Execution Count:23
23
346 -
347 -
348/*!\reimp -
349 */ -
350void QScrollArea::scrollContentsBy(int, int) -
351{ -
352 Q_D(QScrollArea);
executed (the execution status of this line is deduced): QScrollAreaPrivate * const d = d_func();
-
353 if (!d->widget)
evaluated: !d->widget
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:12
2-12
354 return;
executed: return;
Execution Count:2
2
355 d->updateWidgetPosition();
executed (the execution status of this line is deduced): d->updateWidgetPosition();
-
356}
executed: }
Execution Count:12
12
357 -
358 -
359/*! -
360 \property QScrollArea::widgetResizable -
361 \brief whether the scroll area should resize the view widget -
362 -
363 If this property is set to false (the default), the scroll area -
364 honors the size of its widget. Regardless of this property, you -
365 can programmatically resize the widget using widget()->resize(), -
366 and the scroll area will automatically adjust itself to the new -
367 size. -
368 -
369 If this property is set to true, the scroll area will -
370 automatically resize the widget in order to avoid scroll bars -
371 where they can be avoided, or to take advantage of extra space. -
372*/ -
373bool QScrollArea::widgetResizable() const -
374{ -
375 Q_D(const QScrollArea);
executed (the execution status of this line is deduced): const QScrollAreaPrivate * const d = d_func();
-
376 return d->resizable;
executed: return d->resizable;
Execution Count:2
2
377} -
378 -
379void QScrollArea::setWidgetResizable(bool resizable) -
380{ -
381 Q_D(QScrollArea);
executed (the execution status of this line is deduced): QScrollAreaPrivate * const d = d_func();
-
382 d->resizable = resizable;
executed (the execution status of this line is deduced): d->resizable = resizable;
-
383 updateGeometry();
executed (the execution status of this line is deduced): updateGeometry();
-
384 d->updateScrollBars();
executed (the execution status of this line is deduced): d->updateScrollBars();
-
385}
executed: }
Execution Count:26
26
386 -
387/*! -
388 \reimp -
389 */ -
390QSize QScrollArea::sizeHint() const -
391{ -
392 Q_D(const QScrollArea);
executed (the execution status of this line is deduced): const QScrollAreaPrivate * const d = d_func();
-
393 int f = 2 * d->frameWidth;
executed (the execution status of this line is deduced): int f = 2 * d->frameWidth;
-
394 QSize sz(f, f);
executed (the execution status of this line is deduced): QSize sz(f, f);
-
395 int h = fontMetrics().height();
executed (the execution status of this line is deduced): int h = fontMetrics().height();
-
396 if (d->widget) {
partially evaluated: d->widget
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:40
0-40
397 if (!d->widgetSize.isValid())
never evaluated: !d->widgetSize.isValid()
0
398 d->widgetSize = d->resizable ? d->widget->sizeHint() : d->widget->size();
never executed: d->widgetSize = d->resizable ? d->widget->sizeHint() : d->widget->size();
never evaluated: d->resizable
0
399 sz += d->widgetSize;
never executed (the execution status of this line is deduced): sz += d->widgetSize;
-
400 } else {
never executed: }
0
401 sz += QSize(12 * h, 8 * h);
executed (the execution status of this line is deduced): sz += QSize(12 * h, 8 * h);
-
402 }
executed: }
Execution Count:40
40
403 if (d->vbarpolicy == Qt::ScrollBarAlwaysOn)
partially evaluated: d->vbarpolicy == Qt::ScrollBarAlwaysOn
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:40
0-40
404 sz.setWidth(sz.width() + d->vbar->sizeHint().width());
never executed: sz.setWidth(sz.width() + d->vbar->sizeHint().width());
0
405 if (d->hbarpolicy == Qt::ScrollBarAlwaysOn)
partially evaluated: d->hbarpolicy == Qt::ScrollBarAlwaysOn
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:40
0-40
406 sz.setHeight(sz.height() + d->hbar->sizeHint().height());
never executed: sz.setHeight(sz.height() + d->hbar->sizeHint().height());
0
407 return sz.boundedTo(QSize(36 * h, 24 * h));
executed: return sz.boundedTo(QSize(36 * h, 24 * h));
Execution Count:40
40
408} -
409 -
410 -
411 -
412/*! -
413 \reimp -
414 */ -
415bool QScrollArea::focusNextPrevChild(bool next) -
416{ -
417 if (QWidget::focusNextPrevChild(next)) {
never evaluated: QWidget::focusNextPrevChild(next)
0
418 if (QWidget *fw = focusWidget())
never evaluated: QWidget *fw = focusWidget()
0
419 ensureWidgetVisible(fw);
never executed: ensureWidgetVisible(fw);
0
420 return true;
never executed: return true;
0
421 } -
422 return false;
never executed: return false;
0
423} -
424 -
425/*! -
426 Scrolls the contents of the scroll area so that the point (\a x, \a y) is visible -
427 inside the region of the viewport with margins specified in pixels by \a xmargin and -
428 \a ymargin. If the specified point cannot be reached, the contents are scrolled to -
429 the nearest valid position. The default value for both margins is 50 pixels. -
430*/ -
431void QScrollArea::ensureVisible(int x, int y, int xmargin, int ymargin) -
432{ -
433 Q_D(QScrollArea);
never executed (the execution status of this line is deduced): QScrollAreaPrivate * const d = d_func();
-
434 -
435 int logicalX = QStyle::visualPos(layoutDirection(), d->viewport->rect(), QPoint(x, y)).x();
never executed (the execution status of this line is deduced): int logicalX = QStyle::visualPos(layoutDirection(), d->viewport->rect(), QPoint(x, y)).x();
-
436 -
437 if (logicalX - xmargin < d->hbar->value()) {
never evaluated: logicalX - xmargin < d->hbar->value()
0
438 d->hbar->setValue(qMax(0, logicalX - xmargin));
never executed (the execution status of this line is deduced): d->hbar->setValue(qMax(0, logicalX - xmargin));
-
439 } else if (logicalX > d->hbar->value() + d->viewport->width() - xmargin) {
never executed: }
never evaluated: logicalX > d->hbar->value() + d->viewport->width() - xmargin
0
440 d->hbar->setValue(qMin(logicalX - d->viewport->width() + xmargin, d->hbar->maximum()));
never executed (the execution status of this line is deduced): d->hbar->setValue(qMin(logicalX - d->viewport->width() + xmargin, d->hbar->maximum()));
-
441 }
never executed: }
0
442 -
443 if (y - ymargin < d->vbar->value()) {
never evaluated: y - ymargin < d->vbar->value()
0
444 d->vbar->setValue(qMax(0, y - ymargin));
never executed (the execution status of this line is deduced): d->vbar->setValue(qMax(0, y - ymargin));
-
445 } else if (y > d->vbar->value() + d->viewport->height() - ymargin) {
never executed: }
never evaluated: y > d->vbar->value() + d->viewport->height() - ymargin
0
446 d->vbar->setValue(qMin(y - d->viewport->height() + ymargin, d->vbar->maximum()));
never executed (the execution status of this line is deduced): d->vbar->setValue(qMin(y - d->viewport->height() + ymargin, d->vbar->maximum()));
-
447 }
never executed: }
0
448} -
449 -
450/*! -
451 \since 4.2 -
452 -
453 Scrolls the contents of the scroll area so that the \a childWidget -
454 of QScrollArea::widget() is visible inside the viewport with -
455 margins specified in pixels by \a xmargin and \a ymargin. If the -
456 specified point cannot be reached, the contents are scrolled to -
457 the nearest valid position. The default value for both margins is -
458 50 pixels. -
459 -
460*/ -
461void QScrollArea::ensureWidgetVisible(QWidget *childWidget, int xmargin, int ymargin) -
462{ -
463 Q_D(QScrollArea);
executed (the execution status of this line is deduced): QScrollAreaPrivate * const d = d_func();
-
464 -
465 if (!d->widget->isAncestorOf(childWidget))
partially evaluated: !d->widget->isAncestorOf(childWidget)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
466 return;
never executed: return;
0
467 -
468 const QRect microFocus = childWidget->inputMethodQuery(Qt::ImCursorRectangle).toRect();
executed (the execution status of this line is deduced): const QRect microFocus = childWidget->inputMethodQuery(Qt::ImCursorRectangle).toRect();
-
469 const QRect defaultMicroFocus =
executed (the execution status of this line is deduced): const QRect defaultMicroFocus =
-
470 childWidget->QWidget::inputMethodQuery(Qt::ImCursorRectangle).toRect();
executed (the execution status of this line is deduced): childWidget->QWidget::inputMethodQuery(Qt::ImCursorRectangle).toRect();
-
471 QRect focusRect = (microFocus != defaultMicroFocus)
partially evaluated: (microFocus != defaultMicroFocus)
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
472 ? QRect(childWidget->mapTo(d->widget, microFocus.topLeft()), microFocus.size())
executed (the execution status of this line is deduced): ? QRect(childWidget->mapTo(d->widget, microFocus.topLeft()), microFocus.size())
-
473 : QRect(childWidget->mapTo(d->widget, QPoint(0,0)), childWidget->size());
executed (the execution status of this line is deduced): : QRect(childWidget->mapTo(d->widget, QPoint(0,0)), childWidget->size());
-
474 const QRect visibleRect(-d->widget->pos(), d->viewport->size());
executed (the execution status of this line is deduced): const QRect visibleRect(-d->widget->pos(), d->viewport->size());
-
475 -
476 if (visibleRect.contains(focusRect))
partially evaluated: visibleRect.contains(focusRect)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
477 return;
never executed: return;
0
478 -
479 focusRect.adjust(-xmargin, -ymargin, xmargin, ymargin);
executed (the execution status of this line is deduced): focusRect.adjust(-xmargin, -ymargin, xmargin, ymargin);
-
480 -
481 if (focusRect.width() > visibleRect.width())
partially evaluated: focusRect.width() > visibleRect.width()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
482 d->hbar->setValue(focusRect.center().x() - d->viewport->width() / 2);
never executed: d->hbar->setValue(focusRect.center().x() - d->viewport->width() / 2);
0
483 else if (focusRect.right() > visibleRect.right())
partially evaluated: focusRect.right() > visibleRect.right()
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
484 d->hbar->setValue(focusRect.right() - d->viewport->width());
executed: d->hbar->setValue(focusRect.right() - d->viewport->width());
Execution Count:1
1
485 else if (focusRect.left() < visibleRect.left())
never evaluated: focusRect.left() < visibleRect.left()
0
486 d->hbar->setValue(focusRect.left());
never executed: d->hbar->setValue(focusRect.left());
0
487 -
488 if (focusRect.height() > visibleRect.height())
partially evaluated: focusRect.height() > visibleRect.height()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
489 d->vbar->setValue(focusRect.center().y() - d->viewport->height() / 2);
never executed: d->vbar->setValue(focusRect.center().y() - d->viewport->height() / 2);
0
490 else if (focusRect.bottom() > visibleRect.bottom())
partially evaluated: focusRect.bottom() > visibleRect.bottom()
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
491 d->vbar->setValue(focusRect.bottom() - d->viewport->height());
executed: d->vbar->setValue(focusRect.bottom() - d->viewport->height());
Execution Count:1
1
492 else if (focusRect.top() < visibleRect.top())
never evaluated: focusRect.top() < visibleRect.top()
0
493 d->vbar->setValue(focusRect.top());
never executed: d->vbar->setValue(focusRect.top());
0
494} -
495 -
496 -
497/*! -
498 \property QScrollArea::alignment -
499 \brief the alignment of the scroll area's widget -
500 \since 4.2 -
501 -
502 By default, the widget stays rooted to the top-left corner of the -
503 scroll area. -
504*/ -
505 -
506void QScrollArea::setAlignment(Qt::Alignment alignment) -
507{ -
508 Q_D(QScrollArea);
never executed (the execution status of this line is deduced): QScrollAreaPrivate * const d = d_func();
-
509 d->alignment = alignment;
never executed (the execution status of this line is deduced): d->alignment = alignment;
-
510 if (d->widget)
never evaluated: d->widget
0
511 d->updateWidgetPosition();
never executed: d->updateWidgetPosition();
0
512}
never executed: }
0
513 -
514Qt::Alignment QScrollArea::alignment() const -
515{ -
516 Q_D(const QScrollArea);
never executed (the execution status of this line is deduced): const QScrollAreaPrivate * const d = d_func();
-
517 return d->alignment;
never executed: return d->alignment;
0
518} -
519 -
520QT_END_NAMESPACE -
521 -
522#endif // QT_NO_SCROLLAREA -
523 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial