1/* 2 * Copyright (C) 2017 3 * Jean-Luc Barriere <jlbarriere68@gmail.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; version 3. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18import QtQuick 2.9 19import QtQuick.Controls 2.2 20 21Slider { 22 id: control 23 property color foregroundColor: "green" 24 property color backgroundColor: "grey" 25 property color handleColor: "white" 26 property color handleColorPressed: "lightgrey" 27 property color handleBorderColor: "darkgrey" 28 property alias handleSize: thumb.size 29 property real size: units.gu(38) 30 31 background: Item { 32 implicitWidth: (control.orientation == Qt.Horizontal ? control.size : units.gu(5)) 33 implicitHeight: (control.orientation == Qt.Horizontal ? units.gu(5) : control.size) 34 35 Rectangle { 36 x: (control.orientation == Qt.Horizontal ? control.leftPadding : control.leftPadding + control.availableWidth / 2) 37 y: (control.orientation == Qt.Horizontal ? control.topPadding + control.availableHeight / 2 : control.topPadding) 38 width: (control.orientation == Qt.Horizontal ? control.availableWidth : units.dp(2)) 39 height: (control.orientation == Qt.Horizontal ? units.dp(2) : control.availableHeight) 40 radius: 0 41 color: control.backgroundColor 42 opacity: 0.4 43 } 44 45 Rectangle { 46 x: (control.orientation == Qt.Horizontal ? control.leftPadding 47 : control.leftPadding + control.availableWidth / 2) 48 y: (control.orientation == Qt.Horizontal ? control.topPadding + control.availableHeight / 2 49 : control.topPadding + control.visualPosition * control.availableHeight) 50 width: (control.orientation == Qt.Horizontal ? control.visualPosition * control.availableWidth : units.dp(2)) 51 height: (control.orientation == Qt.Horizontal ? units.dp(2) : (1.0 - control.visualPosition) * control.availableHeight) 52 color: control.foregroundColor 53 radius: 2 54 } 55 } 56 57 handle: Rectangle { 58 id: thumb 59 x: (control.orientation == Qt.Horizontal ? control.leftPadding + control.visualPosition * (control.availableWidth - width) 60 : control.leftPadding + (control.availableWidth + units.dp(2) - width) / 2) 61 y: (control.orientation == Qt.Horizontal ? control.topPadding + (control.availableHeight + units.dp(2) - height) / 2 62 : control.topPadding + control.visualPosition * (control.availableHeight - height)) 63 property real size: units.gu(1.5) 64 implicitWidth: size 65 implicitHeight: size 66 radius: size / 2 67 color: control.pressed ? control.handleColorPressed : control.handleColor 68 border.color: control.handleBorderColor 69 } 70} 71