Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | class QToolButtonPrivate : public QAbstractButtonPrivate | - |
7 | { | - |
8 | inline QToolButton* q_func() { return static_cast<QToolButton *>(q_ptr); } inline const QToolButton* q_func() const { return static_cast<const QToolButton *>(q_ptr); } friend class QToolButton; | - |
9 | public: | - |
10 | void init(); | - |
11 | | - |
12 | void _q_buttonPressed(); | - |
13 | void popupTimerDone(); | - |
14 | void _q_updateButtonDown(); | - |
15 | void _q_menuTriggered(QAction *); | - |
16 | | - |
17 | bool updateHoverControl(const QPoint &pos); | - |
18 | void _q_actionTriggered(); | - |
19 | QStyle::SubControl newHoverControl(const QPoint &pos); | - |
20 | QStyle::SubControl hoverControl; | - |
21 | QRect hoverRect; | - |
22 | QPointer<QAction> menuAction; | - |
23 | QBasicTimer popupTimer; | - |
24 | int delay; | - |
25 | Qt::ArrowType arrowType; | - |
26 | Qt::ToolButtonStyle toolButtonStyle; | - |
27 | QToolButton::ToolButtonPopupMode popupMode; | - |
28 | enum { NoButtonPressed=0, MenuButtonPressed=1, ToolButtonPressed=2 }; | - |
29 | uint buttonPressed : 2; | - |
30 | uint menuButtonDown : 1; | - |
31 | uint autoRaise : 1; | - |
32 | uint repeat : 1; | - |
33 | QAction *defaultAction; | - |
34 | | - |
35 | bool hasMenu() const; | - |
36 | | - |
37 | QList<QAction *> actionsCopy; | - |
38 | | - |
39 | }; | - |
40 | | - |
41 | | - |
42 | bool QToolButtonPrivate::hasMenu() const | - |
43 | { | - |
44 | return ((defaultAction && defaultAction->menu()) | 1845 |
45 | || (menuAction && menuAction->menu()) | 1845 |
46 | || actions.size() > (defaultAction ? 1 : 0)); executed: return ((defaultAction && defaultAction->menu()) || (menuAction && menuAction->menu()) || actions.size() > (defaultAction ? 1 : 0)); Execution Count:1845 | 1845 |
47 | } | - |
48 | QToolButton::QToolButton(QWidget * parent) | - |
49 | : QAbstractButton(*new QToolButtonPrivate, parent) | - |
50 | { | - |
51 | QToolButtonPrivate * const d = d_func(); | - |
52 | d->init(); | - |
53 | } executed: } Execution Count:1530 | 1530 |
54 | | - |
55 | | - |
56 | | - |
57 | | - |
58 | | - |
59 | void QToolButtonPrivate::init() | - |
60 | { | - |
61 | QToolButton * const q = q_func(); | - |
62 | delay = q->style()->styleHint(QStyle::SH_ToolButton_PopupDelay, 0, q); | - |
63 | defaultAction = 0; | - |
64 | | - |
65 | if (qobject_cast<QToolBar*>(parent)) evaluated: qobject_cast<QToolBar*>(parent) yes Evaluation Count:20 | yes Evaluation Count:1510 |
| 20-1510 |
66 | autoRaise = true; executed: autoRaise = true; Execution Count:20 | 20 |
67 | else | - |
68 | | - |
69 | autoRaise = false; executed: autoRaise = false; Execution Count:1510 | 1510 |
70 | arrowType = Qt::NoArrow; | - |
71 | menuButtonDown = false; | - |
72 | popupMode = QToolButton::DelayedPopup; | - |
73 | buttonPressed = QToolButtonPrivate::NoButtonPressed; | - |
74 | | - |
75 | toolButtonStyle = Qt::ToolButtonIconOnly; | - |
76 | hoverControl = QStyle::SC_None; | - |
77 | | - |
78 | q->setFocusPolicy(Qt::TabFocus); | - |
79 | q->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed, | - |
80 | QSizePolicy::ToolButton)); | - |
81 | | - |
82 | | - |
83 | QObject::connect(q, "2""pressed()", q, "1""_q_buttonPressed()"); | - |
84 | | - |
85 | | - |
86 | setLayoutItemMargins(QStyle::SE_ToolButtonLayoutItem); | - |
87 | | - |
88 | } executed: } Execution Count:1530 | 1530 |
89 | void QToolButton::initStyleOption(QStyleOptionToolButton *option) const | - |
90 | { | - |
91 | if (!option) partially evaluated: !option no Evaluation Count:0 | yes Evaluation Count:1762 |
| 0-1762 |
92 | return; | 0 |
93 | | - |
94 | const QToolButtonPrivate * const d = d_func(); | - |
95 | option->initFrom(this); | - |
96 | bool forceNoText = false; | - |
97 | option->iconSize = iconSize(); | - |
98 | | - |
99 | | - |
100 | if (parentWidget()) { evaluated: parentWidget() yes Evaluation Count:1747 | yes Evaluation Count:15 |
| 15-1747 |
101 | if (QToolBar *toolBar = qobject_cast<QToolBar *>(parentWidget())) { evaluated: QToolBar *toolBar = qobject_cast<QToolBar *>(parentWidget()) yes Evaluation Count:6 | yes Evaluation Count:1741 |
| 6-1741 |
102 | option->iconSize = toolBar->iconSize(); | - |
103 | } executed: } Execution Count:6 | 6 |
104 | } executed: } Execution Count:1747 | 1747 |
105 | | - |
106 | | - |
107 | if (!forceNoText) partially evaluated: !forceNoText yes Evaluation Count:1762 | no Evaluation Count:0 |
| 0-1762 |
108 | option->text = d->text; executed: option->text = d->text; Execution Count:1762 | 1762 |
109 | option->icon = d->icon; | - |
110 | option->arrowType = d->arrowType; | - |
111 | if (d->down) evaluated: d->down yes Evaluation Count:244 | yes Evaluation Count:1518 |
| 244-1518 |
112 | option->state |= QStyle::State_Sunken; executed: option->state |= QStyle::State_Sunken; Execution Count:244 | 244 |
113 | if (d->checked) partially evaluated: d->checked no Evaluation Count:0 | yes Evaluation Count:1762 |
| 0-1762 |
114 | option->state |= QStyle::State_On; never executed: option->state |= QStyle::State_On; | 0 |
115 | if (d->autoRaise) evaluated: d->autoRaise yes Evaluation Count:1721 | yes Evaluation Count:41 |
| 41-1721 |
116 | option->state |= QStyle::State_AutoRaise; executed: option->state |= QStyle::State_AutoRaise; Execution Count:1721 | 1721 |
117 | if (!d->checked && !d->down) partially evaluated: !d->checked yes Evaluation Count:1762 | no Evaluation Count:0 |
evaluated: !d->down yes Evaluation Count:1518 | yes Evaluation Count:244 |
| 0-1762 |
118 | option->state |= QStyle::State_Raised; executed: option->state |= QStyle::State_Raised; Execution Count:1518 | 1518 |
119 | | - |
120 | option->subControls = QStyle::SC_ToolButton; | - |
121 | option->activeSubControls = QStyle::SC_None; | - |
122 | | - |
123 | option->features = QStyleOptionToolButton::None; | - |
124 | if (d->popupMode == QToolButton::MenuButtonPopup) { evaluated: d->popupMode == QToolButton::MenuButtonPopup yes Evaluation Count:4 | yes Evaluation Count:1758 |
| 4-1758 |
125 | option->subControls |= QStyle::SC_ToolButtonMenu; | - |
126 | option->features |= QStyleOptionToolButton::MenuButtonPopup; | - |
127 | } executed: } Execution Count:4 | 4 |
128 | if (option->state & QStyle::State_MouseOver) { evaluated: option->state & QStyle::State_MouseOver yes Evaluation Count:5 | yes Evaluation Count:1757 |
| 5-1757 |
129 | option->activeSubControls = d->hoverControl; | - |
130 | } executed: } Execution Count:5 | 5 |
131 | if (d->menuButtonDown) { evaluated: d->menuButtonDown yes Evaluation Count:2 | yes Evaluation Count:1760 |
| 2-1760 |
132 | option->state |= QStyle::State_Sunken; | - |
133 | option->activeSubControls |= QStyle::SC_ToolButtonMenu; | - |
134 | } executed: } Execution Count:2 | 2 |
135 | if (d->down) { evaluated: d->down yes Evaluation Count:244 | yes Evaluation Count:1518 |
| 244-1518 |
136 | option->state |= QStyle::State_Sunken; | - |
137 | option->activeSubControls |= QStyle::SC_ToolButton; | - |
138 | } executed: } Execution Count:244 | 244 |
139 | | - |
140 | | - |
141 | if (d->arrowType != Qt::NoArrow) evaluated: d->arrowType != Qt::NoArrow yes Evaluation Count:4 | yes Evaluation Count:1758 |
| 4-1758 |
142 | option->features |= QStyleOptionToolButton::Arrow; executed: option->features |= QStyleOptionToolButton::Arrow; Execution Count:4 | 4 |
143 | if (d->popupMode == QToolButton::DelayedPopup) evaluated: d->popupMode == QToolButton::DelayedPopup yes Evaluation Count:1630 | yes Evaluation Count:132 |
| 132-1630 |
144 | option->features |= QStyleOptionToolButton::PopupDelay; executed: option->features |= QStyleOptionToolButton::PopupDelay; Execution Count:1630 | 1630 |
145 | | - |
146 | if (d->hasMenu()) evaluated: d->hasMenu() yes Evaluation Count:135 | yes Evaluation Count:1627 |
| 135-1627 |
147 | option->features |= QStyleOptionToolButton::HasMenu; executed: option->features |= QStyleOptionToolButton::HasMenu; Execution Count:135 | 135 |
148 | | - |
149 | if (d->toolButtonStyle == Qt::ToolButtonFollowStyle) { partially evaluated: d->toolButtonStyle == Qt::ToolButtonFollowStyle no Evaluation Count:0 | yes Evaluation Count:1762 |
| 0-1762 |
150 | option->toolButtonStyle = Qt::ToolButtonStyle(style()->styleHint(QStyle::SH_ToolButtonStyle, option, this)); | - |
151 | } else | 0 |
152 | option->toolButtonStyle = d->toolButtonStyle; executed: option->toolButtonStyle = d->toolButtonStyle; Execution Count:1762 | 1762 |
153 | | - |
154 | if (option->toolButtonStyle == Qt::ToolButtonTextBesideIcon) { evaluated: option->toolButtonStyle == Qt::ToolButtonTextBesideIcon yes Evaluation Count:2 | yes Evaluation Count:1760 |
| 2-1760 |
155 | | - |
156 | if (d->defaultAction && d->defaultAction->priority() < QAction::NormalPriority) partially evaluated: d->defaultAction yes Evaluation Count:2 | no Evaluation Count:0 |
evaluated: d->defaultAction->priority() < QAction::NormalPriority yes Evaluation Count:1 | yes Evaluation Count:1 |
| 0-2 |
157 | option->toolButtonStyle = Qt::ToolButtonIconOnly; executed: option->toolButtonStyle = Qt::ToolButtonIconOnly; Execution Count:1 | 1 |
158 | } executed: } Execution Count:2 | 2 |
159 | | - |
160 | if (d->icon.isNull() && d->arrowType == Qt::NoArrow && !forceNoText) { evaluated: d->icon.isNull() yes Evaluation Count:292 | yes Evaluation Count:1470 |
evaluated: d->arrowType == Qt::NoArrow yes Evaluation Count:288 | yes Evaluation Count:4 |
partially evaluated: !forceNoText yes Evaluation Count:288 | no Evaluation Count:0 |
| 0-1470 |
161 | if (!d->text.isEmpty()) evaluated: !d->text.isEmpty() yes Evaluation Count:267 | yes Evaluation Count:21 |
| 21-267 |
162 | option->toolButtonStyle = Qt::ToolButtonTextOnly; executed: option->toolButtonStyle = Qt::ToolButtonTextOnly; Execution Count:267 | 267 |
163 | else if (option->toolButtonStyle != Qt::ToolButtonTextOnly) partially evaluated: option->toolButtonStyle != Qt::ToolButtonTextOnly yes Evaluation Count:21 | no Evaluation Count:0 |
| 0-21 |
164 | option->toolButtonStyle = Qt::ToolButtonIconOnly; executed: option->toolButtonStyle = Qt::ToolButtonIconOnly; Execution Count:21 | 21 |
165 | } | - |
166 | | - |
167 | option->pos = pos(); | - |
168 | option->font = font(); | - |
169 | } executed: } Execution Count:1762 | 1762 |
170 | | - |
171 | | - |
172 | | - |
173 | | - |
174 | | - |
175 | QToolButton::~QToolButton() | - |
176 | { | - |
177 | } | - |
178 | | - |
179 | | - |
180 | | - |
181 | | - |
182 | QSize QToolButton::sizeHint() const | - |
183 | { | - |
184 | const QToolButtonPrivate * const d = d_func(); | - |
185 | if (d->sizeHint.isValid()) evaluated: d->sizeHint.isValid() yes Evaluation Count:1419 | yes Evaluation Count:1254 |
| 1254-1419 |
186 | return d->sizeHint; executed: return d->sizeHint; Execution Count:1419 | 1419 |
187 | ensurePolished(); | - |
188 | | - |
189 | int w = 0, h = 0; | - |
190 | QStyleOptionToolButton opt; | - |
191 | initStyleOption(&opt); | - |
192 | | - |
193 | QFontMetrics fm = fontMetrics(); | - |
194 | if (opt.toolButtonStyle != Qt::ToolButtonTextOnly) { evaluated: opt.toolButtonStyle != Qt::ToolButtonTextOnly yes Evaluation Count:1187 | yes Evaluation Count:67 |
| 67-1187 |
195 | QSize icon = opt.iconSize; | - |
196 | w = icon.width(); | - |
197 | h = icon.height(); | - |
198 | } executed: } Execution Count:1187 | 1187 |
199 | | - |
200 | if (opt.toolButtonStyle != Qt::ToolButtonIconOnly) { evaluated: opt.toolButtonStyle != Qt::ToolButtonIconOnly yes Evaluation Count:67 | yes Evaluation Count:1187 |
| 67-1187 |
201 | QSize textSize = fm.size(Qt::TextShowMnemonic, text()); | - |
202 | textSize.setWidth(textSize.width() + fm.width(QLatin1Char(' '))*2); | - |
203 | if (opt.toolButtonStyle == Qt::ToolButtonTextUnderIcon) { partially evaluated: opt.toolButtonStyle == Qt::ToolButtonTextUnderIcon no Evaluation Count:0 | yes Evaluation Count:67 |
| 0-67 |
204 | h += 4 + textSize.height(); | - |
205 | if (textSize.width() > w) never evaluated: textSize.width() > w | 0 |
206 | w = textSize.width(); never executed: w = textSize.width(); | 0 |
207 | } else if (opt.toolButtonStyle == Qt::ToolButtonTextBesideIcon) { partially evaluated: opt.toolButtonStyle == Qt::ToolButtonTextBesideIcon no Evaluation Count:0 | yes Evaluation Count:67 |
| 0-67 |
208 | w += 4 + textSize.width(); | - |
209 | if (textSize.height() > h) never evaluated: textSize.height() > h | 0 |
210 | h = textSize.height(); never executed: h = textSize.height(); | 0 |
211 | } else { | 0 |
212 | w = textSize.width(); | - |
213 | h = textSize.height(); | - |
214 | } executed: } Execution Count:67 | 67 |
215 | } | - |
216 | | - |
217 | opt.rect.setSize(QSize(w, h)); | - |
218 | if (d->popupMode == MenuButtonPopup) evaluated: d->popupMode == MenuButtonPopup yes Evaluation Count:1 | yes Evaluation Count:1253 |
| 1-1253 |
219 | w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this); executed: w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this); Execution Count:1 | 1 |
220 | | - |
221 | d->sizeHint = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(w, h), this). | - |
222 | expandedTo(QApplication::globalStrut()); | - |
223 | return d->sizeHint; executed: return d->sizeHint; Execution Count:1254 | 1254 |
224 | } | - |
225 | | - |
226 | | - |
227 | | - |
228 | | - |
229 | QSize QToolButton::minimumSizeHint() const | - |
230 | { | - |
231 | return sizeHint(); executed: return sizeHint(); Execution Count:1268 | 1268 |
232 | } | - |
233 | Qt::ToolButtonStyle QToolButton::toolButtonStyle() const | - |
234 | { | - |
235 | const QToolButtonPrivate * const d = d_func(); | - |
236 | return d->toolButtonStyle; never executed: return d->toolButtonStyle; | 0 |
237 | } | - |
238 | | - |
239 | Qt::ArrowType QToolButton::arrowType() const | - |
240 | { | - |
241 | const QToolButtonPrivate * const d = d_func(); | - |
242 | return d->arrowType; never executed: return d->arrowType; | 0 |
243 | } | - |
244 | | - |
245 | | - |
246 | void QToolButton::setToolButtonStyle(Qt::ToolButtonStyle style) | - |
247 | { | - |
248 | QToolButtonPrivate * const d = d_func(); | - |
249 | if (d->toolButtonStyle == style) evaluated: d->toolButtonStyle == style yes Evaluation Count:3 | yes Evaluation Count:1 |
| 1-3 |
250 | return; executed: return; Execution Count:3 | 3 |
251 | | - |
252 | d->toolButtonStyle = style; | - |
253 | d->sizeHint = QSize(); | - |
254 | updateGeometry(); | - |
255 | if (isVisible()) { partially evaluated: isVisible() no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
256 | update(); | - |
257 | } | 0 |
258 | } executed: } Execution Count:1 | 1 |
259 | | - |
260 | void QToolButton::setArrowType(Qt::ArrowType type) | - |
261 | { | - |
262 | QToolButtonPrivate * const d = d_func(); | - |
263 | if (d->arrowType == type) evaluated: d->arrowType == type yes Evaluation Count:34 | yes Evaluation Count:30 |
| 30-34 |
264 | return; executed: return; Execution Count:34 | 34 |
265 | | - |
266 | d->arrowType = type; | - |
267 | d->sizeHint = QSize(); | - |
268 | updateGeometry(); | - |
269 | if (isVisible()) { partially evaluated: isVisible() no Evaluation Count:0 | yes Evaluation Count:30 |
| 0-30 |
270 | update(); | - |
271 | } | 0 |
272 | } executed: } Execution Count:30 | 30 |
273 | | - |
274 | | - |
275 | | - |
276 | | - |
277 | | - |
278 | | - |
279 | void QToolButton::paintEvent(QPaintEvent *) | - |
280 | { | - |
281 | QStylePainter p(this); | - |
282 | QStyleOptionToolButton opt; | - |
283 | initStyleOption(&opt); | - |
284 | p.drawComplexControl(QStyle::CC_ToolButton, opt); | - |
285 | } executed: } Execution Count:317 | 317 |
286 | | - |
287 | | - |
288 | | - |
289 | | - |
290 | void QToolButton::actionEvent(QActionEvent *event) | - |
291 | { | - |
292 | QToolButtonPrivate * const d = d_func(); | - |
293 | QAction *action = event->action(); | - |
294 | switch (event->type()) { | - |
295 | case QEvent::ActionChanged: | - |
296 | if (action == d->defaultAction) evaluated: action == d->defaultAction yes Evaluation Count:8 | yes Evaluation Count:11 |
| 8-11 |
297 | setDefaultAction(action); executed: setDefaultAction(action); Execution Count:8 | 8 |
298 | break; executed: break; Execution Count:19 | 19 |
299 | case QEvent::ActionAdded: | - |
300 | connect(action, "2""triggered()", this, "1""_q_actionTriggered()"); | - |
301 | break; executed: break; Execution Count:67 | 67 |
302 | case QEvent::ActionRemoved: | - |
303 | if (d->defaultAction == action) evaluated: d->defaultAction == action yes Evaluation Count:6 | yes Evaluation Count:13 |
| 6-13 |
304 | d->defaultAction = 0; executed: d->defaultAction = 0; Execution Count:6 | 6 |
305 | | - |
306 | if (action == d->menuAction) evaluated: action == d->menuAction yes Evaluation Count:12 | yes Evaluation Count:7 |
| 7-12 |
307 | d->menuAction = 0; executed: d->menuAction = 0; Execution Count:12 | 12 |
308 | | - |
309 | action->disconnect(this); | - |
310 | break; executed: break; Execution Count:19 | 19 |
311 | default: | - |
312 | ; | - |
313 | } | 0 |
314 | QAbstractButton::actionEvent(event); | - |
315 | } executed: } Execution Count:105 | 105 |
316 | | - |
317 | QStyle::SubControl QToolButtonPrivate::newHoverControl(const QPoint &pos) | - |
318 | { | - |
319 | QToolButton * const q = q_func(); | - |
320 | QStyleOptionToolButton opt; | - |
321 | q->initStyleOption(&opt); | - |
322 | opt.subControls = QStyle::SC_All; | - |
323 | hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ToolButton, &opt, pos, q); | - |
324 | if (hoverControl == QStyle::SC_None) never evaluated: hoverControl == QStyle::SC_None | 0 |
325 | hoverRect = QRect(); never executed: hoverRect = QRect(); | 0 |
326 | else | - |
327 | hoverRect = q->style()->subControlRect(QStyle::CC_ToolButton, &opt, hoverControl, q); never executed: hoverRect = q->style()->subControlRect(QStyle::CC_ToolButton, &opt, hoverControl, q); | 0 |
328 | return hoverControl; never executed: return hoverControl; | 0 |
329 | } | - |
330 | | - |
331 | bool QToolButtonPrivate::updateHoverControl(const QPoint &pos) | - |
332 | { | - |
333 | QToolButton * const q = q_func(); | - |
334 | QRect lastHoverRect = hoverRect; | - |
335 | QStyle::SubControl lastHoverControl = hoverControl; | - |
336 | bool doesHover = q->testAttribute(Qt::WA_Hover); | - |
337 | if (lastHoverControl != newHoverControl(pos) && doesHover) { never evaluated: lastHoverControl != newHoverControl(pos) never evaluated: doesHover | 0 |
338 | q->update(lastHoverRect); | - |
339 | q->update(hoverRect); | - |
340 | return true; never executed: return true; | 0 |
341 | } | - |
342 | return !doesHover; never executed: return !doesHover; | 0 |
343 | } | - |
344 | | - |
345 | void QToolButtonPrivate::_q_actionTriggered() | - |
346 | { | - |
347 | QToolButton * const q = q_func(); | - |
348 | if (QAction *action = qobject_cast<QAction *>(q->sender())) partially evaluated: QAction *action = qobject_cast<QAction *>(q->sender()) yes Evaluation Count:37 | no Evaluation Count:0 |
| 0-37 |
349 | q->triggered(action); executed: q->triggered(action); Execution Count:37 | 37 |
350 | } executed: } Execution Count:37 | 37 |
351 | | - |
352 | | - |
353 | | - |
354 | | - |
355 | void QToolButton::enterEvent(QEvent * e) | - |
356 | { | - |
357 | QToolButtonPrivate * const d = d_func(); | - |
358 | if (d->autoRaise) partially evaluated: d->autoRaise yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
359 | update(); executed: update(); Execution Count:1 | 1 |
360 | if (d->defaultAction) partially evaluated: d->defaultAction no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
361 | d->defaultAction->hover(); never executed: d->defaultAction->hover(); | 0 |
362 | QAbstractButton::enterEvent(e); | - |
363 | } executed: } Execution Count:1 | 1 |
364 | | - |
365 | | - |
366 | | - |
367 | | - |
368 | | - |
369 | void QToolButton::leaveEvent(QEvent * e) | - |
370 | { | - |
371 | QToolButtonPrivate * const d = d_func(); | - |
372 | if (d->autoRaise) never evaluated: d->autoRaise | 0 |
373 | update(); never executed: update(); | 0 |
374 | | - |
375 | QAbstractButton::leaveEvent(e); | - |
376 | } | 0 |
377 | | - |
378 | | - |
379 | | - |
380 | | - |
381 | | - |
382 | void QToolButton::timerEvent(QTimerEvent *e) | - |
383 | { | - |
384 | | - |
385 | QToolButtonPrivate * const d = d_func(); | - |
386 | if (e->timerId() == d->popupTimer.timerId()) { partially evaluated: e->timerId() == d->popupTimer.timerId() no Evaluation Count:0 | yes Evaluation Count:27 |
| 0-27 |
387 | d->popupTimerDone(); | - |
388 | return; | 0 |
389 | } | - |
390 | | - |
391 | QAbstractButton::timerEvent(e); | - |
392 | } executed: } Execution Count:27 | 27 |
393 | | - |
394 | | - |
395 | | - |
396 | | - |
397 | | - |
398 | void QToolButton::changeEvent(QEvent *e) | - |
399 | { | - |
400 | | - |
401 | QToolButtonPrivate * const d = d_func(); | - |
402 | if (e->type() == QEvent::ParentChange) { evaluated: e->type() == QEvent::ParentChange yes Evaluation Count:4 | yes Evaluation Count:1422 |
| 4-1422 |
403 | if (qobject_cast<QToolBar*>(parentWidget())) evaluated: qobject_cast<QToolBar*>(parentWidget()) yes Evaluation Count:1 | yes Evaluation Count:3 |
| 1-3 |
404 | d->autoRaise = true; executed: d->autoRaise = true; Execution Count:1 | 1 |
405 | } else if (e->type() == QEvent::StyleChange evaluated: e->type() == QEvent::StyleChange yes Evaluation Count:24 | yes Evaluation Count:1398 |
executed: } Execution Count:4 | 4-1398 |
406 | | - |
407 | | - |
408 | | - |
409 | ) { | - |
410 | d->delay = style()->styleHint(QStyle::SH_ToolButton_PopupDelay, 0, this); | - |
411 | d->setLayoutItemMargins(QStyle::SE_ToolButtonLayoutItem); | - |
412 | } executed: } Execution Count:24 | 24 |
413 | | - |
414 | QAbstractButton::changeEvent(e); | - |
415 | } executed: } Execution Count:1426 | 1426 |
416 | | - |
417 | | - |
418 | | - |
419 | | - |
420 | void QToolButton::mousePressEvent(QMouseEvent *e) | - |
421 | { | - |
422 | QToolButtonPrivate * const d = d_func(); | - |
423 | | - |
424 | QStyleOptionToolButton opt; | - |
425 | initStyleOption(&opt); | - |
426 | if (e->button() == Qt::LeftButton && (d->popupMode == MenuButtonPopup)) { partially evaluated: e->button() == Qt::LeftButton yes Evaluation Count:23 | no Evaluation Count:0 |
partially evaluated: (d->popupMode == MenuButtonPopup) no Evaluation Count:0 | yes Evaluation Count:23 |
| 0-23 |
427 | QRect popupr = style()->subControlRect(QStyle::CC_ToolButton, &opt, | - |
428 | QStyle::SC_ToolButtonMenu, this); | - |
429 | if (popupr.isValid() && popupr.contains(e->pos())) { never evaluated: popupr.isValid() never evaluated: popupr.contains(e->pos()) | 0 |
430 | d->buttonPressed = QToolButtonPrivate::MenuButtonPressed; | - |
431 | showMenu(); | - |
432 | return; | 0 |
433 | } | - |
434 | } | 0 |
435 | | - |
436 | d->buttonPressed = QToolButtonPrivate::ToolButtonPressed; | - |
437 | QAbstractButton::mousePressEvent(e); | - |
438 | } executed: } Execution Count:23 | 23 |
439 | | - |
440 | | - |
441 | | - |
442 | | - |
443 | void QToolButton::mouseReleaseEvent(QMouseEvent *e) | - |
444 | { | - |
445 | QToolButtonPrivate * const d = d_func(); | - |
446 | QAbstractButton::mouseReleaseEvent(e); | - |
447 | d->buttonPressed = QToolButtonPrivate::NoButtonPressed; | - |
448 | } executed: } Execution Count:23 | 23 |
449 | | - |
450 | | - |
451 | | - |
452 | | - |
453 | bool QToolButton::hitButton(const QPoint &pos) const | - |
454 | { | - |
455 | const QToolButtonPrivate * const d = d_func(); | - |
456 | if(QAbstractButton::hitButton(pos)) partially evaluated: QAbstractButton::hitButton(pos) yes Evaluation Count:46 | no Evaluation Count:0 |
| 0-46 |
457 | return (d->buttonPressed != QToolButtonPrivate::MenuButtonPressed); executed: return (d->buttonPressed != QToolButtonPrivate::MenuButtonPressed); Execution Count:46 | 46 |
458 | return false; never executed: return false; | 0 |
459 | } | - |
460 | void QToolButton::setMenu(QMenu* menu) | - |
461 | { | - |
462 | QToolButtonPrivate * const d = d_func(); | - |
463 | | - |
464 | if (d->menuAction) evaluated: d->menuAction yes Evaluation Count:11 | yes Evaluation Count:59 |
| 11-59 |
465 | removeAction(d->menuAction); executed: removeAction(d->menuAction); Execution Count:11 | 11 |
466 | | - |
467 | if (menu) { evaluated: menu yes Evaluation Count:57 | yes Evaluation Count:13 |
| 13-57 |
468 | d->menuAction = menu->menuAction(); | - |
469 | addAction(d->menuAction); | - |
470 | } else { executed: } Execution Count:57 | 57 |
471 | d->menuAction = 0; | - |
472 | } executed: } Execution Count:13 | 13 |
473 | update(); | - |
474 | } executed: } Execution Count:70 | 70 |
475 | | - |
476 | | - |
477 | | - |
478 | | - |
479 | | - |
480 | | - |
481 | QMenu* QToolButton::menu() const | - |
482 | { | - |
483 | const QToolButtonPrivate * const d = d_func(); | - |
484 | if (d->menuAction) evaluated: d->menuAction yes Evaluation Count:57 | yes Evaluation Count:9 |
| 9-57 |
485 | return d->menuAction->menu(); executed: return d->menuAction->menu(); Execution Count:57 | 57 |
486 | return 0; executed: return 0; Execution Count:9 | 9 |
487 | } | - |
488 | | - |
489 | | - |
490 | | - |
491 | | - |
492 | | - |
493 | | - |
494 | void QToolButton::showMenu() | - |
495 | { | - |
496 | QToolButtonPrivate * const d = d_func(); | - |
497 | if (!d->hasMenu()) { partially evaluated: !d->hasMenu() no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
498 | d->menuButtonDown = false; | - |
499 | return; | 0 |
500 | } | - |
501 | | - |
502 | d->menuButtonDown = true; | - |
503 | repaint(); | - |
504 | d->popupTimer.stop(); | - |
505 | d->popupTimerDone(); | - |
506 | } executed: } Execution Count:2 | 2 |
507 | | - |
508 | void QToolButtonPrivate::_q_buttonPressed() | - |
509 | { | - |
510 | QToolButton * const q = q_func(); | - |
511 | if (!hasMenu()) partially evaluated: !hasMenu() yes Evaluation Count:62 | no Evaluation Count:0 |
| 0-62 |
512 | return; executed: return; Execution Count:62 | 62 |
513 | if (popupMode == QToolButton::MenuButtonPopup) never evaluated: popupMode == QToolButton::MenuButtonPopup | 0 |
514 | return; | 0 |
515 | else if (delay > 0 && !popupTimer.isActive() && popupMode == QToolButton::DelayedPopup) never evaluated: delay > 0 never evaluated: !popupTimer.isActive() never evaluated: popupMode == QToolButton::DelayedPopup | 0 |
516 | popupTimer.start(delay, q); never executed: popupTimer.start(delay, q); | 0 |
517 | else if (delay == 0 || popupMode == QToolButton::InstantPopup) never evaluated: delay == 0 never evaluated: popupMode == QToolButton::InstantPopup | 0 |
518 | q->showMenu(); never executed: q->showMenu(); | 0 |
519 | } | - |
520 | | - |
521 | void QToolButtonPrivate::popupTimerDone() | - |
522 | { | - |
523 | QToolButton * const q = q_func(); | - |
524 | popupTimer.stop(); | - |
525 | if (!menuButtonDown && !down) partially evaluated: !menuButtonDown no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
526 | return; | 0 |
527 | | - |
528 | menuButtonDown = true; | - |
529 | QPointer<QMenu> actualMenu; | - |
530 | bool mustDeleteActualMenu = false; | - |
531 | if(menuAction) { evaluated: menuAction yes Evaluation Count:1 | yes Evaluation Count:1 |
| 1 |
532 | actualMenu = menuAction->menu(); | - |
533 | } else if (defaultAction && defaultAction->menu()) { partially evaluated: defaultAction yes Evaluation Count:1 | no Evaluation Count:0 |
partially evaluated: defaultAction->menu() yes Evaluation Count:1 | no Evaluation Count:0 |
executed: } Execution Count:1 | 0-1 |
534 | actualMenu = defaultAction->menu(); | - |
535 | } else { executed: } Execution Count:1 | 1 |
536 | actualMenu = new QMenu(q); | - |
537 | mustDeleteActualMenu = true; | - |
538 | for(int i = 0; i < actions.size(); i++) never evaluated: i < actions.size() | 0 |
539 | actualMenu->addAction(actions.at(i)); never executed: actualMenu->addAction(actions.at(i)); | 0 |
540 | } | 0 |
541 | repeat = q->autoRepeat(); | - |
542 | q->setAutoRepeat(false); | - |
543 | bool horizontal = true; | - |
544 | | - |
545 | QToolBar *tb = qobject_cast<QToolBar*>(parent); | - |
546 | if (tb && tb->orientation() == Qt::Vertical) evaluated: tb yes Evaluation Count:1 | yes Evaluation Count:1 |
partially evaluated: tb->orientation() == Qt::Vertical no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
547 | horizontal = false; never executed: horizontal = false; | 0 |
548 | | - |
549 | QPoint p; | - |
550 | QRect screen = QApplication::desktop()->availableGeometry(q); | - |
551 | QSize sh = ((QToolButton*)(QMenu*)actualMenu)->receivers("2""aboutToShow()")? QSize() : actualMenu->sizeHint(); partially evaluated: ((QToolButton*)(QMenu*)actualMenu)->receivers("2""aboutToShow()") no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
552 | QRect rect = q->rect(); | - |
553 | if (horizontal) { partially evaluated: horizontal yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 |
554 | if (q->isRightToLeft()) { partially evaluated: q->isRightToLeft() no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
555 | if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) { never evaluated: q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height() | 0 |
556 | p = q->mapToGlobal(rect.bottomRight()); | - |
557 | } else { | 0 |
558 | p = q->mapToGlobal(rect.topRight() - QPoint(0, sh.height())); | - |
559 | } | 0 |
560 | p.rx() -= sh.width(); | - |
561 | } else { | 0 |
562 | if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) { partially evaluated: q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height() yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 |
563 | p = q->mapToGlobal(rect.bottomLeft()); | - |
564 | } else { executed: } Execution Count:2 | 2 |
565 | p = q->mapToGlobal(rect.topLeft() - QPoint(0, sh.height())); | - |
566 | } | 0 |
567 | } | - |
568 | } else { | - |
569 | if (q->isRightToLeft()) { never evaluated: q->isRightToLeft() | 0 |
570 | if (q->mapToGlobal(QPoint(rect.left(), 0)).x() - sh.width() <= screen.x()) { never evaluated: q->mapToGlobal(QPoint(rect.left(), 0)).x() - sh.width() <= screen.x() | 0 |
571 | p = q->mapToGlobal(rect.topRight()); | - |
572 | } else { | 0 |
573 | p = q->mapToGlobal(rect.topLeft()); | - |
574 | p.rx() -= sh.width(); | - |
575 | } | 0 |
576 | } else { | - |
577 | if (q->mapToGlobal(QPoint(rect.right(), 0)).x() + sh.width() <= screen.right()) { never evaluated: q->mapToGlobal(QPoint(rect.right(), 0)).x() + sh.width() <= screen.right() | 0 |
578 | p = q->mapToGlobal(rect.topRight()); | - |
579 | } else { | 0 |
580 | p = q->mapToGlobal(rect.topLeft() - QPoint(sh.width(), 0)); | - |
581 | } | 0 |
582 | } | - |
583 | } | - |
584 | p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width())); | - |
585 | p.ry() += 1; | - |
586 | QPointer<QToolButton> that = q; | - |
587 | actualMenu->setNoReplayFor(q); | - |
588 | if (!mustDeleteActualMenu) partially evaluated: !mustDeleteActualMenu yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 |
589 | QObject::connect(actualMenu, "2""triggered(QAction*)", q, "1""_q_menuTriggered(QAction*)"); executed: QObject::connect(actualMenu, "2""triggered(QAction*)", q, "1""_q_menuTriggered(QAction*)"); Execution Count:2 | 2 |
590 | QObject::connect(actualMenu, "2""aboutToHide()", q, "1""_q_updateButtonDown()"); | - |
591 | actualMenu->d_func()->causedPopup.widget = q; | - |
592 | actualMenu->d_func()->causedPopup.action = defaultAction; | - |
593 | actionsCopy = q->actions(); | - |
594 | actualMenu->exec(p); | - |
595 | QObject::disconnect(actualMenu, "2""aboutToHide()", q, "1""_q_updateButtonDown()"); | - |
596 | if (mustDeleteActualMenu) partially evaluated: mustDeleteActualMenu no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
597 | delete actualMenu; never executed: delete actualMenu; | 0 |
598 | else | - |
599 | QObject::disconnect(actualMenu, "2""triggered(QAction*)", q, "1""_q_menuTriggered(QAction*)"); executed: QObject::disconnect(actualMenu, "2""triggered(QAction*)", q, "1""_q_menuTriggered(QAction*)"); Execution Count:2 | 2 |
600 | | - |
601 | if (!that) partially evaluated: !that no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
602 | return; | 0 |
603 | | - |
604 | actionsCopy.clear(); | - |
605 | | - |
606 | if (repeat) partially evaluated: repeat no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
607 | q->setAutoRepeat(true); never executed: q->setAutoRepeat(true); | 0 |
608 | } executed: } Execution Count:2 | 2 |
609 | | - |
610 | void QToolButtonPrivate::_q_updateButtonDown() | - |
611 | { | - |
612 | QToolButton * const q = q_func(); | - |
613 | menuButtonDown = false; | - |
614 | if (q->isDown()) partially evaluated: q->isDown() no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
615 | q->setDown(false); never executed: q->setDown(false); | 0 |
616 | else | - |
617 | q->repaint(); executed: q->repaint(); Execution Count:2 | 2 |
618 | } | - |
619 | | - |
620 | void QToolButtonPrivate::_q_menuTriggered(QAction *action) | - |
621 | { | - |
622 | QToolButton * const q = q_func(); | - |
623 | if (action && !actionsCopy.contains(action)) partially evaluated: action yes Evaluation Count:1 | no Evaluation Count:0 |
partially evaluated: !actionsCopy.contains(action) yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
624 | q->triggered(action); executed: q->triggered(action); Execution Count:1 | 1 |
625 | } executed: } Execution Count:1 | 1 |
626 | void QToolButton::setPopupMode(ToolButtonPopupMode mode) | - |
627 | { | - |
628 | QToolButtonPrivate * const d = d_func(); | - |
629 | d->popupMode = mode; | - |
630 | } executed: } Execution Count:90 | 90 |
631 | | - |
632 | QToolButton::ToolButtonPopupMode QToolButton::popupMode() const | - |
633 | { | - |
634 | const QToolButtonPrivate * const d = d_func(); | - |
635 | return d->popupMode; executed: return d->popupMode; Execution Count:3 | 3 |
636 | } | - |
637 | void QToolButton::setAutoRaise(bool enable) | - |
638 | { | - |
639 | QToolButtonPrivate * const d = d_func(); | - |
640 | d->autoRaise = enable; | - |
641 | | - |
642 | update(); | - |
643 | } executed: } Execution Count:1313 | 1313 |
644 | | - |
645 | bool QToolButton::autoRaise() const | - |
646 | { | - |
647 | const QToolButtonPrivate * const d = d_func(); | - |
648 | return d->autoRaise; executed: return d->autoRaise; Execution Count:3 | 3 |
649 | } | - |
650 | | - |
651 | | - |
652 | | - |
653 | | - |
654 | | - |
655 | | - |
656 | | - |
657 | void QToolButton::setDefaultAction(QAction *action) | - |
658 | { | - |
659 | QToolButtonPrivate * const d = d_func(); | - |
660 | | - |
661 | bool hadMenu = false; | - |
662 | hadMenu = d->hasMenu(); | - |
663 | | - |
664 | d->defaultAction = action; | - |
665 | if (!action) evaluated: !action yes Evaluation Count:1 | yes Evaluation Count:18 |
| 1-18 |
666 | return; executed: return; Execution Count:1 | 1 |
667 | if (!actions().contains(action)) evaluated: !actions().contains(action) yes Evaluation Count:10 | yes Evaluation Count:8 |
| 8-10 |
668 | addAction(action); executed: addAction(action); Execution Count:10 | 10 |
669 | setText(action->iconText()); | - |
670 | setIcon(action->icon()); | - |
671 | | - |
672 | setToolTip(action->toolTip()); | - |
673 | | - |
674 | | - |
675 | setStatusTip(action->statusTip()); | - |
676 | | - |
677 | | - |
678 | setWhatsThis(action->whatsThis()); | - |
679 | | - |
680 | | - |
681 | if (action->menu() && !hadMenu) { evaluated: action->menu() yes Evaluation Count:1 | yes Evaluation Count:17 |
partially evaluated: !hadMenu yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-17 |
682 | | - |
683 | | - |
684 | | - |
685 | setPopupMode(QToolButton::MenuButtonPopup); | - |
686 | } executed: } Execution Count:1 | 1 |
687 | | - |
688 | setCheckable(action->isCheckable()); | - |
689 | setChecked(action->isChecked()); | - |
690 | setEnabled(action->isEnabled()); | - |
691 | if (action->d_func()->fontSet) partially evaluated: action->d_func()->fontSet no Evaluation Count:0 | yes Evaluation Count:18 |
| 0-18 |
692 | setFont(action->font()); never executed: setFont(action->font()); | 0 |
693 | } executed: } Execution Count:18 | 18 |
694 | | - |
695 | | - |
696 | | - |
697 | | - |
698 | | - |
699 | | - |
700 | | - |
701 | QAction *QToolButton::defaultAction() const | - |
702 | { | - |
703 | const QToolButtonPrivate * const d = d_func(); | - |
704 | return d->defaultAction; executed: return d->defaultAction; Execution Count:2 | 2 |
705 | } | - |
706 | | - |
707 | | - |
708 | | - |
709 | | - |
710 | | - |
711 | | - |
712 | void QToolButton::nextCheckState() | - |
713 | { | - |
714 | QToolButtonPrivate * const d = d_func(); | - |
715 | if (!d->defaultAction) evaluated: !d->defaultAction yes Evaluation Count:29 | yes Evaluation Count:36 |
| 29-36 |
716 | QAbstractButton::nextCheckState(); executed: QAbstractButton::nextCheckState(); Execution Count:29 | 29 |
717 | else | - |
718 | d->defaultAction->trigger(); executed: d->defaultAction->trigger(); Execution Count:36 | 36 |
719 | } | - |
720 | | - |
721 | | - |
722 | bool QToolButton::event(QEvent *event) | - |
723 | { | - |
724 | switch(event->type()) { | - |
725 | case QEvent::HoverEnter: | - |
726 | case QEvent::HoverLeave: | - |
727 | case QEvent::HoverMove: | - |
728 | if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event)) never evaluated: const QHoverEvent *he = static_cast<const QHoverEvent *>(event) | 0 |
729 | d_func()->updateHoverControl(he->pos()); never executed: d_func()->updateHoverControl(he->pos()); | 0 |
730 | break; | 0 |
731 | default: | - |
732 | break; executed: break; Execution Count:9135 | 9135 |
733 | } | - |
734 | return QAbstractButton::event(event); executed: return QAbstractButton::event(event); Execution Count:9135 | 9135 |
735 | } | - |
736 | | - |
737 | | - |
738 | | - |
739 | | - |
| | |