| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 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 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 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 | \mainclass
|
|---|
| 84 |
|
|---|
| 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
|
|---|
|
|---|