| 1 | // Copyright (C) 2017 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qquickradiobutton_p.h" |
| 5 | #include "qquickcontrol_p_p.h" |
| 6 | #include "qquickabstractbutton_p_p.h" |
| 7 | |
| 8 | #include <QtGui/qpa/qplatformtheme.h> |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | /*! |
| 13 | \qmltype RadioButton |
| 14 | \inherits AbstractButton |
| 15 | //! \nativetype QQuickRadioButton |
| 16 | \inqmlmodule QtQuick.Controls |
| 17 | \since 5.7 |
| 18 | \ingroup qtquickcontrols-buttons |
| 19 | \brief Exclusive radio button that can be toggled on or off. |
| 20 | |
| 21 | \image qtquickcontrols-radiobutton.gif |
| 22 | |
| 23 | RadioButton presents an option button that can be toggled on (checked) or |
| 24 | off (unchecked). Radio buttons are typically used to select one option |
| 25 | from a set of options. |
| 26 | |
| 27 | RadioButton inherits its API from \l AbstractButton. For instance, |
| 28 | you can set \l {AbstractButton::text}{text} and react to |
| 29 | \l {AbstractButton::clicked}{clicks} using the AbstractButton API. |
| 30 | The state of the radio button can be set with the |
| 31 | \l {AbstractButton::}{checked} property. |
| 32 | |
| 33 | Radio buttons are \l {AbstractButton::autoExclusive}{auto-exclusive} |
| 34 | by default. Only one button can be checked at any time amongst radio |
| 35 | buttons that belong to the same parent item; checking another button |
| 36 | automatically unchecks the previously checked one. For radio buttons |
| 37 | that do not share a common parent, ButtonGroup can be used to manage |
| 38 | exclusivity. |
| 39 | |
| 40 | \l RadioDelegate is similar to RadioButton, except that it is typically |
| 41 | used in views. |
| 42 | |
| 43 | \code |
| 44 | ColumnLayout { |
| 45 | RadioButton { |
| 46 | checked: true |
| 47 | text: qsTr("First") |
| 48 | } |
| 49 | RadioButton { |
| 50 | text: qsTr("Second") |
| 51 | } |
| 52 | RadioButton { |
| 53 | text: qsTr("Third") |
| 54 | } |
| 55 | } |
| 56 | \endcode |
| 57 | |
| 58 | \sa ButtonGroup, {Customizing RadioButton}, {Button Controls}, RadioDelegate |
| 59 | */ |
| 60 | |
| 61 | class Q_QUICKTEMPLATES2_EXPORT QQuickRadioButtonPrivate : public QQuickAbstractButtonPrivate |
| 62 | { |
| 63 | Q_DECLARE_PUBLIC(QQuickRadioButton) |
| 64 | |
| 65 | public: |
| 66 | QPalette defaultPalette() const override { return QQuickTheme::palette(scope: QQuickTheme::RadioButton); } |
| 67 | }; |
| 68 | |
| 69 | QQuickRadioButton::QQuickRadioButton(QQuickItem *parent) |
| 70 | : QQuickAbstractButton(*(new QQuickRadioButtonPrivate), parent) |
| 71 | { |
| 72 | setCheckable(true); |
| 73 | setAutoExclusive(true); |
| 74 | } |
| 75 | |
| 76 | QFont QQuickRadioButton::defaultFont() const |
| 77 | { |
| 78 | return QQuickTheme::font(scope: QQuickTheme::RadioButton); |
| 79 | } |
| 80 | |
| 81 | #if QT_CONFIG(accessibility) |
| 82 | QAccessible::Role QQuickRadioButton::accessibleRole() const |
| 83 | { |
| 84 | return QAccessible::RadioButton; |
| 85 | } |
| 86 | #endif |
| 87 | |
| 88 | QT_END_NAMESPACE |
| 89 | |
| 90 | #include "moc_qquickradiobutton_p.cpp" |
| 91 | |