widgets/qsizegrip.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10 -
11 -
12static QWidget *qt_sizegrip_topLevelWidget(QWidget* w) -
13{ -
14 while (w && !w->isWindow() && w->windowType() != Qt::SubWindow)
partially evaluated: w
TRUEFALSE
yes
Evaluation Count:602
no
Evaluation Count:0
evaluated: !w->isWindow()
TRUEFALSE
yes
Evaluation Count:312
yes
Evaluation Count:290
evaluated: w->windowType() != Qt::SubWindow
TRUEFALSE
yes
Evaluation Count:310
yes
Evaluation Count:2
0-602
15 w = w->parentWidget();
executed: w = w->parentWidget();
Execution Count:310
310
16 return w;
executed: return w;
Execution Count:292
292
17} -
18 -
19class QSizeGripPrivate : public QWidgetPrivate -
20{ -
21 inline QSizeGrip* q_func() { return static_cast<QSizeGrip *>(q_ptr); } inline const QSizeGrip* q_func() const { return static_cast<const QSizeGrip *>(q_ptr); } friend class QSizeGrip; -
22public: -
23 QSizeGripPrivate(); -
24 void init(); -
25 QPoint p; -
26 QRect r; -
27 int d; -
28 int dxMax; -
29 int dyMax; -
30 Qt::Corner m_corner; -
31 bool gotMousePress; -
32 QWidget *tlw; -
33 -
34 -
35 -
36 Qt::Corner corner() const; -
37 inline bool atBottom() const -
38 { -
39 return m_corner == Qt::BottomRightCorner || m_corner == Qt::BottomLeftCorner;
never executed: return m_corner == Qt::BottomRightCorner || m_corner == Qt::BottomLeftCorner;
0
40 } -
41 -
42 inline bool atLeft() const -
43 { -
44 return m_corner == Qt::BottomLeftCorner || m_corner == Qt::TopLeftCorner;
never executed: return m_corner == Qt::BottomLeftCorner || m_corner == Qt::TopLeftCorner;
0
45 } -
46 -
47 void updateTopLevelWidget() -
48 { -
49 QSizeGrip * const q = q_func(); -
50 QWidget *w = qt_sizegrip_topLevelWidget(q); -
51 if (tlw == w)
evaluated: tlw == w
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:216
6-216
52 return;
executed: return;
Execution Count:6
6
53 if (tlw)
evaluated: tlw
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:215
1-215
54 tlw->removeEventFilter(q);
executed: tlw->removeEventFilter(q);
Execution Count:1
1
55 tlw = w; -
56 if (tlw)
partially evaluated: tlw
TRUEFALSE
yes
Evaluation Count:216
no
Evaluation Count:0
0-216
57 tlw->installEventFilter(q);
executed: tlw->installEventFilter(q);
Execution Count:216
216
58 }
executed: }
Execution Count:216
216
59 -
60 -
61 -
62 -
63 -
64 void _q_showIfNotHidden() -
65 { -
66 QSizeGrip * const q = q_func(); -
67 bool showSizeGrip = !(q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide));
partially evaluated: q->isHidden()
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
partially evaluated: q->testAttribute(Qt::WA_WState_ExplicitShowHide)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
0-7
68 updateTopLevelWidget(); -
69 if (tlw && showSizeGrip) {
partially evaluated: tlw
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
partially evaluated: showSizeGrip
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
0-7
70 Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen; -
71 -
72 sizeGripNotVisibleState |= Qt::WindowMaximized; -
73 -
74 -
75 showSizeGrip = !(tlw->windowState() & sizeGripNotVisibleState); -
76 }
executed: }
Execution Count:7
7
77 if (showSizeGrip)
evaluated: showSizeGrip
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:2
2-5
78 q->setVisible(true);
executed: q->setVisible(true);
Execution Count:5
5
79 }
executed: }
Execution Count:7
7
80 -
81 bool m_platformSizeGrip; -
82}; -
83 -
84QSizeGripPrivate::QSizeGripPrivate() -
85 : dxMax(0) -
86 , dyMax(0) -
87 , gotMousePress(false) -
88 , tlw(0) -
89 , m_platformSizeGrip(false) -
90{ -
91}
executed: }
Execution Count:215
215
92Qt::Corner QSizeGripPrivate::corner() const -
93{ -
94 const QSizeGrip * const q = q_func(); -
95 QWidget *tlw = qt_sizegrip_topLevelWidget(const_cast<QSizeGrip *>(q)); -
96 const QPoint sizeGripPos = q->mapTo(tlw, QPoint(0, 0)); -
97 bool isAtBottom = sizeGripPos.y() >= tlw->height() / 2; -
98 bool isAtLeft = sizeGripPos.x() <= tlw->width() / 2; -
99 if (isAtLeft)
evaluated: isAtLeft
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:61
9-61
100 return isAtBottom ? Qt::BottomLeftCorner : Qt::TopLeftCorner;
executed: return isAtBottom ? Qt::BottomLeftCorner : Qt::TopLeftCorner;
Execution Count:9
9
101 else -
102 return isAtBottom ? Qt::BottomRightCorner : Qt::TopRightCorner;
executed: return isAtBottom ? Qt::BottomRightCorner : Qt::TopRightCorner;
Execution Count:61
61
103} -
104QSizeGrip::QSizeGrip(QWidget * parent) -
105 : QWidget(*new QSizeGripPrivate, parent, 0) -
106{ -
107 QSizeGripPrivate * const d = d_func(); -
108 d->init(); -
109}
executed: }
Execution Count:215
215
110 -
111 -
112void QSizeGripPrivate::init() -
113{ -
114 QSizeGrip * const q = q_func(); -
115 m_corner = q->isLeftToRight() ? Qt::BottomRightCorner : Qt::BottomLeftCorner;
partially evaluated: q->isLeftToRight()
TRUEFALSE
yes
Evaluation Count:215
no
Evaluation Count:0
0-215
116 -
117 -
118 q->setCursor(m_corner == Qt::TopLeftCorner || m_corner == Qt::BottomRightCorner -
119 ? Qt::SizeFDiagCursor : Qt::SizeBDiagCursor); -
120 -
121 q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed)); -
122 updateTopLevelWidget(); -
123}
executed: }
Execution Count:215
215
124 -
125 -
126 -
127 -
128 -
129QSizeGrip::~QSizeGrip() -
130{ -
131} -
132 -
133 -
134 -
135 -
136QSize QSizeGrip::sizeHint() const -
137{ -
138 QStyleOption opt(0); -
139 opt.init(this); -
140 return (style()->sizeFromContents(QStyle::CT_SizeGrip, &opt, QSize(13, 13), this). 260
141 expandedTo(QApplication::globalStrut()));
executed: return (style()->sizeFromContents(QStyle::CT_SizeGrip, &opt, QSize(13, 13), this). expandedTo(QApplication::globalStrut()));
Execution Count:260
260
142} -
143void QSizeGrip::paintEvent(QPaintEvent *event) -
144{ -
145 (void)event;; -
146 QSizeGripPrivate * const d = d_func(); -
147 QPainter painter(this); -
148 QStyleOptionSizeGrip opt; -
149 opt.init(this); -
150 opt.corner = d->m_corner; -
151 style()->drawControl(QStyle::CE_SizeGrip, &opt, &painter, this); -
152}
executed: }
Execution Count:45
45
153void QSizeGrip::mousePressEvent(QMouseEvent * e) -
154{ -
155 if (e->button() != Qt::LeftButton) {
never evaluated: e->button() != Qt::LeftButton
0
156 QWidget::mousePressEvent(e); -
157 return;
never executed: return;
0
158 } -
159 -
160 QSizeGripPrivate * const d = d_func(); -
161 QWidget *tlw = qt_sizegrip_topLevelWidget(this); -
162 d->p = e->globalPos(); -
163 d->gotMousePress = true; -
164 d->r = tlw->geometry(); -
165 -
166 -
167 d->m_platformSizeGrip = false; -
168 if (tlw->isWindow()
never evaluated: tlw->isWindow()
0
169 && tlw->windowHandle()
never evaluated: tlw->windowHandle()
0
170 && !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint)
never evaluated: !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint)
0
171 && !tlw->testAttribute(Qt::WA_DontShowOnScreen)
never evaluated: !tlw->testAttribute(Qt::WA_DontShowOnScreen)
0
172 && !tlw->hasHeightForWidth()) {
never evaluated: !tlw->hasHeightForWidth()
0
173 QPlatformWindow *platformWindow = tlw->windowHandle()->handle(); -
174 const QPoint topLevelPos = mapTo(tlw, e->pos()); -
175 d->m_platformSizeGrip = platformWindow && platformWindow->startSystemResize(topLevelPos, d->m_corner);
never evaluated: platformWindow
never evaluated: platformWindow->startSystemResize(topLevelPos, d->m_corner)
0
176 }
never executed: }
0
177 -
178 if (d->m_platformSizeGrip)
never evaluated: d->m_platformSizeGrip
0
179 return;
never executed: return;
0
180 -
181 -
182 QRect availableGeometry; -
183 bool hasVerticalSizeConstraint = true; -
184 bool hasHorizontalSizeConstraint = true; -
185 if (tlw->isWindow())
never evaluated: tlw->isWindow()
0
186 availableGeometry = QApplication::desktop()->availableGeometry(tlw);
never executed: availableGeometry = QApplication::desktop()->availableGeometry(tlw);
0
187 else { -
188 const QWidget *tlwParent = tlw->parentWidget(); -
189 -
190 -
191 -
192 -
193 QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(tlwParent->parentWidget()); -
194 if (scrollArea) {
never evaluated: scrollArea
0
195 hasHorizontalSizeConstraint = scrollArea->horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff; -
196 hasVerticalSizeConstraint = scrollArea->verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff; -
197 }
never executed: }
0
198 -
199 availableGeometry = tlwParent->contentsRect(); -
200 }
never executed: }
0
201 -
202 -
203 const QRect frameGeometry = tlw->frameGeometry(); -
204 const int titleBarHeight = qMax(tlw->geometry().y() - frameGeometry.y(), 0); -
205 const int bottomDecoration = qMax(frameGeometry.height() - tlw->height() - titleBarHeight, 0); -
206 const int leftRightDecoration = qMax((frameGeometry.width() - tlw->width()) / 2, 0); -
207 -
208 -
209 -
210 if (d->atBottom()) {
never evaluated: d->atBottom()
0
211 if (hasVerticalSizeConstraint)
never evaluated: hasVerticalSizeConstraint
0
212 d->dyMax = availableGeometry.bottom() - d->r.bottom() - bottomDecoration;
never executed: d->dyMax = availableGeometry.bottom() - d->r.bottom() - bottomDecoration;
0
213 else -
214 d->dyMax = 2147483647;
never executed: d->dyMax = 2147483647;
0
215 } else { -
216 if (hasVerticalSizeConstraint)
never evaluated: hasVerticalSizeConstraint
0
217 d->dyMax = availableGeometry.y() - d->r.y() + titleBarHeight;
never executed: d->dyMax = availableGeometry.y() - d->r.y() + titleBarHeight;
0
218 else -
219 d->dyMax = -2147483647;
never executed: d->dyMax = -2147483647;
0
220 } -
221 -
222 -
223 -
224 if (d->atLeft()) {
never evaluated: d->atLeft()
0
225 if (hasHorizontalSizeConstraint)
never evaluated: hasHorizontalSizeConstraint
0
226 d->dxMax = availableGeometry.x() - d->r.x() + leftRightDecoration;
never executed: d->dxMax = availableGeometry.x() - d->r.x() + leftRightDecoration;
0
227 else -
228 d->dxMax = -2147483647;
never executed: d->dxMax = -2147483647;
0
229 } else { -
230 if (hasHorizontalSizeConstraint)
never evaluated: hasHorizontalSizeConstraint
0
231 d->dxMax = availableGeometry.right() - d->r.right() - leftRightDecoration;
never executed: d->dxMax = availableGeometry.right() - d->r.right() - leftRightDecoration;
0
232 else -
233 d->dxMax = 2147483647;
never executed: d->dxMax = 2147483647;
0
234 } -
235} -
236 -
237 -
238 -
239 -
240 -
241 -
242 -
243void QSizeGrip::mouseMoveEvent(QMouseEvent * e) -
244{ -
245 QSizeGripPrivate * const d = d_func(); -
246 if (e->buttons() != Qt::LeftButton || d->m_platformSizeGrip) {
never evaluated: e->buttons() != Qt::LeftButton
never evaluated: d->m_platformSizeGrip
0
247 QWidget::mouseMoveEvent(e); -
248 return;
never executed: return;
0
249 } -
250 -
251 QWidget* tlw = qt_sizegrip_topLevelWidget(this); -
252 if (!d->gotMousePress || tlw->testAttribute(Qt::WA_WState_ConfigPending))
never evaluated: !d->gotMousePress
never evaluated: tlw->testAttribute(Qt::WA_WState_ConfigPending)
0
253 return;
never executed: return;
0
254 -
255 QPoint np(e->globalPos()); -
256 -
257 -
258 QSize ns; -
259 if (d->atBottom())
never evaluated: d->atBottom()
0
260 ns.rheight() = d->r.height() + qMin(np.y() - d->p.y(), d->dyMax);
never executed: ns.rheight() = d->r.height() + qMin(np.y() - d->p.y(), d->dyMax);
0
261 else -
262 ns.rheight() = d->r.height() - qMax(np.y() - d->p.y(), d->dyMax);
never executed: ns.rheight() = d->r.height() - qMax(np.y() - d->p.y(), d->dyMax);
0
263 -
264 if (d->atLeft())
never evaluated: d->atLeft()
0
265 ns.rwidth() = d->r.width() - qMax(np.x() - d->p.x(), d->dxMax);
never executed: ns.rwidth() = d->r.width() - qMax(np.x() - d->p.x(), d->dxMax);
0
266 else -
267 ns.rwidth() = d->r.width() + qMin(np.x() - d->p.x(), d->dxMax);
never executed: ns.rwidth() = d->r.width() + qMin(np.x() - d->p.x(), d->dxMax);
0
268 -
269 ns = QLayout::closestAcceptableSize(tlw, ns); -
270 -
271 QPoint p; -
272 QRect nr(p, ns); -
273 if (d->atBottom()) {
never evaluated: d->atBottom()
0
274 if (d->atLeft())
never evaluated: d->atLeft()
0
275 nr.moveTopRight(d->r.topRight());
never executed: nr.moveTopRight(d->r.topRight());
0
276 else -
277 nr.moveTopLeft(d->r.topLeft());
never executed: nr.moveTopLeft(d->r.topLeft());
0
278 } else { -
279 if (d->atLeft())
never evaluated: d->atLeft()
0
280 nr.moveBottomRight(d->r.bottomRight());
never executed: nr.moveBottomRight(d->r.bottomRight());
0
281 else -
282 nr.moveBottomLeft(d->r.bottomLeft());
never executed: nr.moveBottomLeft(d->r.bottomLeft());
0
283 } -
284 -
285 tlw->setGeometry(nr); -
286}
never executed: }
0
287 -
288 -
289 -
290 -
291void QSizeGrip::mouseReleaseEvent(QMouseEvent *mouseEvent) -
292{ -
293 if (mouseEvent->button() == Qt::LeftButton) {
never evaluated: mouseEvent->button() == Qt::LeftButton
0
294 QSizeGripPrivate * const d = d_func(); -
295 d->gotMousePress = false; -
296 d->p = QPoint(); -
297 } else {
never executed: }
0
298 QWidget::mouseReleaseEvent(mouseEvent); -
299 }
never executed: }
0
300} -
301 -
302 -
303 -
304 -
305void QSizeGrip::moveEvent(QMoveEvent * ) -
306{ -
307 QSizeGripPrivate * const d = d_func(); -
308 -
309 if (!d->p.isNull())
partially evaluated: !d->p.isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:70
0-70
310 return;
never executed: return;
0
311 -
312 d->m_corner = d->corner(); -
313 -
314 setCursor(d->m_corner == Qt::TopLeftCorner || d->m_corner == Qt::BottomRightCorner -
315 ? Qt::SizeFDiagCursor : Qt::SizeBDiagCursor); -
316 -
317}
executed: }
Execution Count:70
70
318 -
319 -
320 -
321 -
322void QSizeGrip::showEvent(QShowEvent *showEvent) -
323{ -
324 -
325 -
326 -
327 QWidget::showEvent(showEvent); -
328}
executed: }
Execution Count:66
66
329 -
330 -
331 -
332 -
333void QSizeGrip::hideEvent(QHideEvent *hideEvent) -
334{ -
335 -
336 -
337 -
338 QWidget::hideEvent(hideEvent); -
339}
executed: }
Execution Count:64
64
340 -
341 -
342 -
343 -
344void QSizeGrip::setVisible(bool visible) -
345{ -
346 QWidget::setVisible(visible); -
347}
executed: }
Execution Count:243
243
348 -
349 -
350bool QSizeGrip::eventFilter(QObject *o, QEvent *e) -
351{ -
352 QSizeGripPrivate * const d = d_func(); -
353 if ((isHidden() && testAttribute(Qt::WA_WState_ExplicitShowHide))
evaluated: isHidden()
TRUEFALSE
yes
Evaluation Count:569
yes
Evaluation Count:9896
evaluated: testAttribute(Qt::WA_WState_ExplicitShowHide)
TRUEFALSE
yes
Evaluation Count:495
yes
Evaluation Count:74
74-9896
354 || e->type() != QEvent::WindowStateChange
evaluated: e->type() != QEvent::WindowStateChange
TRUEFALSE
yes
Evaluation Count:9953
yes
Evaluation Count:17
17-9953
355 || o != d->tlw) {
partially evaluated: o != d->tlw
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
356 return QWidget::eventFilter(o, e);
executed: return QWidget::eventFilter(o, e);
Execution Count:10448
10448
357 } -
358 Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen; -
359 -
360 sizeGripNotVisibleState |= Qt::WindowMaximized; -
361 -
362 -
363 setVisible(!(d->tlw->windowState() & sizeGripNotVisibleState)); -
364 setAttribute(Qt::WA_WState_ExplicitShowHide, false); -
365 return QWidget::eventFilter(o, e);
executed: return QWidget::eventFilter(o, e);
Execution Count:17
17
366} -
367 -
368 -
369 -
370 -
371bool QSizeGrip::event(QEvent *event) -
372{ -
373 return QWidget::event(event);
executed: return QWidget::event(event);
Execution Count:1275
1275
374} -
375 -
376 -
377 -
378 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial