QGCCheckBox.qml 2.08 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 19

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

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

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