[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "qradiobutton.h"
|
---|
| 43 | #include "qapplication.h"
|
---|
| 44 | #include "qbitmap.h"
|
---|
| 45 | #include "qbuttongroup.h"
|
---|
| 46 | #include "qstylepainter.h"
|
---|
| 47 | #include "qstyle.h"
|
---|
| 48 | #include "qstyleoption.h"
|
---|
| 49 | #include "qevent.h"
|
---|
| 50 |
|
---|
| 51 | #include "private/qabstractbutton_p.h"
|
---|
| 52 |
|
---|
| 53 | QT_BEGIN_NAMESPACE
|
---|
| 54 |
|
---|
| 55 | class QRadioButtonPrivate : public QAbstractButtonPrivate
|
---|
| 56 | {
|
---|
| 57 | Q_DECLARE_PUBLIC(QRadioButton)
|
---|
| 58 |
|
---|
| 59 | public:
|
---|
| 60 | QRadioButtonPrivate() : QAbstractButtonPrivate(QSizePolicy::RadioButton), hovering(true) {}
|
---|
| 61 | void init();
|
---|
| 62 | uint hovering : 1;
|
---|
| 63 | };
|
---|
| 64 |
|
---|
| 65 | /*
|
---|
| 66 | Initializes the radio button.
|
---|
| 67 | */
|
---|
| 68 | void QRadioButtonPrivate::init()
|
---|
| 69 | {
|
---|
| 70 | Q_Q(QRadioButton);
|
---|
| 71 | q->setCheckable(true);
|
---|
| 72 | q->setAutoExclusive(true);
|
---|
| 73 | q->setMouseTracking(true);
|
---|
| 74 | q->setForegroundRole(QPalette::WindowText);
|
---|
| 75 | setLayoutItemMargins(QStyle::SE_RadioButtonLayoutItem);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | /*!
|
---|
| 79 | \class QRadioButton
|
---|
| 80 | \brief The QRadioButton widget provides a radio button with a text label.
|
---|
| 81 |
|
---|
| 82 | \ingroup basicwidgets
|
---|
| 83 |
|
---|
[561] | 84 |
|
---|
[2] | 85 | A QRadioButton is an option button that can be switched on (checked) or
|
---|
| 86 | off (unchecked). Radio buttons typically present the user with a "one
|
---|
| 87 | of many" choice. In a group of radio buttons only one radio button at
|
---|
| 88 | a time can be checked; if the user selects another button, the
|
---|
| 89 | previously selected button is switched off.
|
---|
| 90 |
|
---|
| 91 | Radio buttons are autoExclusive by default. If auto-exclusive is
|
---|
| 92 | enabled, radio buttons that belong to the same parent widget
|
---|
| 93 | behave as if they were part of the same exclusive button group. If
|
---|
| 94 | you need multiple exclusive button groups for radio buttons that
|
---|
| 95 | belong to the same parent widget, put them into a QButtonGroup.
|
---|
| 96 |
|
---|
| 97 | Whenever a button is switched on or off it emits the toggled() signal.
|
---|
| 98 | Connect to this signal if you want to trigger an action each time the
|
---|
| 99 | button changes state. Use isChecked() to see if a particular button is
|
---|
| 100 | selected.
|
---|
| 101 |
|
---|
| 102 | Just like QPushButton, a radio button displays text, and
|
---|
| 103 | optionally a small icon. The icon is set with setIcon(). The text
|
---|
| 104 | can be set in the constructor or with setText(). A shortcut key
|
---|
| 105 | can be specified by preceding the preferred character with an
|
---|
| 106 | ampersand in the text. For example:
|
---|
| 107 |
|
---|
| 108 | \snippet doc/src/snippets/code/src_gui_widgets_qradiobutton.cpp 0
|
---|
| 109 |
|
---|
| 110 | In this example the shortcut is \e{Alt+c}. See the \l
|
---|
| 111 | {QShortcut#mnemonic}{QShortcut} documentation for details (to
|
---|
| 112 | display an actual ampersand, use '&&').
|
---|
| 113 |
|
---|
| 114 | Important inherited members: text(), setText(), text(),
|
---|
| 115 | setDown(), isDown(), autoRepeat(), group(), setAutoRepeat(),
|
---|
| 116 | toggle(), pressed(), released(), clicked(), and toggled().
|
---|
| 117 |
|
---|
| 118 | \table 100%
|
---|
| 119 | \row \o \inlineimage plastique-radiobutton.png Screenshot of a Plastique radio button
|
---|
| 120 | \o A radio button shown in the \l{Plastique Style Widget Gallery}{Plastique widget style}.
|
---|
| 121 | \row \o \inlineimage windows-radiobutton.png Screenshot of a Windows XP radio button
|
---|
| 122 | \o A radio button shown in the \l{Windows XP Style Widget Gallery}{Windows XP widget style}.
|
---|
| 123 | \row \o \inlineimage macintosh-radiobutton.png Screenshot of a Macintosh radio button
|
---|
| 124 | \o A radio button shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}.
|
---|
| 125 | \endtable
|
---|
| 126 |
|
---|
| 127 | \sa QPushButton, QToolButton, QCheckBox, {fowler}{GUI Design Handbook: Radio Button},
|
---|
| 128 | {Group Box Example}
|
---|
| 129 | */
|
---|
| 130 |
|
---|
| 131 |
|
---|
| 132 | /*!
|
---|
| 133 | Constructs a radio button with the given \a parent, but with no text or
|
---|
| 134 | pixmap.
|
---|
| 135 |
|
---|
| 136 | The \a parent argument is passed on to the QAbstractButton constructor.
|
---|
| 137 | */
|
---|
| 138 |
|
---|
| 139 | QRadioButton::QRadioButton(QWidget *parent)
|
---|
| 140 | : QAbstractButton(*new QRadioButtonPrivate, parent)
|
---|
| 141 | {
|
---|
| 142 | Q_D(QRadioButton);
|
---|
| 143 | d->init();
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | /*!
|
---|
| 147 | Constructs a radio button with the given \a parent and a \a text string.
|
---|
| 148 |
|
---|
| 149 | The \a parent argument is passed on to the QAbstractButton constructor.
|
---|
| 150 | */
|
---|
| 151 |
|
---|
| 152 | QRadioButton::QRadioButton(const QString &text, QWidget *parent)
|
---|
| 153 | : QAbstractButton(*new QRadioButtonPrivate, parent)
|
---|
| 154 | {
|
---|
| 155 | Q_D(QRadioButton);
|
---|
| 156 | d->init();
|
---|
| 157 | setText(text);
|
---|
| 158 | }
|
---|
| |
---|