diff options
Diffstat (limited to 'src/imports/controls/universal/Switch.qml')
-rw-r--r-- | src/imports/controls/universal/Switch.qml | 62 |
1 files changed, 14 insertions, 48 deletions
diff --git a/src/imports/controls/universal/Switch.qml b/src/imports/controls/universal/Switch.qml index 768291fc..b42361dc 100644 --- a/src/imports/controls/universal/Switch.qml +++ b/src/imports/controls/universal/Switch.qml @@ -1,9 +1,9 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2016 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** -** This file is part of the Qt Labs Controls module of the Qt Toolkit. +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL3$ ** Commercial License Usage @@ -35,67 +35,33 @@ ****************************************************************************/ import QtQuick 2.6 -import Qt.labs.templates 1.0 as T -import Qt.labs.controls.universal 1.0 +import QtQuick.Templates 2.0 as T +import QtQuick.Controls.Universal 2.0 T.Switch { id: control implicitWidth: Math.max(background ? background.implicitWidth : 0, - (label ? label.implicitWidth : 0) + - (indicator ? indicator.implicitWidth : 0) + - (label && indicator ? spacing : 0) + leftPadding + rightPadding) + contentItem.implicitWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, - Math.max(label ? label.implicitHeight : 0, + Math.max(contentItem.implicitHeight, indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding) - baselineOffset: label ? label.y + label.baselineOffset : 0 + baselineOffset: contentItem.y + contentItem.baselineOffset padding: 5 spacing: 8 property bool useSystemFocusVisuals: true - //! [indicator] - indicator: Rectangle { - implicitWidth: 44 - implicitHeight: 20 + indicator: SwitchIndicator { x: text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2 y: control.topPadding + (control.availableHeight - height) / 2 - - radius: 10 - color: !control.enabled ? "transparent" : - control.pressed ? control.Universal.baseMediumColor : - control.checked ? control.Universal.accent : "transparent" - border.color: !control.enabled ? control.Universal.baseLowColor : - control.checked && !control.pressed ? control.Universal.accent : control.Universal.baseMediumColor - border.width: 2 - - Rectangle { - width: 10 - height: 10 - radius: 5 - - color: !control.enabled ? control.Universal.baseLowColor : - control.pressed || control.checked ? control.Universal.chromeWhiteColor : control.Universal.baseMediumHighColor - - x: Math.max(5, Math.min(parent.width - width - 5, - control.visualPosition * parent.width - (width / 2))) - y: (parent.height - height) / 2 - - Behavior on x { - enabled: !control.pressed - SmoothedAnimation { velocity: 200 } - } - } + control: control } - //! [indicator] - //! [label] - label: Text { - x: control.mirrored ? control.leftPadding : (indicator.x + indicator.width + control.spacing) - y: control.topPadding - width: control.availableWidth - indicator.width - control.spacing - height: control.availableHeight + 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 @@ -104,7 +70,7 @@ T.Switch { horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter - color: !control.enabled ? control.Universal.baseLowColor : control.Universal.baseHighColor + opacity: enabled ? 1.0 : 0.2 + color: control.Universal.foreground } - //! [label] } |