qabstractbutton.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qabstractbutton.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "private/qabstractbutton_p.h"-
35-
36#include "private/qbuttongroup_p.h"-
37#include "qabstractitemview.h"-
38#include "qbuttongroup.h"-
39#include "qabstractbutton_p.h"-
40#include "qevent.h"-
41#include "qpainter.h"-
42#include "qapplication.h"-
43#include "qstyle.h"-
44#include "qaction.h"-
45#ifndef QT_NO_ACCESSIBILITY-
46#include "qaccessible.h"-
47#endif-
48-
49#include <algorithm>-
50-
51QT_BEGIN_NAMESPACE-
52-
53#define AUTO_REPEAT_DELAY 300-
54#define AUTO_REPEAT_INTERVAL 100-
55-
56Q_WIDGETS_EXPORT extern bool qt_tab_all_widgets();-
57-
58/*!-
59 \class QAbstractButton-
60-
61 \brief The QAbstractButton class is the abstract base class of-
62 button widgets, providing functionality common to buttons.-
63-
64 \ingroup abstractwidgets-
65 \inmodule QtWidgets-
66-
67 This class implements an \e abstract button.-
68 Subclasses of this class handle user actions, and specify how the button-
69 is drawn.-
70-
71 QAbstractButton provides support for both push buttons and checkable-
72 (toggle) buttons. Checkable buttons are implemented in the QRadioButton-
73 and QCheckBox classes. Push buttons are implemented in the-
74 QPushButton and QToolButton classes; these also provide toggle-
75 behavior if required.-
76-
77 Any button can display a label containing text and an icon. setText()-
78 sets the text; setIcon() sets the icon. If a button is disabled, its label-
79 is changed to give the button a "disabled" appearance.-
80-
81 If the button is a text button with a string containing an-
82 ampersand ('&'), QAbstractButton automatically creates a shortcut-
83 key. For example:-
84-
85 \snippet code/src_gui_widgets_qabstractbutton.cpp 0-
86-
87 The \uicontrol Alt+C shortcut is assigned to the button, i.e., when the-
88 user presses \uicontrol Alt+C the button will call animateClick(). See-
89 the \l {QShortcut#mnemonic}{QShortcut} documentation for details. To-
90 display an actual ampersand, use '&&'.-
91-
92 You can also set a custom shortcut key using the setShortcut()-
93 function. This is useful mostly for buttons that do not have any-
94 text, and therefore can't have any automatic shortcut.-
95-
96 \snippet code/src_gui_widgets_qabstractbutton.cpp 1-
97-
98 All the buttons provided by Qt (QPushButton, QToolButton,-
99 QCheckBox, and QRadioButton) can display both \l text and \l{icon}{icons}.-
100-
101 A button can be made the default button in a dialog by means of-
102 QPushButton::setDefault() and QPushButton::setAutoDefault().-
103-
104 QAbstractButton provides most of the states used for buttons:-
105-
106 \list-
107-
108 \li isDown() indicates whether the button is \e pressed down.-
109-
110 \li isChecked() indicates whether the button is \e checked. Only-
111 checkable buttons can be checked and unchecked (see below).-
112-
113 \li isEnabled() indicates whether the button can be pressed by the-
114 user. \note As opposed to other widgets, buttons derived from-
115 QAbstractButton accept mouse and context menu events-
116 when disabled.-
117-
118 \li setAutoRepeat() sets whether the button will auto-repeat if the-
119 user holds it down. \l autoRepeatDelay and \l autoRepeatInterval-
120 define how auto-repetition is done.-
121-
122 \li setCheckable() sets whether the button is a toggle button or not.-
123-
124 \endlist-
125-
126 The difference between isDown() and isChecked() is as follows.-
127 When the user clicks a toggle button to check it, the button is first-
128 \e pressed then released into the \e checked state. When the user-
129 clicks it again (to uncheck it), the button moves first to the-
130 \e pressed state, then to the \e unchecked state (isChecked() and-
131 isDown() are both false).-
132-
133 QAbstractButton provides four signals:-
134-
135 \list 1-
136-
137 \li pressed() is emitted when the left mouse button is pressed while-
138 the mouse cursor is inside the button.-
139-
140 \li released() is emitted when the left mouse button is released.-
141-
142 \li clicked() is emitted when the button is first pressed and then-
143 released, when the shortcut key is typed, or when click() or-
144 animateClick() is called.-
145-
146 \li toggled() is emitted when the state of a toggle button changes.-
147-
148 \endlist-
149-
150 To subclass QAbstractButton, you must reimplement at least-
151 paintEvent() to draw the button's outline and its text or pixmap. It-
152 is generally advisable to reimplement sizeHint() as well, and-
153 sometimes hitButton() (to determine whether a button press is within-
154 the button). For buttons with more than two states (like tri-state-
155 buttons), you will also have to reimplement checkStateSet() and-
156 nextCheckState().-
157-
158 \sa QButtonGroup-
159*/-
160-
161QAbstractButtonPrivate::QAbstractButtonPrivate(QSizePolicy::ControlType type)-
162 :-
163#ifndef QT_NO_SHORTCUT-
164 shortcutId(0),-
165#endif-
166 checkable(false), checked(false), autoRepeat(false), autoExclusive(false),-
167 down(false), blockRefresh(false), pressed(false),-
168#ifndef QT_NO_BUTTONGROUP-
169 group(0),-
170#endif-
171 autoRepeatDelay(AUTO_REPEAT_DELAY),-
172 autoRepeatInterval(AUTO_REPEAT_INTERVAL),-
173 controlType(type)-
174{}
never executed: end of block
0
175-
176QList<QAbstractButton *>QAbstractButtonPrivate::queryButtonList() const-
177{-
178#ifndef QT_NO_BUTTONGROUP-
179 if (group)
groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
180 return group->d_func()->buttonList;
never executed: return group->d_func()->buttonList;
0
181#endif-
182-
183 QList<QAbstractButton*>candidates = parent->findChildren<QAbstractButton *>();-
184 if (autoExclusive) {
autoExclusiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
185 for (int i = candidates.count() - 1; i >= 0; --i) {
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
186 QAbstractButton *candidate = candidates.at(i);-
187 if (!candidate->autoExclusive()
!candidate->autoExclusive()Description
TRUEnever evaluated
FALSEnever evaluated
0
188#ifndef QT_NO_BUTTONGROUP-
189 || candidate->group()
candidate->group()Description
TRUEnever evaluated
FALSEnever evaluated
0
190#endif-
191 )-
192 candidates.removeAt(i);
never executed: candidates.removeAt(i);
0
193 }
never executed: end of block
0
194 }
never executed: end of block
0
195 return candidates;
never executed: return candidates;
0
196}-
197-
198QAbstractButton *QAbstractButtonPrivate::queryCheckedButton() const-
199{-
200#ifndef QT_NO_BUTTONGROUP-
201 if (group)
groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
202 return group->d_func()->checkedButton;
never executed: return group->d_func()->checkedButton;
0
203#endif-
204-
205 Q_Q(const QAbstractButton);-
206 QList<QAbstractButton *> buttonList = queryButtonList();-
207 if (!autoExclusive || buttonList.count() == 1) // no group
!autoExclusiveDescription
TRUEnever evaluated
FALSEnever evaluated
buttonList.count() == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
208 return 0;
never executed: return 0;
0
209-
210 for (int i = 0; i < buttonList.count(); ++i) {
i < buttonList.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
211 QAbstractButton *b = buttonList.at(i);-
212 if (b->d_func()->checked && b != q)
b->d_func()->checkedDescription
TRUEnever evaluated
FALSEnever evaluated
b != qDescription
TRUEnever evaluated
FALSEnever evaluated
0
213 return b;
never executed: return b;
0
214 }
never executed: end of block
0
215 return checked ? const_cast<QAbstractButton *>(q) : 0;
never executed: return checked ? const_cast<QAbstractButton *>(q) : 0;
checkedDescription
TRUEnever evaluated
FALSEnever evaluated
0
216}-
217-
218void QAbstractButtonPrivate::notifyChecked()-
219{-
220#ifndef QT_NO_BUTTONGROUP-
221 Q_Q(QAbstractButton);-
222 if (group) {
groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
223 QAbstractButton *previous = group->d_func()->checkedButton;-
224 group->d_func()->checkedButton = q;-
225 if (group->d_func()->exclusive && previous && previous != q)
group->d_func()->exclusiveDescription
TRUEnever evaluated
FALSEnever evaluated
previousDescription
TRUEnever evaluated
FALSEnever evaluated
previous != qDescription
TRUEnever evaluated
FALSEnever evaluated
0
226 previous->nextCheckState();
never executed: previous->nextCheckState();
0
227 } else
never executed: end of block
0
228#endif-
229 if (autoExclusive) {
autoExclusiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
230 if (QAbstractButton *b = queryCheckedButton())
QAbstractButto...heckedButton()Description
TRUEnever evaluated
FALSEnever evaluated
0
231 b->setChecked(false);
never executed: b->setChecked(false);
0
232 }
never executed: end of block
0
233}
never executed: end of block
0
234-
235void QAbstractButtonPrivate::moveFocus(int key)-
236{-
237 QList<QAbstractButton *> buttonList = queryButtonList();;-
238#ifndef QT_NO_BUTTONGROUP-
239 bool exclusive = group ? group->d_func()->exclusive : autoExclusive;
groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
240#else-
241 bool exclusive = autoExclusive;-
242#endif-
243 QWidget *f = QApplication::focusWidget();-
244 QAbstractButton *fb = qobject_cast<QAbstractButton *>(f);-
245 if (!fb || !buttonList.contains(fb))
!fbDescription
TRUEnever evaluated
FALSEnever evaluated
!buttonList.contains(fb)Description
TRUEnever evaluated
FALSEnever evaluated
0
246 return;
never executed: return;
0
247-
248 QAbstractButton *candidate = 0;-
249 int bestScore = -1;-
250 QRect target = f->rect().translated(f->mapToGlobal(QPoint(0,0)));-
251 QPoint goal = target.center();-
252 uint focus_flag = qt_tab_all_widgets() ? Qt::TabFocus : Qt::StrongFocus;
qt_tab_all_widgets()Description
TRUEnever evaluated
FALSEnever evaluated
0
253-
254 for (int i = 0; i < buttonList.count(); ++i) {
i < buttonList.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
255 QAbstractButton *button = buttonList.at(i);-
256 if (button != f && button->window() == f->window() && button->isEnabled() && !button->isHidden() &&
button != fDescription
TRUEnever evaluated
FALSEnever evaluated
button->window...== f->window()Description
TRUEnever evaluated
FALSEnever evaluated
button->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
!button->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
0
257 (autoExclusive || (button->focusPolicy() & focus_flag) == focus_flag)) {
autoExclusiveDescription
TRUEnever evaluated
FALSEnever evaluated
(button->focus... == focus_flagDescription
TRUEnever evaluated
FALSEnever evaluated
0
258 QRect buttonRect = button->rect().translated(button->mapToGlobal(QPoint(0,0)));-
259 QPoint p = buttonRect.center();-
260-
261 //Priority to widgets that overlap on the same coordinate.-
262 //In that case, the distance in the direction will be used as significant score,-
263 //take also in account orthogonal distance in case two widget are in the same distance.-
264 int score;-
265 if ((buttonRect.x() < target.right() && target.x() < buttonRect.right())
buttonRect.x()...target.right()Description
TRUEnever evaluated
FALSEnever evaluated
target.x() < b...onRect.right()Description
TRUEnever evaluated
FALSEnever evaluated
0
266 && (key == Qt::Key_Up || key == Qt::Key_Down)) {
key == Qt::Key_UpDescription
TRUEnever evaluated
FALSEnever evaluated
key == Qt::Key_DownDescription
TRUEnever evaluated
FALSEnever evaluated
0
267 //one item's is at the vertical of the other-
268 score = (qAbs(p.y() - goal.y()) << 16) + qAbs(p.x() - goal.x());-
269 } else if ((buttonRect.y() < target.bottom() && target.y() < buttonRect.bottom())
never executed: end of block
buttonRect.y()...arget.bottom()Description
TRUEnever evaluated
FALSEnever evaluated
target.y() < b...nRect.bottom()Description
TRUEnever evaluated
FALSEnever evaluated
0
270 && (key == Qt::Key_Left || key == Qt::Key_Right) ) {
key == Qt::Key_LeftDescription
TRUEnever evaluated
FALSEnever evaluated
key == Qt::Key_RightDescription
TRUEnever evaluated
FALSEnever evaluated
0
271 //one item's is at the horizontal of the other-
272 score = (qAbs(p.x() - goal.x()) << 16) + qAbs(p.y() - goal.y());-
273 } else {
never executed: end of block
0
274 score = (1 << 30) + (p.y() - goal.y()) * (p.y() - goal.y()) + (p.x() - goal.x()) * (p.x() - goal.x());-
275 }
never executed: end of block
0
276-
277 if (score > bestScore && candidate)
score > bestScoreDescription
TRUEnever evaluated
FALSEnever evaluated
candidateDescription
TRUEnever evaluated
FALSEnever evaluated
0
278 continue;
never executed: continue;
0
279-
280 switch(key) {-
281 case Qt::Key_Up:
never executed: case Qt::Key_Up:
0
282 if (p.y() < goal.y()) {
p.y() < goal.y()Description
TRUEnever evaluated
FALSEnever evaluated
0
283 candidate = button;-
284 bestScore = score;-
285 }
never executed: end of block
0
286 break;
never executed: break;
0
287 case Qt::Key_Down:
never executed: case Qt::Key_Down:
0
288 if (p.y() > goal.y()) {
p.y() > goal.y()Description
TRUEnever evaluated
FALSEnever evaluated
0
289 candidate = button;-
290 bestScore = score;-
291 }
never executed: end of block
0
292 break;
never executed: break;
0
293 case Qt::Key_Left:
never executed: case Qt::Key_Left:
0
294 if (p.x() < goal.x()) {
p.x() < goal.x()Description
TRUEnever evaluated
FALSEnever evaluated
0
295 candidate = button;-
296 bestScore = score;-
297 }
never executed: end of block
0
298 break;
never executed: break;
0
299 case Qt::Key_Right:
never executed: case Qt::Key_Right:
0
300 if (p.x() > goal.x()) {
p.x() > goal.x()Description
TRUEnever evaluated
FALSEnever evaluated
0
301 candidate = button;-
302 bestScore = score;-
303 }
never executed: end of block
0
304 break;
never executed: break;
0
305 }-
306 }
never executed: end of block
0
307 }
never executed: end of block
0
308-
309 if (exclusive
exclusiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
310#ifdef QT_KEYPAD_NAVIGATION-
311 && !QApplication::keypadNavigationEnabled()-
312#endif-
313 && candidate
candidateDescription
TRUEnever evaluated
FALSEnever evaluated
0
314 && fb->d_func()->checked
fb->d_func()->checkedDescription
TRUEnever evaluated
FALSEnever evaluated
0
315 && candidate->d_func()->checkable)
candidate->d_func()->checkableDescription
TRUEnever evaluated
FALSEnever evaluated
0
316 candidate->click();
never executed: candidate->click();
0
317-
318 if (candidate) {
candidateDescription
TRUEnever evaluated
FALSEnever evaluated
0
319 if (key == Qt::Key_Up || key == Qt::Key_Left)
key == Qt::Key_UpDescription
TRUEnever evaluated
FALSEnever evaluated
key == Qt::Key_LeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
320 candidate->setFocus(Qt::BacktabFocusReason);
never executed: candidate->setFocus(Qt::BacktabFocusReason);
0
321 else-
322 candidate->setFocus(Qt::TabFocusReason);
never executed: candidate->setFocus(Qt::TabFocusReason);
0
323 }-
324}
never executed: end of block
0
325-
326void QAbstractButtonPrivate::fixFocusPolicy()-
327{-
328 Q_Q(QAbstractButton);-
329#ifndef QT_NO_BUTTONGROUP-
330 if (!group && !autoExclusive)
!groupDescription
TRUEnever evaluated
FALSEnever evaluated
!autoExclusiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
331#else-
332 if (!autoExclusive)-
333#endif-
334 return;
never executed: return;
0
335-
336 QList<QAbstractButton *> buttonList = queryButtonList();-
337 for (int i = 0; i < buttonList.count(); ++i) {
i < buttonList.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
338 QAbstractButton *b = buttonList.at(i);-
339 if (!b->isCheckable())
!b->isCheckable()Description
TRUEnever evaluated
FALSEnever evaluated
0
340 continue;
never executed: continue;
0
341 b->setFocusPolicy((Qt::FocusPolicy) ((b == q || !q->isCheckable())-
342 ? (b->focusPolicy() | Qt::TabFocus)-
343 : (b->focusPolicy() & ~Qt::TabFocus)));-
344 }
never executed: end of block
0
345}
never executed: end of block
0
346-
347void QAbstractButtonPrivate::init()-
348{-
349 Q_Q(QAbstractButton);-
350-
351 q->setFocusPolicy(Qt::FocusPolicy(q->style()->styleHint(QStyle::SH_Button_FocusPolicy)));-
352 q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, controlType));-
353 q->setAttribute(Qt::WA_WState_OwnSizePolicy, false);-
354 q->setForegroundRole(QPalette::ButtonText);-
355 q->setBackgroundRole(QPalette::Button);-
356}
never executed: end of block
0
357-
358void QAbstractButtonPrivate::refresh()-
359{-
360 Q_Q(QAbstractButton);-
361-
362 if (blockRefresh)
blockRefreshDescription
TRUEnever evaluated
FALSEnever evaluated
0
363 return;
never executed: return;
0
364 q->update();-
365}
never executed: end of block
0
366-
367void QAbstractButtonPrivate::click()-
368{-
369 Q_Q(QAbstractButton);-
370-
371 down = false;-
372 blockRefresh = true;-
373 bool changeState = true;-
374 if (checked && queryCheckedButton() == q) {
checkedDescription
TRUEnever evaluated
FALSEnever evaluated
queryCheckedButton() == qDescription
TRUEnever evaluated
FALSEnever evaluated
0
375 // the checked button of an exclusive or autoexclusive group cannot be unchecked-
376#ifndef QT_NO_BUTTONGROUP-
377 if (group ? group->d_func()->exclusive : autoExclusive)
group ? group-... autoExclusiveDescription
TRUEnever evaluated
FALSEnever evaluated
groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
378#else-
379 if (autoExclusive)-
380#endif-
381 changeState = false;
never executed: changeState = false;
0
382 }
never executed: end of block
0
383-
384 QPointer<QAbstractButton> guard(q);-
385 if (changeState) {
changeStateDescription
TRUEnever evaluated
FALSEnever evaluated
0
386 q->nextCheckState();-
387 if (!guard)
!guardDescription
TRUEnever evaluated
FALSEnever evaluated
0
388 return;
never executed: return;
0
389 }
never executed: end of block
0
390 blockRefresh = false;-
391 refresh();-
392 q->repaint(); //flush paint event before invoking potentially expensive operation-
393 QApplication::flush();-
394 if (guard)
guardDescription
TRUEnever evaluated
FALSEnever evaluated
0
395 emitReleased();
never executed: emitReleased();
0
396 if (guard)
guardDescription
TRUEnever evaluated
FALSEnever evaluated
0
397 emitClicked();
never executed: emitClicked();
0
398}
never executed: end of block
0
399-
400void QAbstractButtonPrivate::emitClicked()-
401{-
402 Q_Q(QAbstractButton);-
403 QPointer<QAbstractButton> guard(q);-
404 emit q->clicked(checked);-
405#ifndef QT_NO_BUTTONGROUP-
406 if (guard && group) {
guardDescription
TRUEnever evaluated
FALSEnever evaluated
groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
407 emit group->buttonClicked(group->id(q));-
408 if (guard && group)
guardDescription
TRUEnever evaluated
FALSEnever evaluated
groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
409 emit group->buttonClicked(q);
never executed: group->buttonClicked(q);
0
410 }
never executed: end of block
0
411#endif-
412}
never executed: end of block
0
413-
414void QAbstractButtonPrivate::emitPressed()-
415{-
416 Q_Q(QAbstractButton);-
417 QPointer<QAbstractButton> guard(q);-
418 emit q->pressed();-
419#ifndef QT_NO_BUTTONGROUP-
420 if (guard && group) {
guardDescription
TRUEnever evaluated
FALSEnever evaluated
groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
421 emit group->buttonPressed(group->id(q));-
422 if (guard && group)
guardDescription
TRUEnever evaluated
FALSEnever evaluated
groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
423 emit group->buttonPressed(q);
never executed: group->buttonPressed(q);
0
424 }
never executed: end of block
0
425#endif-
426}
never executed: end of block
0
427-
428void QAbstractButtonPrivate::emitReleased()-
429{-
430 Q_Q(QAbstractButton);-
431 QPointer<QAbstractButton> guard(q);-
432 emit q->released();-
433#ifndef QT_NO_BUTTONGROUP-
434 if (guard && group) {
guardDescription
TRUEnever evaluated
FALSEnever evaluated
groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
435 emit group->buttonReleased(group->id(q));-
436 if (guard && group)
guardDescription
TRUEnever evaluated
FALSEnever evaluated
groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
437 emit group->buttonReleased(q);
never executed: group->buttonReleased(q);
0
438 }
never executed: end of block
0
439#endif-
440}
never executed: end of block
0
441-
442void QAbstractButtonPrivate::emitToggled(bool checked)-
443{-
444 Q_Q(QAbstractButton);-
445 QPointer<QAbstractButton> guard(q);-
446 emit q->toggled(checked);-
447#ifndef QT_NO_BUTTONGROUP-
448 if (guard && group) {
guardDescription
TRUEnever evaluated
FALSEnever evaluated
groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
449 emit group->buttonToggled(group->id(q), checked);-
450 if (guard && group)
guardDescription
TRUEnever evaluated
FALSEnever evaluated
groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
451 emit group->buttonToggled(q, checked);
never executed: group->buttonToggled(q, checked);
0
452 }
never executed: end of block
0
453#endif-
454}
never executed: end of block
0
455-
456/*!-
457 Constructs an abstract button with a \a parent.-
458*/-
459QAbstractButton::QAbstractButton(QWidget *parent)-
460 : QWidget(*new QAbstractButtonPrivate, parent, 0)-
461{-
462 Q_D(QAbstractButton);-
463 d->init();-
464}
never executed: end of block
0
465-
466/*!-
467 Destroys the button.-
468 */-
469 QAbstractButton::~QAbstractButton()-
470{-
471#ifndef QT_NO_BUTTONGROUP-
472 Q_D(QAbstractButton);-
473 if (d->group)
d->groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
474 d->group->removeButton(this);
never executed: d->group->removeButton(this);
0
475#endif-
476}
never executed: end of block
0
477-
478-
479/*! \internal-
480 */-
481QAbstractButton::QAbstractButton(QAbstractButtonPrivate &dd, QWidget *parent)-
482 : QWidget(dd, parent, 0)-
483{-
484 Q_D(QAbstractButton);-
485 d->init();-
486}
never executed: end of block
0
487-
488/*!-
489\property QAbstractButton::text-
490\brief the text shown on the button-
491-
492If the button has no text, the text() function will return an empty-
493string.-
494-
495If the text contains an ampersand character ('&'), a shortcut is-
496automatically created for it. The character that follows the '&' will-
497be used as the shortcut key. Any previous shortcut will be-
498overwritten or cleared if no shortcut is defined by the text. See the-
499\l {QShortcut#mnemonic}{QShortcut} documentation for details. To-
500display an actual ampersand, use '&&'.-
501-
502There is no default text.-
503*/-
504-
505void QAbstractButton::setText(const QString &text)-
506{-
507 Q_D(QAbstractButton);-
508 if (d->text == text)
d->text == textDescription
TRUEnever evaluated
FALSEnever evaluated
0
509 return;
never executed: return;
0
510 d->text = text;-
511#ifndef QT_NO_SHORTCUT-
512 QKeySequence newMnemonic = QKeySequence::mnemonic(text);-
513 setShortcut(newMnemonic);-
514#endif-
515 d->sizeHint = QSize();-
516 update();-
517 updateGeometry();-
518#ifndef QT_NO_ACCESSIBILITY-
519 QAccessibleEvent event(this, QAccessible::NameChanged);-
520 QAccessible::updateAccessibility(&event);-
521#endif-
522}
never executed: end of block
0
523-
524QString QAbstractButton::text() const-
525{-
526 Q_D(const QAbstractButton);-
527 return d->text;
never executed: return d->text;
0
528}-
529-
530-
531/*!-
532 \property QAbstractButton::icon-
533 \brief the icon shown on the button-
534-
535 The icon's default size is defined by the GUI style, but can be-
536 adjusted by setting the \l iconSize property.-
537*/-
538void QAbstractButton::setIcon(const QIcon &icon)-
539{-
540 Q_D(QAbstractButton);-
541 d->icon = icon;-
542 d->sizeHint = QSize();-
543 update();-
544 updateGeometry();-
545}
never executed: end of block
0
546-
547QIcon QAbstractButton::icon() const-
548{-
549 Q_D(const QAbstractButton);-
550 return d->icon;
never executed: return d->icon;
0
551}-
552-
553#ifndef QT_NO_SHORTCUT-
554/*!-
555\property QAbstractButton::shortcut-
556\brief the mnemonic associated with the button-
557*/-
558-
559void QAbstractButton::setShortcut(const QKeySequence &key)-
560{-
561 Q_D(QAbstractButton);-
562 if (d->shortcutId != 0)
d->shortcutId != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
563 releaseShortcut(d->shortcutId);
never executed: releaseShortcut(d->shortcutId);
0
564 d->shortcut = key;-
565 d->shortcutId = grabShortcut(key);-
566}
never executed: end of block
0
567-
568QKeySequence QAbstractButton::shortcut() const-
569{-
570 Q_D(const QAbstractButton);-
571 return d->shortcut;
never executed: return d->shortcut;
0
572}-
573#endif // QT_NO_SHORTCUT-
574-
575/*!-
576\property QAbstractButton::checkable-
577\brief whether the button is checkable-
578-
579By default, the button is not checkable.-
580-
581\sa checked-
582*/-
583void QAbstractButton::setCheckable(bool checkable)-
584{-
585 Q_D(QAbstractButton);-
586 if (d->checkable == checkable)
d->checkable == checkableDescription
TRUEnever evaluated
FALSEnever evaluated
0
587 return;
never executed: return;
0
588-
589 d->checkable = checkable;-
590 d->checked = false;-
591}
never executed: end of block
0
592-
593bool QAbstractButton::isCheckable() const-
594{-
595 Q_D(const QAbstractButton);-
596 return d->checkable;
never executed: return d->checkable;
0
597}-
598-
599/*!-
600\property QAbstractButton::checked-
601\brief whether the button is checked-
602-
603Only checkable buttons can be checked. By default, the button is unchecked.-
604-
605\sa checkable-
606*/-
607void QAbstractButton::setChecked(bool checked)-
608{-
609 Q_D(QAbstractButton);-
610 if (!d->checkable || d->checked == checked) {
!d->checkableDescription
TRUEnever evaluated
FALSEnever evaluated
d->checked == checkedDescription
TRUEnever evaluated
FALSEnever evaluated
0
611 if (!d->blockRefresh)
!d->blockRefreshDescription
TRUEnever evaluated
FALSEnever evaluated
0
612 checkStateSet();
never executed: checkStateSet();
0
613 return;
never executed: return;
0
614 }-
615-
616 if (!checked && d->queryCheckedButton() == this) {
!checkedDescription
TRUEnever evaluated
FALSEnever evaluated
d->queryChecke...tton() == thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
617 // the checked button of an exclusive or autoexclusive group cannot be unchecked-
618#ifndef QT_NO_BUTTONGROUP-
619 if (d->group ? d->group->d_func()->exclusive : d->autoExclusive)
d->group ? d->...>autoExclusiveDescription
TRUEnever evaluated
FALSEnever evaluated
d->groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
620 return;
never executed: return;
0
621 if (d->group)
d->groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
622 d->group->d_func()->detectCheckedButton();
never executed: d->group->d_func()->detectCheckedButton();
0
623#else-
624 if (d->autoExclusive)-
625 return;-
626#endif-
627 }
never executed: end of block
0
628-
629 QPointer<QAbstractButton> guard(this);-
630-
631 d->checked = checked;-
632 if (!d->blockRefresh)
!d->blockRefreshDescription
TRUEnever evaluated
FALSEnever evaluated
0
633 checkStateSet();
never executed: checkStateSet();
0
634 d->refresh();-
635-
636 if (guard && checked)
guardDescription
TRUEnever evaluated
FALSEnever evaluated
checkedDescription
TRUEnever evaluated
FALSEnever evaluated
0
637 d->notifyChecked();
never executed: d->notifyChecked();
0
638 if (guard)
guardDescription
TRUEnever evaluated
FALSEnever evaluated
0
639 d->emitToggled(checked);
never executed: d->emitToggled(checked);
0
640-
641-
642#ifndef QT_NO_ACCESSIBILITY-
643 QAccessible::State s;-
644 s.checked = true;-
645 QAccessibleStateChangeEvent event(this, s);-
646 QAccessible::updateAccessibility(&event);-
647#endif-
648}
never executed: end of block
0
649-
650bool QAbstractButton::isChecked() const-
651{-
652 Q_D(const QAbstractButton);-
653 return d->checked;
never executed: return d->checked;
0
654}-
655-
656/*!-
657 \property QAbstractButton::down-
658 \brief whether the button is pressed down-
659-
660 If this property is \c true, the button is pressed down. The signals-
661 pressed() and clicked() are not emitted if you set this property-
662 to true. The default is false.-
663*/-
664-
665void QAbstractButton::setDown(bool down)-
666{-
667 Q_D(QAbstractButton);-
668 if (d->down == down)
d->down == downDescription
TRUEnever evaluated
FALSEnever evaluated
0
669 return;
never executed: return;
0
670 d->down = down;-
671 d->refresh();-
672 if (d->autoRepeat && d->down)
d->autoRepeatDescription
TRUEnever evaluated
FALSEnever evaluated
d->downDescription
TRUEnever evaluated
FALSEnever evaluated
0
673 d->repeatTimer.start(d->autoRepeatDelay, this);
never executed: d->repeatTimer.start(d->autoRepeatDelay, this);
0
674 else-
675 d->repeatTimer.stop();
never executed: d->repeatTimer.stop();
0
676}-
677-
678bool QAbstractButton::isDown() const-
679{-
680 Q_D(const QAbstractButton);-
681 return d->down;
never executed: return d->down;
0
682}-
683-
684/*!-
685\property QAbstractButton::autoRepeat-
686\brief whether autoRepeat is enabled-
687-
688If autoRepeat is enabled, then the pressed(), released(), and clicked() signals are emitted at-
689regular intervals when the button is down. autoRepeat is off by default.-
690The initial delay and the repetition interval are defined in milliseconds by \l-
691autoRepeatDelay and \l autoRepeatInterval.-
692-
693Note: If a button is pressed down by a shortcut key, then auto-repeat is enabled and timed by the-
694system and not by this class. The pressed(), released(), and clicked() signals will be emitted-
695like in the normal case.-
696*/-
697-
698void QAbstractButton::setAutoRepeat(bool autoRepeat)-
699{-
700 Q_D(QAbstractButton);-
701 if (d->autoRepeat == autoRepeat)
d->autoRepeat == autoRepeatDescription
TRUEnever evaluated
FALSEnever evaluated
0
702 return;
never executed: return;
0
703 d->autoRepeat = autoRepeat;-
704 if (d->autoRepeat && d->down)
d->autoRepeatDescription
TRUEnever evaluated
FALSEnever evaluated
d->downDescription
TRUEnever evaluated
FALSEnever evaluated
0
705 d->repeatTimer.start(d->autoRepeatDelay, this);
never executed: d->repeatTimer.start(d->autoRepeatDelay, this);
0
706 else-
707 d->repeatTimer.stop();
never executed: d->repeatTimer.stop();
0
708}-
709-
710bool QAbstractButton::autoRepeat() const-
711{-
712 Q_D(const QAbstractButton);-
713 return d->autoRepeat;
never executed: return d->autoRepeat;
0
714}-
715-
716/*!-
717 \property QAbstractButton::autoRepeatDelay-
718 \brief the initial delay of auto-repetition-
719 \since 4.2-
720-
721 If \l autoRepeat is enabled, then autoRepeatDelay defines the initial-
722 delay in milliseconds before auto-repetition kicks in.-
723-
724 \sa autoRepeat, autoRepeatInterval-
725*/-
726-
727void QAbstractButton::setAutoRepeatDelay(int autoRepeatDelay)-
728{-
729 Q_D(QAbstractButton);-
730 d->autoRepeatDelay = autoRepeatDelay;-
731}
never executed: end of block
0
732-
733int QAbstractButton::autoRepeatDelay() const-
734{-
735 Q_D(const QAbstractButton);-
736 return d->autoRepeatDelay;
never executed: return d->autoRepeatDelay;
0
737}-
738-
739/*!-
740 \property QAbstractButton::autoRepeatInterval-
741 \brief the interval of auto-repetition-
742 \since 4.2-
743-
744 If \l autoRepeat is enabled, then autoRepeatInterval defines the-
745 length of the auto-repetition interval in millisecons.-
746-
747 \sa autoRepeat, autoRepeatDelay-
748*/-
749-
750void QAbstractButton::setAutoRepeatInterval(int autoRepeatInterval)-
751{-
752 Q_D(QAbstractButton);-
753 d->autoRepeatInterval = autoRepeatInterval;-
754}
never executed: end of block
0
755-
756int QAbstractButton::autoRepeatInterval() const-
757{-
758 Q_D(const QAbstractButton);-
759 return d->autoRepeatInterval;
never executed: return d->autoRepeatInterval;
0
760}-
761-
762-
763-
764/*!-
765\property QAbstractButton::autoExclusive-
766\brief whether auto-exclusivity is enabled-
767-
768If auto-exclusivity is enabled, checkable buttons that belong to the-
769same parent widget behave as if they were part of the same-
770exclusive button group. In an exclusive button group, only one button-
771can be checked at any time; checking another button automatically-
772unchecks the previously checked one.-
773-
774The property has no effect on buttons that belong to a button-
775group.-
776-
777autoExclusive is off by default, except for radio buttons.-
778-
779\sa QRadioButton-
780*/-
781void QAbstractButton::setAutoExclusive(bool autoExclusive)-
782{-
783 Q_D(QAbstractButton);-
784 d->autoExclusive = autoExclusive;-
785}
never executed: end of block
0
786-
787bool QAbstractButton::autoExclusive() const-
788{-
789 Q_D(const QAbstractButton);-
790 return d->autoExclusive;
never executed: return d->autoExclusive;
0
791}-
792-
793#ifndef QT_NO_BUTTONGROUP-
794/*!-
795 Returns the group that this button belongs to.-
796-
797 If the button is not a member of any QButtonGroup, this function-
798 returns 0.-
799-
800 \sa QButtonGroup-
801*/-
802QButtonGroup *QAbstractButton::group() const-
803{-
804 Q_D(const QAbstractButton);-
805 return d->group;
never executed: return d->group;
0
806}-
807#endif // QT_NO_BUTTONGROUP-
808-
809/*!-
810Performs an animated click: the button is pressed immediately, and-
811released \a msec milliseconds later (the default is 100 ms).-
812-
813Calling this function again before the button is released resets-
814the release timer.-
815-
816All signals associated with a click are emitted as appropriate.-
817-
818This function does nothing if the button is \l{setEnabled()}{disabled.}-
819-
820\sa click()-
821*/-
822void QAbstractButton::animateClick(int msec)-
823{-
824 if (!isEnabled())
!isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
825 return;
never executed: return;
0
826 Q_D(QAbstractButton);-
827 if (d->checkable && focusPolicy() & Qt::ClickFocus)
d->checkableDescription
TRUEnever evaluated
FALSEnever evaluated
focusPolicy() & Qt::ClickFocusDescription
TRUEnever evaluated
FALSEnever evaluated
0
828 setFocus();
never executed: setFocus();
0
829 setDown(true);-
830 repaint(); //flush paint event before invoking potentially expensive operation-
831 QApplication::flush();-
832 if (!d->animateTimer.isActive())
!d->animateTimer.isActive()Description
TRUEnever evaluated
FALSEnever evaluated
0
833 d->emitPressed();
never executed: d->emitPressed();
0
834 d->animateTimer.start(msec, this);-
835}
never executed: end of block
0
836-
837/*!-
838Performs a click.-
839-
840All the usual signals associated with a click are emitted as-
841appropriate. If the button is checkable, the state of the button is-
842toggled.-
843-
844This function does nothing if the button is \l{setEnabled()}{disabled.}-
845-
846\sa animateClick()-
847 */-
848void QAbstractButton::click()-
849{-
850 if (!isEnabled())
!isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
851 return;
never executed: return;
0
852 Q_D(QAbstractButton);-
853 QPointer<QAbstractButton> guard(this);-
854 d->down = true;-
855 d->emitPressed();-
856 if (guard) {
guardDescription
TRUEnever evaluated
FALSEnever evaluated
0
857 d->down = false;-
858 nextCheckState();-
859 if (guard)
guardDescription
TRUEnever evaluated
FALSEnever evaluated
0
860 d->emitReleased();
never executed: d->emitReleased();
0
861 if (guard)
guardDescription
TRUEnever evaluated
FALSEnever evaluated
0
862 d->emitClicked();
never executed: d->emitClicked();
0
863 }
never executed: end of block
0
864}
never executed: end of block
0
865-
866/*! \fn void QAbstractButton::toggle()-
867-
868 Toggles the state of a checkable button.-
869-
870 \sa checked-
871*/-
872void QAbstractButton::toggle()-
873{-
874 Q_D(QAbstractButton);-
875 setChecked(!d->checked);-
876}
never executed: end of block
0
877-
878-
879/*! This virtual handler is called when setChecked() is used,-
880unless it is called from within nextCheckState(). It allows-
881subclasses to reset their intermediate button states.-
882-
883\sa nextCheckState()-
884 */-
885void QAbstractButton::checkStateSet()-
886{-
887}-
888-
889/*! This virtual handler is called when a button is clicked. The-
890default implementation calls setChecked(!isChecked()) if the button-
891isCheckable(). It allows subclasses to implement intermediate button-
892states.-
893-
894\sa checkStateSet()-
895*/-
896void QAbstractButton::nextCheckState()-
897{-
898 if (isCheckable())
isCheckable()Description
TRUEnever evaluated
FALSEnever evaluated
0
899 setChecked(!isChecked());
never executed: setChecked(!isChecked());
0
900}
never executed: end of block
0
901-
902/*!-
903Returns \c true if \a pos is inside the clickable button rectangle;-
904otherwise returns \c false.-
905-
906By default, the clickable area is the entire widget. Subclasses-
907may reimplement this function to provide support for clickable-
908areas of different shapes and sizes.-
909*/-
910bool QAbstractButton::hitButton(const QPoint &pos) const-
911{-
912 return rect().contains(pos);
never executed: return rect().contains(pos);
0
913}-
914-
915/*! \reimp */-
916bool QAbstractButton::event(QEvent *e)-
917{-
918 // as opposed to other widgets, disabled buttons accept mouse-
919 // events. This avoids surprising click-through scenarios-
920 if (!isEnabled()) {
!isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
921 switch(e->type()) {-
922 case QEvent::TabletPress:
never executed: case QEvent::TabletPress:
0
923 case QEvent::TabletRelease:
never executed: case QEvent::TabletRelease:
0
924 case QEvent::TabletMove:
never executed: case QEvent::TabletMove:
0
925 case QEvent::MouseButtonPress:
never executed: case QEvent::MouseButtonPress:
0
926 case QEvent::MouseButtonRelease:
never executed: case QEvent::MouseButtonRelease:
0
927 case QEvent::MouseButtonDblClick:
never executed: case QEvent::MouseButtonDblClick:
0
928 case QEvent::MouseMove:
never executed: case QEvent::MouseMove:
0
929 case QEvent::HoverMove:
never executed: case QEvent::HoverMove:
0
930 case QEvent::HoverEnter:
never executed: case QEvent::HoverEnter:
0
931 case QEvent::HoverLeave:
never executed: case QEvent::HoverLeave:
0
932 case QEvent::ContextMenu:
never executed: case QEvent::ContextMenu:
0
933#ifndef QT_NO_WHEELEVENT-
934 case QEvent::Wheel:
never executed: case QEvent::Wheel:
0
935#endif-
936 return true;
never executed: return true;
0
937 default:
never executed: default:
0
938 break;
never executed: break;
0
939 }-
940 }-
941-
942#ifndef QT_NO_SHORTCUT-
943 if (e->type() == QEvent::Shortcut) {
e->type() == QEvent::ShortcutDescription
TRUEnever evaluated
FALSEnever evaluated
0
944 Q_D(QAbstractButton);-
945 QShortcutEvent *se = static_cast<QShortcutEvent *>(e);-
946 if (d->shortcutId != se->shortcutId())
d->shortcutId ...->shortcutId()Description
TRUEnever evaluated
FALSEnever evaluated
0
947 return false;
never executed: return false;
0
948 if (!se->isAmbiguous()) {
!se->isAmbiguous()Description
TRUEnever evaluated
FALSEnever evaluated
0
949 if (!d->animateTimer.isActive())
!d->animateTimer.isActive()Description
TRUEnever evaluated
FALSEnever evaluated
0
950 animateClick();
never executed: animateClick();
0
951 } else {
never executed: end of block
0
952 if (focusPolicy() != Qt::NoFocus)
focusPolicy() != Qt::NoFocusDescription
TRUEnever evaluated
FALSEnever evaluated
0
953 setFocus(Qt::ShortcutFocusReason);
never executed: setFocus(Qt::ShortcutFocusReason);
0
954 window()->setAttribute(Qt::WA_KeyboardFocusChange);-
955 }
never executed: end of block
0
956 return true;
never executed: return true;
0
957 }-
958#endif-
959 return QWidget::event(e);
never executed: return QWidget::event(e);
0
960}-
961-
962/*! \reimp */-
963void QAbstractButton::mousePressEvent(QMouseEvent *e)-
964{-
965 Q_D(QAbstractButton);-
966 if (e->button() != Qt::LeftButton) {
e->button() != Qt::LeftButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
967 e->ignore();-
968 return;
never executed: return;
0
969 }-
970 if (hitButton(e->pos())) {
hitButton(e->pos())Description
TRUEnever evaluated
FALSEnever evaluated
0
971 setDown(true);-
972 d->pressed = true;-
973 repaint(); //flush paint event before invoking potentially expensive operation-
974 QApplication::flush();-
975 d->emitPressed();-
976 e->accept();-
977 } else {
never executed: end of block
0
978 e->ignore();-
979 }
never executed: end of block
0
980}-
981-
982/*! \reimp */-
983void QAbstractButton::mouseReleaseEvent(QMouseEvent *e)-
984{-
985 Q_D(QAbstractButton);-
986 d->pressed = false;-
987-
988 if (e->button() != Qt::LeftButton) {
e->button() != Qt::LeftButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
989 e->ignore();-
990 return;
never executed: return;
0
991 }-
992-
993 if (!d->down) {
!d->downDescription
TRUEnever evaluated
FALSEnever evaluated
0
994 // refresh is required by QMacStyle to resume the default button animation-
995 d->refresh();-
996 e->ignore();-
997 return;
never executed: return;
0
998 }-
999-
1000 if (hitButton(e->pos())) {
hitButton(e->pos())Description
TRUEnever evaluated
FALSEnever evaluated
0
1001 d->repeatTimer.stop();-
1002 d->click();-
1003 e->accept();-
1004 } else {
never executed: end of block
0
1005 setDown(false);-
1006 e->ignore();-
1007 }
never executed: end of block
0
1008}-
1009-
1010/*! \reimp */-
1011void QAbstractButton::mouseMoveEvent(QMouseEvent *e)-
1012{-
1013 Q_D(QAbstractButton);-
1014 if (!(e->buttons() & Qt::LeftButton) || !d->pressed) {
!(e->buttons()...t::LeftButton)Description
TRUEnever evaluated
FALSEnever evaluated
!d->pressedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1015 e->ignore();-
1016 return;
never executed: return;
0
1017 }-
1018-
1019 if (hitButton(e->pos()) != d->down) {
hitButton(e->pos()) != d->downDescription
TRUEnever evaluated
FALSEnever evaluated
0
1020 setDown(!d->down);-
1021 repaint(); //flush paint event before invoking potentially expensive operation-
1022 QApplication::flush();-
1023 if (d->down)
d->downDescription
TRUEnever evaluated
FALSEnever evaluated
0
1024 d->emitPressed();
never executed: d->emitPressed();
0
1025 else-
1026 d->emitReleased();
never executed: d->emitReleased();
0
1027 e->accept();-
1028 } else if (!hitButton(e->pos())) {
never executed: end of block
!hitButton(e->pos())Description
TRUEnever evaluated
FALSEnever evaluated
0
1029 e->ignore();-
1030 }
never executed: end of block
0
1031}
never executed: end of block
0
1032-
1033/*! \reimp */-
1034void QAbstractButton::keyPressEvent(QKeyEvent *e)-
1035{-
1036 Q_D(QAbstractButton);-
1037 bool next = true;-
1038 switch (e->key()) {-
1039 case Qt::Key_Enter:
never executed: case Qt::Key_Enter:
0
1040 case Qt::Key_Return:
never executed: case Qt::Key_Return:
0
1041 e->ignore();-
1042 break;
never executed: break;
0
1043 case Qt::Key_Select:
never executed: case Qt::Key_Select:
0
1044 case Qt::Key_Space:
never executed: case Qt::Key_Space:
0
1045 if (!e->isAutoRepeat()) {
!e->isAutoRepeat()Description
TRUEnever evaluated
FALSEnever evaluated
0
1046 setDown(true);-
1047 repaint(); //flush paint event before invoking potentially expensive operation-
1048 QApplication::flush();-
1049 d->emitPressed();-
1050 }
never executed: end of block
0
1051 break;
never executed: break;
0
1052 case Qt::Key_Up:
never executed: case Qt::Key_Up:
0
1053 next = false;-
1054 // fall through-
1055 case Qt::Key_Left:
code before this statement never executed: case Qt::Key_Left:
never executed: case Qt::Key_Left:
0
1056 case Qt::Key_Right:
never executed: case Qt::Key_Right:
0
1057 case Qt::Key_Down: {
never executed: case Qt::Key_Down:
0
1058#ifdef QT_KEYPAD_NAVIGATION-
1059 if ((QApplication::keypadNavigationEnabled()-
1060 && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right))-
1061 || (!QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional-
1062 || (e->key() == Qt::Key_Up || e->key() == Qt::Key_Down))) {-
1063 e->ignore();-
1064 return;-
1065 }-
1066#endif-
1067 QWidget *pw = parentWidget();-
1068 if (d->autoExclusive
d->autoExclusiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
1069#ifndef QT_NO_BUTTONGROUP-
1070 || d->group
d->groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
1071#endif-
1072#ifndef QT_NO_ITEMVIEWS-
1073 || (pw && qobject_cast<QAbstractItemView *>(pw->parentWidget()))
pwDescription
TRUEnever evaluated
FALSEnever evaluated
qobject_cast<Q...arentWidget())Description
TRUEnever evaluated
FALSEnever evaluated
0
1074#endif-
1075 ) {-
1076 // ### Using qobject_cast to check if the parent is a viewport of-
1077 // QAbstractItemView is a crude hack, and should be revisited and-
1078 // cleaned up when fixing task 194373. It's here to ensure that we-
1079 // keep compatibility outside QAbstractItemView.-
1080 d->moveFocus(e->key());-
1081 if (hasFocus()) // nothing happend, propagate
hasFocus()Description
TRUEnever evaluated
FALSEnever evaluated
0
1082 e->ignore();
never executed: e->ignore();
0
1083 } else {
never executed: end of block
0
1084 // Prefer parent widget, use this if parent is absent-
1085 QWidget *w = pw ? pw : this;
pwDescription
TRUEnever evaluated
FALSEnever evaluated
0
1086 bool reverse = (w->layoutDirection() == Qt::RightToLeft);-
1087 if ((e->key() == Qt::Key_Left && !reverse)
e->key() == Qt::Key_LeftDescription
TRUEnever evaluated
FALSEnever evaluated
!reverseDescription
TRUEnever evaluated
FALSEnever evaluated
0
1088 || (e->key() == Qt::Key_Right && reverse)) {
e->key() == Qt::Key_RightDescription
TRUEnever evaluated
FALSEnever evaluated
reverseDescription
TRUEnever evaluated
FALSEnever evaluated
0
1089 next = false;-
1090 }
never executed: end of block
0
1091 focusNextPrevChild(next);-
1092 }
never executed: end of block
0
1093 break;
never executed: break;
0
1094 }-
1095 default:
never executed: default:
0
1096 if (e->matches(QKeySequence::Cancel) && d->down) {
e->matches(QKe...uence::Cancel)Description
TRUEnever evaluated
FALSEnever evaluated
d->downDescription
TRUEnever evaluated
FALSEnever evaluated
0
1097 setDown(false);-
1098 repaint(); //flush paint event before invoking potentially expensive operation-
1099 QApplication::flush();-
1100 d->emitReleased();-
1101 return;
never executed: return;
0
1102 }-
1103 e->ignore();-
1104 }
never executed: end of block
0
1105}-
1106-
1107/*! \reimp */-
1108void QAbstractButton::keyReleaseEvent(QKeyEvent *e)-
1109{-
1110 Q_D(QAbstractButton);-
1111-
1112 if (!e->isAutoRepeat())
!e->isAutoRepeat()Description
TRUEnever evaluated
FALSEnever evaluated
0
1113 d->repeatTimer.stop();
never executed: d->repeatTimer.stop();
0
1114-
1115 switch (e->key()) {-
1116 case Qt::Key_Select:
never executed: case Qt::Key_Select:
0
1117 case Qt::Key_Space:
never executed: case Qt::Key_Space:
0
1118 if (!e->isAutoRepeat() && d->down)
!e->isAutoRepeat()Description
TRUEnever evaluated
FALSEnever evaluated
d->downDescription
TRUEnever evaluated
FALSEnever evaluated
0
1119 d->click();
never executed: d->click();
0
1120 break;
never executed: break;
0
1121 default:
never executed: default:
0
1122 e->ignore();-
1123 }
never executed: end of block
0
1124}-
1125-
1126/*!\reimp-
1127 */-
1128void QAbstractButton::timerEvent(QTimerEvent *e)-
1129{-
1130 Q_D(QAbstractButton);-
1131 if (e->timerId() == d->repeatTimer.timerId()) {
e->timerId() =...imer.timerId()Description
TRUEnever evaluated
FALSEnever evaluated
0
1132 d->repeatTimer.start(d->autoRepeatInterval, this);-
1133 if (d->down) {
d->downDescription
TRUEnever evaluated
FALSEnever evaluated
0
1134 QPointer<QAbstractButton> guard(this);-
1135 nextCheckState();-
1136 if (guard)
guardDescription
TRUEnever evaluated
FALSEnever evaluated
0
1137 d->emitReleased();
never executed: d->emitReleased();
0
1138 if (guard)
guardDescription
TRUEnever evaluated
FALSEnever evaluated
0
1139 d->emitClicked();
never executed: d->emitClicked();
0
1140 if (guard)
guardDescription
TRUEnever evaluated
FALSEnever evaluated
0
1141 d->emitPressed();
never executed: d->emitPressed();
0
1142 }
never executed: end of block
0
1143 } else if (e->timerId() == d->animateTimer.timerId()) {
never executed: end of block
e->timerId() =...imer.timerId()Description
TRUEnever evaluated
FALSEnever evaluated
0
1144 d->animateTimer.stop();-
1145 d->click();-
1146 }
never executed: end of block
0
1147}
never executed: end of block
0
1148-
1149/*! \reimp */-
1150void QAbstractButton::focusInEvent(QFocusEvent *e)-
1151{-
1152 Q_D(QAbstractButton);-
1153#ifdef QT_KEYPAD_NAVIGATION-
1154 if (!QApplication::keypadNavigationEnabled())-
1155#endif-
1156 d->fixFocusPolicy();-
1157 QWidget::focusInEvent(e);-
1158}
never executed: end of block
0
1159-
1160/*! \reimp */-
1161void QAbstractButton::focusOutEvent(QFocusEvent *e)-
1162{-
1163 Q_D(QAbstractButton);-
1164 if (e->reason() != Qt::PopupFocusReason && d->down) {
e->reason() !=...pupFocusReasonDescription
TRUEnever evaluated
FALSEnever evaluated
d->downDescription
TRUEnever evaluated
FALSEnever evaluated
0
1165 d->down = false;-
1166 d->emitReleased();-
1167 }
never executed: end of block
0
1168 QWidget::focusOutEvent(e);-
1169}
never executed: end of block
0
1170-
1171/*! \reimp */-
1172void QAbstractButton::changeEvent(QEvent *e)-
1173{-
1174 Q_D(QAbstractButton);-
1175 switch (e->type()) {-
1176 case QEvent::EnabledChange:
never executed: case QEvent::EnabledChange:
0
1177 if (!isEnabled() && d->down) {
!isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
d->downDescription
TRUEnever evaluated
FALSEnever evaluated
0
1178 d->down = false;-
1179 d->emitReleased();-
1180 }
never executed: end of block
0
1181 break;
never executed: break;
0
1182 default:
never executed: default:
0
1183 d->sizeHint = QSize();-
1184 break;
never executed: break;
0
1185 }-
1186 QWidget::changeEvent(e);-
1187}
never executed: end of block
0
1188-
1189/*!-
1190 \fn void QAbstractButton::paintEvent(QPaintEvent *e)-
1191 \reimp-
1192*/-
1193-
1194/*!-
1195 \fn void QAbstractButton::pressed()-
1196-
1197 This signal is emitted when the button is pressed down.-
1198-
1199 \sa released(), clicked()-
1200*/-
1201-
1202/*!-
1203 \fn void QAbstractButton::released()-
1204-
1205 This signal is emitted when the button is released.-
1206-
1207 \sa pressed(), clicked(), toggled()-
1208*/-
1209-
1210/*!-
1211\fn void QAbstractButton::clicked(bool checked)-
1212-
1213This signal is emitted when the button is activated (i.e., pressed down-
1214then released while the mouse cursor is inside the button), when the-
1215shortcut key is typed, or when click() or animateClick() is called.-
1216Notably, this signal is \e not emitted if you call setDown(),-
1217setChecked() or toggle().-
1218-
1219If the button is checkable, \a checked is true if the button is-
1220checked, or false if the button is unchecked.-
1221-
1222\sa pressed(), released(), toggled()-
1223*/-
1224-
1225/*!-
1226\fn void QAbstractButton::toggled(bool checked)-
1227-
1228This signal is emitted whenever a checkable button changes its state.-
1229\a checked is true if the button is checked, or false if the button is-
1230unchecked.-
1231-
1232This may be the result of a user action, click() slot activation,-
1233or because setChecked() is called.-
1234-
1235The states of buttons in exclusive button groups are updated before this-
1236signal is emitted. This means that slots can act on either the "off"-
1237signal or the "on" signal emitted by the buttons in the group whose-
1238states have changed.-
1239-
1240For example, a slot that reacts to signals emitted by newly checked-
1241buttons but which ignores signals from buttons that have been unchecked-
1242can be implemented using the following pattern:-
1243-
1244\snippet code/src_gui_widgets_qabstractbutton.cpp 2-
1245-
1246Button groups can be created using the QButtonGroup class, and-
1247updates to the button states monitored with the-
1248\l{QButtonGroup::buttonClicked()} signal.-
1249-
1250\sa checked, clicked()-
1251*/-
1252-
1253/*!-
1254 \property QAbstractButton::iconSize-
1255 \brief the icon size used for this button.-
1256-
1257 The default size is defined by the GUI style. This is a maximum-
1258 size for the icons. Smaller icons will not be scaled up.-
1259*/-
1260-
1261QSize QAbstractButton::iconSize() const-
1262{-
1263 Q_D(const QAbstractButton);-
1264 if (d->iconSize.isValid())
d->iconSize.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1265 return d->iconSize;
never executed: return d->iconSize;
0
1266 int e = style()->pixelMetric(QStyle::PM_ButtonIconSize, 0, this);-
1267 return QSize(e, e);
never executed: return QSize(e, e);
0
1268}-
1269-
1270void QAbstractButton::setIconSize(const QSize &size)-
1271{-
1272 Q_D(QAbstractButton);-
1273 if (d->iconSize == size)
d->iconSize == sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1274 return;
never executed: return;
0
1275-
1276 d->iconSize = size;-
1277 d->sizeHint = QSize();-
1278 updateGeometry();-
1279 if (isVisible()) {
isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
1280 update();-
1281 }
never executed: end of block
0
1282}
never executed: end of block
0
1283-
1284-
1285-
1286QT_END_NAMESPACE-
1287-
1288#include "moc_qabstractbutton.cpp"-
Source codeSwitch to Preprocessed file

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