QGCCheckBox.qml 1.91 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 15
    property color  textColor:          _qgcPal.text
    property bool   textBold:           false
    property real   textFontPointSize:  ScreenTools.defaultFontPointSize

    property var    _qgcPal: QGCPalette { colorGroupEnabled: enabled }
    property bool   _noText: text === ""
    property real   _radius: ScreenTools.defaultFontPixelHeight * 0.16
16

17
    activeFocusOnPress: true
Don Gagne's avatar
Don Gagne committed
18 19 20

    style: CheckBoxStyle {
        label: Item {
21 22
            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
23
            baselineOffset: text.baselineOffset
24

Don Gagne's avatar
Don Gagne committed
25
            Text {
26 27 28 29 30 31
                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
32
            }
33
        }
34 35

        indicator:  Item {
36
            implicitWidth:  ScreenTools.checkBoxIndicatorSize
37 38 39
            implicitHeight: implicitWidth

            Rectangle {
40 41 42 43 44 45 46 47 48 49 50
                anchors.fill:   parent
                radius:         _radius
                border.color:   "black"
                opacity:        control.checkedState === Qt.PartiallyChecked ? 0.5 : 1

                Rectangle {
                    anchors.margins:    parent.height / 4
                    anchors.fill:       parent
                    radius:             _radius
                    color:              "black"
                    visible:            control.checkedState === Qt.Checked
51 52
                }
            }
53 54
        }
    }
Don Gagne's avatar
Don Gagne committed
55
}