QGCCheckBox.qml 3.74 KB
Newer Older
1 2
import QtQuick                  2.3
import QtQuick.Controls         1.2
3
import QtQuick.Controls.Styles  1.4
Don Gagne's avatar
Don Gagne committed
4

5 6
import QGroundControl.Palette       1.0
import QGroundControl.ScreenTools   1.0
Don Gagne's avatar
Don Gagne committed
7 8

CheckBox {
9 10
    activeFocusOnPress: true

11
    property var __qgcPal: QGCPalette { colorGroupEnabled: enabled }
Don Gagne's avatar
Don Gagne committed
12 13 14

    style: CheckBoxStyle {
        label: Item {
15
            implicitWidth:  text.implicitWidth + 2
16
            implicitHeight: ScreenTools.implicitCheckBoxHeight
Don Gagne's avatar
Don Gagne committed
17
            baselineOffset: text.baselineOffset
18

Don Gagne's avatar
Don Gagne committed
19
            Rectangle {
20
                anchors.margins:    -1
Don Gagne's avatar
Don Gagne committed
21 22
                anchors.leftMargin: -3
                anchors.rightMargin: -3
23 24 25 26 27 28 29
                anchors.fill:       text
                visible:            control.activeFocus
                height:             6
                radius:             3
                color:              "#224f9fef"
                border.color:       "#47b"
                opacity:            0.6
Don Gagne's avatar
Don Gagne committed
30
            }
31

Don Gagne's avatar
Don Gagne committed
32
            Text {
33 34
                id:             text
                text:           control.text
35
                antialiasing:   true
36
                font.pointSize: ScreenTools.defaultFontPointSize
37 38
                font.family:    ScreenTools.normalFontFamily
                color:          control.__qgcPal.text
dogmaphobic's avatar
dogmaphobic committed
39
                anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
40
            }
41 42 43
        } // label

        indicator:  Item {
44
            implicitWidth:  ScreenTools.checkBoxIndicatorSize
45 46 47 48 49 50 51 52 53 54 55
            implicitHeight: implicitWidth

            Rectangle {
                anchors.fill: parent
                anchors.bottomMargin: -1
                color: "#44ffffff"
                radius: baserect.radius
            }

            Rectangle {
                id: baserect
56
                property var enabledGradient: Gradient {
57 58 59 60
                    GradientStop {color: "#eee" ; position: 0}
                    GradientStop {color: control.pressed ? "#eee" : "#fff" ; position: 0.1}
                    GradientStop {color: "#fff" ; position: 1}
                }
61 62 63 64 65 66 67 68 69
                property var disabledGradient: Gradient {
                    GradientStop {color: "#999" ; position: 0}
                    GradientStop {color: __qgcPal.textField ; position: 0.1}
                    GradientStop {color: __qgcPal.textField ; position: 0.9}
                    GradientStop {color: "#999" ; position: 1}
                }
                gradient: control.enabled ? enabledGradient : disabledGradient


70 71 72
                radius: ScreenTools.defaultFontPixelHeight * 0.16
                anchors.fill: parent
                border.color: control.activeFocus ? "#47b" : "#999"
73
                opacity: control.enabled ? 1 : 0.5
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
            }

            Image {
                source: "/qmlimages/check.png"
                opacity: control.checkedState === Qt.Checked ? control.enabled ? 1 : 0.5 : 0
                anchors.centerIn: parent
                anchors.verticalCenterOffset: 1
                Behavior on opacity {NumberAnimation {duration: 80}}
            }

            Rectangle {
                anchors.fill: parent
                anchors.margins: Math.round(baserect.radius)
                antialiasing: true
                gradient: Gradient {
                    GradientStop {color: control.pressed ? "#555" : "#999" ; position: 0}
                    GradientStop {color: "#555" ; position: 1}
                }
                radius: baserect.radius - 1
                anchors.centerIn: parent
                anchors.alignWhenCentered: true
                border.color: "#222"
                Behavior on opacity {NumberAnimation {duration: 80}}
                opacity: control.checkedState === Qt.PartiallyChecked ? control.enabled ? 1 : 0.5 : 0
            }
        } // indicator
    } // style
Don Gagne's avatar
Don Gagne committed
101
}