RoundButton.qml 2.17 KB
Newer Older
1 2
import QtQuick                  2.3
import QtQuick.Controls         1.2
3
import QtQuick.Controls.Styles  1.4
4 5

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

Item {
    id: _root

    signal          clicked()
12
    property alias  buttonImage:    button.source
dogmaphobic's avatar
dogmaphobic committed
13
    property real   radius:         ScreenTools.isMobile ? ScreenTools.defaultFontPixelHeight * 1.75 : ScreenTools.defaultFontPixelHeight * 1.25
14 15
    property bool   rotateImage:    false
    property bool   lightBorders:   true
16 17 18 19

    width:  radius * 2
    height: radius * 2

20 21 22
    property bool checked: false
    property ExclusiveGroup exclusiveGroup: null

23 24
    QGCPalette { id: qgcPal }

25 26 27 28 29 30
    onExclusiveGroupChanged: {
        if (exclusiveGroup) {
            exclusiveGroup.bindCheckable(_root)
        }
    }

31 32 33 34 35 36 37 38 39
    onRotateImageChanged: {
        if (rotateImage) {
            imageRotation.running = true
        } else {
            imageRotation.running = false
            button.rotation = 0
        }
    }

40 41 42
    Rectangle {
        anchors.fill:   parent
        radius:         width / 2
dogmaphobic's avatar
dogmaphobic committed
43
        border.width:   ScreenTools.defaultFontPixelHeight * 0.0625
44 45
        border.color:   lightBorders ? qgcPal.mapWidgetBorderLight : qgcPal.mapWidgetBorderDark
        color:          checked ? qgcPal.buttonHighlight : qgcPal.button
46

47
        QGCColoredImage {
dogmaphobic's avatar
dogmaphobic committed
48 49 50 51 52 53 54
            id:                 button
            anchors.fill:       parent
            sourceSize.height:  parent.height
            fillMode:           Image.PreserveAspectFit
            mipmap:             true
            smooth:             true
            color:              checked ? qgcPal.buttonHighlightText : qgcPal.buttonText
55

56
            RotationAnimation on rotation {
dogmaphobic's avatar
dogmaphobic committed
57 58 59 60 61 62
                id:             imageRotation
                loops:          Animation.Infinite
                from:           0
                to:             360
                duration:       500
                running:        false
63
            }
64

65 66
            MouseArea {
                anchors.fill:   parent
67 68 69 70
                onClicked: {
                    checked = !checked
                    _root.clicked()
                }
71 72 73 74
            }
        }
    }
}