aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/controls/RangeSlider.qml
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@theqtcompany.com>2015-10-08 12:48:06 +0200
committerMitch Curtis <mitch.curtis@theqtcompany.com>2015-10-14 11:58:33 +0000
commit090db511a36464c78f11df3b6596a56f09986951 (patch)
tree389bf7e9b04fa6cf7dfbc035e9568b98cf7b8e44 /src/imports/controls/RangeSlider.qml
parentb5b6fc732bb7a09996c06b1df3b71cf2548b0d7c (diff)
Add RangeSlider
This is basically Slider, except with two handles. It's used to specify a range of values. Task-number: QTBUG-48667 Change-Id: Ib4f9afe5dc8343e307610943d338a2b574a01e4d Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/imports/controls/RangeSlider.qml')
-rw-r--r--src/imports/controls/RangeSlider.qml136
1 files changed, 136 insertions, 0 deletions
diff --git a/src/imports/controls/RangeSlider.qml b/src/imports/controls/RangeSlider.qml
new file mode 100644
index 00000000..e301eed2
--- /dev/null
+++ b/src/imports/controls/RangeSlider.qml
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs Controls 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.6
+import Qt.labs.controls 1.0
+import Qt.labs.templates 1.0 as T
+
+T.RangeSlider {
+ id: control
+
+ implicitWidth: Math.max(background ? background.implicitWidth : 0,
+ Math.max(track ? track.implicitWidth : 0,
+ first.handle ? first.handle.implicitWidth : 0,
+ second.handle ? second.handle.implicitWidth : 0) + leftPadding + rightPadding)
+ implicitHeight: Math.max(background ? background.implicitHeight : 0,
+ Math.max(track ? track.implicitHeight : 0,
+ first.handle ? first.handle.implicitHeight : 0,
+ second.handle ? second.handle.implicitHeight : 0) + topPadding + bottomPadding)
+
+ padding: 6
+
+ //! [firstHandle]
+ first.handle: Rectangle {
+ x: control.leftPadding + (horizontal ? control.first.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2)
+ y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : control.first.visualPosition * (control.availableHeight - height))
+ implicitWidth: 20
+ implicitHeight: 20
+ radius: width / 2
+ border.width: activeFocus ? 2 : 1
+ border.color: activeFocus ? control.Theme.focusColor : control.Theme.frameColor
+ color: control.Theme.backgroundColor
+
+ readonly property bool horizontal: control.orientation === Qt.Horizontal
+
+ Rectangle {
+ x: (parent.width - width) / 2
+ y: (parent.height - height) / 2
+ width: 12
+ height: 12
+ radius: width / 2
+
+ color: Qt.tint(!control.enabled ? control.Theme.disabledColor :
+ parent.activeFocus ? control.Theme.focusColor : control.Theme.accentColor,
+ control.first.pressed ? control.Theme.pressColor : "transparent")
+ }
+ }
+ //! [firstHandle]
+
+ //! [secondHandle]
+ second.handle: Rectangle {
+ x: control.leftPadding + (horizontal ? control.second.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2)
+ y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : control.second.visualPosition * (control.availableHeight - height))
+ implicitWidth: 20
+ implicitHeight: 20
+ radius: width / 2
+ border.width: activeFocus ? 2 : 1
+ border.color: activeFocus ? control.Theme.focusColor : control.Theme.frameColor
+ color: control.Theme.backgroundColor
+
+ readonly property bool horizontal: control.orientation === Qt.Horizontal
+
+ Rectangle {
+ x: (parent.width - width) / 2
+ y: (parent.height - height) / 2
+ width: 12
+ height: 12
+ radius: width / 2
+
+ color: Qt.tint(!control.enabled ? control.Theme.disabledColor :
+ parent.activeFocus ? control.Theme.focusColor : control.Theme.accentColor,
+ control.second.pressed ? control.Theme.pressColor : "transparent")
+ }
+ }
+ //! [secondHandle]
+
+ //! [track]
+ track: Rectangle {
+ x: control.leftPadding + (horizontal ? 0 : (control.availableWidth - width) / 2)
+ y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : 0)
+ implicitWidth: horizontal ? 200 : 6
+ implicitHeight: horizontal ? 6 : 200
+ width: horizontal ? control.availableWidth : implicitWidth
+ height: horizontal ? implicitHeight : control.availableHeight
+
+ readonly property bool horizontal: control.orientation === Qt.Horizontal
+
+ radius: 3
+ border.color: control.Theme.frameColor
+ color: control.Theme.backgroundColor
+ scale: horizontal && control.mirrored ? -1 : 1
+
+ Rectangle {
+ x: parent.horizontal ? control.first.position * parent.width : 2
+ y: parent.horizontal ? 2 : control.second.visualPosition * parent.height + 2
+ width: parent.horizontal ? control.second.position * parent.width - control.first.position * parent.width - 4 : 2
+ height: parent.horizontal ? 2 : control.second.position * parent.height - control.first.position * parent.height - 4
+
+ radius: 3
+ color: control.enabled ? control.Theme.accentColor : control.Theme.disabledColor
+ }
+ }
+ //! [track]
+}