Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qpushbutton.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 "qapplication.h" | - | ||||||||||||||||||
35 | #include "qbitmap.h" | - | ||||||||||||||||||
36 | #include "qdesktopwidget.h" | - | ||||||||||||||||||
37 | #include "qdialog.h" | - | ||||||||||||||||||
38 | #include <private/qdialog_p.h> | - | ||||||||||||||||||
39 | #include "qdrawutil.h" | - | ||||||||||||||||||
40 | #include "qevent.h" | - | ||||||||||||||||||
41 | #include "qfontmetrics.h" | - | ||||||||||||||||||
42 | #include "qmenu.h" | - | ||||||||||||||||||
43 | #include "qstylepainter.h" | - | ||||||||||||||||||
44 | #include "qpixmap.h" | - | ||||||||||||||||||
45 | #include "qpointer.h" | - | ||||||||||||||||||
46 | #include "qpushbutton.h" | - | ||||||||||||||||||
47 | #include "qstyle.h" | - | ||||||||||||||||||
48 | #include "qstyleoption.h" | - | ||||||||||||||||||
49 | #include "qtoolbar.h" | - | ||||||||||||||||||
50 | #include "qdebug.h" | - | ||||||||||||||||||
51 | #include "qlayoutitem.h" | - | ||||||||||||||||||
52 | #include "qdialogbuttonbox.h" | - | ||||||||||||||||||
53 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
54 | #include "private/qmacstyle_mac_p.h" | - | ||||||||||||||||||
55 | #include "private/qmacstyle_mac_p_p.h" | - | ||||||||||||||||||
56 | #endif // Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
59 | #include "qaccessible.h" | - | ||||||||||||||||||
60 | #endif | - | ||||||||||||||||||
61 | - | |||||||||||||||||||
62 | #include "private/qmenu_p.h" | - | ||||||||||||||||||
63 | #include "private/qpushbutton_p.h" | - | ||||||||||||||||||
64 | - | |||||||||||||||||||
65 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
66 | - | |||||||||||||||||||
67 | - | |||||||||||||||||||
68 | /*! | - | ||||||||||||||||||
69 | \class QPushButton | - | ||||||||||||||||||
70 | \brief The QPushButton widget provides a command button. | - | ||||||||||||||||||
71 | - | |||||||||||||||||||
72 | \ingroup basicwidgets | - | ||||||||||||||||||
73 | \inmodule QtWidgets | - | ||||||||||||||||||
74 | - | |||||||||||||||||||
75 | The push button, or command button, is perhaps the most commonly | - | ||||||||||||||||||
76 | used widget in any graphical user interface. Push (click) a button | - | ||||||||||||||||||
77 | to command the computer to perform some action, or to answer a | - | ||||||||||||||||||
78 | question. Typical buttons are OK, Apply, Cancel, Close, Yes, No | - | ||||||||||||||||||
79 | and Help. | - | ||||||||||||||||||
80 | - | |||||||||||||||||||
81 | A command button is rectangular and typically displays a text | - | ||||||||||||||||||
82 | label describing its action. A shortcut key can be specified by | - | ||||||||||||||||||
83 | preceding the preferred character with an ampersand in the | - | ||||||||||||||||||
84 | text. For example: | - | ||||||||||||||||||
85 | - | |||||||||||||||||||
86 | \snippet code/src_gui_widgets_qpushbutton.cpp 0 | - | ||||||||||||||||||
87 | - | |||||||||||||||||||
88 | In this example the shortcut is \e{Alt+D}. See the \l | - | ||||||||||||||||||
89 | {QShortcut#mnemonic}{QShortcut} documentation for details (to | - | ||||||||||||||||||
90 | display an actual ampersand, use '&&'). | - | ||||||||||||||||||
91 | - | |||||||||||||||||||
92 | Push buttons display a textual label, and optionally a small | - | ||||||||||||||||||
93 | icon. These can be set using the constructors and changed later | - | ||||||||||||||||||
94 | using setText() and setIcon(). If the button is disabled, the | - | ||||||||||||||||||
95 | appearance of the text and icon will be manipulated with respect | - | ||||||||||||||||||
96 | to the GUI style to make the button look "disabled". | - | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | A push button emits the signal clicked() when it is activated by | - | ||||||||||||||||||
99 | the mouse, the Spacebar or by a keyboard shortcut. Connect to | - | ||||||||||||||||||
100 | this signal to perform the button's action. Push buttons also | - | ||||||||||||||||||
101 | provide less commonly used signals, for example pressed() and | - | ||||||||||||||||||
102 | released(). | - | ||||||||||||||||||
103 | - | |||||||||||||||||||
104 | Command buttons in dialogs are by default auto-default buttons, | - | ||||||||||||||||||
105 | i.e., they become the default push button automatically when they | - | ||||||||||||||||||
106 | receive the keyboard input focus. A default button is a push | - | ||||||||||||||||||
107 | button that is activated when the user presses the Enter or Return | - | ||||||||||||||||||
108 | key in a dialog. You can change this with setAutoDefault(). Note | - | ||||||||||||||||||
109 | that auto-default buttons reserve a little extra space which is | - | ||||||||||||||||||
110 | necessary to draw a default-button indicator. If you do not want | - | ||||||||||||||||||
111 | this space around your buttons, call setAutoDefault(false). | - | ||||||||||||||||||
112 | - | |||||||||||||||||||
113 | Being so central, the button widget has grown to accommodate a | - | ||||||||||||||||||
114 | great many variations in the past decade. The Microsoft style | - | ||||||||||||||||||
115 | guide now shows about ten different states of Windows push buttons | - | ||||||||||||||||||
116 | and the text implies that there are dozens more when all the | - | ||||||||||||||||||
117 | combinations of features are taken into consideration. | - | ||||||||||||||||||
118 | - | |||||||||||||||||||
119 | The most important modes or states are: | - | ||||||||||||||||||
120 | \list | - | ||||||||||||||||||
121 | \li Available or not (grayed out, disabled). | - | ||||||||||||||||||
122 | \li Standard push button, toggling push button or menu button. | - | ||||||||||||||||||
123 | \li On or off (only for toggling push buttons). | - | ||||||||||||||||||
124 | \li Default or normal. The default button in a dialog can generally | - | ||||||||||||||||||
125 | be "clicked" using the Enter or Return key. | - | ||||||||||||||||||
126 | \li Auto-repeat or not. | - | ||||||||||||||||||
127 | \li Pressed down or not. | - | ||||||||||||||||||
128 | \endlist | - | ||||||||||||||||||
129 | - | |||||||||||||||||||
130 | As a general rule, use a push button when the application or | - | ||||||||||||||||||
131 | dialog window performs an action when the user clicks on it (such | - | ||||||||||||||||||
132 | as Apply, Cancel, Close and Help) \e and when the widget is | - | ||||||||||||||||||
133 | supposed to have a wide, rectangular shape with a text label. | - | ||||||||||||||||||
134 | Small, typically square buttons that change the state of the | - | ||||||||||||||||||
135 | window rather than performing an action (such as the buttons in | - | ||||||||||||||||||
136 | the top-right corner of the QFileDialog) are not command buttons, | - | ||||||||||||||||||
137 | but tool buttons. Qt provides a special class (QToolButton) for | - | ||||||||||||||||||
138 | these buttons. | - | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | If you need toggle behavior (see setCheckable()) or a button | - | ||||||||||||||||||
141 | that auto-repeats the activation signal when being pushed down | - | ||||||||||||||||||
142 | like the arrows in a scroll bar (see setAutoRepeat()), a command | - | ||||||||||||||||||
143 | button is probably not what you want. When in doubt, use a tool | - | ||||||||||||||||||
144 | button. | - | ||||||||||||||||||
145 | - | |||||||||||||||||||
146 | A variation of a command button is a menu button. These provide | - | ||||||||||||||||||
147 | not just one command, but several, since when they are clicked | - | ||||||||||||||||||
148 | they pop up a menu of options. Use the method setMenu() to | - | ||||||||||||||||||
149 | associate a popup menu with a push button. | - | ||||||||||||||||||
150 | - | |||||||||||||||||||
151 | Other classes of buttons are option buttons (see QRadioButton) and | - | ||||||||||||||||||
152 | check boxes (see QCheckBox). | - | ||||||||||||||||||
153 | - | |||||||||||||||||||
154 | \table 100% | - | ||||||||||||||||||
155 | \row \li \inlineimage macintosh-pushbutton.png Screenshot of a Macintosh style push button | - | ||||||||||||||||||
156 | \li A push button shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}. | - | ||||||||||||||||||
157 | - | |||||||||||||||||||
158 | Note that when a button's width becomes smaller than 50 or | - | ||||||||||||||||||
159 | its height becomes smaller than 30, the button's corners are | - | ||||||||||||||||||
160 | changed from round to square. Use the setMinimumSize() | - | ||||||||||||||||||
161 | function to prevent this behavior. | - | ||||||||||||||||||
162 | - | |||||||||||||||||||
163 | \row \li \inlineimage windowsvista-pushbutton.png Screenshot of a Windows Vista style push button | - | ||||||||||||||||||
164 | \li A push button shown in the \l{Windows Vista Style Widget Gallery}{Windows Vista widget style}. | - | ||||||||||||||||||
165 | \row \li \inlineimage fusion-pushbutton.png Screenshot of a Fusion style push button | - | ||||||||||||||||||
166 | \li A push button shown in the \l{Fusion Style Widget Gallery}{Fusion widget style}. | - | ||||||||||||||||||
167 | \endtable | - | ||||||||||||||||||
168 | - | |||||||||||||||||||
169 | In Qt, the QAbstractButton base class provides most of the modes | - | ||||||||||||||||||
170 | and other API, and QPushButton provides GUI logic. | - | ||||||||||||||||||
171 | See QAbstractButton for more information about the API. | - | ||||||||||||||||||
172 | - | |||||||||||||||||||
173 | \sa QToolButton, QRadioButton, QCheckBox, {fowler}{GUI Design Handbook: Push Button} | - | ||||||||||||||||||
174 | */ | - | ||||||||||||||||||
175 | - | |||||||||||||||||||
176 | /*! | - | ||||||||||||||||||
177 | \property QPushButton::autoDefault | - | ||||||||||||||||||
178 | \brief whether the push button is an auto default button | - | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | If this property is set to true then the push button is an auto | - | ||||||||||||||||||
181 | default button. | - | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | In some GUI styles a default button is drawn with an extra frame | - | ||||||||||||||||||
184 | around it, up to 3 pixels or more. Qt automatically keeps this | - | ||||||||||||||||||
185 | space free around auto-default buttons, i.e., auto-default buttons | - | ||||||||||||||||||
186 | may have a slightly larger size hint. | - | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | This property's default is true for buttons that have a QDialog | - | ||||||||||||||||||
189 | parent; otherwise it defaults to false. | - | ||||||||||||||||||
190 | - | |||||||||||||||||||
191 | See the \l default property for details of how \l default and | - | ||||||||||||||||||
192 | auto-default interact. | - | ||||||||||||||||||
193 | */ | - | ||||||||||||||||||
194 | - | |||||||||||||||||||
195 | /*! | - | ||||||||||||||||||
196 | \property QPushButton::default | - | ||||||||||||||||||
197 | \brief whether the push button is the default button | - | ||||||||||||||||||
198 | - | |||||||||||||||||||
199 | Default and autodefault buttons decide what happens when the user | - | ||||||||||||||||||
200 | presses enter in a dialog. | - | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | A button with this property set to true (i.e., the dialog's | - | ||||||||||||||||||
203 | \e default button,) will automatically be pressed when the user presses enter, | - | ||||||||||||||||||
204 | with one exception: if an \a autoDefault button currently has focus, the autoDefault | - | ||||||||||||||||||
205 | button is pressed. When the dialog has \l autoDefault buttons but no default button, | - | ||||||||||||||||||
206 | pressing enter will press either the \l autoDefault button that currently has focus, or if no | - | ||||||||||||||||||
207 | button has focus, the next \l autoDefault button in the focus chain. | - | ||||||||||||||||||
208 | - | |||||||||||||||||||
209 | In a dialog, only one push button at a time can be the default | - | ||||||||||||||||||
210 | button. This button is then displayed with an additional frame | - | ||||||||||||||||||
211 | (depending on the GUI style). | - | ||||||||||||||||||
212 | - | |||||||||||||||||||
213 | The default button behavior is provided only in dialogs. Buttons | - | ||||||||||||||||||
214 | can always be clicked from the keyboard by pressing Spacebar when | - | ||||||||||||||||||
215 | the button has focus. | - | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | If the default property is set to false on the current default button | - | ||||||||||||||||||
218 | while the dialog is visible, a new default will automatically be | - | ||||||||||||||||||
219 | assigned the next time a push button in the dialog receives focus. | - | ||||||||||||||||||
220 | - | |||||||||||||||||||
221 | This property's default is false. | - | ||||||||||||||||||
222 | */ | - | ||||||||||||||||||
223 | - | |||||||||||||||||||
224 | /*! | - | ||||||||||||||||||
225 | \property QPushButton::flat | - | ||||||||||||||||||
226 | \brief whether the button border is raised | - | ||||||||||||||||||
227 | - | |||||||||||||||||||
228 | This property's default is false. If this property is set, most | - | ||||||||||||||||||
229 | styles will not paint the button background unless the button is | - | ||||||||||||||||||
230 | being pressed. setAutoFillBackground() can be used to ensure that | - | ||||||||||||||||||
231 | the background is filled using the QPalette::Button brush. | - | ||||||||||||||||||
232 | */ | - | ||||||||||||||||||
233 | - | |||||||||||||||||||
234 | /*! | - | ||||||||||||||||||
235 | Constructs a push button with no text and a \a parent. | - | ||||||||||||||||||
236 | */ | - | ||||||||||||||||||
237 | - | |||||||||||||||||||
238 | QPushButton::QPushButton(QWidget *parent) | - | ||||||||||||||||||
239 | : QAbstractButton(*new QPushButtonPrivate, parent) | - | ||||||||||||||||||
240 | { | - | ||||||||||||||||||
241 | Q_D(QPushButton); | - | ||||||||||||||||||
242 | d->init(); | - | ||||||||||||||||||
243 | } never executed: end of block | 0 | ||||||||||||||||||
244 | - | |||||||||||||||||||
245 | /*! | - | ||||||||||||||||||
246 | Constructs a push button with the parent \a parent and the text \a | - | ||||||||||||||||||
247 | text. | - | ||||||||||||||||||
248 | */ | - | ||||||||||||||||||
249 | - | |||||||||||||||||||
250 | QPushButton::QPushButton(const QString &text, QWidget *parent) | - | ||||||||||||||||||
251 | : QAbstractButton(*new QPushButtonPrivate, parent) | - | ||||||||||||||||||
252 | { | - | ||||||||||||||||||
253 | Q_D(QPushButton); | - | ||||||||||||||||||
254 | setText(text); | - | ||||||||||||||||||
255 | d->init(); | - | ||||||||||||||||||
256 | } never executed: end of block | 0 | ||||||||||||||||||
257 | - | |||||||||||||||||||
258 | - | |||||||||||||||||||
259 | /*! | - | ||||||||||||||||||
260 | Constructs a push button with an \a icon and a \a text, and a \a parent. | - | ||||||||||||||||||
261 | - | |||||||||||||||||||
262 | Note that you can also pass a QPixmap object as an icon (thanks to | - | ||||||||||||||||||
263 | the implicit type conversion provided by C++). | - | ||||||||||||||||||
264 | - | |||||||||||||||||||
265 | */ | - | ||||||||||||||||||
266 | QPushButton::QPushButton(const QIcon& icon, const QString &text, QWidget *parent) | - | ||||||||||||||||||
267 | : QAbstractButton(*new QPushButtonPrivate, parent) | - | ||||||||||||||||||
268 | { | - | ||||||||||||||||||
269 | Q_D(QPushButton); | - | ||||||||||||||||||
270 | setText(text); | - | ||||||||||||||||||
271 | setIcon(icon); | - | ||||||||||||||||||
272 | d->init(); | - | ||||||||||||||||||
273 | } never executed: end of block | 0 | ||||||||||||||||||
274 | - | |||||||||||||||||||
275 | /*! \internal | - | ||||||||||||||||||
276 | */ | - | ||||||||||||||||||
277 | QPushButton::QPushButton(QPushButtonPrivate &dd, QWidget *parent) | - | ||||||||||||||||||
278 | : QAbstractButton(dd, parent) | - | ||||||||||||||||||
279 | { | - | ||||||||||||||||||
280 | Q_D(QPushButton); | - | ||||||||||||||||||
281 | d->init(); | - | ||||||||||||||||||
282 | } never executed: end of block | 0 | ||||||||||||||||||
283 | - | |||||||||||||||||||
284 | /*! | - | ||||||||||||||||||
285 | Destroys the push button. | - | ||||||||||||||||||
286 | */ | - | ||||||||||||||||||
287 | QPushButton::~QPushButton() | - | ||||||||||||||||||
288 | { | - | ||||||||||||||||||
289 | } | - | ||||||||||||||||||
290 | - | |||||||||||||||||||
291 | QDialog *QPushButtonPrivate::dialogParent() const | - | ||||||||||||||||||
292 | { | - | ||||||||||||||||||
293 | Q_Q(const QPushButton); | - | ||||||||||||||||||
294 | const QWidget *p = q; | - | ||||||||||||||||||
295 | while (p && !p->isWindow()) {
| 0 | ||||||||||||||||||
296 | p = p->parentWidget(); | - | ||||||||||||||||||
297 | if (const QDialog *dialog = qobject_cast<const QDialog *>(p))
| 0 | ||||||||||||||||||
298 | return const_cast<QDialog *>(dialog); never executed: return const_cast<QDialog *>(dialog); | 0 | ||||||||||||||||||
299 | } never executed: end of block | 0 | ||||||||||||||||||
300 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
301 | } | - | ||||||||||||||||||
302 | - | |||||||||||||||||||
303 | /*! | - | ||||||||||||||||||
304 | Initialize \a option with the values from this QPushButton. This method is useful | - | ||||||||||||||||||
305 | for subclasses when they need a QStyleOptionButton, but don't want to fill | - | ||||||||||||||||||
306 | in all the information themselves. | - | ||||||||||||||||||
307 | - | |||||||||||||||||||
308 | \sa QStyleOption::initFrom() | - | ||||||||||||||||||
309 | */ | - | ||||||||||||||||||
310 | void QPushButton::initStyleOption(QStyleOptionButton *option) const | - | ||||||||||||||||||
311 | { | - | ||||||||||||||||||
312 | if (!option)
| 0 | ||||||||||||||||||
313 | return; never executed: return; | 0 | ||||||||||||||||||
314 | - | |||||||||||||||||||
315 | Q_D(const QPushButton); | - | ||||||||||||||||||
316 | option->initFrom(this); | - | ||||||||||||||||||
317 | option->features = QStyleOptionButton::None; | - | ||||||||||||||||||
318 | if (d->flat)
| 0 | ||||||||||||||||||
319 | option->features |= QStyleOptionButton::Flat; never executed: option->features |= QStyleOptionButton::Flat; | 0 | ||||||||||||||||||
320 | #ifndef QT_NO_MENU | - | ||||||||||||||||||
321 | if (d->menu)
| 0 | ||||||||||||||||||
322 | option->features |= QStyleOptionButton::HasMenu; never executed: option->features |= QStyleOptionButton::HasMenu; | 0 | ||||||||||||||||||
323 | #endif | - | ||||||||||||||||||
324 | if (autoDefault())
| 0 | ||||||||||||||||||
325 | option->features |= QStyleOptionButton::AutoDefaultButton; never executed: option->features |= QStyleOptionButton::AutoDefaultButton; | 0 | ||||||||||||||||||
326 | if (d->defaultButton)
| 0 | ||||||||||||||||||
327 | option->features |= QStyleOptionButton::DefaultButton; never executed: option->features |= QStyleOptionButton::DefaultButton; | 0 | ||||||||||||||||||
328 | if (d->down || d->menuOpen)
| 0 | ||||||||||||||||||
329 | option->state |= QStyle::State_Sunken; never executed: option->state |= QStyle::State_Sunken; | 0 | ||||||||||||||||||
330 | if (d->checked)
| 0 | ||||||||||||||||||
331 | option->state |= QStyle::State_On; never executed: option->state |= QStyle::State_On; | 0 | ||||||||||||||||||
332 | if (!d->flat && !d->down)
| 0 | ||||||||||||||||||
333 | option->state |= QStyle::State_Raised; never executed: option->state |= QStyle::State_Raised; | 0 | ||||||||||||||||||
334 | option->text = d->text; | - | ||||||||||||||||||
335 | option->icon = d->icon; | - | ||||||||||||||||||
336 | option->iconSize = iconSize(); | - | ||||||||||||||||||
337 | } never executed: end of block | 0 | ||||||||||||||||||
338 | - | |||||||||||||||||||
339 | void QPushButton::setAutoDefault(bool enable) | - | ||||||||||||||||||
340 | { | - | ||||||||||||||||||
341 | Q_D(QPushButton); | - | ||||||||||||||||||
342 | uint state = enable ? QPushButtonPrivate::On : QPushButtonPrivate::Off;
| 0 | ||||||||||||||||||
343 | if (d->autoDefault != QPushButtonPrivate::Auto && d->autoDefault == state)
| 0 | ||||||||||||||||||
344 | return; never executed: return; | 0 | ||||||||||||||||||
345 | d->autoDefault = state; | - | ||||||||||||||||||
346 | d->sizeHint = QSize(); | - | ||||||||||||||||||
347 | update(); | - | ||||||||||||||||||
348 | updateGeometry(); | - | ||||||||||||||||||
349 | } never executed: end of block | 0 | ||||||||||||||||||
350 | - | |||||||||||||||||||
351 | bool QPushButton::autoDefault() const | - | ||||||||||||||||||
352 | { | - | ||||||||||||||||||
353 | Q_D(const QPushButton); | - | ||||||||||||||||||
354 | if(d->autoDefault == QPushButtonPrivate::Auto)
| 0 | ||||||||||||||||||
355 | return ( d->dialogParent() != 0 ); never executed: return ( d->dialogParent() != 0 ); | 0 | ||||||||||||||||||
356 | return d->autoDefault; never executed: return d->autoDefault; | 0 | ||||||||||||||||||
357 | } | - | ||||||||||||||||||
358 | - | |||||||||||||||||||
359 | void QPushButton::setDefault(bool enable) | - | ||||||||||||||||||
360 | { | - | ||||||||||||||||||
361 | Q_D(QPushButton); | - | ||||||||||||||||||
362 | if (d->defaultButton == enable)
| 0 | ||||||||||||||||||
363 | return; never executed: return; | 0 | ||||||||||||||||||
364 | d->defaultButton = enable; | - | ||||||||||||||||||
365 | if (d->defaultButton) {
| 0 | ||||||||||||||||||
366 | if (QDialog *dlg = d->dialogParent())
| 0 | ||||||||||||||||||
367 | dlg->d_func()->setMainDefault(this); never executed: dlg->d_func()->setMainDefault(this); | 0 | ||||||||||||||||||
368 | } never executed: end of block | 0 | ||||||||||||||||||
369 | update(); | - | ||||||||||||||||||
370 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
371 | QAccessible::State s; | - | ||||||||||||||||||
372 | s.defaultButton = true; | - | ||||||||||||||||||
373 | QAccessibleStateChangeEvent event(this, s); | - | ||||||||||||||||||
374 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||
375 | #endif | - | ||||||||||||||||||
376 | } never executed: end of block | 0 | ||||||||||||||||||
377 | - | |||||||||||||||||||
378 | bool QPushButton::isDefault() const | - | ||||||||||||||||||
379 | { | - | ||||||||||||||||||
380 | Q_D(const QPushButton); | - | ||||||||||||||||||
381 | return d->defaultButton; never executed: return d->defaultButton; | 0 | ||||||||||||||||||
382 | } | - | ||||||||||||||||||
383 | - | |||||||||||||||||||
384 | /*! | - | ||||||||||||||||||
385 | \reimp | - | ||||||||||||||||||
386 | */ | - | ||||||||||||||||||
387 | QSize QPushButton::sizeHint() const | - | ||||||||||||||||||
388 | { | - | ||||||||||||||||||
389 | Q_D(const QPushButton); | - | ||||||||||||||||||
390 | if (d->sizeHint.isValid() && d->lastAutoDefault == autoDefault())
| 0 | ||||||||||||||||||
391 | return d->sizeHint; never executed: return d->sizeHint; | 0 | ||||||||||||||||||
392 | d->lastAutoDefault = autoDefault(); | - | ||||||||||||||||||
393 | ensurePolished(); | - | ||||||||||||||||||
394 | - | |||||||||||||||||||
395 | int w = 0, h = 0; | - | ||||||||||||||||||
396 | - | |||||||||||||||||||
397 | QStyleOptionButton opt; | - | ||||||||||||||||||
398 | initStyleOption(&opt); | - | ||||||||||||||||||
399 | - | |||||||||||||||||||
400 | // calculate contents size... | - | ||||||||||||||||||
401 | #ifndef QT_NO_ICON | - | ||||||||||||||||||
402 | - | |||||||||||||||||||
403 | bool showButtonBoxIcons = qobject_cast<QDialogButtonBox*>(parentWidget())
| 0 | ||||||||||||||||||
404 | && style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons);
| 0 | ||||||||||||||||||
405 | - | |||||||||||||||||||
406 | if (!icon().isNull() || showButtonBoxIcons) {
| 0 | ||||||||||||||||||
407 | int ih = opt.iconSize.height(); | - | ||||||||||||||||||
408 | int iw = opt.iconSize.width() + 4; | - | ||||||||||||||||||
409 | w += iw; | - | ||||||||||||||||||
410 | h = qMax(h, ih); | - | ||||||||||||||||||
411 | } never executed: end of block | 0 | ||||||||||||||||||
412 | #endif | - | ||||||||||||||||||
413 | QString s(text()); | - | ||||||||||||||||||
414 | bool empty = s.isEmpty(); | - | ||||||||||||||||||
415 | if (empty)
| 0 | ||||||||||||||||||
416 | s = QString::fromLatin1("XXXX"); never executed: s = QString::fromLatin1("XXXX"); | 0 | ||||||||||||||||||
417 | QFontMetrics fm = fontMetrics(); | - | ||||||||||||||||||
418 | QSize sz = fm.size(Qt::TextShowMnemonic, s); | - | ||||||||||||||||||
419 | if(!empty || !w)
| 0 | ||||||||||||||||||
420 | w += sz.width(); never executed: w += sz.width(); | 0 | ||||||||||||||||||
421 | if(!empty || !h)
| 0 | ||||||||||||||||||
422 | h = qMax(h, sz.height()); never executed: h = qMax(h, sz.height()); | 0 | ||||||||||||||||||
423 | opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height | - | ||||||||||||||||||
424 | #ifndef QT_NO_MENU | - | ||||||||||||||||||
425 | if (menu())
| 0 | ||||||||||||||||||
426 | w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this); never executed: w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this); | 0 | ||||||||||||||||||
427 | #endif | - | ||||||||||||||||||
428 | d->sizeHint = (style()->sizeFromContents(QStyle::CT_PushButton, &opt, QSize(w, h), this). | - | ||||||||||||||||||
429 | expandedTo(QApplication::globalStrut())); | - | ||||||||||||||||||
430 | return d->sizeHint; never executed: return d->sizeHint; | 0 | ||||||||||||||||||
431 | } | - | ||||||||||||||||||
432 | - | |||||||||||||||||||
433 | /*! | - | ||||||||||||||||||
434 | \reimp | - | ||||||||||||||||||
435 | */ | - | ||||||||||||||||||
436 | QSize QPushButton::minimumSizeHint() const | - | ||||||||||||||||||
437 | { | - | ||||||||||||||||||
438 | return sizeHint(); never executed: return sizeHint(); | 0 | ||||||||||||||||||
439 | } | - | ||||||||||||||||||
440 | - | |||||||||||||||||||
441 | - | |||||||||||||||||||
442 | /*!\reimp | - | ||||||||||||||||||
443 | */ | - | ||||||||||||||||||
444 | void QPushButton::paintEvent(QPaintEvent *) | - | ||||||||||||||||||
445 | { | - | ||||||||||||||||||
446 | QStylePainter p(this); | - | ||||||||||||||||||
447 | QStyleOptionButton option; | - | ||||||||||||||||||
448 | initStyleOption(&option); | - | ||||||||||||||||||
449 | p.drawControl(QStyle::CE_PushButton, option); | - | ||||||||||||||||||
450 | } never executed: end of block | 0 | ||||||||||||||||||
451 | - | |||||||||||||||||||
452 | - | |||||||||||||||||||
453 | /*! \reimp */ | - | ||||||||||||||||||
454 | void QPushButton::keyPressEvent(QKeyEvent *e) | - | ||||||||||||||||||
455 | { | - | ||||||||||||||||||
456 | Q_D(QPushButton); | - | ||||||||||||||||||
457 | switch (e->key()) { | - | ||||||||||||||||||
458 | case Qt::Key_Enter: never executed: case Qt::Key_Enter: | 0 | ||||||||||||||||||
459 | case Qt::Key_Return: never executed: case Qt::Key_Return: | 0 | ||||||||||||||||||
460 | if (autoDefault() || d->defaultButton) {
| 0 | ||||||||||||||||||
461 | click(); | - | ||||||||||||||||||
462 | break; never executed: break; | 0 | ||||||||||||||||||
463 | } | - | ||||||||||||||||||
464 | // fall through | - | ||||||||||||||||||
465 | default: code before this statement never executed: default: never executed: default: | 0 | ||||||||||||||||||
466 | QAbstractButton::keyPressEvent(e); | - | ||||||||||||||||||
467 | } never executed: end of block | 0 | ||||||||||||||||||
468 | } | - | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | /*! | - | ||||||||||||||||||
471 | \reimp | - | ||||||||||||||||||
472 | */ | - | ||||||||||||||||||
473 | void QPushButton::focusInEvent(QFocusEvent *e) | - | ||||||||||||||||||
474 | { | - | ||||||||||||||||||
475 | Q_D(QPushButton); | - | ||||||||||||||||||
476 | if (e->reason() != Qt::PopupFocusReason && autoDefault() && !d->defaultButton) {
| 0 | ||||||||||||||||||
477 | d->defaultButton = true; | - | ||||||||||||||||||
478 | QDialog *dlg = qobject_cast<QDialog*>(window()); | - | ||||||||||||||||||
479 | if (dlg)
| 0 | ||||||||||||||||||
480 | dlg->d_func()->setDefault(this); never executed: dlg->d_func()->setDefault(this); | 0 | ||||||||||||||||||
481 | } never executed: end of block | 0 | ||||||||||||||||||
482 | QAbstractButton::focusInEvent(e); | - | ||||||||||||||||||
483 | } never executed: end of block | 0 | ||||||||||||||||||
484 | - | |||||||||||||||||||
485 | /*! | - | ||||||||||||||||||
486 | \reimp | - | ||||||||||||||||||
487 | */ | - | ||||||||||||||||||
488 | void QPushButton::focusOutEvent(QFocusEvent *e) | - | ||||||||||||||||||
489 | { | - | ||||||||||||||||||
490 | Q_D(QPushButton); | - | ||||||||||||||||||
491 | if (e->reason() != Qt::PopupFocusReason && autoDefault() && d->defaultButton) {
| 0 | ||||||||||||||||||
492 | QDialog *dlg = qobject_cast<QDialog*>(window()); | - | ||||||||||||||||||
493 | if (dlg)
| 0 | ||||||||||||||||||
494 | dlg->d_func()->setDefault(0); never executed: dlg->d_func()->setDefault(0); | 0 | ||||||||||||||||||
495 | else | - | ||||||||||||||||||
496 | d->defaultButton = false; never executed: d->defaultButton = false; | 0 | ||||||||||||||||||
497 | } | - | ||||||||||||||||||
498 | - | |||||||||||||||||||
499 | QAbstractButton::focusOutEvent(e); | - | ||||||||||||||||||
500 | #ifndef QT_NO_MENU | - | ||||||||||||||||||
501 | if (d->menu && d->menu->isVisible()) // restore pressed status
| 0 | ||||||||||||||||||
502 | setDown(true); never executed: setDown(true); | 0 | ||||||||||||||||||
503 | #endif | - | ||||||||||||||||||
504 | } never executed: end of block | 0 | ||||||||||||||||||
505 | - | |||||||||||||||||||
506 | #ifndef QT_NO_MENU | - | ||||||||||||||||||
507 | /*! | - | ||||||||||||||||||
508 | Associates the popup menu \a menu with this push button. This | - | ||||||||||||||||||
509 | turns the button into a menu button, which in some styles will | - | ||||||||||||||||||
510 | produce a small triangle to the right of the button's text. | - | ||||||||||||||||||
511 | - | |||||||||||||||||||
512 | Ownership of the menu is \e not transferred to the push button. | - | ||||||||||||||||||
513 | - | |||||||||||||||||||
514 | \image fusion-pushbutton-menu.png Screenshot of a Fusion style push button with popup menu. | - | ||||||||||||||||||
515 | A push button with popup menus shown in the \l{Fusion Style Widget Gallery}{Fusion widget style}. | - | ||||||||||||||||||
516 | - | |||||||||||||||||||
517 | \sa menu() | - | ||||||||||||||||||
518 | */ | - | ||||||||||||||||||
519 | void QPushButton::setMenu(QMenu* menu) | - | ||||||||||||||||||
520 | { | - | ||||||||||||||||||
521 | Q_D(QPushButton); | - | ||||||||||||||||||
522 | if (menu == d->menu)
| 0 | ||||||||||||||||||
523 | return; never executed: return; | 0 | ||||||||||||||||||
524 | - | |||||||||||||||||||
525 | if (menu && !d->menu) {
| 0 | ||||||||||||||||||
526 | connect(this, SIGNAL(pressed()), this, SLOT(_q_popupPressed()), Qt::UniqueConnection); | - | ||||||||||||||||||
527 | } never executed: end of block | 0 | ||||||||||||||||||
528 | if (d->menu)
| 0 | ||||||||||||||||||
529 | removeAction(d->menu->menuAction()); never executed: removeAction(d->menu->menuAction()); | 0 | ||||||||||||||||||
530 | d->menu = menu; | - | ||||||||||||||||||
531 | if (d->menu)
| 0 | ||||||||||||||||||
532 | addAction(d->menu->menuAction()); never executed: addAction(d->menu->menuAction()); | 0 | ||||||||||||||||||
533 | - | |||||||||||||||||||
534 | d->resetLayoutItemMargins(); | - | ||||||||||||||||||
535 | d->sizeHint = QSize(); | - | ||||||||||||||||||
536 | update(); | - | ||||||||||||||||||
537 | updateGeometry(); | - | ||||||||||||||||||
538 | } never executed: end of block | 0 | ||||||||||||||||||
539 | - | |||||||||||||||||||
540 | /*! | - | ||||||||||||||||||
541 | Returns the button's associated popup menu or 0 if no popup menu | - | ||||||||||||||||||
542 | has been set. | - | ||||||||||||||||||
543 | - | |||||||||||||||||||
544 | \sa setMenu() | - | ||||||||||||||||||
545 | */ | - | ||||||||||||||||||
546 | QMenu* QPushButton::menu() const | - | ||||||||||||||||||
547 | { | - | ||||||||||||||||||
548 | Q_D(const QPushButton); | - | ||||||||||||||||||
549 | return d->menu; never executed: return d->menu; | 0 | ||||||||||||||||||
550 | } | - | ||||||||||||||||||
551 | - | |||||||||||||||||||
552 | /*! | - | ||||||||||||||||||
553 | Shows (pops up) the associated popup menu. If there is no such | - | ||||||||||||||||||
554 | menu, this function does nothing. This function does not return | - | ||||||||||||||||||
555 | until the popup menu has been closed by the user. | - | ||||||||||||||||||
556 | */ | - | ||||||||||||||||||
557 | void QPushButton::showMenu() | - | ||||||||||||||||||
558 | { | - | ||||||||||||||||||
559 | Q_D(QPushButton); | - | ||||||||||||||||||
560 | if (!d || !d->menu)
| 0 | ||||||||||||||||||
561 | return; never executed: return; | 0 | ||||||||||||||||||
562 | setDown(true); | - | ||||||||||||||||||
563 | d->_q_popupPressed(); | - | ||||||||||||||||||
564 | } never executed: end of block | 0 | ||||||||||||||||||
565 | - | |||||||||||||||||||
566 | void QPushButtonPrivate::_q_popupPressed() | - | ||||||||||||||||||
567 | { | - | ||||||||||||||||||
568 | Q_Q(QPushButton); | - | ||||||||||||||||||
569 | if (!down || !menu)
| 0 | ||||||||||||||||||
570 | return; never executed: return; | 0 | ||||||||||||||||||
571 | - | |||||||||||||||||||
572 | menu->setNoReplayFor(q); | - | ||||||||||||||||||
573 | - | |||||||||||||||||||
574 | QPoint menuPos = adjustedMenuPosition(); | - | ||||||||||||||||||
575 | - | |||||||||||||||||||
576 | QPointer<QPushButton> guard(q); | - | ||||||||||||||||||
577 | QMenuPrivate::get(menu)->causedPopup.widget = guard; | - | ||||||||||||||||||
578 | - | |||||||||||||||||||
579 | //Because of a delay in menu effects, we must keep track of the | - | ||||||||||||||||||
580 | //menu visibility to avoid flicker on button release | - | ||||||||||||||||||
581 | menuOpen = true; | - | ||||||||||||||||||
582 | menu->exec(menuPos); | - | ||||||||||||||||||
583 | if (guard) {
| 0 | ||||||||||||||||||
584 | menuOpen = false; | - | ||||||||||||||||||
585 | q->setDown(false); | - | ||||||||||||||||||
586 | } never executed: end of block | 0 | ||||||||||||||||||
587 | } never executed: end of block | 0 | ||||||||||||||||||
588 | - | |||||||||||||||||||
589 | QPoint QPushButtonPrivate::adjustedMenuPosition() | - | ||||||||||||||||||
590 | { | - | ||||||||||||||||||
591 | Q_Q(QPushButton); | - | ||||||||||||||||||
592 | - | |||||||||||||||||||
593 | bool horizontal = true; | - | ||||||||||||||||||
594 | #if !defined(QT_NO_TOOLBAR) | - | ||||||||||||||||||
595 | QToolBar *tb = qobject_cast<QToolBar*>(parent); | - | ||||||||||||||||||
596 | if (tb && tb->orientation() == Qt::Vertical)
| 0 | ||||||||||||||||||
597 | horizontal = false; never executed: horizontal = false; | 0 | ||||||||||||||||||
598 | #endif | - | ||||||||||||||||||
599 | - | |||||||||||||||||||
600 | QWidgetItem item(q); | - | ||||||||||||||||||
601 | QRect rect = item.geometry(); | - | ||||||||||||||||||
602 | rect.setRect(rect.x() - q->x(), rect.y() - q->y(), rect.width(), rect.height()); | - | ||||||||||||||||||
603 | - | |||||||||||||||||||
604 | QSize menuSize = menu->sizeHint(); | - | ||||||||||||||||||
605 | QPoint globalPos = q->mapToGlobal(rect.topLeft()); | - | ||||||||||||||||||
606 | int x = globalPos.x(); | - | ||||||||||||||||||
607 | int y = globalPos.y(); | - | ||||||||||||||||||
608 | if (horizontal) {
| 0 | ||||||||||||||||||
609 | if (globalPos.y() + rect.height() + menuSize.height() <= QApplication::desktop()->availableGeometry(q).height()) {
| 0 | ||||||||||||||||||
610 | y += rect.height(); | - | ||||||||||||||||||
611 | } else { never executed: end of block | 0 | ||||||||||||||||||
612 | y -= menuSize.height(); | - | ||||||||||||||||||
613 | } never executed: end of block | 0 | ||||||||||||||||||
614 | if (q->layoutDirection() == Qt::RightToLeft)
| 0 | ||||||||||||||||||
615 | x += rect.width() - menuSize.width(); never executed: x += rect.width() - menuSize.width(); | 0 | ||||||||||||||||||
616 | } else { never executed: end of block | 0 | ||||||||||||||||||
617 | if (globalPos.x() + rect.width() + menu->sizeHint().width() <= QApplication::desktop()->availableGeometry(q).width())
| 0 | ||||||||||||||||||
618 | x += rect.width(); never executed: x += rect.width(); | 0 | ||||||||||||||||||
619 | else | - | ||||||||||||||||||
620 | x -= menuSize.width(); never executed: x -= menuSize.width(); | 0 | ||||||||||||||||||
621 | } | - | ||||||||||||||||||
622 | - | |||||||||||||||||||
623 | return QPoint(x,y); never executed: return QPoint(x,y); | 0 | ||||||||||||||||||
624 | } | - | ||||||||||||||||||
625 | - | |||||||||||||||||||
626 | #endif // QT_NO_MENU | - | ||||||||||||||||||
627 | - | |||||||||||||||||||
628 | void QPushButtonPrivate::resetLayoutItemMargins() | - | ||||||||||||||||||
629 | { | - | ||||||||||||||||||
630 | Q_Q(QPushButton); | - | ||||||||||||||||||
631 | QStyleOptionButton opt; | - | ||||||||||||||||||
632 | q->initStyleOption(&opt); | - | ||||||||||||||||||
633 | setLayoutItemMargins(QStyle::SE_PushButtonLayoutItem, &opt); | - | ||||||||||||||||||
634 | } never executed: end of block | 0 | ||||||||||||||||||
635 | - | |||||||||||||||||||
636 | void QPushButton::setFlat(bool flat) | - | ||||||||||||||||||
637 | { | - | ||||||||||||||||||
638 | Q_D(QPushButton); | - | ||||||||||||||||||
639 | if (d->flat == flat)
| 0 | ||||||||||||||||||
640 | return; never executed: return; | 0 | ||||||||||||||||||
641 | d->flat = flat; | - | ||||||||||||||||||
642 | d->resetLayoutItemMargins(); | - | ||||||||||||||||||
643 | d->sizeHint = QSize(); | - | ||||||||||||||||||
644 | update(); | - | ||||||||||||||||||
645 | updateGeometry(); | - | ||||||||||||||||||
646 | } never executed: end of block | 0 | ||||||||||||||||||
647 | - | |||||||||||||||||||
648 | bool QPushButton::isFlat() const | - | ||||||||||||||||||
649 | { | - | ||||||||||||||||||
650 | Q_D(const QPushButton); | - | ||||||||||||||||||
651 | return d->flat; never executed: return d->flat; | 0 | ||||||||||||||||||
652 | } | - | ||||||||||||||||||
653 | - | |||||||||||||||||||
654 | /*! \reimp */ | - | ||||||||||||||||||
655 | bool QPushButton::event(QEvent *e) | - | ||||||||||||||||||
656 | { | - | ||||||||||||||||||
657 | Q_D(QPushButton); | - | ||||||||||||||||||
658 | if (e->type() == QEvent::ParentChange) {
| 0 | ||||||||||||||||||
659 | if (QDialog *dialog = d->dialogParent()) {
| 0 | ||||||||||||||||||
660 | if (d->defaultButton)
| 0 | ||||||||||||||||||
661 | dialog->d_func()->setMainDefault(this); never executed: dialog->d_func()->setMainDefault(this); | 0 | ||||||||||||||||||
662 | } never executed: end of block | 0 | ||||||||||||||||||
663 | } else if (e->type() == QEvent::StyleChange never executed: end of block
| 0 | ||||||||||||||||||
664 | #ifdef Q_OS_MAC | - | ||||||||||||||||||
665 | || e->type() == QEvent::MacSizeChange | - | ||||||||||||||||||
666 | #endif | - | ||||||||||||||||||
667 | ) { | - | ||||||||||||||||||
668 | d->resetLayoutItemMargins(); | - | ||||||||||||||||||
669 | updateGeometry(); | - | ||||||||||||||||||
670 | } else if (e->type() == QEvent::PolishRequest) { never executed: end of block
| 0 | ||||||||||||||||||
671 | updateGeometry(); | - | ||||||||||||||||||
672 | } never executed: end of block | 0 | ||||||||||||||||||
673 | return QAbstractButton::event(e); never executed: return QAbstractButton::event(e); | 0 | ||||||||||||||||||
674 | } | - | ||||||||||||||||||
675 | - | |||||||||||||||||||
676 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
677 | /*! \reimp */ | - | ||||||||||||||||||
678 | bool QPushButton::hitButton(const QPoint &pos) const | - | ||||||||||||||||||
679 | { | - | ||||||||||||||||||
680 | QStyleOptionButton opt; | - | ||||||||||||||||||
681 | initStyleOption(&opt); | - | ||||||||||||||||||
682 | if (qt_mac_buttonIsRenderedFlat(this, &opt)) | - | ||||||||||||||||||
683 | return QAbstractButton::hitButton(pos); | - | ||||||||||||||||||
684 | - | |||||||||||||||||||
685 | // Now that we know we are using the native style, let's proceed. | - | ||||||||||||||||||
686 | Q_D(const QPushButton); | - | ||||||||||||||||||
687 | QPushButtonPrivate *nonConst = const_cast<QPushButtonPrivate *>(d); | - | ||||||||||||||||||
688 | // In OSX buttons are round, which causes the hit method to be special. | - | ||||||||||||||||||
689 | // We cannot simply relay on detecting if something is inside the rect or not, | - | ||||||||||||||||||
690 | // we need to check if it is inside the "rounded area" or not. A point might | - | ||||||||||||||||||
691 | // be inside the rect but not inside the rounded area. | - | ||||||||||||||||||
692 | // Notice this method is only reimplemented for OSX. | - | ||||||||||||||||||
693 | return nonConst->hitButton(pos); | - | ||||||||||||||||||
694 | } | - | ||||||||||||||||||
695 | - | |||||||||||||||||||
696 | bool QPushButtonPrivate::hitButton(const QPoint &pos) | - | ||||||||||||||||||
697 | { | - | ||||||||||||||||||
698 | Q_Q(QPushButton); | - | ||||||||||||||||||
699 | QRect roundedRect(q->rect().left() + QMacStylePrivate::PushButtonLeftOffset, | - | ||||||||||||||||||
700 | q->rect().top() + QMacStylePrivate::PushButtonContentPadding, | - | ||||||||||||||||||
701 | q->rect().width() - QMacStylePrivate::PushButtonRightOffset, | - | ||||||||||||||||||
702 | q->rect().height() - QMacStylePrivate::PushButtonBottomOffset); | - | ||||||||||||||||||
703 | return roundedRect.contains(pos); | - | ||||||||||||||||||
704 | } | - | ||||||||||||||||||
705 | #endif // Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
706 | - | |||||||||||||||||||
707 | - | |||||||||||||||||||
708 | QT_END_NAMESPACE | - | ||||||||||||||||||
709 | - | |||||||||||||||||||
710 | #include "moc_qpushbutton.cpp" | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |