widgets/qwidgetresizehandler.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 "qwidgetresizehandler_p.h" -
43 -
44#ifndef QT_NO_RESIZEHANDLER -
45#include "qframe.h" -
46#include "qapplication.h" -
47#include "qdesktopwidget.h" -
48#include "qcursor.h" -
49#include "qsizegrip.h" -
50#include "qevent.h" -
51#include "qdebug.h" -
52#include "private/qlayoutengine_p.h" -
53 -
54QT_BEGIN_NAMESPACE -
55 -
56#define RANGE 4 -
57 -
58static bool resizeHorizontalDirectionFixed = false; -
59static bool resizeVerticalDirectionFixed = false; -
60 -
61QWidgetResizeHandler::QWidgetResizeHandler(QWidget *parent, QWidget *cw) -
62 : QObject(parent), widget(parent), childWidget(cw ? cw : parent), -
63 fw(0), extrahei(0), buttonDown(false), moveResizeMode(false), sizeprotect(true), movingEnabled(true) -
64{ -
65 mode = Nowhere;
executed (the execution status of this line is deduced): mode = Nowhere;
-
66 widget->setMouseTracking(true);
executed (the execution status of this line is deduced): widget->setMouseTracking(true);
-
67 QFrame *frame = qobject_cast<QFrame*>(widget);
executed (the execution status of this line is deduced): QFrame *frame = qobject_cast<QFrame*>(widget);
-
68 range = frame ? frame->frameWidth() : RANGE;
partially evaluated: frame
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:27
0-27
69 range = qMax(RANGE, range);
executed (the execution status of this line is deduced): range = qMax(4, range);
-
70 activeForMove = activeForResize = true;
executed (the execution status of this line is deduced): activeForMove = activeForResize = true;
-
71 widget->installEventFilter(this);
executed (the execution status of this line is deduced): widget->installEventFilter(this);
-
72}
executed: }
Execution Count:27
27
73 -
74void QWidgetResizeHandler::setActive(Action ac, bool b) -
75{ -
76 if (ac & Move)
evaluated: ac & Move
TRUEFALSE
yes
Evaluation Count:27
yes
Evaluation Count:22
22-27
77 activeForMove = b;
executed: activeForMove = b;
Execution Count:27
27
78 if (ac & Resize)
partially evaluated: ac & Resize
TRUEFALSE
yes
Evaluation Count:49
no
Evaluation Count:0
0-49
79 activeForResize = b;
executed: activeForResize = b;
Execution Count:49
49
80 -
81 if (!isActive())
evaluated: !isActive()
TRUEFALSE
yes
Evaluation Count:39
yes
Evaluation Count:10
10-39
82 setMouseCursor(Nowhere);
executed: setMouseCursor(Nowhere);
Execution Count:39
39
83}
executed: }
Execution Count:49
49
84 -
85bool QWidgetResizeHandler::isActive(Action ac) const -
86{ -
87 bool b = false;
executed (the execution status of this line is deduced): bool b = false;
-
88 if (ac & Move) b = activeForMove;
executed: b = activeForMove;
Execution Count:742
partially evaluated: ac & Move
TRUEFALSE
yes
Evaluation Count:742
no
Evaluation Count:0
0-742
89 if (ac & Resize) b |= activeForResize;
executed: b |= activeForResize;
Execution Count:742
partially evaluated: ac & Resize
TRUEFALSE
yes
Evaluation Count:742
no
Evaluation Count:0
0-742
90 -
91 return b;
executed: return b;
Execution Count:742
742
92} -
93 -
94bool QWidgetResizeHandler::eventFilter(QObject *o, QEvent *ee) -
95{ -
96 if (!isActive()
evaluated: !isActive()
TRUEFALSE
yes
Evaluation Count:597
yes
Evaluation Count:96
96-597
97 || (ee->type() != QEvent::MouseButtonPress
partially evaluated: ee->type() != QEvent::MouseButtonPress
TRUEFALSE
yes
Evaluation Count:96
no
Evaluation Count:0
0-96
98 && ee->type() != QEvent::MouseButtonRelease
partially evaluated: ee->type() != QEvent::MouseButtonRelease
TRUEFALSE
yes
Evaluation Count:96
no
Evaluation Count:0
0-96
99 && ee->type() != QEvent::MouseMove
partially evaluated: ee->type() != QEvent::MouseMove
TRUEFALSE
yes
Evaluation Count:96
no
Evaluation Count:0
0-96
100 && ee->type() != QEvent::KeyPress
partially evaluated: ee->type() != QEvent::KeyPress
TRUEFALSE
yes
Evaluation Count:96
no
Evaluation Count:0
0-96
101 && ee->type() != QEvent::ShortcutOverride)
partially evaluated: ee->type() != QEvent::ShortcutOverride
TRUEFALSE
yes
Evaluation Count:96
no
Evaluation Count:0
0-96
102 ) -
103 return false;
executed: return false;
Execution Count:693
693
104 -
105 Q_ASSERT(o == widget);
never executed (the execution status of this line is deduced): qt_noop();
-
106 QWidget *w = widget;
never executed (the execution status of this line is deduced): QWidget *w = widget;
-
107 if (QApplication::activePopupWidget()) {
never evaluated: QApplication::activePopupWidget()
0
108 if (buttonDown && ee->type() == QEvent::MouseButtonRelease)
never evaluated: buttonDown
never evaluated: ee->type() == QEvent::MouseButtonRelease
0
109 buttonDown = false;
never executed: buttonDown = false;
0
110 return false;
never executed: return false;
0
111 } -
112 -
113 QMouseEvent *e = (QMouseEvent*)ee;
never executed (the execution status of this line is deduced): QMouseEvent *e = (QMouseEvent*)ee;
-
114 switch (e->type()) { -
115 case QEvent::MouseButtonPress: { -
116 if (w->isMaximized())
never evaluated: w->isMaximized()
0
117 break;
never executed: break;
0
118 if (!widget->rect().contains(widget->mapFromGlobal(e->globalPos())))
never evaluated: !widget->rect().contains(widget->mapFromGlobal(e->globalPos()))
0
119 return false;
never executed: return false;
0
120 if (e->button() == Qt::LeftButton) {
never evaluated: e->button() == Qt::LeftButton
0
121#if defined(Q_WS_X11) -
122 /* -
123 Implicit grabs do not stop the X server from changing -
124 the cursor in children, which looks *really* bad when -
125 doing resizingk, so we grab the cursor. Note that we do -
126 not do this on Windows since double clicks are lost due -
127 to the grab (see change 198463). -
128 */ -
129 if (e->spontaneous()) -
130# if !defined(QT_NO_CURSOR) -
131 widget->grabMouse(widget->cursor()); -
132# else -
133 widget->grabMouse(); -
134# endif // QT_NO_CURSOR -
135#endif // Q_WS_X11 -
136 buttonDown = false;
never executed (the execution status of this line is deduced): buttonDown = false;
-
137 emit activate();
never executed (the execution status of this line is deduced): activate();
-
138 bool me = movingEnabled;
never executed (the execution status of this line is deduced): bool me = movingEnabled;
-
139 movingEnabled = (me && o == widget);
never evaluated: me
never evaluated: o == widget
0
140 mouseMoveEvent(e);
never executed (the execution status of this line is deduced): mouseMoveEvent(e);
-
141 movingEnabled = me;
never executed (the execution status of this line is deduced): movingEnabled = me;
-
142 buttonDown = true;
never executed (the execution status of this line is deduced): buttonDown = true;
-
143 moveOffset = widget->mapFromGlobal(e->globalPos());
never executed (the execution status of this line is deduced): moveOffset = widget->mapFromGlobal(e->globalPos());
-
144 invertedMoveOffset = widget->rect().bottomRight() - moveOffset;
never executed (the execution status of this line is deduced): invertedMoveOffset = widget->rect().bottomRight() - moveOffset;
-
145 if (mode == Center) {
never evaluated: mode == Center
0
146 if (movingEnabled)
never evaluated: movingEnabled
0
147 return true;
never executed: return true;
0
148 } else {
never executed: }
0
149 return true;
never executed: return true;
0
150 } -
151 } -
152 } break;
never executed: break;
0
153 case QEvent::MouseButtonRelease: -
154 if (w->isMaximized())
never evaluated: w->isMaximized()
0
155 break;
never executed: break;
0
156 if (e->button() == Qt::LeftButton) {
never evaluated: e->button() == Qt::LeftButton
0
157 moveResizeMode = false;
never executed (the execution status of this line is deduced): moveResizeMode = false;
-
158 buttonDown = false;
never executed (the execution status of this line is deduced): buttonDown = false;
-
159 widget->releaseMouse();
never executed (the execution status of this line is deduced): widget->releaseMouse();
-
160 widget->releaseKeyboard();
never executed (the execution status of this line is deduced): widget->releaseKeyboard();
-
161 if (mode == Center) {
never evaluated: mode == Center
0
162 if (movingEnabled)
never evaluated: movingEnabled
0
163 return true;
never executed: return true;
0
164 } else {
never executed: }
0
165 return true;
never executed: return true;
0
166 } -
167 } -
168 break;
never executed: break;
0
169 case QEvent::MouseMove: { -
170 if (w->isMaximized())
never evaluated: w->isMaximized()
0
171 break;
never executed: break;
0
172 buttonDown = buttonDown && (e->buttons() & Qt::LeftButton); // safety, state machine broken!
never evaluated: buttonDown
never evaluated: (e->buttons() & Qt::LeftButton)
0
173 bool me = movingEnabled;
never executed (the execution status of this line is deduced): bool me = movingEnabled;
-
174 movingEnabled = (me && o == widget && (buttonDown || moveResizeMode));
never evaluated: me
never evaluated: o == widget
never evaluated: buttonDown
never evaluated: moveResizeMode
0
175 mouseMoveEvent(e);
never executed (the execution status of this line is deduced): mouseMoveEvent(e);
-
176 movingEnabled = me;
never executed (the execution status of this line is deduced): movingEnabled = me;
-
177 if (mode == Center) {
never evaluated: mode == Center
0
178 if (movingEnabled)
never evaluated: movingEnabled
0
179 return true;
never executed: return true;
0
180 } else {
never executed: }
0
181 return true;
never executed: return true;
0
182 } -
183 } break;
never executed: break;
0
184 case QEvent::KeyPress: -
185 keyPressEvent((QKeyEvent*)e);
never executed (the execution status of this line is deduced): keyPressEvent((QKeyEvent*)e);
-
186 break;
never executed: break;
0
187 case QEvent::ShortcutOverride: -
188 if (buttonDown) {
never evaluated: buttonDown
0
189 ((QKeyEvent*)ee)->accept();
never executed (the execution status of this line is deduced): ((QKeyEvent*)ee)->accept();
-
190 return true;
never executed: return true;
0
191 } -
192 break;
never executed: break;
0
193 default: -
194 break;
never executed: break;
0
195 } -
196 -
197 return false;
never executed: return false;
0
198} -
199 -
200void QWidgetResizeHandler::mouseMoveEvent(QMouseEvent *e) -
201{ -
202 QPoint pos = widget->mapFromGlobal(e->globalPos());
never executed (the execution status of this line is deduced): QPoint pos = widget->mapFromGlobal(e->globalPos());
-
203 if (!moveResizeMode && !buttonDown) {
never evaluated: !moveResizeMode
never evaluated: !buttonDown
0
204 if (pos.y() <= range && pos.x() <= range)
never evaluated: pos.y() <= range
never evaluated: pos.x() <= range
0
205 mode = TopLeft;
never executed: mode = TopLeft;
0
206 else if (pos.y() >= widget->height()-range && pos.x() >= widget->width()-range)
never evaluated: pos.y() >= widget->height()-range
never evaluated: pos.x() >= widget->width()-range
0
207 mode = BottomRight;
never executed: mode = BottomRight;
0
208 else if (pos.y() >= widget->height()-range && pos.x() <= range)
never evaluated: pos.y() >= widget->height()-range
never evaluated: pos.x() <= range
0
209 mode = BottomLeft;
never executed: mode = BottomLeft;
0
210 else if (pos.y() <= range && pos.x() >= widget->width()-range)
never evaluated: pos.y() <= range
never evaluated: pos.x() >= widget->width()-range
0
211 mode = TopRight;
never executed: mode = TopRight;
0
212 else if (pos.y() <= range)
never evaluated: pos.y() <= range
0
213 mode = Top;
never executed: mode = Top;
0
214 else if (pos.y() >= widget->height()-range)
never evaluated: pos.y() >= widget->height()-range
0
215 mode = Bottom;
never executed: mode = Bottom;
0
216 else if (pos.x() <= range)
never evaluated: pos.x() <= range
0
217 mode = Left;
never executed: mode = Left;
0
218 else if ( pos.x() >= widget->width()-range)
never evaluated: pos.x() >= widget->width()-range
0
219 mode = Right;
never executed: mode = Right;
0
220 else if (widget->rect().contains(pos))
never evaluated: widget->rect().contains(pos)
0
221 mode = Center;
never executed: mode = Center;
0
222 else -
223 mode = Nowhere;
never executed: mode = Nowhere;
0
224 -
225 if (widget->isMinimized() || !isActive(Resize))
never evaluated: widget->isMinimized()
never evaluated: !isActive(Resize)
0
226 mode = Center;
never executed: mode = Center;
0
227#ifndef QT_NO_CURSOR -
228 setMouseCursor(mode);
never executed (the execution status of this line is deduced): setMouseCursor(mode);
-
229#endif -
230 return;
never executed: return;
0
231 } -
232 -
233 if (mode == Center && !movingEnabled)
never evaluated: mode == Center
never evaluated: !movingEnabled
0
234 return;
never executed: return;
0
235 -
236 if (widget->testAttribute(Qt::WA_WState_ConfigPending))
never evaluated: widget->testAttribute(Qt::WA_WState_ConfigPending)
0
237 return;
never executed: return;
0
238 -
239 -
240 QPoint globalPos = (!widget->isWindow() && widget->parentWidget()) ?
never evaluated: !widget->isWindow()
never evaluated: widget->parentWidget()
0
241 widget->parentWidget()->mapFromGlobal(e->globalPos()) : e->globalPos();
never executed (the execution status of this line is deduced): widget->parentWidget()->mapFromGlobal(e->globalPos()) : e->globalPos();
-
242 if (!widget->isWindow() && !widget->parentWidget()->rect().contains(globalPos)) {
never evaluated: !widget->isWindow()
never evaluated: !widget->parentWidget()->rect().contains(globalPos)
0
243 if (globalPos.x() < 0)
never evaluated: globalPos.x() < 0
0
244 globalPos.rx() = 0;
never executed: globalPos.rx() = 0;
0
245 if (globalPos.y() < 0)
never evaluated: globalPos.y() < 0
0
246 globalPos.ry() = 0;
never executed: globalPos.ry() = 0;
0
247 if (sizeprotect && globalPos.x() > widget->parentWidget()->width())
never evaluated: sizeprotect
never evaluated: globalPos.x() > widget->parentWidget()->width()
0
248 globalPos.rx() = widget->parentWidget()->width();
never executed: globalPos.rx() = widget->parentWidget()->width();
0
249 if (sizeprotect && globalPos.y() > widget->parentWidget()->height())
never evaluated: sizeprotect
never evaluated: globalPos.y() > widget->parentWidget()->height()
0
250 globalPos.ry() = widget->parentWidget()->height();
never executed: globalPos.ry() = widget->parentWidget()->height();
0
251 }
never executed: }
0
252 -
253 QPoint p = globalPos + invertedMoveOffset;
never executed (the execution status of this line is deduced): QPoint p = globalPos + invertedMoveOffset;
-
254 QPoint pp = globalPos - moveOffset;
never executed (the execution status of this line is deduced): QPoint pp = globalPos - moveOffset;
-
255 -
256 // Workaround for window managers which refuse to move a tool window partially offscreen. -
257 if (QGuiApplication::platformName() == QLatin1String("xcb")) {
never evaluated: QGuiApplication::platformName() == QLatin1String("xcb")
0
258 const QRect desktop = QApplication::desktop()->availableGeometry(widget);
never executed (the execution status of this line is deduced): const QRect desktop = QApplication::desktop()->availableGeometry(widget);
-
259 pp.rx() = qMax(pp.x(), desktop.left());
never executed (the execution status of this line is deduced): pp.rx() = qMax(pp.x(), desktop.left());
-
260 pp.ry() = qMax(pp.y(), desktop.top());
never executed (the execution status of this line is deduced): pp.ry() = qMax(pp.y(), desktop.top());
-
261 p.rx() = qMin(p.x(), desktop.right());
never executed (the execution status of this line is deduced): p.rx() = qMin(p.x(), desktop.right());
-
262 p.ry() = qMin(p.y(), desktop.bottom());
never executed (the execution status of this line is deduced): p.ry() = qMin(p.y(), desktop.bottom());
-
263 }
never executed: }
0
264 -
265 QSize ms = qSmartMinSize(childWidget);
never executed (the execution status of this line is deduced): QSize ms = qSmartMinSize(childWidget);
-
266 int mw = ms.width();
never executed (the execution status of this line is deduced): int mw = ms.width();
-
267 int mh = ms.height();
never executed (the execution status of this line is deduced): int mh = ms.height();
-
268 if (childWidget != widget) {
never evaluated: childWidget != widget
0
269 mw += 2 * fw;
never executed (the execution status of this line is deduced): mw += 2 * fw;
-
270 mh += 2 * fw + extrahei;
never executed (the execution status of this line is deduced): mh += 2 * fw + extrahei;
-
271 }
never executed: }
0
272 -
273 QSize maxsize(childWidget->maximumSize());
never executed (the execution status of this line is deduced): QSize maxsize(childWidget->maximumSize());
-
274 if (childWidget != widget)
never evaluated: childWidget != widget
0
275 maxsize += QSize(2 * fw, 2 * fw + extrahei);
never executed: maxsize += QSize(2 * fw, 2 * fw + extrahei);
0
276 QSize mpsize(widget->geometry().right() - pp.x() + 1,
never executed (the execution status of this line is deduced): QSize mpsize(widget->geometry().right() - pp.x() + 1,
-
277 widget->geometry().bottom() - pp.y() + 1);
never executed (the execution status of this line is deduced): widget->geometry().bottom() - pp.y() + 1);
-
278 mpsize = mpsize.expandedTo(widget->minimumSize()).expandedTo(QSize(mw, mh))
never executed (the execution status of this line is deduced): mpsize = mpsize.expandedTo(widget->minimumSize()).expandedTo(QSize(mw, mh))
-
279 .boundedTo(maxsize);
never executed (the execution status of this line is deduced): .boundedTo(maxsize);
-
280 QPoint mp(widget->geometry().right() - mpsize.width() + 1,
never executed (the execution status of this line is deduced): QPoint mp(widget->geometry().right() - mpsize.width() + 1,
-
281 widget->geometry().bottom() - mpsize.height() + 1);
never executed (the execution status of this line is deduced): widget->geometry().bottom() - mpsize.height() + 1);
-
282 -
283 QRect geom = widget->geometry();
never executed (the execution status of this line is deduced): QRect geom = widget->geometry();
-
284 -
285 switch (mode) { -
286 case TopLeft: -
287 geom = QRect(mp, widget->geometry().bottomRight()) ;
never executed (the execution status of this line is deduced): geom = QRect(mp, widget->geometry().bottomRight()) ;
-
288 break;
never executed: break;
0
289 case BottomRight: -
290 geom = QRect(widget->geometry().topLeft(), p) ;
never executed (the execution status of this line is deduced): geom = QRect(widget->geometry().topLeft(), p) ;
-
291 break;
never executed: break;
0
292 case BottomLeft: -
293 geom = QRect(QPoint(mp.x(), widget->geometry().y()), QPoint(widget->geometry().right(), p.y())) ;
never executed (the execution status of this line is deduced): geom = QRect(QPoint(mp.x(), widget->geometry().y()), QPoint(widget->geometry().right(), p.y())) ;
-
294 break;
never executed: break;
0
295 case TopRight: -
296 geom = QRect(QPoint(widget->geometry().x(), mp.y()), QPoint(p.x(), widget->geometry().bottom())) ;
never executed (the execution status of this line is deduced): geom = QRect(QPoint(widget->geometry().x(), mp.y()), QPoint(p.x(), widget->geometry().bottom())) ;
-
297 break;
never executed: break;
0
298 case Top: -
299 geom = QRect(QPoint(widget->geometry().left(), mp.y()), widget->geometry().bottomRight()) ;
never executed (the execution status of this line is deduced): geom = QRect(QPoint(widget->geometry().left(), mp.y()), widget->geometry().bottomRight()) ;
-
300 break;
never executed: break;
0
301 case Bottom: -
302 geom = QRect(widget->geometry().topLeft(), QPoint(widget->geometry().right(), p.y())) ;
never executed (the execution status of this line is deduced): geom = QRect(widget->geometry().topLeft(), QPoint(widget->geometry().right(), p.y())) ;
-
303 break;
never executed: break;
0
304 case Left: -
305 geom = QRect(QPoint(mp.x(), widget->geometry().top()), widget->geometry().bottomRight()) ;
never executed (the execution status of this line is deduced): geom = QRect(QPoint(mp.x(), widget->geometry().top()), widget->geometry().bottomRight()) ;
-
306 break;
never executed: break;
0
307 case Right: -
308 geom = QRect(widget->geometry().topLeft(), QPoint(p.x(), widget->geometry().bottom())) ;
never executed (the execution status of this line is deduced): geom = QRect(widget->geometry().topLeft(), QPoint(p.x(), widget->geometry().bottom())) ;
-
309 break;
never executed: break;
0
310 case Center: -
311 geom.moveTopLeft(pp);
never executed (the execution status of this line is deduced): geom.moveTopLeft(pp);
-
312 break;
never executed: break;
0
313 default: -
314 break;
never executed: break;
0
315 } -
316 -
317 geom = QRect(geom.topLeft(),
never executed (the execution status of this line is deduced): geom = QRect(geom.topLeft(),
-
318 geom.size().expandedTo(widget->minimumSize())
never executed (the execution status of this line is deduced): geom.size().expandedTo(widget->minimumSize())
-
319 .expandedTo(QSize(mw, mh))
never executed (the execution status of this line is deduced): .expandedTo(QSize(mw, mh))
-
320 .boundedTo(maxsize));
never executed (the execution status of this line is deduced): .boundedTo(maxsize));
-
321 -
322 if (geom != widget->geometry() &&
never evaluated: geom != widget->geometry()
0
323 (widget->isWindow() || widget->parentWidget()->rect().intersects(geom))) {
never evaluated: widget->isWindow()
never evaluated: widget->parentWidget()->rect().intersects(geom)
0
324 if (mode == Center)
never evaluated: mode == Center
0
325 widget->move(geom.topLeft());
never executed: widget->move(geom.topLeft());
0
326 else -
327 widget->setGeometry(geom);
never executed: widget->setGeometry(geom);
0
328 } -
329}
never executed: }
0
330 -
331void QWidgetResizeHandler::setMouseCursor(MousePosition m) -
332{ -
333#ifdef QT_NO_CURSOR -
334 Q_UNUSED(m); -
335#else -
336 QObjectList children = widget->children();
executed (the execution status of this line is deduced): QObjectList children = widget->children();
-
337 for (int i = 0; i < children.size(); ++i) {
evaluated: i < children.size()
TRUEFALSE
yes
Evaluation Count:180
yes
Evaluation Count:39
39-180
338 if (QWidget *w = qobject_cast<QWidget*>(children.at(i))) {
evaluated: QWidget *w = qobject_cast<QWidget*>(children.at(i))
TRUEFALSE
yes
Evaluation Count:84
yes
Evaluation Count:96
84-96
339 if (!w->testAttribute(Qt::WA_SetCursor)) {
evaluated: !w->testAttribute(Qt::WA_SetCursor)
TRUEFALSE
yes
Evaluation Count:57
yes
Evaluation Count:27
27-57
340 w->setCursor(Qt::ArrowCursor);
executed (the execution status of this line is deduced): w->setCursor(Qt::ArrowCursor);
-
341 }
executed: }
Execution Count:57
57
342 }
executed: }
Execution Count:84
84
343 }
executed: }
Execution Count:180
180
344 -
345 switch (m) { -
346 case TopLeft: -
347 case BottomRight: -
348 widget->setCursor(Qt::SizeFDiagCursor);
never executed (the execution status of this line is deduced): widget->setCursor(Qt::SizeFDiagCursor);
-
349 break;
never executed: break;
0
350 case BottomLeft: -
351 case TopRight: -
352 widget->setCursor(Qt::SizeBDiagCursor);
never executed (the execution status of this line is deduced): widget->setCursor(Qt::SizeBDiagCursor);
-
353 break;
never executed: break;
0
354 case Top: -
355 case Bottom: -
356 widget->setCursor(Qt::SizeVerCursor);
never executed (the execution status of this line is deduced): widget->setCursor(Qt::SizeVerCursor);
-
357 break;
never executed: break;
0
358 case Left: -
359 case Right: -
360 widget->setCursor(Qt::SizeHorCursor);
never executed (the execution status of this line is deduced): widget->setCursor(Qt::SizeHorCursor);
-
361 break;
never executed: break;
0
362 default: -
363 widget->setCursor(Qt::ArrowCursor);
executed (the execution status of this line is deduced): widget->setCursor(Qt::ArrowCursor);
-
364 break;
executed: break;
Execution Count:39
39
365 } -
366#endif // QT_NO_CURSOR -
367}
executed: }
Execution Count:39
39
368 -
369void QWidgetResizeHandler::keyPressEvent(QKeyEvent * e) -
370{ -
371 if (!isMove() && !isResize())
never evaluated: !isMove()
never evaluated: !isResize()
0
372 return;
never executed: return;
0
373 bool is_control = e->modifiers() & Qt::ControlModifier;
never executed (the execution status of this line is deduced): bool is_control = e->modifiers() & Qt::ControlModifier;
-
374 int delta = is_control?1:8;
never evaluated: is_control
0
375 QPoint pos = QCursor::pos();
never executed (the execution status of this line is deduced): QPoint pos = QCursor::pos();
-
376 switch (e->key()) { -
377 case Qt::Key_Left: -
378 pos.rx() -= delta;
never executed (the execution status of this line is deduced): pos.rx() -= delta;
-
379 if (pos.x() <= QApplication::desktop()->geometry().left()) {
never evaluated: pos.x() <= QApplication::desktop()->geometry().left()
0
380 if (mode == TopLeft || mode == BottomLeft) {
never evaluated: mode == TopLeft
never evaluated: mode == BottomLeft
0
381 moveOffset.rx() += delta;
never executed (the execution status of this line is deduced): moveOffset.rx() += delta;
-
382 invertedMoveOffset.rx() += delta;
never executed (the execution status of this line is deduced): invertedMoveOffset.rx() += delta;
-
383 } else {
never executed: }
0
384 moveOffset.rx() -= delta;
never executed (the execution status of this line is deduced): moveOffset.rx() -= delta;
-
385 invertedMoveOffset.rx() -= delta;
never executed (the execution status of this line is deduced): invertedMoveOffset.rx() -= delta;
-
386 }
never executed: }
0
387 } -
388 if (isResize() && !resizeHorizontalDirectionFixed) {
never evaluated: isResize()
never evaluated: !resizeHorizontalDirectionFixed
0
389 resizeHorizontalDirectionFixed = true;
never executed (the execution status of this line is deduced): resizeHorizontalDirectionFixed = true;
-
390 if (mode == BottomRight)
never evaluated: mode == BottomRight
0
391 mode = BottomLeft;
never executed: mode = BottomLeft;
0
392 else if (mode == TopRight)
never evaluated: mode == TopRight
0
393 mode = TopLeft;
never executed: mode = TopLeft;
0
394#ifndef QT_NO_CURSOR -
395 setMouseCursor(mode);
never executed (the execution status of this line is deduced): setMouseCursor(mode);
-
396 widget->grabMouse(widget->cursor());
never executed (the execution status of this line is deduced): widget->grabMouse(widget->cursor());
-
397#else -
398 widget->grabMouse(); -
399#endif -
400 }
never executed: }
0
401 break;
never executed: break;
0
402 case Qt::Key_Right: -
403 pos.rx() += delta;
never executed (the execution status of this line is deduced): pos.rx() += delta;
-
404 if (pos.x() >= QApplication::desktop()->geometry().right()) {
never evaluated: pos.x() >= QApplication::desktop()->geometry().right()
0
405 if (mode == TopRight || mode == BottomRight) {
never evaluated: mode == TopRight
never evaluated: mode == BottomRight
0
406 moveOffset.rx() += delta;
never executed (the execution status of this line is deduced): moveOffset.rx() += delta;
-
407 invertedMoveOffset.rx() += delta;
never executed (the execution status of this line is deduced): invertedMoveOffset.rx() += delta;
-
408 } else {
never executed: }
0
409 moveOffset.rx() -= delta;
never executed (the execution status of this line is deduced): moveOffset.rx() -= delta;
-
410 invertedMoveOffset.rx() -= delta;
never executed (the execution status of this line is deduced): invertedMoveOffset.rx() -= delta;
-
411 }
never executed: }
0
412 } -
413 if (isResize() && !resizeHorizontalDirectionFixed) {
never evaluated: isResize()
never evaluated: !resizeHorizontalDirectionFixed
0
414 resizeHorizontalDirectionFixed = true;
never executed (the execution status of this line is deduced): resizeHorizontalDirectionFixed = true;
-
415 if (mode == BottomLeft)
never evaluated: mode == BottomLeft
0
416 mode = BottomRight;
never executed: mode = BottomRight;
0
417 else if (mode == TopLeft)
never evaluated: mode == TopLeft
0
418 mode = TopRight;
never executed: mode = TopRight;
0
419#ifndef QT_NO_CURSOR -
420 setMouseCursor(mode);
never executed (the execution status of this line is deduced): setMouseCursor(mode);
-
421 widget->grabMouse(widget->cursor());
never executed (the execution status of this line is deduced): widget->grabMouse(widget->cursor());
-
422#else -
423 widget->grabMouse(); -
424#endif -
425 }
never executed: }
0
426 break;
never executed: break;
0
427 case Qt::Key_Up: -
428 pos.ry() -= delta;
never executed (the execution status of this line is deduced): pos.ry() -= delta;
-
429 if (pos.y() <= QApplication::desktop()->geometry().top()) {
never evaluated: pos.y() <= QApplication::desktop()->geometry().top()
0
430 if (mode == TopLeft || mode == TopRight) {
never evaluated: mode == TopLeft
never evaluated: mode == TopRight
0
431 moveOffset.ry() += delta;
never executed (the execution status of this line is deduced): moveOffset.ry() += delta;
-
432 invertedMoveOffset.ry() += delta;
never executed (the execution status of this line is deduced): invertedMoveOffset.ry() += delta;
-
433 } else {
never executed: }
0
434 moveOffset.ry() -= delta;
never executed (the execution status of this line is deduced): moveOffset.ry() -= delta;
-
435 invertedMoveOffset.ry() -= delta;
never executed (the execution status of this line is deduced): invertedMoveOffset.ry() -= delta;
-
436 }
never executed: }
0
437 } -
438 if (isResize() && !resizeVerticalDirectionFixed) {
never evaluated: isResize()
never evaluated: !resizeVerticalDirectionFixed
0
439 resizeVerticalDirectionFixed = true;
never executed (the execution status of this line is deduced): resizeVerticalDirectionFixed = true;
-
440 if (mode == BottomLeft)
never evaluated: mode == BottomLeft
0
441 mode = TopLeft;
never executed: mode = TopLeft;
0
442 else if (mode == BottomRight)
never evaluated: mode == BottomRight
0
443 mode = TopRight;
never executed: mode = TopRight;
0
444#ifndef QT_NO_CURSOR -
445 setMouseCursor(mode);
never executed (the execution status of this line is deduced): setMouseCursor(mode);
-
446 widget->grabMouse(widget->cursor());
never executed (the execution status of this line is deduced): widget->grabMouse(widget->cursor());
-
447#else -
448 widget->grabMouse(); -
449#endif -
450 }
never executed: }
0
451 break;
never executed: break;
0
452 case Qt::Key_Down: -
453 pos.ry() += delta;
never executed (the execution status of this line is deduced): pos.ry() += delta;
-
454 if (pos.y() >= QApplication::desktop()->geometry().bottom()) {
never evaluated: pos.y() >= QApplication::desktop()->geometry().bottom()
0
455 if (mode == BottomLeft || mode == BottomRight) {
never evaluated: mode == BottomLeft
never evaluated: mode == BottomRight
0
456 moveOffset.ry() += delta;
never executed (the execution status of this line is deduced): moveOffset.ry() += delta;
-
457 invertedMoveOffset.ry() += delta;
never executed (the execution status of this line is deduced): invertedMoveOffset.ry() += delta;
-
458 } else {
never executed: }
0
459 moveOffset.ry() -= delta;
never executed (the execution status of this line is deduced): moveOffset.ry() -= delta;
-
460 invertedMoveOffset.ry() -= delta;
never executed (the execution status of this line is deduced): invertedMoveOffset.ry() -= delta;
-
461 }
never executed: }
0
462 } -
463 if (isResize() && !resizeVerticalDirectionFixed) {
never evaluated: isResize()
never evaluated: !resizeVerticalDirectionFixed
0
464 resizeVerticalDirectionFixed = true;
never executed (the execution status of this line is deduced): resizeVerticalDirectionFixed = true;
-
465 if (mode == TopLeft)
never evaluated: mode == TopLeft
0
466 mode = BottomLeft;
never executed: mode = BottomLeft;
0
467 else if (mode == TopRight)
never evaluated: mode == TopRight
0
468 mode = BottomRight;
never executed: mode = BottomRight;
0
469#ifndef QT_NO_CURSOR -
470 setMouseCursor(mode);
never executed (the execution status of this line is deduced): setMouseCursor(mode);
-
471 widget->grabMouse(widget->cursor());
never executed (the execution status of this line is deduced): widget->grabMouse(widget->cursor());
-
472#else -
473 widget->grabMouse(); -
474#endif -
475 }
never executed: }
0
476 break;
never executed: break;
0
477 case Qt::Key_Space: -
478 case Qt::Key_Return: -
479 case Qt::Key_Enter: -
480 case Qt::Key_Escape: -
481 moveResizeMode = false;
never executed (the execution status of this line is deduced): moveResizeMode = false;
-
482 widget->releaseMouse();
never executed (the execution status of this line is deduced): widget->releaseMouse();
-
483 widget->releaseKeyboard();
never executed (the execution status of this line is deduced): widget->releaseKeyboard();
-
484 buttonDown = false;
never executed (the execution status of this line is deduced): buttonDown = false;
-
485 break;
never executed: break;
0
486 default: -
487 return;
never executed: return;
0
488 } -
489 QCursor::setPos(pos);
never executed (the execution status of this line is deduced): QCursor::setPos(pos);
-
490}
never executed: }
0
491 -
492 -
493void QWidgetResizeHandler::doResize() -
494{ -
495 if (!activeForResize)
never evaluated: !activeForResize
0
496 return;
never executed: return;
0
497 -
498 moveResizeMode = true;
never executed (the execution status of this line is deduced): moveResizeMode = true;
-
499 moveOffset = widget->mapFromGlobal(QCursor::pos());
never executed (the execution status of this line is deduced): moveOffset = widget->mapFromGlobal(QCursor::pos());
-
500 if (moveOffset.x() < widget->width()/2) {
never evaluated: moveOffset.x() < widget->width()/2
0
501 if (moveOffset.y() < widget->height()/2)
never evaluated: moveOffset.y() < widget->height()/2
0
502 mode = TopLeft;
never executed: mode = TopLeft;
0
503 else -
504 mode = BottomLeft;
never executed: mode = BottomLeft;
0
505 } else { -
506 if (moveOffset.y() < widget->height()/2)
never evaluated: moveOffset.y() < widget->height()/2
0
507 mode = TopRight;
never executed: mode = TopRight;
0
508 else -
509 mode = BottomRight;
never executed: mode = BottomRight;
0
510 } -
511 invertedMoveOffset = widget->rect().bottomRight() - moveOffset;
never executed (the execution status of this line is deduced): invertedMoveOffset = widget->rect().bottomRight() - moveOffset;
-
512#ifndef QT_NO_CURSOR -
513 setMouseCursor(mode);
never executed (the execution status of this line is deduced): setMouseCursor(mode);
-
514 widget->grabMouse(widget->cursor() );
never executed (the execution status of this line is deduced): widget->grabMouse(widget->cursor() );
-
515#else -
516 widget->grabMouse(); -
517#endif -
518 widget->grabKeyboard();
never executed (the execution status of this line is deduced): widget->grabKeyboard();
-
519 resizeHorizontalDirectionFixed = false;
never executed (the execution status of this line is deduced): resizeHorizontalDirectionFixed = false;
-
520 resizeVerticalDirectionFixed = false;
never executed (the execution status of this line is deduced): resizeVerticalDirectionFixed = false;
-
521}
never executed: }
0
522 -
523void QWidgetResizeHandler::doMove() -
524{ -
525 if (!activeForMove)
never evaluated: !activeForMove
0
526 return;
never executed: return;
0
527 -
528 mode = Center;
never executed (the execution status of this line is deduced): mode = Center;
-
529 moveResizeMode = true;
never executed (the execution status of this line is deduced): moveResizeMode = true;
-
530 moveOffset = widget->mapFromGlobal(QCursor::pos());
never executed (the execution status of this line is deduced): moveOffset = widget->mapFromGlobal(QCursor::pos());
-
531 invertedMoveOffset = widget->rect().bottomRight() - moveOffset;
never executed (the execution status of this line is deduced): invertedMoveOffset = widget->rect().bottomRight() - moveOffset;
-
532#ifndef QT_NO_CURSOR -
533 widget->grabMouse(Qt::SizeAllCursor);
never executed (the execution status of this line is deduced): widget->grabMouse(Qt::SizeAllCursor);
-
534#else -
535 widget->grabMouse(); -
536#endif -
537 widget->grabKeyboard();
never executed (the execution status of this line is deduced): widget->grabKeyboard();
-
538}
never executed: }
0
539 -
540QT_END_NAMESPACE -
541 -
542#endif //QT_NO_RESIZEHANDLER -
543 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial