RoundButton.qml 1.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
import QtQuick                  2.4
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.2

import QGroundControl.ScreenTools   1.0

Item {
    id: _root

    signal          clicked()
    property alias  buttonImage:        button.source
    property real   radius:             (ScreenTools.defaultFontPixelHeight * 3) / 2

    width:  radius * 2
    height: radius * 2

17 18 19 20 21 22 23 24 25
    property bool checked: false
    property ExclusiveGroup exclusiveGroup: null

    onExclusiveGroupChanged: {
        if (exclusiveGroup) {
            exclusiveGroup.bindCheckable(_root)
        }
    }

26 27 28 29 30
    Rectangle {
        anchors.fill:   parent
        radius:         width / 2
        border.width:   2
        border.color:   "white"
31 32
        opacity:        checked ? 0.95 : 0.65
        color:          checked ? "orange" : "black"
33 34 35 36 37 38 39 40
        Image {
            id:             button
            anchors.fill:   parent
            fillMode:       Image.PreserveAspectFit
            mipmap:         true
            smooth:         true
            MouseArea {
                anchors.fill:   parent
41 42 43 44
                onClicked: {
                    checked = !checked
                    _root.clicked()
                }
45 46 47 48
            }
        }
    }
}