From b57245ac65d339d4aa803d38005118b99783b2b3 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 10 Jun 2015 16:35:47 +0200 Subject: Docs: Switch Change-Id: I1cdac365b12b7c7fb88c10f8a1de9d68ec1b44d8 Reviewed-by: J-P Nurmi --- .../images/qtquickcontrols2-switch-background.png | Bin 0 -> 2136 bytes .../doc/images/qtquickcontrols2-switch-checked.png | Bin 0 -> 2344 bytes .../images/qtquickcontrols2-switch-disabled.png | Bin 0 -> 2401 bytes .../doc/images/qtquickcontrols2-switch-focused.png | Bin 0 -> 2417 bytes .../images/qtquickcontrols2-switch-indicator.png | Bin 0 -> 2014 bytes .../doc/images/qtquickcontrols2-switch-label.png | Bin 0 -> 2082 bytes .../doc/images/qtquickcontrols2-switch-normal.png | Bin 0 -> 1925 bytes .../doc/src/qtquickcontrols2-customize.qdoc | 24 +++++++++++ src/controls/qquickswitch.cpp | 47 +++++++++++++++++++-- 9 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 src/controls/doc/images/qtquickcontrols2-switch-background.png create mode 100644 src/controls/doc/images/qtquickcontrols2-switch-checked.png create mode 100644 src/controls/doc/images/qtquickcontrols2-switch-disabled.png create mode 100644 src/controls/doc/images/qtquickcontrols2-switch-focused.png create mode 100644 src/controls/doc/images/qtquickcontrols2-switch-indicator.png create mode 100644 src/controls/doc/images/qtquickcontrols2-switch-label.png create mode 100644 src/controls/doc/images/qtquickcontrols2-switch-normal.png (limited to 'src/controls') diff --git a/src/controls/doc/images/qtquickcontrols2-switch-background.png b/src/controls/doc/images/qtquickcontrols2-switch-background.png new file mode 100644 index 00000000..bfa24fe6 Binary files /dev/null and b/src/controls/doc/images/qtquickcontrols2-switch-background.png differ diff --git a/src/controls/doc/images/qtquickcontrols2-switch-checked.png b/src/controls/doc/images/qtquickcontrols2-switch-checked.png new file mode 100644 index 00000000..fadf851a Binary files /dev/null and b/src/controls/doc/images/qtquickcontrols2-switch-checked.png differ diff --git a/src/controls/doc/images/qtquickcontrols2-switch-disabled.png b/src/controls/doc/images/qtquickcontrols2-switch-disabled.png new file mode 100644 index 00000000..328ff6a9 Binary files /dev/null and b/src/controls/doc/images/qtquickcontrols2-switch-disabled.png differ diff --git a/src/controls/doc/images/qtquickcontrols2-switch-focused.png b/src/controls/doc/images/qtquickcontrols2-switch-focused.png new file mode 100644 index 00000000..795868b8 Binary files /dev/null and b/src/controls/doc/images/qtquickcontrols2-switch-focused.png differ diff --git a/src/controls/doc/images/qtquickcontrols2-switch-indicator.png b/src/controls/doc/images/qtquickcontrols2-switch-indicator.png new file mode 100644 index 00000000..5fc9c83b Binary files /dev/null and b/src/controls/doc/images/qtquickcontrols2-switch-indicator.png differ diff --git a/src/controls/doc/images/qtquickcontrols2-switch-label.png b/src/controls/doc/images/qtquickcontrols2-switch-label.png new file mode 100644 index 00000000..57deabc6 Binary files /dev/null and b/src/controls/doc/images/qtquickcontrols2-switch-label.png differ diff --git a/src/controls/doc/images/qtquickcontrols2-switch-normal.png b/src/controls/doc/images/qtquickcontrols2-switch-normal.png new file mode 100644 index 00000000..a162e898 Binary files /dev/null and b/src/controls/doc/images/qtquickcontrols2-switch-normal.png differ diff --git a/src/controls/doc/src/qtquickcontrols2-customize.qdoc b/src/controls/doc/src/qtquickcontrols2-customize.qdoc index 6e4827a1..8b02a62b 100644 --- a/src/controls/doc/src/qtquickcontrols2-customize.qdoc +++ b/src/controls/doc/src/qtquickcontrols2-customize.qdoc @@ -101,4 +101,28 @@ \image qtquickcontrols2-radiobutton-indicator.png \snippet RadioButton.qml indicator + + \section1 Customizing Switch + + Switch consists of three parts: \l {Control::background}{background}, + \l {Button::label}{label} and \l {Checkable::indicator}{indicator}. Their + implicit sizes are used to calculate the implicit size of the control. + + \section3 Background + + \image qtquickcontrols2-switch-background.png + + Switch has no background item by default. + + \section3 Label + + \image qtquickcontrols2-switch-label.png + + \snippet Switch.qml label + + \section3 Indicator + + \image qtquickcontrols2-switch-indicator.png + + \snippet Switch.qml indicator */ diff --git a/src/controls/qquickswitch.cpp b/src/controls/qquickswitch.cpp index 8f970c9b..7f6d3ebd 100644 --- a/src/controls/qquickswitch.cpp +++ b/src/controls/qquickswitch.cpp @@ -49,7 +49,32 @@ QT_BEGIN_NAMESPACE \ingroup buttons \brief A switch control. - TODO + Switch is an option button that can be dragged or toggled on (checked) or + off (unchecked). Switches are typically used to select between two states. + + \table + \row \li \image qtquickcontrols2-switch-normal.png + \li A switch in its normal state. + \row \li \image qtquickcontrols2-switch-checked.png + \li A switch that is checked. + \row \li \image qtquickcontrols2-switch-focused.png + \li A switch that has active focus. + \row \li \image qtquickcontrols2-switch-disabled.png + \li A switch that is disabled. + \endtable + + \code + ColumnLayout { + Switch { + text: qsTr("Wi-Fi") + } + Switch { + text: qsTr("Bluetooth") + } + } + \endcode + + \sa {Customizing Switch} */ class QQuickSwitchPrivate : public QQuickCheckablePrivate @@ -81,7 +106,14 @@ QQuickSwitch::QQuickSwitch(QQuickItem *parent) : /*! \qmlproperty real QtQuickControls2::Switch::position - TODO + This property holds the logical position of the thumb indicator. + + The position is defined as a percentage of the control's size, scaled to + \c 0.0 - \c 1.0. The position can be used for example to determine whether + the thumb has been dragged past the halfway. For visualizing a thumb + indicator, the right-to-left aware \l visualPosition should be used instead. + + \sa visualPosition */ qreal QQuickSwitch::position() const { @@ -103,7 +135,16 @@ void QQuickSwitch::setPosition(qreal position) /*! \qmlproperty real QtQuickControls2::Switch::visualPosition - TODO + This property holds the visual position of the thumb indicator. + + The position is defined as a percentage of the control's size, scaled to + \c 0.0 - \c 1.0. When the control is \l mirrored, the value is equal to + \c {1.0 - position}. This makes the value suitable for visualizing the + thumb indicator taking right-to-left support into account. In order to + for example determine whether the thumb has been dragged past the halfway, + the logical \l position should be used instead. + + \sa position */ qreal QQuickSwitch::visualPosition() const { -- cgit v1.2.3