Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window); | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | void QToolBarPrivate::init() | - |
22 | { | - |
23 | QToolBar * const q = q_func(); | - |
24 | q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); | - |
25 | q->setBackgroundRole(QPalette::Button); | - |
26 | q->setAttribute(Qt::WA_Hover); | - |
27 | q->setAttribute(Qt::WA_X11NetWmWindowTypeToolBar); | - |
28 | | - |
29 | QStyle *style = q->style(); | - |
30 | int e = style->pixelMetric(QStyle::PM_ToolBarIconSize, 0, q); | - |
31 | iconSize = QSize(e, e); | - |
32 | | - |
33 | layout = new QToolBarLayout(q); | - |
34 | layout->updateMarginAndSpacing(); | - |
35 | toggleViewAction = new QAction(q); | - |
36 | toggleViewAction->setCheckable(true); | - |
37 | q->setMovable(q->style()->styleHint(QStyle::SH_ToolBar_Movable, 0, q )); | - |
38 | QObject::connect(toggleViewAction, "2""triggered(bool)", q, "1""_q_toggleView(bool)"); | - |
39 | } executed: } Execution Count:16 | 16 |
40 | | - |
41 | void QToolBarPrivate::_q_toggleView(bool b) | - |
42 | { | - |
43 | QToolBar * const q = q_func(); | - |
44 | if (b == q->isHidden()) { never evaluated: b == q->isHidden() | 0 |
45 | if (b) | 0 |
46 | q->show(); never executed: q->show(); | 0 |
47 | else | - |
48 | q->close(); never executed: q->close(); | 0 |
49 | } | - |
50 | } | 0 |
51 | | - |
52 | void QToolBarPrivate::_q_updateIconSize(const QSize &sz) | - |
53 | { | - |
54 | QToolBar * const q = q_func(); | - |
55 | if (!explicitIconSize) { partially evaluated: !explicitIconSize yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 |
56 | | - |
57 | q->setIconSize(sz); | - |
58 | explicitIconSize = false; | - |
59 | } executed: } Execution Count:2 | 2 |
60 | } executed: } Execution Count:2 | 2 |
61 | | - |
62 | void QToolBarPrivate::_q_updateToolButtonStyle(Qt::ToolButtonStyle style) | - |
63 | { | - |
64 | QToolBar * const q = q_func(); | - |
65 | if (!explicitToolButtonStyle) { partially evaluated: !explicitToolButtonStyle yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 |
66 | q->setToolButtonStyle(style); | - |
67 | explicitToolButtonStyle = false; | - |
68 | } executed: } Execution Count:2 | 2 |
69 | } executed: } Execution Count:2 | 2 |
70 | | - |
71 | void QToolBarPrivate::updateWindowFlags(bool floating, bool unplug) | - |
72 | { | - |
73 | QToolBar * const q = q_func(); | - |
74 | Qt::WindowFlags flags = floating ? Qt::Tool : Qt::Widget; partially evaluated: floating no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
75 | | - |
76 | flags |= Qt::FramelessWindowHint; | - |
77 | | - |
78 | if (unplug) { partially evaluated: unplug no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
79 | flags |= Qt::X11BypassWindowManagerHint; | - |
80 | | - |
81 | | - |
82 | | - |
83 | } | 0 |
84 | | - |
85 | q->setWindowFlags(flags); | - |
86 | } executed: } Execution Count:2 | 2 |
87 | | - |
88 | void QToolBarPrivate::setWindowState(bool floating, bool unplug, const QRect &rect) | - |
89 | { | - |
90 | QToolBar * const q = q_func(); | - |
91 | bool visible = !q->isHidden(); | - |
92 | bool wasFloating = q->isFloating(); | - |
93 | | - |
94 | q->hide(); | - |
95 | | - |
96 | updateWindowFlags(floating, unplug); | - |
97 | | - |
98 | if (floating != wasFloating) never evaluated: floating != wasFloating | 0 |
99 | layout->checkUsePopupMenu(); never executed: layout->checkUsePopupMenu(); | 0 |
100 | | - |
101 | if (!rect.isNull()) never evaluated: !rect.isNull() | 0 |
102 | q->setGeometry(rect); never executed: q->setGeometry(rect); | 0 |
103 | | - |
104 | if (visible) | 0 |
105 | q->show(); never executed: q->show(); | 0 |
106 | | - |
107 | if (floating != wasFloating) never evaluated: floating != wasFloating | 0 |
108 | q->topLevelChanged(floating); never executed: q->topLevelChanged(floating); | 0 |
109 | } | 0 |
110 | | - |
111 | void QToolBarPrivate::initDrag(const QPoint &pos) | - |
112 | { | - |
113 | QToolBar * const q = q_func(); | - |
114 | | - |
115 | if (state != 0) never evaluated: state != 0 | 0 |
116 | return; | 0 |
117 | | - |
118 | QMainWindow *win = qobject_cast<QMainWindow*>(parent); | - |
119 | qt_noop(); | - |
120 | QMainWindowLayout *layout = qt_mainwindow_layout(win); | - |
121 | qt_noop(); | - |
122 | if (layout->pluggingWidget != 0) never evaluated: layout->pluggingWidget != 0 | 0 |
123 | return; | 0 |
124 | | - |
125 | state = new DragState; | - |
126 | state->pressPos = pos; | - |
127 | state->dragging = false; | - |
128 | state->moving = false; | - |
129 | state->widgetItem = 0; | - |
130 | | - |
131 | if (q->isRightToLeft()) never evaluated: q->isRightToLeft() | 0 |
132 | state->pressPos = QPoint(q->width() - state->pressPos.x(), state->pressPos.y()); never executed: state->pressPos = QPoint(q->width() - state->pressPos.x(), state->pressPos.y()); | 0 |
133 | } | 0 |
134 | | - |
135 | void QToolBarPrivate::startDrag(bool moving) | - |
136 | { | - |
137 | QToolBar * const q = q_func(); | - |
138 | | - |
139 | qt_noop(); | - |
140 | | - |
141 | if ((moving && state->moving) || state->dragging) never evaluated: state->moving never evaluated: state->dragging | 0 |
142 | return; | 0 |
143 | | - |
144 | QMainWindow *win = qobject_cast<QMainWindow*>(parent); | - |
145 | qt_noop(); | - |
146 | QMainWindowLayout *layout = qt_mainwindow_layout(win); | - |
147 | qt_noop(); | - |
148 | | - |
149 | if (!moving) { | 0 |
150 | state->widgetItem = layout->unplug(q); | - |
151 | qt_noop(); | - |
152 | } | 0 |
153 | state->dragging = !moving; | - |
154 | state->moving = moving; | - |
155 | } | 0 |
156 | | - |
157 | void QToolBarPrivate::endDrag() | - |
158 | { | - |
159 | QToolBar * const q = q_func(); | - |
160 | qt_noop(); | - |
161 | | - |
162 | q->releaseMouse(); | - |
163 | | - |
164 | if (state->dragging) { never evaluated: state->dragging | 0 |
165 | QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget())); | - |
166 | qt_noop(); | - |
167 | | - |
168 | if (!layout->plug(state->widgetItem)) { never evaluated: !layout->plug(state->widgetItem) | 0 |
169 | if (q->isFloatable()) { never evaluated: q->isFloatable() | 0 |
170 | layout->restore(); | - |
171 | | - |
172 | | - |
173 | | - |
174 | | - |
175 | q->activateWindow(); | - |
176 | } else { | 0 |
177 | layout->revert(state->widgetItem); | - |
178 | } | 0 |
179 | } | - |
180 | } | 0 |
181 | | - |
182 | delete state; | - |
183 | state = 0; | - |
184 | } | 0 |
185 | | - |
186 | bool QToolBarPrivate::mousePressEvent(QMouseEvent *event) | - |
187 | { | - |
188 | QToolBar * const q = q_func(); | - |
189 | QStyleOptionToolBar opt; | - |
190 | q->initStyleOption(&opt); | - |
191 | if (q->style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, q).contains(event->pos()) == false) { never evaluated: q->style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, q).contains(event->pos()) == false | 0 |
192 | return false; never executed: return false; | 0 |
193 | } | - |
194 | | - |
195 | if (event->button() != Qt::LeftButton) never evaluated: event->button() != Qt::LeftButton | 0 |
196 | return true; never executed: return true; | 0 |
197 | | - |
198 | if (!layout->movable()) never evaluated: !layout->movable() | 0 |
199 | return true; never executed: return true; | 0 |
200 | | - |
201 | initDrag(event->pos()); | - |
202 | return true; never executed: return true; | 0 |
203 | } | - |
204 | | - |
205 | bool QToolBarPrivate::mouseReleaseEvent(QMouseEvent*) | - |
206 | { | - |
207 | if (state != 0) { never evaluated: state != 0 | 0 |
208 | endDrag(); | - |
209 | return true; never executed: return true; | 0 |
210 | } else { | - |
211 | | - |
212 | | - |
213 | | - |
214 | | - |
215 | | - |
216 | | - |
217 | | - |
218 | return false; never executed: return false; | 0 |
219 | } | - |
220 | } | - |
221 | | - |
222 | bool QToolBarPrivate::mouseMoveEvent(QMouseEvent *event) | - |
223 | { | - |
224 | QToolBar * const q = q_func(); | - |
225 | | - |
226 | if (!state) { | 0 |
227 | return false; never executed: return false; | 0 |
228 | } | - |
229 | | - |
230 | QMainWindow *win = qobject_cast<QMainWindow*>(parent); | - |
231 | if (win == 0) never evaluated: win == 0 | 0 |
232 | return true; never executed: return true; | 0 |
233 | | - |
234 | QMainWindowLayout *layout = qt_mainwindow_layout(win); | - |
235 | qt_noop(); | - |
236 | | - |
237 | if (layout->pluggingWidget == 0 never evaluated: layout->pluggingWidget == 0 | 0 |
238 | && (event->pos() - state->pressPos).manhattanLength() > QApplication::startDragDistance()) { never evaluated: (event->pos() - state->pressPos).manhattanLength() > QApplication::startDragDistance() | 0 |
239 | const bool wasDragging = state->dragging; | - |
240 | const bool moving = !q->isWindow() && (orientation == Qt::Vertical ? never evaluated: !q->isWindow() never evaluated: orientation == Qt::Vertical | 0 |
241 | event->x() >= 0 && event->x() < q->width() : | - |
242 | event->y() >= 0 && event->y() < q->height()); | - |
243 | | - |
244 | startDrag(moving); | - |
245 | if (!moving && !wasDragging) { never evaluated: !wasDragging | 0 |
246 | | - |
247 | | - |
248 | | - |
249 | q->grabMouse(); | - |
250 | | - |
251 | } | 0 |
252 | } | 0 |
253 | | - |
254 | if (state->dragging) { never evaluated: state->dragging | 0 |
255 | QPoint pos = event->globalPos(); | - |
256 | | - |
257 | | - |
258 | if (q->isLeftToRight()) never evaluated: q->isLeftToRight() | 0 |
259 | pos -= state->pressPos; never executed: pos -= state->pressPos; | 0 |
260 | else | - |
261 | pos += QPoint(state->pressPos.x() - q->width(), -state->pressPos.y()); never executed: pos += QPoint(state->pressPos.x() - q->width(), -state->pressPos.y()); | 0 |
262 | | - |
263 | q->move(pos); | - |
264 | layout->hover(state->widgetItem, event->globalPos()); | - |
265 | } else if (state->moving) { never evaluated: state->moving | 0 |
266 | | - |
267 | const QPoint rtl(q->width() - state->pressPos.x(), state->pressPos.y()); | - |
268 | const QPoint globalPressPos = q->mapToGlobal(q->isRightToLeft() ? rtl : state->pressPos); | - |
269 | int pos = 0; | - |
270 | | - |
271 | QPoint delta = event->globalPos() - globalPressPos; | - |
272 | if (orientation == Qt::Vertical) { never evaluated: orientation == Qt::Vertical | 0 |
273 | pos = q->y() + delta.y(); | - |
274 | } else { | 0 |
275 | if (q->isRightToLeft()) { never evaluated: q->isRightToLeft() | 0 |
276 | pos = win->width() - q->width() - q->x() - delta.x(); | - |
277 | } else { | 0 |
278 | pos = q->x() + delta.x(); | - |
279 | } | 0 |
280 | } | - |
281 | | - |
282 | layout->moveToolBar(q, pos); | - |
283 | } | 0 |
284 | return true; never executed: return true; | 0 |
285 | } | - |
286 | | - |
287 | void QToolBarPrivate::unplug(const QRect &_r) | - |
288 | { | - |
289 | QToolBar * const q = q_func(); | - |
290 | QRect r = _r; | - |
291 | r.moveTopLeft(q->mapToGlobal(QPoint(0, 0))); | - |
292 | setWindowState(true, true, r); | - |
293 | layout->setExpanded(false); | - |
294 | } | 0 |
295 | | - |
296 | void QToolBarPrivate::plug(const QRect &r) | - |
297 | { | - |
298 | setWindowState(false, false, r); | - |
299 | } | 0 |
300 | QToolBar::QToolBar(QWidget *parent) | - |
301 | : QWidget(*new QToolBarPrivate, parent, 0) | - |
302 | { | - |
303 | QToolBarPrivate * const d = d_func(); | - |
304 | d->init(); | - |
305 | } executed: } Execution Count:16 | 16 |
306 | QToolBar::QToolBar(const QString &title, QWidget *parent) | - |
307 | : QWidget(*new QToolBarPrivate, parent, 0) | - |
308 | { | - |
309 | QToolBarPrivate * const d = d_func(); | - |
310 | d->init(); | - |
311 | setWindowTitle(title); | - |
312 | } | 0 |
313 | | - |
314 | | - |
315 | | - |
316 | | - |
317 | | - |
318 | QToolBar::~QToolBar() | - |
319 | { | - |
320 | | - |
321 | QMainWindow *mainwindow = qobject_cast<QMainWindow *>(parentWidget()); | - |
322 | if (mainwindow) { evaluated: mainwindow yes Evaluation Count:1 | yes Evaluation Count:15 |
| 1-15 |
323 | | - |
324 | | - |
325 | | - |
326 | | - |
327 | | - |
328 | | - |
329 | } executed: } Execution Count:1 | 1 |
330 | } executed: } Execution Count:16 | 16 |
331 | void QToolBar::setMovable(bool movable) | - |
332 | { | - |
333 | QToolBarPrivate * const d = d_func(); | - |
334 | if (!movable == !d->movable) partially evaluated: !movable == !d->movable yes Evaluation Count:16 | no Evaluation Count:0 |
| 0-16 |
335 | return; executed: return; Execution Count:16 | 16 |
336 | d->movable = movable; | - |
337 | d->layout->invalidate(); | - |
338 | movableChanged(d->movable); | - |
339 | } | 0 |
340 | | - |
341 | bool QToolBar::isMovable() const | - |
342 | { | - |
343 | const QToolBarPrivate * const d = d_func(); | - |
344 | return d->movable; executed: return d->movable; Execution Count:250 | 250 |
345 | } | - |
346 | | - |
347 | | - |
348 | | - |
349 | | - |
350 | | - |
351 | | - |
352 | | - |
353 | bool QToolBar::isFloatable() const | - |
354 | { | - |
355 | const QToolBarPrivate * const d = d_func(); | - |
356 | return d->floatable; never executed: return d->floatable; | 0 |
357 | } | - |
358 | | - |
359 | void QToolBar::setFloatable(bool floatable) | - |
360 | { | - |
361 | QToolBarPrivate * const d = d_func(); | - |
362 | d->floatable = floatable; | - |
363 | } | 0 |
364 | bool QToolBar::isFloating() const | - |
365 | { | - |
366 | return isWindow(); executed: return isWindow(); Execution Count:11 | 11 |
367 | } | - |
368 | void QToolBar::setAllowedAreas(Qt::ToolBarAreas areas) | - |
369 | { | - |
370 | QToolBarPrivate * const d = d_func(); | - |
371 | areas &= Qt::ToolBarArea_Mask; | - |
372 | if (areas == d->allowedAreas) never evaluated: areas == d->allowedAreas | 0 |
373 | return; | 0 |
374 | d->allowedAreas = areas; | - |
375 | allowedAreasChanged(d->allowedAreas); | - |
376 | } | 0 |
377 | | - |
378 | Qt::ToolBarAreas QToolBar::allowedAreas() const | - |
379 | { | - |
380 | const QToolBarPrivate * const d = d_func(); | - |
381 | | - |
382 | | - |
383 | | - |
384 | | - |
385 | | - |
386 | | - |
387 | return d->allowedAreas; never executed: return d->allowedAreas; | 0 |
388 | } | - |
389 | void QToolBar::setOrientation(Qt::Orientation orientation) | - |
390 | { | - |
391 | QToolBarPrivate * const d = d_func(); | - |
392 | if (orientation == d->orientation) partially evaluated: orientation == d->orientation yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 |
393 | return; executed: return; Execution Count:2 | 2 |
394 | | - |
395 | d->orientation = orientation; | - |
396 | | - |
397 | if (orientation == Qt::Vertical) never evaluated: orientation == Qt::Vertical | 0 |
398 | setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred)); never executed: setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred)); | 0 |
399 | else | - |
400 | setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); never executed: setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); | 0 |
401 | | - |
402 | d->layout->invalidate(); | - |
403 | d->layout->activate(); | - |
404 | | - |
405 | orientationChanged(d->orientation); | - |
406 | } | 0 |
407 | | - |
408 | Qt::Orientation QToolBar::orientation() const | - |
409 | { const QToolBarPrivate * const d = d_func(); return d->orientation; } executed: return d->orientation; Execution Count:323 | 323 |
410 | QSize QToolBar::iconSize() const | - |
411 | { const QToolBarPrivate * const d = d_func(); return d->iconSize; } executed: return d->iconSize; Execution Count:9 | 9 |
412 | | - |
413 | void QToolBar::setIconSize(const QSize &iconSize) | - |
414 | { | - |
415 | QToolBarPrivate * const d = d_func(); | - |
416 | QSize sz = iconSize; | - |
417 | if (!sz.isValid()) { partially evaluated: !sz.isValid() no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
418 | QMainWindow *mw = qobject_cast<QMainWindow *>(parentWidget()); | - |
419 | if (mw && mw->layout()) { never evaluated: mw->layout() | 0 |
420 | QLayout *layout = mw->layout(); | - |
421 | int i = 0; | - |
422 | QLayoutItem *item = 0; | - |
423 | do { | - |
424 | item = layout->itemAt(i++); | - |
425 | if (item && (item->widget() == this)) never evaluated: (item->widget() == this) | 0 |
426 | sz = mw->iconSize(); never executed: sz = mw->iconSize(); | 0 |
427 | } while (!sz.isValid() && item != 0); never evaluated: !sz.isValid() never evaluated: item != 0 | 0 |
428 | } | 0 |
429 | } | 0 |
430 | if (!sz.isValid()) { partially evaluated: !sz.isValid() no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
431 | const int metric = style()->pixelMetric(QStyle::PM_ToolBarIconSize, 0, this); | - |
432 | sz = QSize(metric, metric); | - |
433 | } | 0 |
434 | if (d->iconSize != sz) { partially evaluated: d->iconSize != sz no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
435 | d->iconSize = sz; | - |
436 | setMinimumSize(0, 0); | - |
437 | iconSizeChanged(d->iconSize); | - |
438 | } | 0 |
439 | d->explicitIconSize = iconSize.isValid(); | - |
440 | | - |
441 | d->layout->invalidate(); | - |
442 | } executed: } Execution Count:2 | 2 |
443 | Qt::ToolButtonStyle QToolBar::toolButtonStyle() const | - |
444 | { const QToolBarPrivate * const d = d_func(); return d->toolButtonStyle; } executed: return d->toolButtonStyle; Execution Count:3 | 3 |
445 | | - |
446 | void QToolBar::setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle) | - |
447 | { | - |
448 | QToolBarPrivate * const d = d_func(); | - |
449 | d->explicitToolButtonStyle = true; | - |
450 | if (d->toolButtonStyle == toolButtonStyle) partially evaluated: d->toolButtonStyle == toolButtonStyle yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 |
451 | return; executed: return; Execution Count:2 | 2 |
452 | d->toolButtonStyle = toolButtonStyle; | - |
453 | setMinimumSize(0, 0); | - |
454 | toolButtonStyleChanged(d->toolButtonStyle); | - |
455 | } | 0 |
456 | | - |
457 | | - |
458 | | - |
459 | | - |
460 | | - |
461 | | - |
462 | void QToolBar::clear() | - |
463 | { | - |
464 | QList<QAction *> actions = this->actions(); | - |
465 | for(int i = 0; i < actions.size(); i++) never evaluated: i < actions.size() | 0 |
466 | removeAction(actions.at(i)); never executed: removeAction(actions.at(i)); | 0 |
467 | } | 0 |
468 | | - |
469 | | - |
470 | | - |
471 | | - |
472 | | - |
473 | | - |
474 | | - |
475 | QAction *QToolBar::addAction(const QString &text) | - |
476 | { | - |
477 | QAction *action = new QAction(text, this); | - |
478 | addAction(action); | - |
479 | return action; never executed: return action; | 0 |
480 | } | - |
481 | | - |
482 | | - |
483 | | - |
484 | | - |
485 | | - |
486 | | - |
487 | | - |
488 | QAction *QToolBar::addAction(const QIcon &icon, const QString &text) | - |
489 | { | - |
490 | QAction *action = new QAction(icon, text, this); | - |
491 | addAction(action); | - |
492 | return action; never executed: return action; | 0 |
493 | } | - |
494 | QAction *QToolBar::addAction(const QString &text, | - |
495 | const QObject *receiver, const char* member) | - |
496 | { | - |
497 | QAction *action = new QAction(text, this); | - |
498 | QObject::connect(action, "2""triggered(bool)", receiver, member); | - |
499 | addAction(action); | - |
500 | return action; never executed: return action; | 0 |
501 | } | - |
502 | QAction *QToolBar::addAction(const QIcon &icon, const QString &text, | - |
503 | const QObject *receiver, const char* member) | - |
504 | { | - |
505 | QAction *action = new QAction(icon, text, this); | - |
506 | QObject::connect(action, "2""triggered(bool)", receiver, member); | - |
507 | addAction(action); | - |
508 | return action; never executed: return action; | 0 |
509 | } | - |
510 | | - |
511 | | - |
512 | | - |
513 | | - |
514 | | - |
515 | | - |
516 | QAction *QToolBar::addSeparator() | - |
517 | { | - |
518 | QAction *action = new QAction(this); | - |
519 | action->setSeparator(true); | - |
520 | addAction(action); | - |
521 | return action; never executed: return action; | 0 |
522 | } | - |
523 | | - |
524 | | - |
525 | | - |
526 | | - |
527 | | - |
528 | | - |
529 | | - |
530 | QAction *QToolBar::insertSeparator(QAction *before) | - |
531 | { | - |
532 | QAction *action = new QAction(this); | - |
533 | action->setSeparator(true); | - |
534 | insertAction(before, action); | - |
535 | return action; never executed: return action; | 0 |
536 | } | - |
537 | QAction *QToolBar::addWidget(QWidget *widget) | - |
538 | { | - |
539 | QWidgetAction *action = new QWidgetAction(this); | - |
540 | action->setDefaultWidget(widget); | - |
541 | action->d_func()->autoCreated = true; | - |
542 | addAction(action); | - |
543 | return action; executed: return action; Execution Count:4 | 4 |
544 | } | - |
545 | QAction *QToolBar::insertWidget(QAction *before, QWidget *widget) | - |
546 | { | - |
547 | QWidgetAction *action = new QWidgetAction(this); | - |
548 | action->setDefaultWidget(widget); | - |
549 | action->d_func()->autoCreated = true; | - |
550 | insertAction(before, action); | - |
551 | return action; never executed: return action; | 0 |
552 | } | - |
553 | | - |
554 | | - |
555 | | - |
556 | | - |
557 | | - |
558 | | - |
559 | | - |
560 | QRect QToolBar::actionGeometry(QAction *action) const | - |
561 | { | - |
562 | const QToolBarPrivate * const d = d_func(); | - |
563 | | - |
564 | int index = d->layout->indexOf(action); | - |
565 | if (index == -1) partially evaluated: index == -1 no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
566 | return QRect(); never executed: return QRect(); | 0 |
567 | return d->layout->itemAt(index)->widget()->geometry(); executed: return d->layout->itemAt(index)->widget()->geometry(); Execution Count:1 | 1 |
568 | } | - |
569 | | - |
570 | | - |
571 | | - |
572 | | - |
573 | | - |
574 | | - |
575 | | - |
576 | QAction *QToolBar::actionAt(const QPoint &p) const | - |
577 | { | - |
578 | const QToolBarPrivate * const d = d_func(); | - |
579 | QWidget *widget = childAt(p); | - |
580 | int index = d->layout->indexOf(widget); | - |
581 | if (index == -1) never evaluated: index == -1 | 0 |
582 | return 0; never executed: return 0; | 0 |
583 | QLayoutItem *item = d->layout->itemAt(index); | - |
584 | return static_cast<QToolBarItem*>(item)->action; never executed: return static_cast<QToolBarItem*>(item)->action; | 0 |
585 | } | - |
586 | void QToolBar::actionEvent(QActionEvent *event) | - |
587 | { | - |
588 | QToolBarPrivate * const d = d_func(); | - |
589 | QAction *action = event->action(); | - |
590 | QWidgetAction *widgetAction = qobject_cast<QWidgetAction *>(action); | - |
591 | | - |
592 | switch (event->type()) { | - |
593 | case QEvent::ActionAdded: { | - |
594 | qt_noop(); | - |
595 | | - |
596 | | - |
597 | | - |
598 | | - |
599 | | - |
600 | | - |
601 | | - |
602 | if (widgetAction != 0 && widgetAction->d_func()->autoCreated) evaluated: widgetAction != 0 yes Evaluation Count:15 | yes Evaluation Count:1 |
evaluated: widgetAction->d_func()->autoCreated yes Evaluation Count:4 | yes Evaluation Count:11 |
| 1-15 |
603 | widgetAction->setParent(this); executed: widgetAction->setParent(this); Execution Count:4 | 4 |
604 | | - |
605 | int index = d->layout->count(); | - |
606 | if (event->before()) { partially evaluated: event->before() no Evaluation Count:0 | yes Evaluation Count:16 |
| 0-16 |
607 | index = d->layout->indexOf(event->before()); | - |
608 | qt_noop(); | - |
609 | } | 0 |
610 | d->layout->insertAction(index, action); | - |
611 | break; executed: break; Execution Count:16 | 16 |
612 | } | - |
613 | | - |
614 | case QEvent::ActionChanged: | - |
615 | d->layout->invalidate(); | - |
616 | break; executed: break; Execution Count:3 | 3 |
617 | | - |
618 | case QEvent::ActionRemoved: { | - |
619 | int index = d->layout->indexOf(action); | - |
620 | if (index != -1) { evaluated: index != -1 yes Evaluation Count:6 | yes Evaluation Count:3 |
| 3-6 |
621 | delete d->layout->takeAt(index); | - |
622 | } executed: } Execution Count:6 | 6 |
623 | break; executed: break; Execution Count:9 | 9 |
624 | } | - |
625 | | - |
626 | default: | - |
627 | qt_noop(); | - |
628 | } | 0 |
629 | } executed: } Execution Count:28 | 28 |
630 | | - |
631 | | - |
632 | void QToolBar::changeEvent(QEvent *event) | - |
633 | { | - |
634 | QToolBarPrivate * const d = d_func(); | - |
635 | switch (event->type()) { | - |
636 | case QEvent::WindowTitleChange: | - |
637 | d->toggleViewAction->setText(windowTitle()); | - |
638 | break; executed: break; Execution Count:1 | 1 |
639 | case QEvent::StyleChange: | - |
640 | d->layout->invalidate(); | - |
641 | if (!d->explicitIconSize) never evaluated: !d->explicitIconSize | 0 |
642 | setIconSize(QSize()); never executed: setIconSize(QSize()); | 0 |
643 | d->layout->updateMarginAndSpacing(); | - |
644 | break; | 0 |
645 | case QEvent::LayoutDirectionChange: | - |
646 | d->layout->invalidate(); | - |
647 | break; | 0 |
648 | default: | - |
649 | break; executed: break; Execution Count:29 | 29 |
650 | } | - |
651 | QWidget::changeEvent(event); | - |
652 | } executed: } Execution Count:30 | 30 |
653 | | - |
654 | | - |
655 | void QToolBar::paintEvent(QPaintEvent *) | - |
656 | { | - |
657 | QToolBarPrivate * const d = d_func(); | - |
658 | | - |
659 | QPainter p(this); | - |
660 | QStyle *style = this->style(); | - |
661 | QStyleOptionToolBar opt; | - |
662 | initStyleOption(&opt); | - |
663 | | - |
664 | if (d->layout->expanded || d->layout->animating || isWindow()) { partially evaluated: d->layout->expanded no Evaluation Count:0 | yes Evaluation Count:7 |
partially evaluated: d->layout->animating no Evaluation Count:0 | yes Evaluation Count:7 |
evaluated: isWindow() yes Evaluation Count:1 | yes Evaluation Count:6 |
| 0-7 |
665 | | - |
666 | | - |
667 | p.fillRect(opt.rect, palette().background()); | - |
668 | style->drawControl(QStyle::CE_ToolBar, &opt, &p, this); | - |
669 | style->drawPrimitive(QStyle::PE_FrameMenu, &opt, &p, this); | - |
670 | } else { executed: } Execution Count:1 | 1 |
671 | style->drawControl(QStyle::CE_ToolBar, &opt, &p, this); | - |
672 | } executed: } Execution Count:6 | 6 |
673 | | - |
674 | opt.rect = style->subElementRect(QStyle::SE_ToolBarHandle, &opt, this); | - |
675 | if (opt.rect.isValid()) evaluated: opt.rect.isValid() yes Evaluation Count:6 | yes Evaluation Count:1 |
| 1-6 |
676 | style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &opt, &p, this); executed: style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &opt, &p, this); Execution Count:6 | 6 |
677 | } executed: } Execution Count:7 | 7 |
678 | | - |
679 | | - |
680 | | - |
681 | | - |
682 | | - |
683 | | - |
684 | | - |
685 | static bool waitForPopup(QToolBar *tb, QWidget *popup) | - |
686 | { | - |
687 | if (popup == 0 || popup->isHidden()) never evaluated: popup == 0 never evaluated: popup->isHidden() | 0 |
688 | return false; never executed: return false; | 0 |
689 | | - |
690 | QWidget *w = popup; | - |
691 | while (w != 0) { | 0 |
692 | if (w == tb) | 0 |
693 | return true; never executed: return true; | 0 |
694 | w = w->parentWidget(); | - |
695 | } | 0 |
696 | | - |
697 | QMenu *menu = qobject_cast<QMenu*>(popup); | - |
698 | if (menu == 0) never evaluated: menu == 0 | 0 |
699 | return false; never executed: return false; | 0 |
700 | | - |
701 | QAction *action = menu->menuAction(); | - |
702 | QList<QWidget*> widgets = action->associatedWidgets(); | - |
703 | for (int i = 0; i < widgets.count(); ++i) { never evaluated: i < widgets.count() | 0 |
704 | if (waitForPopup(tb, widgets.at(i))) never evaluated: waitForPopup(tb, widgets.at(i)) | 0 |
705 | return true; never executed: return true; | 0 |
706 | } | 0 |
707 | | - |
708 | return false; never executed: return false; | 0 |
709 | } | - |
710 | bool QToolBar::event(QEvent *event) | - |
711 | { | - |
712 | QToolBarPrivate * const d = d_func(); | - |
713 | | - |
714 | switch (event->type()) { | - |
715 | case QEvent::Timer: | - |
716 | if (d->waitForPopupTimer.timerId() == static_cast<QTimerEvent*>(event)->timerId()) { never evaluated: d->waitForPopupTimer.timerId() == static_cast<QTimerEvent*>(event)->timerId() | 0 |
717 | QWidget *w = QApplication::activePopupWidget(); | - |
718 | if (!waitForPopup(this, w)) { never evaluated: !waitForPopup(this, w) | 0 |
719 | d->waitForPopupTimer.stop(); | - |
720 | if (!this->underMouse()) never evaluated: !this->underMouse() | 0 |
721 | d->layout->setExpanded(false); never executed: d->layout->setExpanded(false); | 0 |
722 | } | 0 |
723 | } | 0 |
724 | break; | 0 |
725 | case QEvent::Hide: | - |
726 | if (!isHidden()) partially evaluated: !isHidden() yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
727 | break; executed: break; Execution Count:1 | 1 |
728 | | - |
729 | case QEvent::Show: code before this statement never executed: case QEvent::Show: | 0 |
730 | d->toggleViewAction->setChecked(event->type() == QEvent::Show); | - |
731 | visibilityChanged(event->type() == QEvent::Show); | - |
732 | break; executed: break; Execution Count:11 | 11 |
733 | case QEvent::ParentChange: | - |
734 | d->layout->checkUsePopupMenu(); | - |
735 | | - |
736 | | - |
737 | | - |
738 | | - |
739 | break; executed: break; Execution Count:10 | 10 |
740 | | - |
741 | case QEvent::MouseButtonPress: { | - |
742 | if (d->mousePressEvent(static_cast<QMouseEvent*>(event))) never evaluated: d->mousePressEvent(static_cast<QMouseEvent*>(event)) | 0 |
743 | return true; never executed: return true; | 0 |
744 | break; | 0 |
745 | } | - |
746 | case QEvent::MouseButtonRelease: | - |
747 | if (d->mouseReleaseEvent(static_cast<QMouseEvent*>(event))) never evaluated: d->mouseReleaseEvent(static_cast<QMouseEvent*>(event)) | 0 |
748 | return true; never executed: return true; | 0 |
749 | break; | 0 |
750 | case QEvent::HoverEnter: | - |
751 | case QEvent::HoverLeave: | - |
752 | | - |
753 | return true; executed: return true; Execution Count:1 | 1 |
754 | case QEvent::HoverMove: { | - |
755 | | - |
756 | QHoverEvent *e = static_cast<QHoverEvent*>(event); | - |
757 | QStyleOptionToolBar opt; | - |
758 | initStyleOption(&opt); | - |
759 | if (style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, this).contains(e->pos())) never evaluated: style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, this).contains(e->pos()) | 0 |
760 | setCursor(Qt::SizeAllCursor); never executed: setCursor(Qt::SizeAllCursor); | 0 |
761 | else | - |
762 | unsetCursor(); never executed: unsetCursor(); | 0 |
763 | | - |
764 | break; | 0 |
765 | } | - |
766 | case QEvent::MouseMove: | - |
767 | if (d->mouseMoveEvent(static_cast<QMouseEvent*>(event))) never evaluated: d->mouseMoveEvent(static_cast<QMouseEvent*>(event)) | 0 |
768 | return true; never executed: return true; | 0 |
769 | break; | 0 |
770 | case QEvent::Leave: | - |
771 | if (d->state != 0 && d->state->dragging) { never evaluated: d->state != 0 never evaluated: d->state->dragging | 0 |
772 | | - |
773 | | - |
774 | | - |
775 | | - |
776 | | - |
777 | | - |
778 | | - |
779 | } else { | 0 |
780 | if (!d->layout->expanded) never evaluated: !d->layout->expanded | 0 |
781 | break; | 0 |
782 | | - |
783 | QWidget *w = QApplication::activePopupWidget(); | - |
784 | if (waitForPopup(this, w)) { never evaluated: waitForPopup(this, w) | 0 |
785 | d->waitForPopupTimer.start(500, this); | - |
786 | break; | 0 |
787 | } | - |
788 | | - |
789 | d->waitForPopupTimer.stop(); | - |
790 | d->layout->setExpanded(false); | - |
791 | break; | 0 |
792 | } | - |
793 | default: | - |
794 | break; executed: break; Execution Count:285 | 285 |
795 | } | - |
796 | return QWidget::event(event); executed: return QWidget::event(event); Execution Count:307 | 307 |
797 | } | - |
798 | QAction *QToolBar::toggleViewAction() const | - |
799 | { const QToolBarPrivate * const d = d_func(); return d->toggleViewAction; } never executed: return d->toggleViewAction; | 0 |
800 | QWidget *QToolBar::widgetForAction(QAction *action) const | - |
801 | { | - |
802 | const QToolBarPrivate * const d = d_func(); | - |
803 | | - |
804 | int index = d->layout->indexOf(action); | - |
805 | if (index == -1) never evaluated: index == -1 | 0 |
806 | return 0; never executed: return 0; | 0 |
807 | | - |
808 | return d->layout->itemAt(index)->widget(); never executed: return d->layout->itemAt(index)->widget(); | 0 |
809 | } | - |
810 | | - |
811 | extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window); | - |
812 | | - |
813 | | - |
814 | | - |
815 | | - |
816 | void QToolBar::initStyleOption(QStyleOptionToolBar *option) const | - |
817 | { | - |
818 | const QToolBarPrivate * const d = d_func(); | - |
819 | | - |
820 | if (!option) partially evaluated: !option no Evaluation Count:0 | yes Evaluation Count:158 |
| 0-158 |
821 | return; | 0 |
822 | | - |
823 | option->initFrom(this); | - |
824 | if (orientation() == Qt::Horizontal) partially evaluated: orientation() == Qt::Horizontal yes Evaluation Count:158 | no Evaluation Count:0 |
| 0-158 |
825 | option->state |= QStyle::State_Horizontal; executed: option->state |= QStyle::State_Horizontal; Execution Count:158 | 158 |
826 | option->lineWidth = style()->pixelMetric(QStyle::PM_ToolBarFrameWidth, 0, this); | - |
827 | option->features = d->layout->movable() evaluated: d->layout->movable() yes Evaluation Count:33 | yes Evaluation Count:125 |
| 33-125 |
828 | ? QStyleOptionToolBar::Movable | - |
829 | : QStyleOptionToolBar::None; | - |
830 | | - |
831 | option->toolBarArea = Qt::NoToolBarArea; | - |
832 | | - |
833 | | - |
834 | QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parentWidget()); | - |
835 | | - |
836 | if (!mainWindow) evaluated: !mainWindow yes Evaluation Count:125 | yes Evaluation Count:33 |
| 33-125 |
837 | return; executed: return; Execution Count:125 | 125 |
838 | | - |
839 | QMainWindowLayout *layout = qt_mainwindow_layout(mainWindow); | - |
840 | qt_noop(); | - |
841 | | - |
842 | | - |
843 | layout->getStyleOptionInfo(option, const_cast<QToolBar *>(this)); | - |
844 | } executed: } Execution Count:33 | 33 |
845 | | - |
846 | | - |
847 | | - |
848 | | - |
| | |