aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoris Verria <doris.verria@qt.io>2022-03-03 15:45:05 +0100
committerDoris Verria <doris.verria@qt.io>2022-03-11 16:14:53 +0100
commit91c7c3b565b257c483627de857c17b104049a372 (patch)
treede9a5989715b3200a700a3cf5c726f2d3d44a9c4
parente798058823d6b3b813807151b91ee7d4c9417c3e (diff)
iOS style: Add Switch control
Change-Id: I1b1c316cd46d57ec28b80d2206495330424face2 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/quickcontrols2/ios/CMakeLists.txt1
-rw-r--r--src/quickcontrols2/ios/Switch.qml115
-rw-r--r--src/quickcontrols2/ios/images/switch-handle-disabled-dark.9.pngbin0 -> 1132 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-handle-disabled-dark@2x.9.pngbin0 -> 1911 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-handle-disabled-dark@3x.9.pngbin0 -> 3055 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-handle-disabled-light.9.pngbin0 -> 1117 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-handle-disabled-light@2x.9.pngbin0 -> 1944 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-handle-disabled-light@3x.9.pngbin0 -> 3110 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-handle.9.pngbin0 -> 876 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-handle@2x.9.pngbin0 -> 1863 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-handle@3x.9.pngbin0 -> 2974 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-indicator-checked-dark.pngbin0 -> 569 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-indicator-checked-dark@2x.pngbin0 -> 1129 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-indicator-checked-dark@3x.pngbin0 -> 1656 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-indicator-checked-light.pngbin0 -> 631 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-indicator-checked-light@2x.pngbin0 -> 1226 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-indicator-checked-light@3x.pngbin0 -> 1799 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-indicator-dark.pngbin0 -> 580 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-indicator-dark@2x.pngbin0 -> 1267 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-indicator-dark@3x.pngbin0 -> 1835 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-indicator-light.pngbin0 -> 619 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-indicator-light@2x.pngbin0 -> 1210 bytes
-rw-r--r--src/quickcontrols2/ios/images/switch-indicator-light@3x.pngbin0 -> 1788 bytes
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
new file mode 100644
index 0000000000..744cdfd6ad
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-handle-disabled-dark.9.png
Binary files differ
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
new file mode 100644
index 0000000000..2683c202a4
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-handle-disabled-dark@2x.9.png
Binary files differ
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
new file mode 100644
index 0000000000..417ecf9c01
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-handle-disabled-dark@3x.9.png
Binary files differ
diff --git a/src/quickcontrols2/ios/images/switch-handle-disabled-light.9.png b/src/quickcontrols2/ios/images/switch-handle-disabled-light.9.png
new file mode 100644
index 0000000000..69c9e22bfc
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-handle-disabled-light.9.png
Binary files differ
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
new file mode 100644
index 0000000000..812c4c65e1
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-handle-disabled-light@2x.9.png
Binary files differ
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
new file mode 100644
index 0000000000..a5522d756d
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-handle-disabled-light@3x.9.png
Binary files differ
diff --git a/src/quickcontrols2/ios/images/switch-handle.9.png b/src/quickcontrols2/ios/images/switch-handle.9.png
new file mode 100644
index 0000000000..a87f1ff398
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-handle.9.png
Binary files differ
diff --git a/src/quickcontrols2/ios/images/switch-handle@2x.9.png b/src/quickcontrols2/ios/images/switch-handle@2x.9.png
new file mode 100644
index 0000000000..646bee16dd
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-handle@2x.9.png
Binary files differ
diff --git a/src/quickcontrols2/ios/images/switch-handle@3x.9.png b/src/quickcontrols2/ios/images/switch-handle@3x.9.png
new file mode 100644
index 0000000000..ee2454d0bf
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-handle@3x.9.png
Binary files differ
diff --git a/src/quickcontrols2/ios/images/switch-indicator-checked-dark.png b/src/quickcontrols2/ios/images/switch-indicator-checked-dark.png
new file mode 100644
index 0000000000..9f71c2cb8f
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-indicator-checked-dark.png
Binary files differ
diff --git a/src/quickcontrols2/ios/images/switch-indicator-checked-dark@2x.png b/src/quickcontrols2/ios/images/switch-indicator-checked-dark@2x.png
new file mode 100644
index 0000000000..8c3225917e
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-indicator-checked-dark@2x.png
Binary files differ
diff --git a/src/quickcontrols2/ios/images/switch-indicator-checked-dark@3x.png b/src/quickcontrols2/ios/images/switch-indicator-checked-dark@3x.png
new file mode 100644
index 0000000000..ad96405a97
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-indicator-checked-dark@3x.png
Binary files differ
diff --git a/src/quickcontrols2/ios/images/switch-indicator-checked-light.png b/src/quickcontrols2/ios/images/switch-indicator-checked-light.png
new file mode 100644
index 0000000000..3663ce0462
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-indicator-checked-light.png
Binary files differ
diff --git a/src/quickcontrols2/ios/images/switch-indicator-checked-light@2x.png b/src/quickcontrols2/ios/images/switch-indicator-checked-light@2x.png
new file mode 100644
index 0000000000..bc10581905
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-indicator-checked-light@2x.png
Binary files differ
diff --git a/src/quickcontrols2/ios/images/switch-indicator-checked-light@3x.png b/src/quickcontrols2/ios/images/switch-indicator-checked-light@3x.png
new file mode 100644
index 0000000000..ee3a25b6b5
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-indicator-checked-light@3x.png
Binary files differ
diff --git a/src/quickcontrols2/ios/images/switch-indicator-dark.png b/src/quickcontrols2/ios/images/switch-indicator-dark.png
new file mode 100644
index 0000000000..c9eb5ad985
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-indicator-dark.png
Binary files differ
diff --git a/src/quickcontrols2/ios/images/switch-indicator-dark@2x.png b/src/quickcontrols2/ios/images/switch-indicator-dark@2x.png
new file mode 100644
index 0000000000..8cf2a79f2d
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-indicator-dark@2x.png
Binary files differ
diff --git a/src/quickcontrols2/ios/images/switch-indicator-dark@3x.png b/src/quickcontrols2/ios/images/switch-indicator-dark@3x.png
new file mode 100644
index 0000000000..d7c93e5161
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-indicator-dark@3x.png
Binary files differ
diff --git a/src/quickcontrols2/ios/images/switch-indicator-light.png b/src/quickcontrols2/ios/images/switch-indicator-light.png
new file mode 100644
index 0000000000..9cbf63c137
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-indicator-light.png
Binary files differ
diff --git a/src/quickcontrols2/ios/images/switch-indicator-light@2x.png b/src/quickcontrols2/ios/images/switch-indicator-light@2x.png
new file mode 100644
index 0000000000..f20259ebf7
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-indicator-light@2x.png
Binary files differ
diff --git a/src/quickcontrols2/ios/images/switch-indicator-light@3x.png b/src/quickcontrols2/ios/images/switch-indicator-light@3x.png
new file mode 100644
index 0000000000..ae31fb21aa
--- /dev/null
+++ b/src/quickcontrols2/ios/images/switch-indicator-light@3x.png
Binary files differ