qtoolbutton.cpp

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

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