QGCCheckBox.qml 2.15 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 11 12 13 14
    property color  textColor:          _qgcPal.text
    property bool   textBold:           false
    property real   textFontPointSize:  ScreenTools.defaultFontPointSize

    property var    _qgcPal: QGCPalette { colorGroupEnabled: enabled }
    property bool   _noText: text === ""
15

16
    activeFocusOnPress: true
Don Gagne's avatar
Don Gagne committed
17 18

    style: CheckBoxStyle {
19 20
        spacing: _noText ? 0 : ScreenTools.defaultFontPixelWidth * 0.25

Don Gagne's avatar
Don Gagne committed
21
        label: Item {
22 23
            implicitWidth:  _noText ? 0 : text.implicitWidth + ScreenTools.defaultFontPixelWidth * 0.25
            implicitHeight: _noText ? 0 : Math.max(text.implicitHeight, ScreenTools.checkBoxIndicatorSize)
Don Gagne's avatar
Don Gagne committed
24
            baselineOffset: text.baselineOffset
25

Don Gagne's avatar
Don Gagne committed
26
            Text {
27 28 29 30 31 32
                id:                 text
                text:               control.text
                font.pointSize:     textFontPointSize
                font.bold:          control.textBold
                color:              control.textColor
                anchors.centerIn:   parent
Don Gagne's avatar
Don Gagne committed
33
            }
34
        }
35 36

        indicator:  Item {
37
            implicitWidth:  ScreenTools.checkBoxIndicatorSize
38 39
            implicitHeight: implicitWidth
            Rectangle {
40
                anchors.fill:   parent
41 42
                color:          "white"
                border.color:   qgcPal.text
43
                border.width:   1
44
                opacity:        control.checkedState === Qt.PartiallyChecked ? 0.5 : 1
45 46
                QGCColoredImage {
                    source: "/qmlimages/checkbox-check.svg"
47 48
                    color:      "black"
                    opacity:    control.checkedState === Qt.Checked ? (control.enabled ? 1 : 0.5) : 0
49 50 51 52 53 54
                    mipmap:     true
                    fillMode:   Image.PreserveAspectFit
                    width:      parent.width * 0.75
                    height:     width
                    sourceSize.height: height
                    anchors.centerIn:  parent
55 56
                }
            }
57 58
        }
    }
Don Gagne's avatar
Don Gagne committed
59
}