qscrollarea.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qscrollarea.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6QScrollArea::QScrollArea(QWidget *parent)-
7 : QAbstractScrollArea(*new QScrollAreaPrivate,parent)-
8{-
9 QScrollAreaPrivate * const d = d_func();-
10 d->viewport->setBackgroundRole(QPalette::NoRole);-
11 d->vbar->setSingleStep(20);-
12 d->hbar->setSingleStep(20);-
13 d->layoutChildren();-
14}
never executed: end of block
0
15-
16-
17-
18-
19QScrollArea::QScrollArea(QScrollAreaPrivate &dd, QWidget *parent)-
20 : QAbstractScrollArea(dd, parent)-
21{-
22 QScrollAreaPrivate * const d = d_func();-
23 d->viewport->setBackgroundRole(QPalette::NoRole);-
24 d->vbar->setSingleStep(20);-
25 d->hbar->setSingleStep(20);-
26 d->layoutChildren();-
27}
never executed: end of block
0
28-
29-
30-
31-
32-
33-
34QScrollArea::~QScrollArea()-
35{-
36}-
37-
38void QScrollAreaPrivate::updateWidgetPosition()-
39{-
40 QScrollArea * const q = q_func();-
41 Qt::LayoutDirection dir = q->layoutDirection();-
42 QRect scrolled = QStyle::visualRect(dir, viewport->rect(), QRect(QPoint(-hbar->value(), -vbar->value()), widget->size()));-
43 QRect aligned = QStyle::alignedRect(dir, alignment, widget->size(), viewport->rect());-
44 widget->move(widget->width() < viewport->width() ? aligned.x() : scrolled.x(),-
45 widget->height() < viewport->height() ? aligned.y() : scrolled.y());-
46}
never executed: end of block
0
47-
48void QScrollAreaPrivate::updateScrollBars()-
49{-
50 QScrollArea * const q = q_func();-
51 if (!widget
!widgetDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
52 return;
never executed: return;
0
53 QSize p = viewport->size();-
54 QSize m = q->maximumViewportSize();-
55-
56 QSize min = qSmartMinSize(widget);-
57 QSize max = qSmartMaxSize(widget);-
58-
59 if (resizable
resizableDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
60 if ((
(widget->layou...ghtForWidth())Description
TRUEnever evaluated
FALSEnever evaluated
widget->layout()
widget->layout()Description
TRUEnever evaluated
FALSEnever evaluated
? widget->layout()->hasHeightForWidth() : widget->sizePolicy().hasHeightForWidth())
(widget->layou...ghtForWidth())Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
61 QSize p_hfw = p.expandedTo(min).boundedTo(max);-
62 int h = widget->heightForWidth( p_hfw.width() );-
63 min = QSize(p_hfw.width(), qMax(p_hfw.height(), h));-
64 }
never executed: end of block
0
65 }
never executed: end of block
0
66-
67 if ((resizable
resizableDescription
TRUEnever evaluated
FALSEnever evaluated
&& m.expandedTo(min) == m
m.expandedTo(min) == mDescription
TRUEnever evaluated
FALSEnever evaluated
&& m.boundedTo(max) == m
m.boundedTo(max) == mDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
68 || (!resizable
!resizableDescription
TRUEnever evaluated
FALSEnever evaluated
&& m.expandedTo(widget->size()) == m
m.expandedTo(w...->size()) == mDescription
TRUEnever evaluated
FALSEnever evaluated
))
0
69 p = m;
never executed: p = m;
0
70-
71 if (resizable
resizableDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
72 widget->resize(p.expandedTo(min).boundedTo(max));
never executed: widget->resize(p.expandedTo(min).boundedTo(max));
0
73 QSize v = widget->size();-
74-
75 hbar->setRange(0, v.width() - p.width());-
76 hbar->setPageStep(p.width());-
77 vbar->setRange(0, v.height() - p.height());-
78 vbar->setPageStep(p.height());-
79 updateWidgetPosition();-
80-
81}
never executed: end of block
0
82-
83-
84-
85-
86-
87-
88-
89QWidget *QScrollArea::widget() const-
90{-
91 const QScrollAreaPrivate * const d = d_func();-
92 return
never executed: return d->widget;
d->widget;
never executed: return d->widget;
0
93}-
94void QScrollArea::setWidget(QWidget *widget)-
95{-
96 QScrollAreaPrivate * const d = d_func();-
97 if (widget == d->widget
widget == d->widgetDescription
TRUEnever evaluated
FALSEnever evaluated
|| !widget
!widgetDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
98 return;
never executed: return;
0
99-
100 delete d->widget;-
101 d->widget = 0;-
102 d->hbar->setValue(0);-
103 d->vbar->setValue(0);-
104 if (widget->parentWidget() != d->viewport
widget->parent...!= d->viewportDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
105 widget->setParent(d->viewport);
never executed: widget->setParent(d->viewport);
0
106 if (!widget->testAttribute(Qt::WA_Resized)
!widget->testA...t::WA_Resized)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
107 widget->resize(widget->sizeHint());
never executed: widget->resize(widget->sizeHint());
0
108 d->widget = widget;-
109 d->widget->setAutoFillBackground(true);-
110 widget->installEventFilter(this);-
111 d->widgetSize = QSize();-
112 d->updateScrollBars();-
113 d->widget->show();-
114-
115}
never executed: end of block
0
116-
117-
118-
119-
120-
121-
122-
123QWidget *QScrollArea::takeWidget()-
124{-
125 QScrollAreaPrivate * const d = d_func();-
126 QWidget *w = d->widget;-
127 d->widget = 0;-
128 if (w
wDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
129 w->setParent(0);
never executed: w->setParent(0);
0
130 return
never executed: return w;
w;
never executed: return w;
0
131}-
132-
133-
134-
135-
136bool QScrollArea::event(QEvent *e)-
137{-
138 QScrollAreaPrivate * const d = d_func();-
139 if (e->type() == QEvent::StyleChange
e->type() == Q...t::StyleChangeDescription
TRUEnever evaluated
FALSEnever evaluated
|| e->type() == QEvent::LayoutRequest
e->type() == Q...:LayoutRequestDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
140 d->updateScrollBars();-
141 }
never executed: end of block
0
142 return
never executed: return QAbstractScrollArea::event(e);
QAbstractScrollArea::event(e);
never executed: return QAbstractScrollArea::event(e);
0
143}-
144-
145-
146-
147-
148-
149bool QScrollArea::eventFilter(QObject *o, QEvent *e)-
150{-
151 QScrollAreaPrivate * const d = d_func();-
152-
153-
154-
155-
156-
157-
158-
159 if (o == d->widget
o == d->widgetDescription
TRUEnever evaluated
FALSEnever evaluated
&& e->type() == QEvent::Resize
e->type() == QEvent::ResizeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
160 d->updateScrollBars();
never executed: d->updateScrollBars();
0
161-
162 return
never executed: return QAbstractScrollArea::eventFilter(o, e);
QAbstractScrollArea::eventFilter(o, e);
never executed: return QAbstractScrollArea::eventFilter(o, e);
0
163}-
164-
165-
166-
167-
168void QScrollArea::resizeEvent(QResizeEvent *)-
169{-
170 QScrollAreaPrivate * const d = d_func();-
171 d->updateScrollBars();-
172-
173}
never executed: end of block
0
174-
175-
176-
177-
178void QScrollArea::scrollContentsBy(int, int)-
179{-
180 QScrollAreaPrivate * const d = d_func();-
181 if (!d->widget
!d->widgetDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
182 return;
never executed: return;
0
183 d->updateWidgetPosition();-
184}
never executed: end of block
0
185bool QScrollArea::widgetResizable() const-
186{-
187 const QScrollAreaPrivate * const d = d_func();-
188 return
never executed: return d->resizable;
d->resizable;
never executed: return d->resizable;
0
189}-
190-
191void QScrollArea::setWidgetResizable(bool resizable)-
192{-
193 QScrollAreaPrivate * const d = d_func();-
194 d->resizable = resizable;-
195 updateGeometry();-
196 d->updateScrollBars();-
197}
never executed: end of block
0
198-
199-
200-
201-
202QSize QScrollArea::sizeHint() const-
203{-
204 const QScrollAreaPrivate * const d = d_func();-
205 int f = 2 * d->frameWidth;-
206 QSize sz(f, f);-
207 int h = fontMetrics().height();-
208 if (d->widget
d->widgetDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
209 if (!d->widgetSize.isValid()
!d->widgetSize.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
210 d->widgetSize = d->resizable
d->resizableDescription
TRUEnever evaluated
FALSEnever evaluated
? d->widget->sizeHint() : d->widget->size();
never executed: d->widgetSize = d->resizable ? d->widget->sizeHint() : d->widget->size();
0
211 sz += d->widgetSize;-
212 }
never executed: end of block
else {
0
213 sz += QSize(12 * h, 8 * h);-
214 }
never executed: end of block
0
215 if (d->vbarpolicy == Qt::ScrollBarAlwaysOn
d->vbarpolicy ...ollBarAlwaysOnDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
216 sz.setWidth(sz.width() + d->vbar->sizeHint().width());
never executed: sz.setWidth(sz.width() + d->vbar->sizeHint().width());
0
217 if (d->hbarpolicy == Qt::ScrollBarAlwaysOn
d->hbarpolicy ...ollBarAlwaysOnDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
218 sz.setHeight(sz.height() + d->hbar->sizeHint().height());
never executed: sz.setHeight(sz.height() + d->hbar->sizeHint().height());
0
219 return
never executed: return sz.boundedTo(QSize(36 * h, 24 * h));
sz.boundedTo(QSize(36 * h, 24 * h));
never executed: return sz.boundedTo(QSize(36 * h, 24 * h));
0
220}-
221-
222-
223-
224-
225QSize QScrollArea::viewportSizeHint() const-
226{-
227 const QScrollAreaPrivate * const d = d_func();-
228 if (d->widget
d->widgetDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
229 return
never executed: return d->resizable ? d->widget->sizeHint() : d->widget->size();
d->resizable ? d->widget->sizeHint() : d->widget->size();
never executed: return d->resizable ? d->widget->sizeHint() : d->widget->size();
0
230 }-
231 const int h = fontMetrics().height();-
232 return
never executed: return QSize(6 * h, 4 * h);
QSize(6 * h, 4 * h);
never executed: return QSize(6 * h, 4 * h);
0
233}-
234-
235-
236-
237-
238-
239bool QScrollArea::focusNextPrevChild(bool next)-
240{-
241 if (QWidget::focusNextPrevChild(next)
QWidget::focus...revChild(next)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
242 if (QWidget *fw = focusWidget()
QWidget *fw = focusWidget()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
243 ensureWidgetVisible(fw);
never executed: ensureWidgetVisible(fw);
0
244 return
never executed: return true;
true;
never executed: return true;
0
245 }-
246 return
never executed: return false;
false;
never executed: return false;
0
247}-
248-
249-
250-
251-
252-
253-
254-
255void QScrollArea::ensureVisible(int x, int y, int xmargin, int ymargin)-
256{-
257 QScrollAreaPrivate * const d = d_func();-
258-
259 int logicalX = QStyle::visualPos(layoutDirection(), d->viewport->rect(), QPoint(x, y)).x();-
260-
261 if (logicalX - xmargin < d->hbar->value()
logicalX - xma...>hbar->value()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
262 d->hbar->setValue(qMax(0, logicalX - xmargin));-
263 }
never executed: end of block
else if (logicalX > d->hbar->value() + d->viewport->width() - xmargin
logicalX > d->...th() - xmarginDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
264 d->hbar->setValue(qMin(logicalX - d->viewport->width() + xmargin, d->hbar->maximum()));-
265 }
never executed: end of block
0
266-
267 if (y - ymargin < d->vbar->value()
y - ymargin < d->vbar->value()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
268 d->vbar->setValue(qMax(0, y - ymargin));-
269 }
never executed: end of block
else if (y > d->vbar->value() + d->viewport->height() - ymargin
y > d->vbar->v...ht() - ymarginDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
270 d->vbar->setValue(qMin(y - d->viewport->height() + ymargin, d->vbar->maximum()));-
271 }
never executed: end of block
0
272}
never executed: end of block
0
273void QScrollArea::ensureWidgetVisible(QWidget *childWidget, int xmargin, int ymargin)-
274{-
275 QScrollAreaPrivate * const d = d_func();-
276-
277 if (!d->widget->isAncestorOf(childWidget)
!d->widget->is...f(childWidget)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
278 return;
never executed: return;
0
279-
280 const QRect microFocus = childWidget->inputMethodQuery(Qt::ImCursorRectangle).toRect();-
281 const QRect defaultMicroFocus =-
282 childWidget->QWidget::inputMethodQuery(Qt::ImCursorRectangle).toRect();-
283 QRect focusRect = (
(microFocus !=...ultMicroFocus)Description
TRUEnever evaluated
FALSEnever evaluated
microFocus != defaultMicroFocus)
(microFocus !=...ultMicroFocus)Description
TRUEnever evaluated
FALSEnever evaluated
0
284 ? QRect(childWidget->mapTo(d->widget, microFocus.topLeft()), microFocus.size())-
285 : QRect(childWidget->mapTo(d->widget, QPoint(0,0)), childWidget->size());-
286 const QRect visibleRect(-d->widget->pos(), d->viewport->size());-
287-
288 if (visibleRect.contains(focusRect)
visibleRect.co...ins(focusRect)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
289 return;
never executed: return;
0
290-
291 focusRect.adjust(-xmargin, -ymargin, xmargin, ymargin);-
292-
293 if (focusRect.width() > visibleRect.width()
focusRect.widt...leRect.width()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
294 d->hbar->setValue(focusRect.center().x() - d->viewport->width() / 2);
never executed: d->hbar->setValue(focusRect.center().x() - d->viewport->width() / 2);
0
295 else if (focusRect.right() > visibleRect.right()
focusRect.righ...leRect.right()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
296 d->hbar->setValue(focusRect.right() - d->viewport->width());
never executed: d->hbar->setValue(focusRect.right() - d->viewport->width());
0
297 else if (focusRect.left() < visibleRect.left()
focusRect.left...bleRect.left()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
298 d->hbar->setValue(focusRect.left());
never executed: d->hbar->setValue(focusRect.left());
0
299-
300 if (focusRect.height() > visibleRect.height()
focusRect.heig...eRect.height()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
301 d->vbar->setValue(focusRect.center().y() - d->viewport->height() / 2);
never executed: d->vbar->setValue(focusRect.center().y() - d->viewport->height() / 2);
0
302 else if (focusRect.bottom() > visibleRect.bottom()
focusRect.bott...eRect.bottom()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
303 d->vbar->setValue(focusRect.bottom() - d->viewport->height());
never executed: d->vbar->setValue(focusRect.bottom() - d->viewport->height());
0
304 else if (focusRect.top() < visibleRect.top()
focusRect.top(...ibleRect.top()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
305 d->vbar->setValue(focusRect.top());
never executed: d->vbar->setValue(focusRect.top());
0
306}
never executed: end of block
0
307void QScrollArea::setAlignment(Qt::Alignment alignment)-
308{-
309 QScrollAreaPrivate * const d = d_func();-
310 d->alignment = alignment;-
311 if (d->widget
d->widgetDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
312 d->updateWidgetPosition();
never executed: d->updateWidgetPosition();
0
313}
never executed: end of block
0
314-
315Qt::Alignment QScrollArea::alignment() const-
316{-
317 const QScrollAreaPrivate * const d = d_func();-
318 return
never executed: return d->alignment;
d->alignment;
never executed: return d->alignment;
0
319}-
320-
321-
322-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9