QGCSlider.qml 2.77 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

10 11
import QtQuick                  2.3
import QtQuick.Controls         1.2
12
import QtQuick.Controls.Styles  1.4
13
import QtQuick.Controls.Private 1.0
14 15 16 17 18

import QGroundControl.Palette       1.0
import QGroundControl.ScreenTools   1.0

Slider {
19 20 21
    id:             _root
    implicitHeight: ScreenTools.implicitSliderHeight

DonLakeFlyer's avatar
DonLakeFlyer committed
22 23
    // Value indicator starts display from zero instead of min value
    property bool zeroCentered: false
24 25

    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
26 27 28 29

    style: SliderStyle {
        groove: Item {
            anchors.verticalCenter: parent.verticalCenter
30 31
            implicitWidth:  Math.round(ScreenTools.defaultFontPixelHeight * 4.5)
            implicitHeight: Math.round(ScreenTools.defaultFontPixelHeight * 0.3)
32 33

            Rectangle {
34 35 36 37 38
                radius:         height / 2
                anchors.fill:   parent
                color:          qgcPal.button
                border.width:   1
                border.color:   qgcPal.buttonText
39 40 41
            }

            Item {
DonLakeFlyer's avatar
DonLakeFlyer committed
42
                id:     indicatorBar
43
                clip:   true
DonLakeFlyer's avatar
DonLakeFlyer committed
44 45
                x:      _root.zeroCentered ? zeroCenteredIndicatorStart : 0
                width:  _root.zeroCentered ? centerIndicatorWidth : styleData.handlePosition
46
                height: parent.height
47

DonLakeFlyer's avatar
DonLakeFlyer committed
48 49 50 51
                property real zeroValuePosition:            (Math.abs(control.minimumValue) / (control.maximumValue - control.minimumValue)) * parent.width
                property real zeroCenteredIndicatorStart:   Math.min(styleData.handlePosition, zeroValuePosition)
                property real zeroCenteredIndicatorStop:    Math.max(styleData.handlePosition, zeroValuePosition)
                property real centerIndicatorWidth:         zeroCenteredIndicatorStop - zeroCenteredIndicatorStart
52

53
                Rectangle {
54 55 56 57
                    anchors.fill:   parent
                    color:          qgcPal.colorBlue
                    border.color:   Qt.darker(color, 1.2)
                    radius:         height/2
58 59 60
                }
            }
        }
61 62 63 64 65 66 67 68 69 70 71 72

        handle: Rectangle {
            anchors.centerIn: parent
            color:          qgcPal.button
            border.color:   qgcPal.buttonText
            border.width:   1
            implicitWidth:  _radius * 2
            implicitHeight: _radius * 2
            radius:         _radius

            property real _radius: Math.round(ScreenTools.defaultFontPixelHeight * 0.75)
        }
73 74
    }
}