QGCCheckBox.qml 2.21 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
                id:                 text
                text:               control.text
                font.pointSize:     textFontPointSize
                font.bold:          control.textBold
Gus Grubba's avatar
Gus Grubba committed
31
                font.family:        ScreenTools.normalFontFamily
32 33
                color:              control.textColor
                anchors.centerIn:   parent
Don Gagne's avatar
Don Gagne committed
34
            }
35
        }
36 37

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