QGCSlider.qml 3.11 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
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
Don Gagne's avatar
Don Gagne committed
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
Gus Grubba's avatar
Gus Grubba committed
24
    property bool displayValue: false
25

Don Gagne's avatar
Don Gagne committed
26 27 28
    style: SliderStyle {
        groove: Item {
            anchors.verticalCenter: parent.verticalCenter
29 30
            implicitWidth:  Math.round(ScreenTools.defaultFontPixelHeight * 4.5)
            implicitHeight: Math.round(ScreenTools.defaultFontPixelHeight * 0.3)
Don Gagne's avatar
Don Gagne committed
31 32

            Rectangle {
33 34 35 36 37
                radius:         height / 2
                anchors.fill:   parent
                color:          qgcPal.button
                border.width:   1
                border.color:   qgcPal.buttonText
Don Gagne's avatar
Don Gagne committed
38 39 40
            }

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

DonLakeFlyer's avatar
DonLakeFlyer committed
47 48 49 50
                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
51

Don Gagne's avatar
Don Gagne committed
52
                Rectangle {
53 54 55 56
                    anchors.fill:   parent
                    color:          qgcPal.colorBlue
                    border.color:   Qt.darker(color, 1.2)
                    radius:         height/2
Don Gagne's avatar
Don Gagne committed
57 58 59
                }
            }
        }
60 61 62 63 64 65 66 67 68 69

        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)
Gus Grubba's avatar
Gus Grubba committed
70 71 72 73 74 75 76 77
            Label {
                text:               _root.value.toFixed(0)
                visible:            _root.displayValue
                anchors.centerIn:   parent
                font.family:        ScreenTools.normalFontFamily
                font.pointSize:     ScreenTools.smallFontPointSize
                color:              qgcPal.buttonText
            }
78
        }
Don Gagne's avatar
Don Gagne committed
79 80
    }
}