From 02c44ee00777a76c3bf13cd0705d91435654a4c1 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 31 Oct 2017 15:06:32 +0100 Subject: Default: merge SwitchIndicator back to Switch & SwitchDelegate See the previous commit (CheckIndicator) for more details. Before: running: /home/jpnurmi/Projects/qmlbench/benchmarks/auto/creation/quick.controls2/delegates_switch.qml [...] Average: 87.8 frames; using samples; MedianAll=87; StdDev=2.16795, CoV=0.0246919 After: running: qmlbench/benchmarks/auto/creation/quick.controls2/delegates_switch.qml [...] Average: 92.6 frames; using samples; MedianAll=92; StdDev=2.19089, CoV=0.0236597 Change-Id: Iea9e88e4e771ac27d336c2c87232704d33a226ec Reviewed-by: Mitch Curtis --- src/imports/controls/Switch.qml | 28 +++++++++- src/imports/controls/SwitchDelegate.qml | 28 +++++++++- src/imports/controls/SwitchIndicator.qml | 68 ------------------------- src/imports/controls/controls.pri | 1 - src/imports/controls/plugins.qmltypes | 9 ---- src/imports/controls/qtquickcontrols2plugin.cpp | 1 - 6 files changed, 52 insertions(+), 83 deletions(-) delete mode 100644 src/imports/controls/SwitchIndicator.qml (limited to 'src') diff --git a/src/imports/controls/Switch.qml b/src/imports/controls/Switch.qml index 66f624d9..71317967 100644 --- a/src/imports/controls/Switch.qml +++ b/src/imports/controls/Switch.qml @@ -52,10 +52,34 @@ T.Switch { padding: 6 spacing: 6 - indicator: SwitchIndicator { + indicator: PaddedRectangle { + implicitWidth: 56 + implicitHeight: 28 + x: text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2 y: control.topPadding + (control.availableHeight - height) / 2 - control: control + + radius: 8 + leftPadding: 0 + rightPadding: 0 + padding: (height - 16) / 2 + color: control.checked ? control.palette.dark : control.palette.midlight + + Rectangle { + x: Math.max(0, Math.min(parent.width - width, control.visualPosition * parent.width - (width / 2))) + y: (parent.height - height) / 2 + width: 28 + height: 28 + radius: 16 + color: control.down ? control.palette.light : control.palette.window + border.width: control.visualFocus ? 2 : 1 + border.color: control.visualFocus ? control.palette.highlight : control.enabled ? control.palette.mid : control.palette.midlight + + Behavior on x { + enabled: !control.down + SmoothedAnimation { velocity: 200 } + } + } } contentItem: CheckLabel { diff --git a/src/imports/controls/SwitchDelegate.qml b/src/imports/controls/SwitchDelegate.qml index 1c57c907..08a9d641 100644 --- a/src/imports/controls/SwitchDelegate.qml +++ b/src/imports/controls/SwitchDelegate.qml @@ -56,10 +56,34 @@ T.SwitchDelegate { icon.height: 24 icon.color: control.palette.text - indicator: SwitchIndicator { + indicator: PaddedRectangle { + implicitWidth: 56 + implicitHeight: 28 + x: text ? (control.mirrored ? control.leftPadding : control.width - width - control.rightPadding) : control.leftPadding + (control.availableWidth - width) / 2 y: control.topPadding + (control.availableHeight - height) / 2 - control: control + + radius: 8 + leftPadding: 0 + rightPadding: 0 + padding: (height - 16) / 2 + color: control.checked ? control.palette.dark : control.palette.midlight + + Rectangle { + x: Math.max(0, Math.min(parent.width - width, control.visualPosition * parent.width - (width / 2))) + y: (parent.height - height) / 2 + width: 28 + height: 28 + radius: 16 + color: control.down ? control.palette.light : control.palette.window + border.width: control.visualFocus ? 2 : 1 + border.color: control.visualFocus ? control.palette.highlight : control.enabled ? control.palette.mid : control.palette.midlight + + Behavior on x { + enabled: !control.down + SmoothedAnimation { velocity: 200 } + } + } } contentItem: IconLabel { diff --git a/src/imports/controls/SwitchIndicator.qml b/src/imports/controls/SwitchIndicator.qml deleted file mode 100644 index 6b421bb6..00000000 --- a/src/imports/controls/SwitchIndicator.qml +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.10 -import QtQuick.Controls 2.3 -import QtQuick.Controls.impl 2.3 - -PaddedRectangle { - implicitWidth: 56 - implicitHeight: 28 - - property AbstractButton control - - radius: 8 - leftPadding: 0 - rightPadding: 0 - padding: (height - 16) / 2 - color: control.checked ? control.palette.dark : control.palette.midlight - - Rectangle { - x: Math.max(0, Math.min(parent.width - width, control.visualPosition * parent.width - (width / 2))) - y: (parent.height - height) / 2 - width: 28 - height: 28 - radius: 16 - color: control.down ? control.palette.light : control.palette.window - border.width: control.visualFocus ? 2 : 1 - border.color: control.visualFocus ? control.palette.highlight : control.enabled ? control.palette.mid : control.palette.midlight - - Behavior on x { - enabled: !control.down - SmoothedAnimation { velocity: 200 } - } - } -} diff --git a/src/imports/controls/controls.pri b/src/imports/controls/controls.pri index e31d455b..7840f6bf 100644 --- a/src/imports/controls/controls.pri +++ b/src/imports/controls/controls.pri @@ -56,7 +56,6 @@ QML_CONTROLS = \ $$PWD/StackView.qml \ $$PWD/SwipeDelegate.qml \ $$PWD/Switch.qml \ - $$PWD/SwitchIndicator.qml \ $$PWD/SwitchDelegate.qml \ $$PWD/SwipeView.qml \ $$PWD/TabBar.qml \ diff --git a/src/imports/controls/plugins.qmltypes b/src/imports/controls/plugins.qmltypes index 0dd0d720..8f936960 100644 --- a/src/imports/controls/plugins.qmltypes +++ b/src/imports/controls/plugins.qmltypes @@ -542,15 +542,6 @@ Module { isComposite: true defaultProperty: "data" } - Component { - prototype: "QQuickItem" - name: "QtQuick.Controls.impl/SwitchIndicator 2.0" - exports: ["QtQuick.Controls.impl/SwitchIndicator 2.0"] - exportMetaObjectRevisions: [0] - isComposite: true - defaultProperty: "data" - Property { name: "control"; type: "QQuickItem"; isPointer: true } - } Component { prototype: "QQuickTabBar" name: "QtQuick.Controls/TabBar 2.0" diff --git a/src/imports/controls/qtquickcontrols2plugin.cpp b/src/imports/controls/qtquickcontrols2plugin.cpp index ea234939..5f019a4e 100644 --- a/src/imports/controls/qtquickcontrols2plugin.cpp +++ b/src/imports/controls/qtquickcontrols2plugin.cpp @@ -194,7 +194,6 @@ void QtQuickControls2Plugin::initializeEngine(QQmlEngine *engine, const char *ur qmlRegisterType(import, 2, 1, "TumblerView"); #endif qmlRegisterSingletonType(import, 2, 1, "Default", styleSingleton); - qmlRegisterType(typeUrl(QStringLiteral("SwitchIndicator.qml")), import, 2, 0, "SwitchIndicator"); qmlRegisterType(import, 2, 3, "ColorImage"); qmlRegisterType(import, 2, 3, "IconImage"); -- cgit v1.2.3