QGCSlider.qml 2.61 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 22 23 24 25
    id:             _root
    implicitHeight: ScreenTools.implicitSliderHeight

    // Value indicator starts display from center instead of min value
    property bool indicatorCentered: false

    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
Don Gagne's avatar
Don Gagne committed
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)
Don Gagne's avatar
Don Gagne committed
32 33

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

            Item {
42 43 44
                clip:   true
                x:      _root.indicatorCentered ? indicatorCenteredIndicatorStart : 0
                width:  _root.indicatorCentered ? centerIndicatorWidth : styleData.handlePosition
Don Gagne's avatar
Don Gagne committed
45
                height: parent.height
46 47 48 49 50

                property real indicatorCenteredIndicatorStart:   Math.min(styleData.handlePosition, parent.width / 2)
                property real indicatorCenteredIndicatorStop:    Math.max(styleData.handlePosition, parent.width / 2)
                property real centerIndicatorWidth:     indicatorCenteredIndicatorStop - indicatorCenteredIndicatorStart

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

        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)
        }
Don Gagne's avatar
Don Gagne committed
71 72
    }
}