QGCSlider.qml 3.17 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 26

    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
Don Gagne's avatar
Don Gagne committed
27 28 29 30

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

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

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

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

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

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