widgets/qtoolbutton.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qtoolbutton.h" -
43#ifndef QT_NO_TOOLBUTTON -
44 -
45#include <qapplication.h> -
46#include <qdesktopwidget.h> -
47#include <qdrawutil.h> -
48#include <qevent.h> -
49#include <qicon.h> -
50#include <qmenu.h> -
51#include <qpainter.h> -
52#include <qpointer.h> -
53#include <qstyle.h> -
54#include <qstyleoption.h> -
55#include <qtooltip.h> -
56#include <qmainwindow.h> -
57#include <qtoolbar.h> -
58#include <qvariant.h> -
59#include <qstylepainter.h> -
60#include <private/qabstractbutton_p.h> -
61#include <private/qaction_p.h> -
62#include <private/qmenu_p.h> -
63 -
64QT_BEGIN_NAMESPACE -
65 -
66class QToolButtonPrivate : public QAbstractButtonPrivate -
67{ -
68 Q_DECLARE_PUBLIC(QToolButton) -
69public: -
70 void init(); -
71#ifndef QT_NO_MENU -
72 void _q_buttonPressed(); -
73 void popupTimerDone(); -
74 void _q_updateButtonDown(); -
75 void _q_menuTriggered(QAction *); -
76#endif -
77 bool updateHoverControl(const QPoint &pos); -
78 void _q_actionTriggered(); -
79 QStyle::SubControl newHoverControl(const QPoint &pos); -
80 QStyle::SubControl hoverControl; -
81 QRect hoverRect; -
82 QPointer<QAction> menuAction; //the menu set by the user (setMenu) -
83 QBasicTimer popupTimer; -
84 int delay; -
85 Qt::ArrowType arrowType; -
86 Qt::ToolButtonStyle toolButtonStyle; -
87 QToolButton::ToolButtonPopupMode popupMode; -
88 enum { NoButtonPressed=0, MenuButtonPressed=1, ToolButtonPressed=2 }; -
89 uint buttonPressed : 2; -
90 uint menuButtonDown : 1; -
91 uint autoRaise : 1; -
92 uint repeat : 1; -
93 QAction *defaultAction; -
94#ifndef QT_NO_MENU -
95 bool hasMenu() const; -
96 //workaround for task 177850 -
97 QList<QAction *> actionsCopy; -
98#endif -
99}; -
100 -
101#ifndef QT_NO_MENU -
102bool QToolButtonPrivate::hasMenu() const -
103{ -
104 return ((defaultAction && defaultAction->menu())
executed: return ((defaultAction && defaultAction->menu()) || (menuAction && menuAction->menu()) || actions.size() > (defaultAction ? 1 : 0));
Execution Count:1845
1845
105 || (menuAction && menuAction->menu())
executed: return ((defaultAction && defaultAction->menu()) || (menuAction && menuAction->menu()) || actions.size() > (defaultAction ? 1 : 0));
Execution Count:1845
1845
106 || actions.size() > (defaultAction ? 1 : 0));
executed: return ((defaultAction && defaultAction->menu()) || (menuAction && menuAction->menu()) || actions.size() > (defaultAction ? 1 : 0));
Execution Count:1845
1845
107} -
108#endif -
109 -
110/*! -
111 \class QToolButton -
112 \brief The QToolButton class provides a quick-access button to -
113 commands or options, usually used inside a QToolBar. -
114 -
115 \ingroup basicwidgets -
116 \inmodule QtWidgets -
117 -
118 A tool button is a special button that provides quick-access to -
119 specific commands or options. As opposed to a normal command -
120 button, a tool button usually doesn't show a text label, but shows -
121 an icon instead. -
122 -
123 Tool buttons are normally created when new QAction instances are -
124 created with QToolBar::addAction() or existing actions are added -
125 to a toolbar with QToolBar::addAction(). It is also possible to -
126 construct tool buttons in the same way as any other widget, and -
127 arrange them alongside other widgets in layouts. -
128 -
129 One classic use of a tool button is to select tools; for example, -
130 the "pen" tool in a drawing program. This would be implemented -
131 by using a QToolButton as a toggle button (see setToggleButton()). -
132 -
133 QToolButton supports auto-raising. In auto-raise mode, the button -
134 draws a 3D frame only when the mouse points at it. The feature is -
135 automatically turned on when a button is used inside a QToolBar. -
136 Change it with setAutoRaise(). -
137 -
138 A tool button's icon is set as QIcon. This makes it possible to -
139 specify different pixmaps for the disabled and active state. The -
140 disabled pixmap is used when the button's functionality is not -
141 available. The active pixmap is displayed when the button is -
142 auto-raised because the mouse pointer is hovering over it. -
143 -
144 The button's look and dimension is adjustable with -
145 setToolButtonStyle() and setIconSize(). When used inside a -
146 QToolBar in a QMainWindow, the button automatically adjusts to -
147 QMainWindow's settings (see QMainWindow::setToolButtonStyle() and -
148 QMainWindow::setIconSize()). Instead of an icon, a tool button can -
149 also display an arrow symbol, specified with -
150 \l{QToolButton::arrowType} {arrowType}. -
151 -
152 A tool button can offer additional choices in a popup menu. The -
153 popup menu can be set using setMenu(). Use setPopupMode() to -
154 configure the different modes available for tool buttons with a -
155 menu set. The default mode is DelayedPopupMode which is sometimes -
156 used with the "Back" button in a web browser. After pressing and -
157 holding the button down for a while, a menu pops up showing a list -
158 of possible pages to jump to. The default delay is 600 ms; you can -
159 adjust it with setPopupDelay(). -
160 -
161 \table 100% -
162 \row \li \inlineimage assistant-toolbar.png Qt Assistant's toolbar with tool buttons -
163 \row \li Qt Assistant's toolbar contains tool buttons that are associated -
164 with actions used in other parts of the main window. -
165 \endtable -
166 -
167 \sa QPushButton, QToolBar, QMainWindow, QAction, -
168 {fowler}{GUI Design Handbook: Push Button} -
169*/ -
170 -
171/*! -
172 \fn void QToolButton::triggered(QAction *action) -
173 -
174 This signal is emitted when the given \a action is triggered. -
175 -
176 The action may also be associated with other parts of the user interface, -
177 such as menu items and keyboard shortcuts. Sharing actions in this -
178 way helps make the user interface more consistent and is often less work -
179 to implement. -
180*/ -
181 -
182/*! -
183 Constructs an empty tool button with parent \a -
184 parent. -
185*/ -
186QToolButton::QToolButton(QWidget * parent) -
187 : QAbstractButton(*new QToolButtonPrivate, parent) -
188{ -
189 Q_D(QToolButton);
executed (the execution status of this line is deduced): QToolButtonPrivate * const d = d_func();
-
190 d->init();
executed (the execution status of this line is deduced): d->init();
-
191}
executed: }
Execution Count:1530
1530
192 -
193 -
194 -
195/* Set-up code common to all the constructors */ -
196 -
197void QToolButtonPrivate::init() -
198{ -
199 Q_Q(QToolButton);
executed (the execution status of this line is deduced): QToolButton * const q = q_func();
-
200 delay = q->style()->styleHint(QStyle::SH_ToolButton_PopupDelay, 0, q);
executed (the execution status of this line is deduced): delay = q->style()->styleHint(QStyle::SH_ToolButton_PopupDelay, 0, q);
-
201 defaultAction = 0;
executed (the execution status of this line is deduced): defaultAction = 0;
-
202#ifndef QT_NO_TOOLBAR -
203 if (qobject_cast<QToolBar*>(parent))
evaluated: qobject_cast<QToolBar*>(parent)
TRUEFALSE
yes
Evaluation Count:20
yes
Evaluation Count:1510
20-1510
204 autoRaise = true;
executed: autoRaise = true;
Execution Count:20
20
205 else -
206#endif -
207 autoRaise = false;
executed: autoRaise = false;
Execution Count:1510
1510
208 arrowType = Qt::NoArrow;
executed (the execution status of this line is deduced): arrowType = Qt::NoArrow;
-
209 menuButtonDown = false;
executed (the execution status of this line is deduced): menuButtonDown = false;
-
210 popupMode = QToolButton::DelayedPopup;
executed (the execution status of this line is deduced): popupMode = QToolButton::DelayedPopup;
-
211 buttonPressed = QToolButtonPrivate::NoButtonPressed;
executed (the execution status of this line is deduced): buttonPressed = QToolButtonPrivate::NoButtonPressed;
-
212 -
213 toolButtonStyle = Qt::ToolButtonIconOnly;
executed (the execution status of this line is deduced): toolButtonStyle = Qt::ToolButtonIconOnly;
-
214 hoverControl = QStyle::SC_None;
executed (the execution status of this line is deduced): hoverControl = QStyle::SC_None;
-
215 -
216 q->setFocusPolicy(Qt::TabFocus);
executed (the execution status of this line is deduced): q->setFocusPolicy(Qt::TabFocus);
-
217 q->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed,
executed (the execution status of this line is deduced): q->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed,
-
218 QSizePolicy::ToolButton));
executed (the execution status of this line is deduced): QSizePolicy::ToolButton));
-
219 -
220#ifndef QT_NO_MENU -
221 QObject::connect(q, SIGNAL(pressed()), q, SLOT(_q_buttonPressed()));
executed (the execution status of this line is deduced): QObject::connect(q, "2""pressed()", q, "1""_q_buttonPressed()");
-
222#endif -
223 -
224 setLayoutItemMargins(QStyle::SE_ToolButtonLayoutItem);
executed (the execution status of this line is deduced): setLayoutItemMargins(QStyle::SE_ToolButtonLayoutItem);
-
225 -
226}
executed: }
Execution Count:1530
1530
227 -
228/*! -
229 Initialize \a option with the values from this QToolButton. This method -
230 is useful for subclasses when they need a QStyleOptionToolButton, but don't want -
231 to fill in all the information themselves. -
232 -
233 \sa QStyleOption::initFrom() -
234*/ -
235void QToolButton::initStyleOption(QStyleOptionToolButton *option) const -
236{ -
237 if (!option)
partially evaluated: !option
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1762
0-1762
238 return;
never executed: return;
0
239 -
240 Q_D(const QToolButton);
executed (the execution status of this line is deduced): const QToolButtonPrivate * const d = d_func();
-
241 option->initFrom(this);
executed (the execution status of this line is deduced): option->initFrom(this);
-
242 bool forceNoText = false;
executed (the execution status of this line is deduced): bool forceNoText = false;
-
243 option->iconSize = iconSize(); //default value
executed (the execution status of this line is deduced): option->iconSize = iconSize();
-
244 -
245#ifndef QT_NO_TOOLBAR -
246 if (parentWidget()) {
evaluated: parentWidget()
TRUEFALSE
yes
Evaluation Count:1747
yes
Evaluation Count:15
15-1747
247 if (QToolBar *toolBar = qobject_cast<QToolBar *>(parentWidget())) {
evaluated: QToolBar *toolBar = qobject_cast<QToolBar *>(parentWidget())
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:1741
6-1741
248 option->iconSize = toolBar->iconSize();
executed (the execution status of this line is deduced): option->iconSize = toolBar->iconSize();
-
249 }
executed: }
Execution Count:6
6
250 }
executed: }
Execution Count:1747
1747
251#endif // QT_NO_TOOLBAR -
252 -
253 if (!forceNoText)
partially evaluated: !forceNoText
TRUEFALSE
yes
Evaluation Count:1762
no
Evaluation Count:0
0-1762
254 option->text = d->text;
executed: option->text = d->text;
Execution Count:1762
1762
255 option->icon = d->icon;
executed (the execution status of this line is deduced): option->icon = d->icon;
-
256 option->arrowType = d->arrowType;
executed (the execution status of this line is deduced): option->arrowType = d->arrowType;
-
257 if (d->down)
evaluated: d->down
TRUEFALSE
yes
Evaluation Count:244
yes
Evaluation Count:1518
244-1518
258 option->state |= QStyle::State_Sunken;
executed: option->state |= QStyle::State_Sunken;
Execution Count:244
244
259 if (d->checked)
partially evaluated: d->checked
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1762
0-1762
260 option->state |= QStyle::State_On;
never executed: option->state |= QStyle::State_On;
0
261 if (d->autoRaise)
evaluated: d->autoRaise
TRUEFALSE
yes
Evaluation Count:1721
yes
Evaluation Count:41
41-1721
262 option->state |= QStyle::State_AutoRaise;
executed: option->state |= QStyle::State_AutoRaise;
Execution Count:1721
1721
263 if (!d->checked && !d->down)
partially evaluated: !d->checked
TRUEFALSE
yes
Evaluation Count:1762
no
Evaluation Count:0
evaluated: !d->down
TRUEFALSE
yes
Evaluation Count:1518
yes
Evaluation Count:244
0-1762
264 option->state |= QStyle::State_Raised;
executed: option->state |= QStyle::State_Raised;
Execution Count:1518
1518
265 -
266 option->subControls = QStyle::SC_ToolButton;
executed (the execution status of this line is deduced): option->subControls = QStyle::SC_ToolButton;
-
267 option->activeSubControls = QStyle::SC_None;
executed (the execution status of this line is deduced): option->activeSubControls = QStyle::SC_None;
-
268 -
269 option->features = QStyleOptionToolButton::None;
executed (the execution status of this line is deduced): option->features = QStyleOptionToolButton::None;
-
270 if (d->popupMode == QToolButton::MenuButtonPopup) {
evaluated: d->popupMode == QToolButton::MenuButtonPopup
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:1758
4-1758
271 option->subControls |= QStyle::SC_ToolButtonMenu;
executed (the execution status of this line is deduced): option->subControls |= QStyle::SC_ToolButtonMenu;
-
272 option->features |= QStyleOptionToolButton::MenuButtonPopup;
executed (the execution status of this line is deduced): option->features |= QStyleOptionToolButton::MenuButtonPopup;
-
273 }
executed: }
Execution Count:4
4
274 if (option->state & QStyle::State_MouseOver) {
evaluated: option->state & QStyle::State_MouseOver
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:1757
5-1757
275 option->activeSubControls = d->hoverControl;
executed (the execution status of this line is deduced): option->activeSubControls = d->hoverControl;
-
276 }
executed: }
Execution Count:5
5
277 if (d->menuButtonDown) {
evaluated: d->menuButtonDown
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:1760
2-1760
278 option->state |= QStyle::State_Sunken;
executed (the execution status of this line is deduced): option->state |= QStyle::State_Sunken;
-
279 option->activeSubControls |= QStyle::SC_ToolButtonMenu;
executed (the execution status of this line is deduced): option->activeSubControls |= QStyle::SC_ToolButtonMenu;
-
280 }
executed: }
Execution Count:2
2
281 if (d->down) {
evaluated: d->down
TRUEFALSE
yes
Evaluation Count:244
yes
Evaluation Count:1518
244-1518
282 option->state |= QStyle::State_Sunken;
executed (the execution status of this line is deduced): option->state |= QStyle::State_Sunken;
-
283 option->activeSubControls |= QStyle::SC_ToolButton;
executed (the execution status of this line is deduced): option->activeSubControls |= QStyle::SC_ToolButton;
-
284 }
executed: }
Execution Count:244
244
285 -
286 -
287 if (d->arrowType != Qt::NoArrow)
evaluated: d->arrowType != Qt::NoArrow
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:1758
4-1758
288 option->features |= QStyleOptionToolButton::Arrow;
executed: option->features |= QStyleOptionToolButton::Arrow;
Execution Count:4
4
289 if (d->popupMode == QToolButton::DelayedPopup)
evaluated: d->popupMode == QToolButton::DelayedPopup
TRUEFALSE
yes
Evaluation Count:1630
yes
Evaluation Count:132
132-1630
290 option->features |= QStyleOptionToolButton::PopupDelay;
executed: option->features |= QStyleOptionToolButton::PopupDelay;
Execution Count:1630
1630
291#ifndef QT_NO_MENU -
292 if (d->hasMenu())
evaluated: d->hasMenu()
TRUEFALSE
yes
Evaluation Count:135
yes
Evaluation Count:1627
135-1627
293 option->features |= QStyleOptionToolButton::HasMenu;
executed: option->features |= QStyleOptionToolButton::HasMenu;
Execution Count:135
135
294#endif -
295 if (d->toolButtonStyle == Qt::ToolButtonFollowStyle) {
partially evaluated: d->toolButtonStyle == Qt::ToolButtonFollowStyle
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1762
0-1762
296 option->toolButtonStyle = Qt::ToolButtonStyle(style()->styleHint(QStyle::SH_ToolButtonStyle, option, this));
never executed (the execution status of this line is deduced): option->toolButtonStyle = Qt::ToolButtonStyle(style()->styleHint(QStyle::SH_ToolButtonStyle, option, this));
-
297 } else
never executed: }
0
298 option->toolButtonStyle = d->toolButtonStyle;
executed: option->toolButtonStyle = d->toolButtonStyle;
Execution Count:1762
1762
299 -
300 if (option->toolButtonStyle == Qt::ToolButtonTextBesideIcon) {
evaluated: option->toolButtonStyle == Qt::ToolButtonTextBesideIcon
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:1760
2-1760
301 // If the action is not prioritized, remove the text label to save space -
302 if (d->defaultAction && d->defaultAction->priority() < QAction::NormalPriority)
partially evaluated: d->defaultAction
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
evaluated: d->defaultAction->priority() < QAction::NormalPriority
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
0-2
303 option->toolButtonStyle = Qt::ToolButtonIconOnly;
executed: option->toolButtonStyle = Qt::ToolButtonIconOnly;
Execution Count:1
1
304 }
executed: }
Execution Count:2
2
305 -
306 if (d->icon.isNull() && d->arrowType == Qt::NoArrow && !forceNoText) {
evaluated: d->icon.isNull()
TRUEFALSE
yes
Evaluation Count:292
yes
Evaluation Count:1470
evaluated: d->arrowType == Qt::NoArrow
TRUEFALSE
yes
Evaluation Count:288
yes
Evaluation Count:4
partially evaluated: !forceNoText
TRUEFALSE
yes
Evaluation Count:288
no
Evaluation Count:0
0-1470
307 if (!d->text.isEmpty())
evaluated: !d->text.isEmpty()
TRUEFALSE
yes
Evaluation Count:267
yes
Evaluation Count:21
21-267
308 option->toolButtonStyle = Qt::ToolButtonTextOnly;
executed: option->toolButtonStyle = Qt::ToolButtonTextOnly;
Execution Count:267
267
309 else if (option->toolButtonStyle != Qt::ToolButtonTextOnly)
partially evaluated: option->toolButtonStyle != Qt::ToolButtonTextOnly
TRUEFALSE
yes
Evaluation Count:21
no
Evaluation Count:0
0-21
310 option->toolButtonStyle = Qt::ToolButtonIconOnly;
executed: option->toolButtonStyle = Qt::ToolButtonIconOnly;
Execution Count:21
21
311 } -
312 -
313 option->pos = pos();
executed (the execution status of this line is deduced): option->pos = pos();
-
314 option->font = font();
executed (the execution status of this line is deduced): option->font = font();
-
315}
executed: }
Execution Count:1762
1762
316 -
317/*! -
318 Destroys the object and frees any allocated resources. -
319*/ -
320 -
321QToolButton::~QToolButton() -
322{ -
323} -
324 -
325/*! -
326 \reimp -
327*/ -
328QSize QToolButton::sizeHint() const -
329{ -
330 Q_D(const QToolButton);
executed (the execution status of this line is deduced): const QToolButtonPrivate * const d = d_func();
-
331 if (d->sizeHint.isValid())
evaluated: d->sizeHint.isValid()
TRUEFALSE
yes
Evaluation Count:1419
yes
Evaluation Count:1254
1254-1419
332 return d->sizeHint;
executed: return d->sizeHint;
Execution Count:1419
1419
333 ensurePolished();
executed (the execution status of this line is deduced): ensurePolished();
-
334 -
335 int w = 0, h = 0;
executed (the execution status of this line is deduced): int w = 0, h = 0;
-
336 QStyleOptionToolButton opt;
executed (the execution status of this line is deduced): QStyleOptionToolButton opt;
-
337 initStyleOption(&opt);
executed (the execution status of this line is deduced): initStyleOption(&opt);
-
338 -
339 QFontMetrics fm = fontMetrics();
executed (the execution status of this line is deduced): QFontMetrics fm = fontMetrics();
-
340 if (opt.toolButtonStyle != Qt::ToolButtonTextOnly) {
evaluated: opt.toolButtonStyle != Qt::ToolButtonTextOnly
TRUEFALSE
yes
Evaluation Count:1187
yes
Evaluation Count:67
67-1187
341 QSize icon = opt.iconSize;
executed (the execution status of this line is deduced): QSize icon = opt.iconSize;
-
342 w = icon.width();
executed (the execution status of this line is deduced): w = icon.width();
-
343 h = icon.height();
executed (the execution status of this line is deduced): h = icon.height();
-
344 }
executed: }
Execution Count:1187
1187
345 -
346 if (opt.toolButtonStyle != Qt::ToolButtonIconOnly) {
evaluated: opt.toolButtonStyle != Qt::ToolButtonIconOnly
TRUEFALSE
yes
Evaluation Count:67
yes
Evaluation Count:1187
67-1187
347 QSize textSize = fm.size(Qt::TextShowMnemonic, text());
executed (the execution status of this line is deduced): QSize textSize = fm.size(Qt::TextShowMnemonic, text());
-
348 textSize.setWidth(textSize.width() + fm.width(QLatin1Char(' '))*2);
executed (the execution status of this line is deduced): textSize.setWidth(textSize.width() + fm.width(QLatin1Char(' '))*2);
-
349 if (opt.toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
partially evaluated: opt.toolButtonStyle == Qt::ToolButtonTextUnderIcon
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:67
0-67
350 h += 4 + textSize.height();
never executed (the execution status of this line is deduced): h += 4 + textSize.height();
-
351 if (textSize.width() > w)
never evaluated: textSize.width() > w
0
352 w = textSize.width();
never executed: w = textSize.width();
0
353 } else if (opt.toolButtonStyle == Qt::ToolButtonTextBesideIcon) {
never executed: }
partially evaluated: opt.toolButtonStyle == Qt::ToolButtonTextBesideIcon
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:67
0-67
354 w += 4 + textSize.width();
never executed (the execution status of this line is deduced): w += 4 + textSize.width();
-
355 if (textSize.height() > h)
never evaluated: textSize.height() > h
0
356 h = textSize.height();
never executed: h = textSize.height();
0
357 } else { // TextOnly
never executed: }
0
358 w = textSize.width();
executed (the execution status of this line is deduced): w = textSize.width();
-
359 h = textSize.height();
executed (the execution status of this line is deduced): h = textSize.height();
-
360 }
executed: }
Execution Count:67
67
361 } -
362 -
363 opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height
executed (the execution status of this line is deduced): opt.rect.setSize(QSize(w, h));
-
364 if (d->popupMode == MenuButtonPopup)
evaluated: d->popupMode == MenuButtonPopup
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1253
1-1253
365 w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this);
executed: w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this);
Execution Count:1
1
366 -
367 d->sizeHint = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(w, h), this).
executed (the execution status of this line is deduced): d->sizeHint = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(w, h), this).
-
368 expandedTo(QApplication::globalStrut());
executed (the execution status of this line is deduced): expandedTo(QApplication::globalStrut());
-
369 return d->sizeHint;
executed: return d->sizeHint;
Execution Count:1254
1254
370} -
371 -
372/*! -
373 \reimp -
374 */ -
375QSize QToolButton::minimumSizeHint() const -
376{ -
377 return sizeHint();
executed: return sizeHint();
Execution Count:1268
1268
378} -
379 -
380/*! -
381 \property QToolButton::toolButtonStyle -
382 \brief whether the tool button displays an icon only, text only, -
383 or text beside/below the icon. -
384 -
385 The default is Qt::ToolButtonIconOnly. -
386 -
387 To have the style of toolbuttons follow the system settings (as available -
388 in GNOME and KDE desktop environments), set this property to Qt::ToolButtonFollowStyle. -
389 -
390 QToolButton automatically connects this slot to the relevant -
391 signal in the QMainWindow in which is resides. -
392*/ -
393 -
394/*! -
395 \property QToolButton::arrowType -
396 \brief whether the button displays an arrow instead of a normal icon -
397 -
398 This displays an arrow as the icon for the QToolButton. -
399 -
400 By default, this property is set to Qt::NoArrow. -
401*/ -
402 -
403Qt::ToolButtonStyle QToolButton::toolButtonStyle() const -
404{ -
405 Q_D(const QToolButton);
never executed (the execution status of this line is deduced): const QToolButtonPrivate * const d = d_func();
-
406 return d->toolButtonStyle;
never executed: return d->toolButtonStyle;
0
407} -
408 -
409Qt::ArrowType QToolButton::arrowType() const -
410{ -
411 Q_D(const QToolButton);
never executed (the execution status of this line is deduced): const QToolButtonPrivate * const d = d_func();
-
412 return d->arrowType;
never executed: return d->arrowType;
0
413} -
414 -
415 -
416void QToolButton::setToolButtonStyle(Qt::ToolButtonStyle style) -
417{ -
418 Q_D(QToolButton);
executed (the execution status of this line is deduced): QToolButtonPrivate * const d = d_func();
-
419 if (d->toolButtonStyle == style)
evaluated: d->toolButtonStyle == style
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1
1-3
420 return;
executed: return;
Execution Count:3
3
421 -
422 d->toolButtonStyle = style;
executed (the execution status of this line is deduced): d->toolButtonStyle = style;
-
423 d->sizeHint = QSize();
executed (the execution status of this line is deduced): d->sizeHint = QSize();
-
424 updateGeometry();
executed (the execution status of this line is deduced): updateGeometry();
-
425 if (isVisible()) {
partially evaluated: isVisible()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
426 update();
never executed (the execution status of this line is deduced): update();
-
427 }
never executed: }
0
428}
executed: }
Execution Count:1
1
429 -
430void QToolButton::setArrowType(Qt::ArrowType type) -
431{ -
432 Q_D(QToolButton);
executed (the execution status of this line is deduced): QToolButtonPrivate * const d = d_func();
-
433 if (d->arrowType == type)
evaluated: d->arrowType == type
TRUEFALSE
yes
Evaluation Count:34
yes
Evaluation Count:30
30-34
434 return;
executed: return;
Execution Count:34
34
435 -
436 d->arrowType = type;
executed (the execution status of this line is deduced): d->arrowType = type;
-
437 d->sizeHint = QSize();
executed (the execution status of this line is deduced): d->sizeHint = QSize();
-
438 updateGeometry();
executed (the execution status of this line is deduced): updateGeometry();
-
439 if (isVisible()) {
partially evaluated: isVisible()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:30
0-30
440 update();
never executed (the execution status of this line is deduced): update();
-
441 }
never executed: }
0
442}
executed: }
Execution Count:30
30
443 -
444/*! -
445 \fn void QToolButton::paintEvent(QPaintEvent *event) -
446 -
447 Paints the button in response to the paint \a event. -
448*/ -
449void QToolButton::paintEvent(QPaintEvent *) -
450{ -
451 QStylePainter p(this);
executed (the execution status of this line is deduced): QStylePainter p(this);
-
452 QStyleOptionToolButton opt;
executed (the execution status of this line is deduced): QStyleOptionToolButton opt;
-
453 initStyleOption(&opt);
executed (the execution status of this line is deduced): initStyleOption(&opt);
-
454 p.drawComplexControl(QStyle::CC_ToolButton, opt);
executed (the execution status of this line is deduced): p.drawComplexControl(QStyle::CC_ToolButton, opt);
-
455}
executed: }
Execution Count:317
317
456 -
457/*! -
458 \reimp -
459 */ -
460void QToolButton::actionEvent(QActionEvent *event) -
461{ -
462 Q_D(QToolButton);
executed (the execution status of this line is deduced): QToolButtonPrivate * const d = d_func();
-
463 QAction *action = event->action();
executed (the execution status of this line is deduced): QAction *action = event->action();
-
464 switch (event->type()) { -
465 case QEvent::ActionChanged: -
466 if (action == d->defaultAction)
evaluated: action == d->defaultAction
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:11
8-11
467 setDefaultAction(action); // update button state
executed: setDefaultAction(action);
Execution Count:8
8
468 break;
executed: break;
Execution Count:19
19
469 case QEvent::ActionAdded: -
470 connect(action, SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
executed (the execution status of this line is deduced): connect(action, "2""triggered()", this, "1""_q_actionTriggered()");
-
471 break;
executed: break;
Execution Count:67
67
472 case QEvent::ActionRemoved: -
473 if (d->defaultAction == action)
evaluated: d->defaultAction == action
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:13
6-13
474 d->defaultAction = 0;
executed: d->defaultAction = 0;
Execution Count:6
6
475#ifndef QT_NO_MENU -
476 if (action == d->menuAction)
evaluated: action == d->menuAction
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:7
7-12
477 d->menuAction = 0;
executed: d->menuAction = 0;
Execution Count:12
12
478#endif -
479 action->disconnect(this);
executed (the execution status of this line is deduced): action->disconnect(this);
-
480 break;
executed: break;
Execution Count:19
19
481 default: -
482 ; -
483 }
never executed: }
0
484 QAbstractButton::actionEvent(event);
executed (the execution status of this line is deduced): QAbstractButton::actionEvent(event);
-
485}
executed: }
Execution Count:105
105
486 -
487QStyle::SubControl QToolButtonPrivate::newHoverControl(const QPoint &pos) -
488{ -
489 Q_Q(QToolButton);
never executed (the execution status of this line is deduced): QToolButton * const q = q_func();
-
490 QStyleOptionToolButton opt;
never executed (the execution status of this line is deduced): QStyleOptionToolButton opt;
-
491 q->initStyleOption(&opt);
never executed (the execution status of this line is deduced): q->initStyleOption(&opt);
-
492 opt.subControls = QStyle::SC_All;
never executed (the execution status of this line is deduced): opt.subControls = QStyle::SC_All;
-
493 hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ToolButton, &opt, pos, q);
never executed (the execution status of this line is deduced): hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ToolButton, &opt, pos, q);
-
494 if (hoverControl == QStyle::SC_None)
never evaluated: hoverControl == QStyle::SC_None
0
495 hoverRect = QRect();
never executed: hoverRect = QRect();
0
496 else -
497 hoverRect = q->style()->subControlRect(QStyle::CC_ToolButton, &opt, hoverControl, q);
never executed: hoverRect = q->style()->subControlRect(QStyle::CC_ToolButton, &opt, hoverControl, q);
0
498 return hoverControl;
never executed: return hoverControl;
0
499} -
500 -
501bool QToolButtonPrivate::updateHoverControl(const QPoint &pos) -
502{ -
503 Q_Q(QToolButton);
never executed (the execution status of this line is deduced): QToolButton * const q = q_func();
-
504 QRect lastHoverRect = hoverRect;
never executed (the execution status of this line is deduced): QRect lastHoverRect = hoverRect;
-
505 QStyle::SubControl lastHoverControl = hoverControl;
never executed (the execution status of this line is deduced): QStyle::SubControl lastHoverControl = hoverControl;
-
506 bool doesHover = q->testAttribute(Qt::WA_Hover);
never executed (the execution status of this line is deduced): bool doesHover = q->testAttribute(Qt::WA_Hover);
-
507 if (lastHoverControl != newHoverControl(pos) && doesHover) {
never evaluated: lastHoverControl != newHoverControl(pos)
never evaluated: doesHover
0
508 q->update(lastHoverRect);
never executed (the execution status of this line is deduced): q->update(lastHoverRect);
-
509 q->update(hoverRect);
never executed (the execution status of this line is deduced): q->update(hoverRect);
-
510 return true;
never executed: return true;
0
511 } -
512 return !doesHover;
never executed: return !doesHover;
0
513} -
514 -
515void QToolButtonPrivate::_q_actionTriggered() -
516{ -
517 Q_Q(QToolButton);
executed (the execution status of this line is deduced): QToolButton * const q = q_func();
-
518 if (QAction *action = qobject_cast<QAction *>(q->sender()))
partially evaluated: QAction *action = qobject_cast<QAction *>(q->sender())
TRUEFALSE
yes
Evaluation Count:37
no
Evaluation Count:0
0-37
519 emit q->triggered(action);
executed: q->triggered(action);
Execution Count:37
37
520}
executed: }
Execution Count:37
37
521 -
522/*! -
523 \reimp -
524 */ -
525void QToolButton::enterEvent(QEvent * e) -
526{ -
527 Q_D(QToolButton);
executed (the execution status of this line is deduced): QToolButtonPrivate * const d = d_func();
-
528 if (d->autoRaise)
partially evaluated: d->autoRaise
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
529 update();
executed: update();
Execution Count:1
1
530 if (d->defaultAction)
partially evaluated: d->defaultAction
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
531 d->defaultAction->hover();
never executed: d->defaultAction->hover();
0
532 QAbstractButton::enterEvent(e);
executed (the execution status of this line is deduced): QAbstractButton::enterEvent(e);
-
533}
executed: }
Execution Count:1
1
534 -
535 -
536/*! -
537 \reimp -
538 */ -
539void QToolButton::leaveEvent(QEvent * e) -
540{ -
541 Q_D(QToolButton);
never executed (the execution status of this line is deduced): QToolButtonPrivate * const d = d_func();
-
542 if (d->autoRaise)
never evaluated: d->autoRaise
0
543 update();
never executed: update();
0
544 -
545 QAbstractButton::leaveEvent(e);
never executed (the execution status of this line is deduced): QAbstractButton::leaveEvent(e);
-
546}
never executed: }
0
547 -
548 -
549/*! -
550 \reimp -
551 */ -
552void QToolButton::timerEvent(QTimerEvent *e) -
553{ -
554#ifndef QT_NO_MENU -
555 Q_D(QToolButton);
executed (the execution status of this line is deduced): QToolButtonPrivate * const d = d_func();
-
556 if (e->timerId() == d->popupTimer.timerId()) {
partially evaluated: e->timerId() == d->popupTimer.timerId()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:27
0-27
557 d->popupTimerDone();
never executed (the execution status of this line is deduced): d->popupTimerDone();
-
558 return;
never executed: return;
0
559 } -
560#endif -
561 QAbstractButton::timerEvent(e);
executed (the execution status of this line is deduced): QAbstractButton::timerEvent(e);
-
562}
executed: }
Execution Count:27
27
563 -
564 -
565/*! -
566 \reimp -
567*/ -
568void QToolButton::changeEvent(QEvent *e) -
569{ -
570#ifndef QT_NO_TOOLBAR -
571 Q_D(QToolButton);
executed (the execution status of this line is deduced): QToolButtonPrivate * const d = d_func();
-
572 if (e->type() == QEvent::ParentChange) {
evaluated: e->type() == QEvent::ParentChange
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:1422
4-1422
573 if (qobject_cast<QToolBar*>(parentWidget()))
evaluated: qobject_cast<QToolBar*>(parentWidget())
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:3
1-3
574 d->autoRaise = true;
executed: d->autoRaise = true;
Execution Count:1
1
575 } else if (e->type() == QEvent::StyleChange
executed: }
Execution Count:4
evaluated: e->type() == QEvent::StyleChange
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:1398
4-1398
576#ifdef Q_OS_MAC -
577 || e->type() == QEvent::MacSizeChange -
578#endif -
579 ) { -
580 d->delay = style()->styleHint(QStyle::SH_ToolButton_PopupDelay, 0, this);
executed (the execution status of this line is deduced): d->delay = style()->styleHint(QStyle::SH_ToolButton_PopupDelay, 0, this);
-
581 d->setLayoutItemMargins(QStyle::SE_ToolButtonLayoutItem);
executed (the execution status of this line is deduced): d->setLayoutItemMargins(QStyle::SE_ToolButtonLayoutItem);
-
582 }
executed: }
Execution Count:24
24
583#endif -
584 QAbstractButton::changeEvent(e);
executed (the execution status of this line is deduced): QAbstractButton::changeEvent(e);
-
585}
executed: }
Execution Count:1426
1426
586 -
587/*! -
588 \reimp -
589*/ -
590void QToolButton::mousePressEvent(QMouseEvent *e) -
591{ -
592 Q_D(QToolButton);
executed (the execution status of this line is deduced): QToolButtonPrivate * const d = d_func();
-
593#ifndef QT_NO_MENU -
594 QStyleOptionToolButton opt;
executed (the execution status of this line is deduced): QStyleOptionToolButton opt;
-
595 initStyleOption(&opt);
executed (the execution status of this line is deduced): initStyleOption(&opt);
-
596 if (e->button() == Qt::LeftButton && (d->popupMode == MenuButtonPopup)) {
partially evaluated: e->button() == Qt::LeftButton
TRUEFALSE
yes
Evaluation Count:23
no
Evaluation Count:0
partially evaluated: (d->popupMode == MenuButtonPopup)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:23
0-23
597 QRect popupr = style()->subControlRect(QStyle::CC_ToolButton, &opt,
never executed (the execution status of this line is deduced): QRect popupr = style()->subControlRect(QStyle::CC_ToolButton, &opt,
-
598 QStyle::SC_ToolButtonMenu, this);
never executed (the execution status of this line is deduced): QStyle::SC_ToolButtonMenu, this);
-
599 if (popupr.isValid() && popupr.contains(e->pos())) {
never evaluated: popupr.isValid()
never evaluated: popupr.contains(e->pos())
0
600 d->buttonPressed = QToolButtonPrivate::MenuButtonPressed;
never executed (the execution status of this line is deduced): d->buttonPressed = QToolButtonPrivate::MenuButtonPressed;
-
601 showMenu();
never executed (the execution status of this line is deduced): showMenu();
-
602 return;
never executed: return;
0
603 } -
604 }
never executed: }
0
605#endif -
606 d->buttonPressed = QToolButtonPrivate::ToolButtonPressed;
executed (the execution status of this line is deduced): d->buttonPressed = QToolButtonPrivate::ToolButtonPressed;
-
607 QAbstractButton::mousePressEvent(e);
executed (the execution status of this line is deduced): QAbstractButton::mousePressEvent(e);
-
608}
executed: }
Execution Count:23
23
609 -
610/*! -
611 \reimp -
612*/ -
613void QToolButton::mouseReleaseEvent(QMouseEvent *e) -
614{ -
615 Q_D(QToolButton);
executed (the execution status of this line is deduced): QToolButtonPrivate * const d = d_func();
-
616 QAbstractButton::mouseReleaseEvent(e);
executed (the execution status of this line is deduced): QAbstractButton::mouseReleaseEvent(e);
-
617 d->buttonPressed = QToolButtonPrivate::NoButtonPressed;
executed (the execution status of this line is deduced): d->buttonPressed = QToolButtonPrivate::NoButtonPressed;
-
618}
executed: }
Execution Count:23
23
619 -
620/*! -
621 \reimp -
622*/ -
623bool QToolButton::hitButton(const QPoint &pos) const -
624{ -
625 Q_D(const QToolButton);
executed (the execution status of this line is deduced): const QToolButtonPrivate * const d = d_func();
-
626 if(QAbstractButton::hitButton(pos))
partially evaluated: QAbstractButton::hitButton(pos)
TRUEFALSE
yes
Evaluation Count:46
no
Evaluation Count:0
0-46
627 return (d->buttonPressed != QToolButtonPrivate::MenuButtonPressed);
executed: return (d->buttonPressed != QToolButtonPrivate::MenuButtonPressed);
Execution Count:46
46
628 return false;
never executed: return false;
0
629} -
630 -
631 -
632#ifndef QT_NO_MENU -
633/*! -
634 Associates the given \a menu with this tool button. -
635 -
636 The menu will be shown according to the button's \l popupMode. -
637 -
638 Ownership of the menu is not transferred to the tool button. -
639 -
640 \sa menu() -
641*/ -
642void QToolButton::setMenu(QMenu* menu) -
643{ -
644 Q_D(QToolButton);
executed (the execution status of this line is deduced): QToolButtonPrivate * const d = d_func();
-
645 -
646 if (d->menuAction)
evaluated: d->menuAction
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:59
11-59
647 removeAction(d->menuAction);
executed: removeAction(d->menuAction);
Execution Count:11
11
648 -
649 if (menu) {
evaluated: menu
TRUEFALSE
yes
Evaluation Count:57
yes
Evaluation Count:13
13-57
650 d->menuAction = menu->menuAction();
executed (the execution status of this line is deduced): d->menuAction = menu->menuAction();
-
651 addAction(d->menuAction);
executed (the execution status of this line is deduced): addAction(d->menuAction);
-
652 } else {
executed: }
Execution Count:57
57
653 d->menuAction = 0;
executed (the execution status of this line is deduced): d->menuAction = 0;
-
654 }
executed: }
Execution Count:13
13
655 update();
executed (the execution status of this line is deduced): update();
-
656}
executed: }
Execution Count:70
70
657 -
658/*! -
659 Returns the associated menu, or 0 if no menu has been defined. -
660 -
661 \sa setMenu() -
662*/ -
663QMenu* QToolButton::menu() const -
664{ -
665 Q_D(const QToolButton);
executed (the execution status of this line is deduced): const QToolButtonPrivate * const d = d_func();
-
666 if (d->menuAction)
evaluated: d->menuAction
TRUEFALSE
yes
Evaluation Count:57
yes
Evaluation Count:9
9-57
667 return d->menuAction->menu();
executed: return d->menuAction->menu();
Execution Count:57
57
668 return 0;
executed: return 0;
Execution Count:9
9
669} -
670 -
671/*! -
672 Shows (pops up) the associated popup menu. If there is no such -
673 menu, this function does nothing. This function does not return -
674 until the popup menu has been closed by the user. -
675*/ -
676void QToolButton::showMenu() -
677{ -
678 Q_D(QToolButton);
executed (the execution status of this line is deduced): QToolButtonPrivate * const d = d_func();
-
679 if (!d->hasMenu()) {
partially evaluated: !d->hasMenu()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
680 d->menuButtonDown = false;
never executed (the execution status of this line is deduced): d->menuButtonDown = false;
-
681 return; // no menu to show
never executed: return;
0
682 } -
683 -
684 d->menuButtonDown = true;
executed (the execution status of this line is deduced): d->menuButtonDown = true;
-
685 repaint();
executed (the execution status of this line is deduced): repaint();
-
686 d->popupTimer.stop();
executed (the execution status of this line is deduced): d->popupTimer.stop();
-
687 d->popupTimerDone();
executed (the execution status of this line is deduced): d->popupTimerDone();
-
688}
executed: }
Execution Count:2
2
689 -
690void QToolButtonPrivate::_q_buttonPressed() -
691{ -
692 Q_Q(QToolButton);
executed (the execution status of this line is deduced): QToolButton * const q = q_func();
-
693 if (!hasMenu())
partially evaluated: !hasMenu()
TRUEFALSE
yes
Evaluation Count:62
no
Evaluation Count:0
0-62
694 return; // no menu to show
executed: return;
Execution Count:62
62
695 if (popupMode == QToolButton::MenuButtonPopup)
never evaluated: popupMode == QToolButton::MenuButtonPopup
0
696 return;
never executed: return;
0
697 else if (delay > 0 && !popupTimer.isActive() && popupMode == QToolButton::DelayedPopup)
never evaluated: delay > 0
never evaluated: !popupTimer.isActive()
never evaluated: popupMode == QToolButton::DelayedPopup
0
698 popupTimer.start(delay, q);
never executed: popupTimer.start(delay, q);
0
699 else if (delay == 0 || popupMode == QToolButton::InstantPopup)
never evaluated: delay == 0
never evaluated: popupMode == QToolButton::InstantPopup
0
700 q->showMenu();
never executed: q->showMenu();
0
701} -
702 -
703void QToolButtonPrivate::popupTimerDone() -
704{ -
705 Q_Q(QToolButton);
executed (the execution status of this line is deduced): QToolButton * const q = q_func();
-
706 popupTimer.stop();
executed (the execution status of this line is deduced): popupTimer.stop();
-
707 if (!menuButtonDown && !down)
partially evaluated: !menuButtonDown
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
never evaluated: !down
0-2
708 return;
never executed: return;
0
709 -
710 menuButtonDown = true;
executed (the execution status of this line is deduced): menuButtonDown = true;
-
711 QPointer<QMenu> actualMenu;
executed (the execution status of this line is deduced): QPointer<QMenu> actualMenu;
-
712 bool mustDeleteActualMenu = false;
executed (the execution status of this line is deduced): bool mustDeleteActualMenu = false;
-
713 if(menuAction) {
evaluated: menuAction
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
714 actualMenu = menuAction->menu();
executed (the execution status of this line is deduced): actualMenu = menuAction->menu();
-
715 } else if (defaultAction && defaultAction->menu()) {
executed: }
Execution Count:1
partially evaluated: defaultAction
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
partially evaluated: defaultAction->menu()
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
716 actualMenu = defaultAction->menu();
executed (the execution status of this line is deduced): actualMenu = defaultAction->menu();
-
717 } else {
executed: }
Execution Count:1
1
718 actualMenu = new QMenu(q);
never executed (the execution status of this line is deduced): actualMenu = new QMenu(q);
-
719 mustDeleteActualMenu = true;
never executed (the execution status of this line is deduced): mustDeleteActualMenu = true;
-
720 for(int i = 0; i < actions.size(); i++)
never evaluated: i < actions.size()
0
721 actualMenu->addAction(actions.at(i));
never executed: actualMenu->addAction(actions.at(i));
0
722 }
never executed: }
0
723 repeat = q->autoRepeat();
executed (the execution status of this line is deduced): repeat = q->autoRepeat();
-
724 q->setAutoRepeat(false);
executed (the execution status of this line is deduced): q->setAutoRepeat(false);
-
725 bool horizontal = true;
executed (the execution status of this line is deduced): bool horizontal = true;
-
726#if !defined(QT_NO_TOOLBAR) -
727 QToolBar *tb = qobject_cast<QToolBar*>(parent);
executed (the execution status of this line is deduced): QToolBar *tb = qobject_cast<QToolBar*>(parent);
-
728 if (tb && tb->orientation() == Qt::Vertical)
evaluated: tb
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
partially evaluated: tb->orientation() == Qt::Vertical
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
729 horizontal = false;
never executed: horizontal = false;
0
730#endif -
731 QPoint p;
executed (the execution status of this line is deduced): QPoint p;
-
732 QRect screen = QApplication::desktop()->availableGeometry(q);
executed (the execution status of this line is deduced): QRect screen = QApplication::desktop()->availableGeometry(q);
-
733 QSize sh = ((QToolButton*)(QMenu*)actualMenu)->receivers(SIGNAL(aboutToShow()))? QSize() : actualMenu->sizeHint();
partially evaluated: ((QToolButton*)(QMenu*)actualMenu)->receivers("2""aboutToShow()")
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
734 QRect rect = q->rect();
executed (the execution status of this line is deduced): QRect rect = q->rect();
-
735 if (horizontal) {
partially evaluated: horizontal
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
736 if (q->isRightToLeft()) {
partially evaluated: q->isRightToLeft()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
737 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
738 p = q->mapToGlobal(rect.bottomRight());
never executed (the execution status of this line is deduced): p = q->mapToGlobal(rect.bottomRight());
-
739 } else {
never executed: }
0
740 p = q->mapToGlobal(rect.topRight() - QPoint(0, sh.height()));
never executed (the execution status of this line is deduced): p = q->mapToGlobal(rect.topRight() - QPoint(0, sh.height()));
-
741 }
never executed: }
0
742 p.rx() -= sh.width();
never executed (the execution status of this line is deduced): p.rx() -= sh.width();
-
743 } else {
never executed: }
0
744 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()
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
745 p = q->mapToGlobal(rect.bottomLeft());
executed (the execution status of this line is deduced): p = q->mapToGlobal(rect.bottomLeft());
-
746 } else {
executed: }
Execution Count:2
2
747 p = q->mapToGlobal(rect.topLeft() - QPoint(0, sh.height()));
never executed (the execution status of this line is deduced): p = q->mapToGlobal(rect.topLeft() - QPoint(0, sh.height()));
-
748 }
never executed: }
0
749 } -
750 } else { -
751 if (q->isRightToLeft()) {
never evaluated: q->isRightToLeft()
0
752 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
753 p = q->mapToGlobal(rect.topRight());
never executed (the execution status of this line is deduced): p = q->mapToGlobal(rect.topRight());
-
754 } else {
never executed: }
0
755 p = q->mapToGlobal(rect.topLeft());
never executed (the execution status of this line is deduced): p = q->mapToGlobal(rect.topLeft());
-
756 p.rx() -= sh.width();
never executed (the execution status of this line is deduced): p.rx() -= sh.width();
-
757 }
never executed: }
0
758 } else { -
759 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
760 p = q->mapToGlobal(rect.topRight());
never executed (the execution status of this line is deduced): p = q->mapToGlobal(rect.topRight());
-
761 } else {
never executed: }
0
762 p = q->mapToGlobal(rect.topLeft() - QPoint(sh.width(), 0));
never executed (the execution status of this line is deduced): p = q->mapToGlobal(rect.topLeft() - QPoint(sh.width(), 0));
-
763 }
never executed: }
0
764 } -
765 } -
766 p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width()));
executed (the execution status of this line is deduced): p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width()));
-
767 p.ry() += 1;
executed (the execution status of this line is deduced): p.ry() += 1;
-
768 QPointer<QToolButton> that = q;
executed (the execution status of this line is deduced): QPointer<QToolButton> that = q;
-
769 actualMenu->setNoReplayFor(q);
executed (the execution status of this line is deduced): actualMenu->setNoReplayFor(q);
-
770 if (!mustDeleteActualMenu) //only if action are not in this widget
partially evaluated: !mustDeleteActualMenu
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
771 QObject::connect(actualMenu, SIGNAL(triggered(QAction*)), q, SLOT(_q_menuTriggered(QAction*)));
executed: QObject::connect(actualMenu, "2""triggered(QAction*)", q, "1""_q_menuTriggered(QAction*)");
Execution Count:2
2
772 QObject::connect(actualMenu, SIGNAL(aboutToHide()), q, SLOT(_q_updateButtonDown()));
executed (the execution status of this line is deduced): QObject::connect(actualMenu, "2""aboutToHide()", q, "1""_q_updateButtonDown()");
-
773 actualMenu->d_func()->causedPopup.widget = q;
executed (the execution status of this line is deduced): actualMenu->d_func()->causedPopup.widget = q;
-
774 actualMenu->d_func()->causedPopup.action = defaultAction;
executed (the execution status of this line is deduced): actualMenu->d_func()->causedPopup.action = defaultAction;
-
775 actionsCopy = q->actions(); //(the list of action may be modified in slots)
executed (the execution status of this line is deduced): actionsCopy = q->actions();
-
776 actualMenu->exec(p);
executed (the execution status of this line is deduced): actualMenu->exec(p);
-
777 QObject::disconnect(actualMenu, SIGNAL(aboutToHide()), q, SLOT(_q_updateButtonDown()));
executed (the execution status of this line is deduced): QObject::disconnect(actualMenu, "2""aboutToHide()", q, "1""_q_updateButtonDown()");
-
778 if (mustDeleteActualMenu)
partially evaluated: mustDeleteActualMenu
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
779 delete actualMenu;
never executed: delete actualMenu;
0
780 else -
781 QObject::disconnect(actualMenu, SIGNAL(triggered(QAction*)), q, SLOT(_q_menuTriggered(QAction*)));
executed: QObject::disconnect(actualMenu, "2""triggered(QAction*)", q, "1""_q_menuTriggered(QAction*)");
Execution Count:2
2
782 -
783 if (!that)
partially evaluated: !that
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
784 return;
never executed: return;
0
785 -
786 actionsCopy.clear();
executed (the execution status of this line is deduced): actionsCopy.clear();
-
787 -
788 if (repeat)
partially evaluated: repeat
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
789 q->setAutoRepeat(true);
never executed: q->setAutoRepeat(true);
0
790}
executed: }
Execution Count:2
2
791 -
792void QToolButtonPrivate::_q_updateButtonDown() -
793{ -
794 Q_Q(QToolButton);
executed (the execution status of this line is deduced): QToolButton * const q = q_func();
-
795 menuButtonDown = false;
executed (the execution status of this line is deduced): menuButtonDown = false;
-
796 if (q->isDown())
partially evaluated: q->isDown()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
797 q->setDown(false);
never executed: q->setDown(false);
0
798 else -
799 q->repaint();
executed: q->repaint();
Execution Count:2
2
800} -
801 -
802void QToolButtonPrivate::_q_menuTriggered(QAction *action) -
803{ -
804 Q_Q(QToolButton);
executed (the execution status of this line is deduced): QToolButton * const q = q_func();
-
805 if (action && !actionsCopy.contains(action))
partially evaluated: action
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
partially evaluated: !actionsCopy.contains(action)
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
806 emit q->triggered(action);
executed: q->triggered(action);
Execution Count:1
1
807}
executed: }
Execution Count:1
1
808#endif // QT_NO_MENU -
809 -
810 -
811#ifndef QT_NO_MENU -
812/*! \enum QToolButton::ToolButtonPopupMode -
813 -
814 Describes how a menu should be popped up for tool buttons that has -
815 a menu set or contains a list of actions. -
816 -
817 \value DelayedPopup After pressing and holding the tool button -
818 down for a certain amount of time (the timeout is style dependant, -
819 see QStyle::SH_ToolButton_PopupDelay), the menu is displayed. A -
820 typical application example is the "back" button in some web -
821 browsers's tool bars. If the user clicks it, the browser simply -
822 browses back to the previous page. If the user presses and holds -
823 the button down for a while, the tool button shows a menu -
824 containing the current history list -
825 -
826 \value MenuButtonPopup In this mode the tool button displays a -
827 special arrow to indicate that a menu is present. The menu is -
828 displayed when the arrow part of the button is pressed. -
829 -
830 \value InstantPopup The menu is displayed, without delay, when -
831 the tool button is pressed. In this mode, the button's own action -
832 is not triggered. -
833*/ -
834 -
835/*! -
836 \property QToolButton::popupMode -
837 \brief describes the way that popup menus are used with tool buttons -
838 -
839 By default, this property is set to \l DelayedPopup. -
840*/ -
841 -
842void QToolButton::setPopupMode(ToolButtonPopupMode mode) -
843{ -
844 Q_D(QToolButton);
executed (the execution status of this line is deduced): QToolButtonPrivate * const d = d_func();
-
845 d->popupMode = mode;
executed (the execution status of this line is deduced): d->popupMode = mode;
-
846}
executed: }
Execution Count:90
90
847 -
848QToolButton::ToolButtonPopupMode QToolButton::popupMode() const -
849{ -
850 Q_D(const QToolButton);
executed (the execution status of this line is deduced): const QToolButtonPrivate * const d = d_func();
-
851 return d->popupMode;
executed: return d->popupMode;
Execution Count:3
3
852} -
853#endif -
854 -
855/*! -
856 \property QToolButton::autoRaise -
857 \brief whether auto-raising is enabled or not. -
858 -
859 The default is disabled (i.e. false). -
860 -
861 This property is currently ignored on Mac OS X when using QMacStyle. -
862*/ -
863void QToolButton::setAutoRaise(bool enable) -
864{ -
865 Q_D(QToolButton);
executed (the execution status of this line is deduced): QToolButtonPrivate * const d = d_func();
-
866 d->autoRaise = enable;
executed (the execution status of this line is deduced): d->autoRaise = enable;
-
867 -
868 update();
executed (the execution status of this line is deduced): update();
-
869}
executed: }
Execution Count:1313
1313
870 -
871bool QToolButton::autoRaise() const -
872{ -
873 Q_D(const QToolButton);
executed (the execution status of this line is deduced): const QToolButtonPrivate * const d = d_func();
-
874 return d->autoRaise;
executed: return d->autoRaise;
Execution Count:3
3
875} -
876 -
877/*! -
878 Sets the default action to \a action. -
879 -
880 If a tool button has a default action, the action defines the -
881 button's properties like text, icon, tool tip, etc. -
882 */ -
883void QToolButton::setDefaultAction(QAction *action) -
884{ -
885 Q_D(QToolButton);
executed (the execution status of this line is deduced): QToolButtonPrivate * const d = d_func();
-
886#ifndef QT_NO_MENU -
887 bool hadMenu = false;
executed (the execution status of this line is deduced): bool hadMenu = false;
-
888 hadMenu = d->hasMenu();
executed (the execution status of this line is deduced): hadMenu = d->hasMenu();
-
889#endif -
890 d->defaultAction = action;
executed (the execution status of this line is deduced): d->defaultAction = action;
-
891 if (!action)
evaluated: !action
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:18
1-18
892 return;
executed: return;
Execution Count:1
1
893 if (!actions().contains(action))
evaluated: !actions().contains(action)
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:8
8-10
894 addAction(action);
executed: addAction(action);
Execution Count:10
10
895 setText(action->iconText());
executed (the execution status of this line is deduced): setText(action->iconText());
-
896 setIcon(action->icon());
executed (the execution status of this line is deduced): setIcon(action->icon());
-
897#ifndef QT_NO_TOOLTIP -
898 setToolTip(action->toolTip());
executed (the execution status of this line is deduced): setToolTip(action->toolTip());
-
899#endif -
900#ifndef QT_NO_STATUSTIP -
901 setStatusTip(action->statusTip());
executed (the execution status of this line is deduced): setStatusTip(action->statusTip());
-
902#endif -
903#ifndef QT_NO_WHATSTHIS -
904 setWhatsThis(action->whatsThis());
executed (the execution status of this line is deduced): setWhatsThis(action->whatsThis());
-
905#endif -
906#ifndef QT_NO_MENU -
907 if (action->menu() && !hadMenu) {
evaluated: action->menu()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:17
partially evaluated: !hadMenu
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-17
908 // new 'default' popup mode defined introduced by tool bar. We -
909 // should have changed QToolButton's default instead. Do that -
910 // in 4.2. -
911 setPopupMode(QToolButton::MenuButtonPopup);
executed (the execution status of this line is deduced): setPopupMode(QToolButton::MenuButtonPopup);
-
912 }
executed: }
Execution Count:1
1
913#endif -
914 setCheckable(action->isCheckable());
executed (the execution status of this line is deduced): setCheckable(action->isCheckable());
-
915 setChecked(action->isChecked());
executed (the execution status of this line is deduced): setChecked(action->isChecked());
-
916 setEnabled(action->isEnabled());
executed (the execution status of this line is deduced): setEnabled(action->isEnabled());
-
917 if (action->d_func()->fontSet)
partially evaluated: action->d_func()->fontSet
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18
0-18
918 setFont(action->font());
never executed: setFont(action->font());
0
919}
executed: }
Execution Count:18
18
920 -
921 -
922/*! -
923 Returns the default action. -
924 -
925 \sa setDefaultAction() -
926 */ -
927QAction *QToolButton::defaultAction() const -
928{ -
929 Q_D(const QToolButton);
executed (the execution status of this line is deduced): const QToolButtonPrivate * const d = d_func();
-
930 return d->defaultAction;
executed: return d->defaultAction;
Execution Count:2
2
931} -
932 -
933 -
934 -
935/*! -
936 \reimp -
937 */ -
938void QToolButton::nextCheckState() -
939{ -
940 Q_D(QToolButton);
executed (the execution status of this line is deduced): QToolButtonPrivate * const d = d_func();
-
941 if (!d->defaultAction)
evaluated: !d->defaultAction
TRUEFALSE
yes
Evaluation Count:29
yes
Evaluation Count:36
29-36
942 QAbstractButton::nextCheckState();
executed: QAbstractButton::nextCheckState();
Execution Count:29
29
943 else -
944 d->defaultAction->trigger();
executed: d->defaultAction->trigger();
Execution Count:36
36
945} -
946 -
947/*! \reimp */ -
948bool QToolButton::event(QEvent *event) -
949{ -
950 switch(event->type()) { -
951 case QEvent::HoverEnter: -
952 case QEvent::HoverLeave: -
953 case QEvent::HoverMove: -
954 if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event))
never evaluated: const QHoverEvent *he = static_cast<const QHoverEvent *>(event)
0
955 d_func()->updateHoverControl(he->pos());
never executed: d_func()->updateHoverControl(he->pos());
0
956 break;
never executed: break;
0
957 default: -
958 break;
executed: break;
Execution Count:9135
9135
959 } -
960 return QAbstractButton::event(event);
executed: return QAbstractButton::event(event);
Execution Count:9135
9135
961} -
962 -
963QT_END_NAMESPACE -
964 -
965#include "moc_qtoolbutton.cpp" -
966 -
967#endif -
968 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial