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