diff options
author | Doris Verria <doris.verria@qt.io> | 2022-03-03 15:45:05 +0100 |
---|---|---|
committer | Doris Verria <doris.verria@qt.io> | 2022-03-11 16:14:53 +0100 |
commit | 91c7c3b565b257c483627de857c17b104049a372 (patch) | |
tree | de9a5989715b3200a700a3cf5c726f2d3d44a9c4 | |
parent | e798058823d6b3b813807151b91ee7d4c9417c3e (diff) |
iOS style: Add Switch control
Change-Id: I1b1c316cd46d57ec28b80d2206495330424face2
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
23 files changed, 116 insertions, 0 deletions
diff --git a/src/quickcontrols2/ios/CMakeLists.txt b/src/quickcontrols2/ios/CMakeLists.txt index 10975a8f02..3815401573 100644 --- a/src/quickcontrols2/ios/CMakeLists.txt +++ b/src/quickcontrols2/ios/CMakeLists.txt @@ -5,6 +5,7 @@ set(qml_files "Slider.qml" "RangeSlider.qml" + "Switch.qml" ) set_source_files_properties(Slider.qml PROPERTIES QT_QML_SOURCE_VERSIONS "2.2;6.0" diff --git a/src/quickcontrols2/ios/Switch.qml b/src/quickcontrols2/ios/Switch.qml new file mode 100644 index 0000000000..a8f2660bdc --- /dev/null +++ b/src/quickcontrols2/ios/Switch.qml @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick +import QtQuick.Templates as T +import QtQuick.Controls.impl +import QtQuick.Controls.iOS + +T.Switch { + id: control + + implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, + implicitContentWidth + leftPadding + rightPadding) + implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, + implicitContentHeight + topPadding + bottomPadding, + implicitIndicatorHeight + topPadding + bottomPadding) + + padding: 0 + topInset: 0 + leftInset: 0 + rightInset: 0 + bottomInset: 0 + spacing: 6 + + indicator: Image { + x: control.text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2 + y: control.topPadding + (control.availableHeight - height) / 2 + width: implicitWidth + height: Math.max(implicitHeight, handle.implicitHeight) + opacity: control.enabled ? 1 : 0.5 + + source: control.IOS.url + "switch-indicator" + ImageSelector on source { + states: [ + {"light": control.IOS.theme == IOS.Light}, + {"dark": control.IOS.theme == IOS.Dark}, + {"checked": control.checked} + ] + } + + property NinePatchImage handle: NinePatchImage { + property real margin: 2 + readonly property real minPos: leftPadding - leftInset + margin + readonly property real maxPos: parent.width - width + rightPadding + rightInset - margin + readonly property real dragPos: control.visualPosition * parent.width - (width / 2) + + parent: control.indicator + + x: Math.max(minPos, Math.min(maxPos, dragPos)) + y: (parent.height - height) / 2 - topInset + margin + width: control.pressed ? implicitWidth + 4 : implicitWidth + + source: control.IOS.url + "switch-handle" + NinePatchImageSelector on source { + states: [ + {"light": control.IOS.theme == IOS.Light}, + {"dark": control.IOS.theme == IOS.Dark}, + {"disabled": !control.enabled} + ] + } + + Behavior on x { + enabled: !control.down + SmoothedAnimation { velocity: 150 } + } + } + } + + contentItem: Text { + leftPadding: control.indicator && !control.mirrored ? control.indicator.width + control.spacing : 0 + rightPadding: control.indicator && control.mirrored ? control.indicator.width + control.spacing : 0 + + text: control.text + font: control.font + color: control.palette.windowText + elide: Text.ElideRight + verticalAlignment: Text.AlignVCenter + } +} diff --git a/src/quickcontrols2/ios/images/switch-handle-disabled-dark.9.png b/src/quickcontrols2/ios/images/switch-handle-disabled-dark.9.png Binary files differnew file mode 100644 index 0000000000..744cdfd6ad --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-handle-disabled-dark.9.png diff --git a/src/quickcontrols2/ios/images/switch-handle-disabled-dark@2x.9.png b/src/quickcontrols2/ios/images/switch-handle-disabled-dark@2x.9.png Binary files differnew file mode 100644 index 0000000000..2683c202a4 --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-handle-disabled-dark@2x.9.png diff --git a/src/quickcontrols2/ios/images/switch-handle-disabled-dark@3x.9.png b/src/quickcontrols2/ios/images/switch-handle-disabled-dark@3x.9.png Binary files differnew file mode 100644 index 0000000000..417ecf9c01 --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-handle-disabled-dark@3x.9.png diff --git a/src/quickcontrols2/ios/images/switch-handle-disabled-light.9.png b/src/quickcontrols2/ios/images/switch-handle-disabled-light.9.png Binary files differnew file mode 100644 index 0000000000..69c9e22bfc --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-handle-disabled-light.9.png diff --git a/src/quickcontrols2/ios/images/switch-handle-disabled-light@2x.9.png b/src/quickcontrols2/ios/images/switch-handle-disabled-light@2x.9.png Binary files differnew file mode 100644 index 0000000000..812c4c65e1 --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-handle-disabled-light@2x.9.png diff --git a/src/quickcontrols2/ios/images/switch-handle-disabled-light@3x.9.png b/src/quickcontrols2/ios/images/switch-handle-disabled-light@3x.9.png Binary files differnew file mode 100644 index 0000000000..a5522d756d --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-handle-disabled-light@3x.9.png diff --git a/src/quickcontrols2/ios/images/switch-handle.9.png b/src/quickcontrols2/ios/images/switch-handle.9.png Binary files differnew file mode 100644 index 0000000000..a87f1ff398 --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-handle.9.png diff --git a/src/quickcontrols2/ios/images/switch-handle@2x.9.png b/src/quickcontrols2/ios/images/switch-handle@2x.9.png Binary files differnew file mode 100644 index 0000000000..646bee16dd --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-handle@2x.9.png diff --git a/src/quickcontrols2/ios/images/switch-handle@3x.9.png b/src/quickcontrols2/ios/images/switch-handle@3x.9.png Binary files differnew file mode 100644 index 0000000000..ee2454d0bf --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-handle@3x.9.png diff --git a/src/quickcontrols2/ios/images/switch-indicator-checked-dark.png b/src/quickcontrols2/ios/images/switch-indicator-checked-dark.png Binary files differnew file mode 100644 index 0000000000..9f71c2cb8f --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-indicator-checked-dark.png diff --git a/src/quickcontrols2/ios/images/switch-indicator-checked-dark@2x.png b/src/quickcontrols2/ios/images/switch-indicator-checked-dark@2x.png Binary files differnew file mode 100644 index 0000000000..8c3225917e --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-indicator-checked-dark@2x.png diff --git a/src/quickcontrols2/ios/images/switch-indicator-checked-dark@3x.png b/src/quickcontrols2/ios/images/switch-indicator-checked-dark@3x.png Binary files differnew file mode 100644 index 0000000000..ad96405a97 --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-indicator-checked-dark@3x.png diff --git a/src/quickcontrols2/ios/images/switch-indicator-checked-light.png b/src/quickcontrols2/ios/images/switch-indicator-checked-light.png Binary files differnew file mode 100644 index 0000000000..3663ce0462 --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-indicator-checked-light.png diff --git a/src/quickcontrols2/ios/images/switch-indicator-checked-light@2x.png b/src/quickcontrols2/ios/images/switch-indicator-checked-light@2x.png Binary files differnew file mode 100644 index 0000000000..bc10581905 --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-indicator-checked-light@2x.png diff --git a/src/quickcontrols2/ios/images/switch-indicator-checked-light@3x.png b/src/quickcontrols2/ios/images/switch-indicator-checked-light@3x.png Binary files differnew file mode 100644 index 0000000000..ee3a25b6b5 --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-indicator-checked-light@3x.png diff --git a/src/quickcontrols2/ios/images/switch-indicator-dark.png b/src/quickcontrols2/ios/images/switch-indicator-dark.png Binary files differnew file mode 100644 index 0000000000..c9eb5ad985 --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-indicator-dark.png diff --git a/src/quickcontrols2/ios/images/switch-indicator-dark@2x.png b/src/quickcontrols2/ios/images/switch-indicator-dark@2x.png Binary files differnew file mode 100644 index 0000000000..8cf2a79f2d --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-indicator-dark@2x.png diff --git a/src/quickcontrols2/ios/images/switch-indicator-dark@3x.png b/src/quickcontrols2/ios/images/switch-indicator-dark@3x.png Binary files differnew file mode 100644 index 0000000000..d7c93e5161 --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-indicator-dark@3x.png diff --git a/src/quickcontrols2/ios/images/switch-indicator-light.png b/src/quickcontrols2/ios/images/switch-indicator-light.png Binary files differnew file mode 100644 index 0000000000..9cbf63c137 --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-indicator-light.png diff --git a/src/quickcontrols2/ios/images/switch-indicator-light@2x.png b/src/quickcontrols2/ios/images/switch-indicator-light@2x.png Binary files differnew file mode 100644 index 0000000000..f20259ebf7 --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-indicator-light@2x.png diff --git a/src/quickcontrols2/ios/images/switch-indicator-light@3x.png b/src/quickcontrols2/ios/images/switch-indicator-light@3x.png Binary files differnew file mode 100644 index 0000000000..ae31fb21aa --- /dev/null +++ b/src/quickcontrols2/ios/images/switch-indicator-light@3x.png |