| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qabstractbutton.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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 | - | |||||||||||||||||||||||||
| 51 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 52 | - | |||||||||||||||||||||||||
| 53 | #define AUTO_REPEAT_DELAY 300 | - | ||||||||||||||||||||||||
| 54 | #define AUTO_REPEAT_INTERVAL 100 | - | ||||||||||||||||||||||||
| 55 | - | |||||||||||||||||||||||||
| 56 | Q_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 | - | |||||||||||||||||||||||||
| 161 | QAbstractButtonPrivate::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 | - | |||||||||||||||||||||||||
| 176 | QList<QAbstractButton *>QAbstractButtonPrivate::queryButtonList() const | - | ||||||||||||||||||||||||
| 177 | { | - | ||||||||||||||||||||||||
| 178 | #ifndef QT_NO_BUTTONGROUP | - | ||||||||||||||||||||||||
| 179 | if (group)
| 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) {
| 0 | ||||||||||||||||||||||||
| 185 | for (int i = candidates.count() - 1; i >= 0; --i) {
| 0 | ||||||||||||||||||||||||
| 186 | QAbstractButton *candidate = candidates.at(i); | - | ||||||||||||||||||||||||
| 187 | if (!candidate->autoExclusive()
| 0 | ||||||||||||||||||||||||
| 188 | #ifndef QT_NO_BUTTONGROUP | - | ||||||||||||||||||||||||
| 189 | || candidate->group()
| 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 | - | |||||||||||||||||||||||||
| 198 | QAbstractButton *QAbstractButtonPrivate::queryCheckedButton() const | - | ||||||||||||||||||||||||
| 199 | { | - | ||||||||||||||||||||||||
| 200 | #ifndef QT_NO_BUTTONGROUP | - | ||||||||||||||||||||||||
| 201 | if (group)
| 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
| 0 | ||||||||||||||||||||||||
| 208 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 209 | - | |||||||||||||||||||||||||
| 210 | for (int i = 0; i < buttonList.count(); ++i) {
| 0 | ||||||||||||||||||||||||
| 211 | QAbstractButton *b = buttonList.at(i); | - | ||||||||||||||||||||||||
| 212 | if (b->d_func()->checked && b != q)
| 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;
| 0 | ||||||||||||||||||||||||
| 216 | } | - | ||||||||||||||||||||||||
| 217 | - | |||||||||||||||||||||||||
| 218 | void QAbstractButtonPrivate::notifyChecked() | - | ||||||||||||||||||||||||
| 219 | { | - | ||||||||||||||||||||||||
| 220 | #ifndef QT_NO_BUTTONGROUP | - | ||||||||||||||||||||||||
| 221 | Q_Q(QAbstractButton); | - | ||||||||||||||||||||||||
| 222 | if (group) {
| 0 | ||||||||||||||||||||||||
| 223 | QAbstractButton *previous = group->d_func()->checkedButton; | - | ||||||||||||||||||||||||
| 224 | group->d_func()->checkedButton = q; | - | ||||||||||||||||||||||||
| 225 | if (group->d_func()->exclusive && previous && previous != q)
| 0 | ||||||||||||||||||||||||
| 226 | previous->nextCheckState(); never executed: previous->nextCheckState(); | 0 | ||||||||||||||||||||||||
| 227 | } else never executed: end of block | 0 | ||||||||||||||||||||||||
| 228 | #endif | - | ||||||||||||||||||||||||
| 229 | if (autoExclusive) {
| 0 | ||||||||||||||||||||||||
| 230 | if (QAbstractButton *b = queryCheckedButton())
| 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 | - | |||||||||||||||||||||||||
| 235 | void QAbstractButtonPrivate::moveFocus(int key) | - | ||||||||||||||||||||||||
| 236 | { | - | ||||||||||||||||||||||||
| 237 | QList<QAbstractButton *> buttonList = queryButtonList();; | - | ||||||||||||||||||||||||
| 238 | #ifndef QT_NO_BUTTONGROUP | - | ||||||||||||||||||||||||
| 239 | bool exclusive = group ? group->d_func()->exclusive : autoExclusive;
| 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))
| 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;
| 0 | ||||||||||||||||||||||||
| 253 | - | |||||||||||||||||||||||||
| 254 | for (int i = 0; i < buttonList.count(); ++i) {
| 0 | ||||||||||||||||||||||||
| 255 | QAbstractButton *button = buttonList.at(i); | - | ||||||||||||||||||||||||
| 256 | if (button != f && button->window() == f->window() && button->isEnabled() && !button->isHidden() &&
| 0 | ||||||||||||||||||||||||
| 257 | (autoExclusive || (button->focusPolicy() & focus_flag) == focus_flag)) {
| 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())
| 0 | ||||||||||||||||||||||||
| 266 | && (key == Qt::Key_Up || key == Qt::Key_Down)) {
| 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
| 0 | ||||||||||||||||||||||||
| 270 | && (key == Qt::Key_Left || key == Qt::Key_Right) ) {
| 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)
| 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()) {
| 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()) {
| 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()) {
| 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()) {
| 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
| 0 | ||||||||||||||||||||||||
| 310 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
| 311 | && !QApplication::keypadNavigationEnabled() | - | ||||||||||||||||||||||||
| 312 | #endif | - | ||||||||||||||||||||||||
| 313 | && candidate
| 0 | ||||||||||||||||||||||||
| 314 | && fb->d_func()->checked
| 0 | ||||||||||||||||||||||||
| 315 | && candidate->d_func()->checkable)
| 0 | ||||||||||||||||||||||||
| 316 | candidate->click(); never executed: candidate->click(); | 0 | ||||||||||||||||||||||||
| 317 | - | |||||||||||||||||||||||||
| 318 | if (candidate) {
| 0 | ||||||||||||||||||||||||
| 319 | if (key == Qt::Key_Up || key == Qt::Key_Left)
| 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 | - | |||||||||||||||||||||||||
| 326 | void QAbstractButtonPrivate::fixFocusPolicy() | - | ||||||||||||||||||||||||
| 327 | { | - | ||||||||||||||||||||||||
| 328 | Q_Q(QAbstractButton); | - | ||||||||||||||||||||||||
| 329 | #ifndef QT_NO_BUTTONGROUP | - | ||||||||||||||||||||||||
| 330 | if (!group && !autoExclusive)
| 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) {
| 0 | ||||||||||||||||||||||||
| 338 | QAbstractButton *b = buttonList.at(i); | - | ||||||||||||||||||||||||
| 339 | if (!b->isCheckable())
| 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 | - | |||||||||||||||||||||||||
| 347 | void 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 | - | |||||||||||||||||||||||||
| 358 | void QAbstractButtonPrivate::refresh() | - | ||||||||||||||||||||||||
| 359 | { | - | ||||||||||||||||||||||||
| 360 | Q_Q(QAbstractButton); | - | ||||||||||||||||||||||||
| 361 | - | |||||||||||||||||||||||||
| 362 | if (blockRefresh)
| 0 | ||||||||||||||||||||||||
| 363 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 364 | q->update(); | - | ||||||||||||||||||||||||
| 365 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 366 | - | |||||||||||||||||||||||||
| 367 | void QAbstractButtonPrivate::click() | - | ||||||||||||||||||||||||
| 368 | { | - | ||||||||||||||||||||||||
| 369 | Q_Q(QAbstractButton); | - | ||||||||||||||||||||||||
| 370 | - | |||||||||||||||||||||||||
| 371 | down = false; | - | ||||||||||||||||||||||||
| 372 | blockRefresh = true; | - | ||||||||||||||||||||||||
| 373 | bool changeState = true; | - | ||||||||||||||||||||||||
| 374 | if (checked && queryCheckedButton() == q) {
| 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)
| 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) {
| 0 | ||||||||||||||||||||||||
| 386 | q->nextCheckState(); | - | ||||||||||||||||||||||||
| 387 | if (!guard)
| 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)
| 0 | ||||||||||||||||||||||||
| 395 | emitReleased(); never executed: emitReleased(); | 0 | ||||||||||||||||||||||||
| 396 | if (guard)
| 0 | ||||||||||||||||||||||||
| 397 | emitClicked(); never executed: emitClicked(); | 0 | ||||||||||||||||||||||||
| 398 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 399 | - | |||||||||||||||||||||||||
| 400 | void 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) {
| 0 | ||||||||||||||||||||||||
| 407 | emit group->buttonClicked(group->id(q)); | - | ||||||||||||||||||||||||
| 408 | if (guard && group)
| 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 | - | |||||||||||||||||||||||||
| 414 | void 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) {
| 0 | ||||||||||||||||||||||||
| 421 | emit group->buttonPressed(group->id(q)); | - | ||||||||||||||||||||||||
| 422 | if (guard && group)
| 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 | - | |||||||||||||||||||||||||
| 428 | void 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) {
| 0 | ||||||||||||||||||||||||
| 435 | emit group->buttonReleased(group->id(q)); | - | ||||||||||||||||||||||||
| 436 | if (guard && group)
| 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 | - | |||||||||||||||||||||||||
| 442 | void 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) {
| 0 | ||||||||||||||||||||||||
| 449 | emit group->buttonToggled(group->id(q), checked); | - | ||||||||||||||||||||||||
| 450 | if (guard && group)
| 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 | */ | - | ||||||||||||||||||||||||
| 459 | QAbstractButton::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)
| 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 | */ | - | ||||||||||||||||||||||||
| 481 | QAbstractButton::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 | - | |||||||||||||||||||||||||
| 492 | If the button has no text, the text() function will return an empty | - | ||||||||||||||||||||||||
| 493 | string. | - | ||||||||||||||||||||||||
| 494 | - | |||||||||||||||||||||||||
| 495 | If the text contains an ampersand character ('&'), a shortcut is | - | ||||||||||||||||||||||||
| 496 | automatically created for it. The character that follows the '&' will | - | ||||||||||||||||||||||||
| 497 | be used as the shortcut key. Any previous shortcut will be | - | ||||||||||||||||||||||||
| 498 | overwritten or cleared if no shortcut is defined by the text. See the | - | ||||||||||||||||||||||||
| 499 | \l {QShortcut#mnemonic}{QShortcut} documentation for details. To | - | ||||||||||||||||||||||||
| 500 | display an actual ampersand, use '&&'. | - | ||||||||||||||||||||||||
| 501 | - | |||||||||||||||||||||||||
| 502 | There is no default text. | - | ||||||||||||||||||||||||
| 503 | */ | - | ||||||||||||||||||||||||
| 504 | - | |||||||||||||||||||||||||
| 505 | void QAbstractButton::setText(const QString &text) | - | ||||||||||||||||||||||||
| 506 | { | - | ||||||||||||||||||||||||
| 507 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 508 | if (d->text == text)
| 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 | - | |||||||||||||||||||||||||
| 524 | QString 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 | */ | - | ||||||||||||||||||||||||
| 538 | void 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 | - | |||||||||||||||||||||||||
| 547 | QIcon 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 | - | |||||||||||||||||||||||||
| 559 | void QAbstractButton::setShortcut(const QKeySequence &key) | - | ||||||||||||||||||||||||
| 560 | { | - | ||||||||||||||||||||||||
| 561 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 562 | if (d->shortcutId != 0)
| 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 | - | |||||||||||||||||||||||||
| 568 | QKeySequence 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 | - | |||||||||||||||||||||||||
| 579 | By default, the button is not checkable. | - | ||||||||||||||||||||||||
| 580 | - | |||||||||||||||||||||||||
| 581 | \sa checked | - | ||||||||||||||||||||||||
| 582 | */ | - | ||||||||||||||||||||||||
| 583 | void QAbstractButton::setCheckable(bool checkable) | - | ||||||||||||||||||||||||
| 584 | { | - | ||||||||||||||||||||||||
| 585 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 586 | if (d->checkable == checkable)
| 0 | ||||||||||||||||||||||||
| 587 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 588 | - | |||||||||||||||||||||||||
| 589 | d->checkable = checkable; | - | ||||||||||||||||||||||||
| 590 | d->checked = false; | - | ||||||||||||||||||||||||
| 591 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 592 | - | |||||||||||||||||||||||||
| 593 | bool 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 | - | |||||||||||||||||||||||||
| 603 | Only checkable buttons can be checked. By default, the button is unchecked. | - | ||||||||||||||||||||||||
| 604 | - | |||||||||||||||||||||||||
| 605 | \sa checkable | - | ||||||||||||||||||||||||
| 606 | */ | - | ||||||||||||||||||||||||
| 607 | void QAbstractButton::setChecked(bool checked) | - | ||||||||||||||||||||||||
| 608 | { | - | ||||||||||||||||||||||||
| 609 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 610 | if (!d->checkable || d->checked == checked) {
| 0 | ||||||||||||||||||||||||
| 611 | if (!d->blockRefresh)
| 0 | ||||||||||||||||||||||||
| 612 | checkStateSet(); never executed: checkStateSet(); | 0 | ||||||||||||||||||||||||
| 613 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 614 | } | - | ||||||||||||||||||||||||
| 615 | - | |||||||||||||||||||||||||
| 616 | if (!checked && d->queryCheckedButton() == this) {
| 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)
| 0 | ||||||||||||||||||||||||
| 620 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 621 | if (d->group)
| 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)
| 0 | ||||||||||||||||||||||||
| 633 | checkStateSet(); never executed: checkStateSet(); | 0 | ||||||||||||||||||||||||
| 634 | d->refresh(); | - | ||||||||||||||||||||||||
| 635 | - | |||||||||||||||||||||||||
| 636 | if (guard && checked)
| 0 | ||||||||||||||||||||||||
| 637 | d->notifyChecked(); never executed: d->notifyChecked(); | 0 | ||||||||||||||||||||||||
| 638 | if (guard)
| 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 | - | |||||||||||||||||||||||||
| 650 | bool 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 | - | |||||||||||||||||||||||||
| 665 | void QAbstractButton::setDown(bool down) | - | ||||||||||||||||||||||||
| 666 | { | - | ||||||||||||||||||||||||
| 667 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 668 | if (d->down == down)
| 0 | ||||||||||||||||||||||||
| 669 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 670 | d->down = down; | - | ||||||||||||||||||||||||
| 671 | d->refresh(); | - | ||||||||||||||||||||||||
| 672 | if (d->autoRepeat && d->down)
| 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 | - | |||||||||||||||||||||||||
| 678 | bool 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 | - | |||||||||||||||||||||||||
| 688 | If autoRepeat is enabled, then the pressed(), released(), and clicked() signals are emitted at | - | ||||||||||||||||||||||||
| 689 | regular intervals when the button is down. autoRepeat is off by default. | - | ||||||||||||||||||||||||
| 690 | The initial delay and the repetition interval are defined in milliseconds by \l | - | ||||||||||||||||||||||||
| 691 | autoRepeatDelay and \l autoRepeatInterval. | - | ||||||||||||||||||||||||
| 692 | - | |||||||||||||||||||||||||
| 693 | Note: If a button is pressed down by a shortcut key, then auto-repeat is enabled and timed by the | - | ||||||||||||||||||||||||
| 694 | system and not by this class. The pressed(), released(), and clicked() signals will be emitted | - | ||||||||||||||||||||||||
| 695 | like in the normal case. | - | ||||||||||||||||||||||||
| 696 | */ | - | ||||||||||||||||||||||||
| 697 | - | |||||||||||||||||||||||||
| 698 | void QAbstractButton::setAutoRepeat(bool autoRepeat) | - | ||||||||||||||||||||||||
| 699 | { | - | ||||||||||||||||||||||||
| 700 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 701 | if (d->autoRepeat == autoRepeat)
| 0 | ||||||||||||||||||||||||
| 702 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 703 | d->autoRepeat = autoRepeat; | - | ||||||||||||||||||||||||
| 704 | if (d->autoRepeat && d->down)
| 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 | - | |||||||||||||||||||||||||
| 710 | bool 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 | - | |||||||||||||||||||||||||
| 727 | void QAbstractButton::setAutoRepeatDelay(int autoRepeatDelay) | - | ||||||||||||||||||||||||
| 728 | { | - | ||||||||||||||||||||||||
| 729 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 730 | d->autoRepeatDelay = autoRepeatDelay; | - | ||||||||||||||||||||||||
| 731 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 732 | - | |||||||||||||||||||||||||
| 733 | int 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 | - | |||||||||||||||||||||||||
| 750 | void QAbstractButton::setAutoRepeatInterval(int autoRepeatInterval) | - | ||||||||||||||||||||||||
| 751 | { | - | ||||||||||||||||||||||||
| 752 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 753 | d->autoRepeatInterval = autoRepeatInterval; | - | ||||||||||||||||||||||||
| 754 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 755 | - | |||||||||||||||||||||||||
| 756 | int 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 | - | |||||||||||||||||||||||||
| 768 | If auto-exclusivity is enabled, checkable buttons that belong to the | - | ||||||||||||||||||||||||
| 769 | same parent widget behave as if they were part of the same | - | ||||||||||||||||||||||||
| 770 | exclusive button group. In an exclusive button group, only one button | - | ||||||||||||||||||||||||
| 771 | can be checked at any time; checking another button automatically | - | ||||||||||||||||||||||||
| 772 | unchecks the previously checked one. | - | ||||||||||||||||||||||||
| 773 | - | |||||||||||||||||||||||||
| 774 | The property has no effect on buttons that belong to a button | - | ||||||||||||||||||||||||
| 775 | group. | - | ||||||||||||||||||||||||
| 776 | - | |||||||||||||||||||||||||
| 777 | autoExclusive is off by default, except for radio buttons. | - | ||||||||||||||||||||||||
| 778 | - | |||||||||||||||||||||||||
| 779 | \sa QRadioButton | - | ||||||||||||||||||||||||
| 780 | */ | - | ||||||||||||||||||||||||
| 781 | void QAbstractButton::setAutoExclusive(bool autoExclusive) | - | ||||||||||||||||||||||||
| 782 | { | - | ||||||||||||||||||||||||
| 783 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 784 | d->autoExclusive = autoExclusive; | - | ||||||||||||||||||||||||
| 785 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 786 | - | |||||||||||||||||||||||||
| 787 | bool 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 | */ | - | ||||||||||||||||||||||||
| 802 | QButtonGroup *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 | /*! | - | ||||||||||||||||||||||||
| 810 | Performs an animated click: the button is pressed immediately, and | - | ||||||||||||||||||||||||
| 811 | released \a msec milliseconds later (the default is 100 ms). | - | ||||||||||||||||||||||||
| 812 | - | |||||||||||||||||||||||||
| 813 | Calling this function again before the button is released resets | - | ||||||||||||||||||||||||
| 814 | the release timer. | - | ||||||||||||||||||||||||
| 815 | - | |||||||||||||||||||||||||
| 816 | All signals associated with a click are emitted as appropriate. | - | ||||||||||||||||||||||||
| 817 | - | |||||||||||||||||||||||||
| 818 | This function does nothing if the button is \l{setEnabled()}{disabled.} | - | ||||||||||||||||||||||||
| 819 | - | |||||||||||||||||||||||||
| 820 | \sa click() | - | ||||||||||||||||||||||||
| 821 | */ | - | ||||||||||||||||||||||||
| 822 | void QAbstractButton::animateClick(int msec) | - | ||||||||||||||||||||||||
| 823 | { | - | ||||||||||||||||||||||||
| 824 | if (!isEnabled())
| 0 | ||||||||||||||||||||||||
| 825 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 826 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 827 | if (d->checkable && focusPolicy() & Qt::ClickFocus)
| 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())
| 0 | ||||||||||||||||||||||||
| 833 | d->emitPressed(); never executed: d->emitPressed(); | 0 | ||||||||||||||||||||||||
| 834 | d->animateTimer.start(msec, this); | - | ||||||||||||||||||||||||
| 835 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 836 | - | |||||||||||||||||||||||||
| 837 | /*! | - | ||||||||||||||||||||||||
| 838 | Performs a click. | - | ||||||||||||||||||||||||
| 839 | - | |||||||||||||||||||||||||
| 840 | All the usual signals associated with a click are emitted as | - | ||||||||||||||||||||||||
| 841 | appropriate. If the button is checkable, the state of the button is | - | ||||||||||||||||||||||||
| 842 | toggled. | - | ||||||||||||||||||||||||
| 843 | - | |||||||||||||||||||||||||
| 844 | This function does nothing if the button is \l{setEnabled()}{disabled.} | - | ||||||||||||||||||||||||
| 845 | - | |||||||||||||||||||||||||
| 846 | \sa animateClick() | - | ||||||||||||||||||||||||
| 847 | */ | - | ||||||||||||||||||||||||
| 848 | void QAbstractButton::click() | - | ||||||||||||||||||||||||
| 849 | { | - | ||||||||||||||||||||||||
| 850 | if (!isEnabled())
| 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) {
| 0 | ||||||||||||||||||||||||
| 857 | d->down = false; | - | ||||||||||||||||||||||||
| 858 | nextCheckState(); | - | ||||||||||||||||||||||||
| 859 | if (guard)
| 0 | ||||||||||||||||||||||||
| 860 | d->emitReleased(); never executed: d->emitReleased(); | 0 | ||||||||||||||||||||||||
| 861 | if (guard)
| 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 | */ | - | ||||||||||||||||||||||||
| 872 | void 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, | - | ||||||||||||||||||||||||
| 880 | unless it is called from within nextCheckState(). It allows | - | ||||||||||||||||||||||||
| 881 | subclasses to reset their intermediate button states. | - | ||||||||||||||||||||||||
| 882 | - | |||||||||||||||||||||||||
| 883 | \sa nextCheckState() | - | ||||||||||||||||||||||||
| 884 | */ | - | ||||||||||||||||||||||||
| 885 | void QAbstractButton::checkStateSet() | - | ||||||||||||||||||||||||
| 886 | { | - | ||||||||||||||||||||||||
| 887 | } | - | ||||||||||||||||||||||||
| 888 | - | |||||||||||||||||||||||||
| 889 | /*! This virtual handler is called when a button is clicked. The | - | ||||||||||||||||||||||||
| 890 | default implementation calls setChecked(!isChecked()) if the button | - | ||||||||||||||||||||||||
| 891 | isCheckable(). It allows subclasses to implement intermediate button | - | ||||||||||||||||||||||||
| 892 | states. | - | ||||||||||||||||||||||||
| 893 | - | |||||||||||||||||||||||||
| 894 | \sa checkStateSet() | - | ||||||||||||||||||||||||
| 895 | */ | - | ||||||||||||||||||||||||
| 896 | void QAbstractButton::nextCheckState() | - | ||||||||||||||||||||||||
| 897 | { | - | ||||||||||||||||||||||||
| 898 | if (isCheckable())
| 0 | ||||||||||||||||||||||||
| 899 | setChecked(!isChecked()); never executed: setChecked(!isChecked()); | 0 | ||||||||||||||||||||||||
| 900 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 901 | - | |||||||||||||||||||||||||
| 902 | /*! | - | ||||||||||||||||||||||||
| 903 | Returns \c true if \a pos is inside the clickable button rectangle; | - | ||||||||||||||||||||||||
| 904 | otherwise returns \c false. | - | ||||||||||||||||||||||||
| 905 | - | |||||||||||||||||||||||||
| 906 | By default, the clickable area is the entire widget. Subclasses | - | ||||||||||||||||||||||||
| 907 | may reimplement this function to provide support for clickable | - | ||||||||||||||||||||||||
| 908 | areas of different shapes and sizes. | - | ||||||||||||||||||||||||
| 909 | */ | - | ||||||||||||||||||||||||
| 910 | bool QAbstractButton::hitButton(const QPoint &pos) const | - | ||||||||||||||||||||||||
| 911 | { | - | ||||||||||||||||||||||||
| 912 | return rect().contains(pos); never executed: return rect().contains(pos); | 0 | ||||||||||||||||||||||||
| 913 | } | - | ||||||||||||||||||||||||
| 914 | - | |||||||||||||||||||||||||
| 915 | /*! \reimp */ | - | ||||||||||||||||||||||||
| 916 | bool 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()) {
| 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) {
| 0 | ||||||||||||||||||||||||
| 944 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 945 | QShortcutEvent *se = static_cast<QShortcutEvent *>(e); | - | ||||||||||||||||||||||||
| 946 | if (d->shortcutId != se->shortcutId())
| 0 | ||||||||||||||||||||||||
| 947 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 948 | if (!se->isAmbiguous()) {
| 0 | ||||||||||||||||||||||||
| 949 | if (!d->animateTimer.isActive())
| 0 | ||||||||||||||||||||||||
| 950 | animateClick(); never executed: animateClick(); | 0 | ||||||||||||||||||||||||
| 951 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 952 | if (focusPolicy() != Qt::NoFocus)
| 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 */ | - | ||||||||||||||||||||||||
| 963 | void QAbstractButton::mousePressEvent(QMouseEvent *e) | - | ||||||||||||||||||||||||
| 964 | { | - | ||||||||||||||||||||||||
| 965 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 966 | if (e->button() != Qt::LeftButton) {
| 0 | ||||||||||||||||||||||||
| 967 | e->ignore(); | - | ||||||||||||||||||||||||
| 968 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 969 | } | - | ||||||||||||||||||||||||
| 970 | if (hitButton(e->pos())) {
| 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 */ | - | ||||||||||||||||||||||||
| 983 | void QAbstractButton::mouseReleaseEvent(QMouseEvent *e) | - | ||||||||||||||||||||||||
| 984 | { | - | ||||||||||||||||||||||||
| 985 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 986 | d->pressed = false; | - | ||||||||||||||||||||||||
| 987 | - | |||||||||||||||||||||||||
| 988 | if (e->button() != Qt::LeftButton) {
| 0 | ||||||||||||||||||||||||
| 989 | e->ignore(); | - | ||||||||||||||||||||||||
| 990 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 991 | } | - | ||||||||||||||||||||||||
| 992 | - | |||||||||||||||||||||||||
| 993 | if (!d->down) {
| 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())) {
| 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 */ | - | ||||||||||||||||||||||||
| 1011 | void QAbstractButton::mouseMoveEvent(QMouseEvent *e) | - | ||||||||||||||||||||||||
| 1012 | { | - | ||||||||||||||||||||||||
| 1013 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 1014 | if (!(e->buttons() & Qt::LeftButton) || !d->pressed) {
| 0 | ||||||||||||||||||||||||
| 1015 | e->ignore(); | - | ||||||||||||||||||||||||
| 1016 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1017 | } | - | ||||||||||||||||||||||||
| 1018 | - | |||||||||||||||||||||||||
| 1019 | if (hitButton(e->pos()) != d->down) {
| 0 | ||||||||||||||||||||||||
| 1020 | setDown(!d->down); | - | ||||||||||||||||||||||||
| 1021 | repaint(); //flush paint event before invoking potentially expensive operation | - | ||||||||||||||||||||||||
| 1022 | QApplication::flush(); | - | ||||||||||||||||||||||||
| 1023 | if (d->down)
| 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
| 0 | ||||||||||||||||||||||||
| 1029 | e->ignore(); | - | ||||||||||||||||||||||||
| 1030 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1031 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1032 | - | |||||||||||||||||||||||||
| 1033 | /*! \reimp */ | - | ||||||||||||||||||||||||
| 1034 | void 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()) {
| 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
| 0 | ||||||||||||||||||||||||
| 1069 | #ifndef QT_NO_BUTTONGROUP | - | ||||||||||||||||||||||||
| 1070 | || d->group
| 0 | ||||||||||||||||||||||||
| 1071 | #endif | - | ||||||||||||||||||||||||
| 1072 | #ifndef QT_NO_ITEMVIEWS | - | ||||||||||||||||||||||||
| 1073 | || (pw && qobject_cast<QAbstractItemView *>(pw->parentWidget()))
| 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
| 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;
| 0 | ||||||||||||||||||||||||
| 1086 | bool reverse = (w->layoutDirection() == Qt::RightToLeft); | - | ||||||||||||||||||||||||
| 1087 | if ((e->key() == Qt::Key_Left && !reverse)
| 0 | ||||||||||||||||||||||||
| 1088 | || (e->key() == Qt::Key_Right && reverse)) {
| 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) {
| 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 */ | - | ||||||||||||||||||||||||
| 1108 | void QAbstractButton::keyReleaseEvent(QKeyEvent *e) | - | ||||||||||||||||||||||||
| 1109 | { | - | ||||||||||||||||||||||||
| 1110 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 1111 | - | |||||||||||||||||||||||||
| 1112 | if (!e->isAutoRepeat())
| 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)
| 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 | */ | - | ||||||||||||||||||||||||
| 1128 | void QAbstractButton::timerEvent(QTimerEvent *e) | - | ||||||||||||||||||||||||
| 1129 | { | - | ||||||||||||||||||||||||
| 1130 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 1131 | if (e->timerId() == d->repeatTimer.timerId()) {
| 0 | ||||||||||||||||||||||||
| 1132 | d->repeatTimer.start(d->autoRepeatInterval, this); | - | ||||||||||||||||||||||||
| 1133 | if (d->down) {
| 0 | ||||||||||||||||||||||||
| 1134 | QPointer<QAbstractButton> guard(this); | - | ||||||||||||||||||||||||
| 1135 | nextCheckState(); | - | ||||||||||||||||||||||||
| 1136 | if (guard)
| 0 | ||||||||||||||||||||||||
| 1137 | d->emitReleased(); never executed: d->emitReleased(); | 0 | ||||||||||||||||||||||||
| 1138 | if (guard)
| 0 | ||||||||||||||||||||||||
| 1139 | d->emitClicked(); never executed: d->emitClicked(); | 0 | ||||||||||||||||||||||||
| 1140 | if (guard)
| 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
| 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 */ | - | ||||||||||||||||||||||||
| 1150 | void 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 */ | - | ||||||||||||||||||||||||
| 1161 | void QAbstractButton::focusOutEvent(QFocusEvent *e) | - | ||||||||||||||||||||||||
| 1162 | { | - | ||||||||||||||||||||||||
| 1163 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 1164 | if (e->reason() != Qt::PopupFocusReason && d->down) {
| 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 */ | - | ||||||||||||||||||||||||
| 1172 | void 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) {
| 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 | - | |||||||||||||||||||||||||
| 1213 | This signal is emitted when the button is activated (i.e., pressed down | - | ||||||||||||||||||||||||
| 1214 | then released while the mouse cursor is inside the button), when the | - | ||||||||||||||||||||||||
| 1215 | shortcut key is typed, or when click() or animateClick() is called. | - | ||||||||||||||||||||||||
| 1216 | Notably, this signal is \e not emitted if you call setDown(), | - | ||||||||||||||||||||||||
| 1217 | setChecked() or toggle(). | - | ||||||||||||||||||||||||
| 1218 | - | |||||||||||||||||||||||||
| 1219 | If the button is checkable, \a checked is true if the button is | - | ||||||||||||||||||||||||
| 1220 | checked, or false if the button is unchecked. | - | ||||||||||||||||||||||||
| 1221 | - | |||||||||||||||||||||||||
| 1222 | \sa pressed(), released(), toggled() | - | ||||||||||||||||||||||||
| 1223 | */ | - | ||||||||||||||||||||||||
| 1224 | - | |||||||||||||||||||||||||
| 1225 | /*! | - | ||||||||||||||||||||||||
| 1226 | \fn void QAbstractButton::toggled(bool checked) | - | ||||||||||||||||||||||||
| 1227 | - | |||||||||||||||||||||||||
| 1228 | This 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 | - | ||||||||||||||||||||||||
| 1230 | unchecked. | - | ||||||||||||||||||||||||
| 1231 | - | |||||||||||||||||||||||||
| 1232 | This may be the result of a user action, click() slot activation, | - | ||||||||||||||||||||||||
| 1233 | or because setChecked() is called. | - | ||||||||||||||||||||||||
| 1234 | - | |||||||||||||||||||||||||
| 1235 | The states of buttons in exclusive button groups are updated before this | - | ||||||||||||||||||||||||
| 1236 | signal is emitted. This means that slots can act on either the "off" | - | ||||||||||||||||||||||||
| 1237 | signal or the "on" signal emitted by the buttons in the group whose | - | ||||||||||||||||||||||||
| 1238 | states have changed. | - | ||||||||||||||||||||||||
| 1239 | - | |||||||||||||||||||||||||
| 1240 | For example, a slot that reacts to signals emitted by newly checked | - | ||||||||||||||||||||||||
| 1241 | buttons but which ignores signals from buttons that have been unchecked | - | ||||||||||||||||||||||||
| 1242 | can be implemented using the following pattern: | - | ||||||||||||||||||||||||
| 1243 | - | |||||||||||||||||||||||||
| 1244 | \snippet code/src_gui_widgets_qabstractbutton.cpp 2 | - | ||||||||||||||||||||||||
| 1245 | - | |||||||||||||||||||||||||
| 1246 | Button groups can be created using the QButtonGroup class, and | - | ||||||||||||||||||||||||
| 1247 | updates 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 | - | |||||||||||||||||||||||||
| 1261 | QSize QAbstractButton::iconSize() const | - | ||||||||||||||||||||||||
| 1262 | { | - | ||||||||||||||||||||||||
| 1263 | Q_D(const QAbstractButton); | - | ||||||||||||||||||||||||
| 1264 | if (d->iconSize.isValid())
| 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 | - | |||||||||||||||||||||||||
| 1270 | void QAbstractButton::setIconSize(const QSize &size) | - | ||||||||||||||||||||||||
| 1271 | { | - | ||||||||||||||||||||||||
| 1272 | Q_D(QAbstractButton); | - | ||||||||||||||||||||||||
| 1273 | if (d->iconSize == size)
| 0 | ||||||||||||||||||||||||
| 1274 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1275 | - | |||||||||||||||||||||||||
| 1276 | d->iconSize = size; | - | ||||||||||||||||||||||||
| 1277 | d->sizeHint = QSize(); | - | ||||||||||||||||||||||||
| 1278 | updateGeometry(); | - | ||||||||||||||||||||||||
| 1279 | if (isVisible()) {
| 0 | ||||||||||||||||||||||||
| 1280 | update(); | - | ||||||||||||||||||||||||
| 1281 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1282 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1283 | - | |||||||||||||||||||||||||
| 1284 | - | |||||||||||||||||||||||||
| 1285 | - | |||||||||||||||||||||||||
| 1286 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| 1287 | - | |||||||||||||||||||||||||
| 1288 | #include "moc_qabstractbutton.cpp" | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |