Skip to content
QGCCheckBox.qml 2.15 KiB
Newer Older
import QtQuick                  2.3
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.4
Don Gagne's avatar
Don Gagne committed

import QGroundControl.Palette       1.0
import QGroundControl.ScreenTools   1.0
Don Gagne's avatar
Don Gagne committed

CheckBox {
Don Gagne's avatar
 
Don Gagne committed
    property color  textColor:          _qgcPal.text
    property bool   textBold:           false
    property real   textFontPointSize:  ScreenTools.defaultFontPointSize

    property var    _qgcPal: QGCPalette { colorGroupEnabled: enabled }
    property bool   _noText: text === ""
Don Gagne's avatar
 
Don Gagne committed
    activeFocusOnPress: true
Don Gagne's avatar
Don Gagne committed

    style: CheckBoxStyle {
Don Gagne's avatar
 
Don Gagne committed
        spacing: _noText ? 0 : ScreenTools.defaultFontPixelWidth * 0.25

Don Gagne's avatar
Don Gagne committed
        label: Item {
Don Gagne's avatar
 
Don Gagne committed
            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
            baselineOffset: text.baselineOffset
Don Gagne's avatar
Don Gagne committed
            Text {
Don Gagne's avatar
 
Don Gagne committed
                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
            }
Don Gagne's avatar
 
Don Gagne committed
        }
            implicitWidth:  ScreenTools.checkBoxIndicatorSize
            implicitHeight: implicitWidth
            Rectangle {
Don Gagne's avatar
 
Don Gagne committed
                anchors.fill:   parent
                color:          "white"
                border.color:   qgcPal.text
                border.width:   1
Don Gagne's avatar
 
Don Gagne committed
                opacity:        control.checkedState === Qt.PartiallyChecked ? 0.5 : 1
                QGCColoredImage {
                    source: "/qmlimages/checkbox-check.svg"
                    color:      "black"
                    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
Don Gagne's avatar
 
Don Gagne committed
        }
    }
Don Gagne's avatar
Don Gagne committed
}