RoundButton.qml 1.32 KB
Newer Older
1 2 3 4 5
import QtQuick                  2.4
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.2

import QGroundControl.ScreenTools   1.0
6
import QGroundControl.Palette       1.0
7 8 9 10 11 12

Item {
    id: _root

    signal          clicked()
    property alias  buttonImage:        button.source
dogmaphobic's avatar
dogmaphobic committed
13
    property real   radius:             ScreenTools.defaultFontPixelHeight * 1.5
14 15 16 17

    width:  radius * 2
    height: radius * 2

18 19 20
    property bool checked: false
    property ExclusiveGroup exclusiveGroup: null

21 22
    QGCPalette { id: qgcPal }

23 24 25 26 27 28
    onExclusiveGroupChanged: {
        if (exclusiveGroup) {
            exclusiveGroup.bindCheckable(_root)
        }
    }

29 30 31
    Rectangle {
        anchors.fill:   parent
        radius:         width / 2
dogmaphobic's avatar
dogmaphobic committed
32
        border.width:   ScreenTools.defaultFontPixelHeight * 0.0625
33
        border.color:   "white"
34
        color:          checked ? qgcPal.mapButtonHighlight : qgcPal.mapButton
35

36 37 38 39 40 41
        Image {
            id:             button
            anchors.fill:   parent
            fillMode:       Image.PreserveAspectFit
            mipmap:         true
            smooth:         true
42

43 44
            MouseArea {
                anchors.fill:   parent
45 46 47 48
                onClicked: {
                    checked = !checked
                    _root.clicked()
                }
49 50 51 52
            }
        }
    }
}