QGCToolBarButton.qml 3.56 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9 10 11


import QtQuick          2.4
12 13
import QtQuick.Controls 1.2

14 15 16
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0
import QGroundControl.ScreenTools   1.0
17

dogmaphobic's avatar
dogmaphobic committed
18
Item {
19 20 21
    id:     _root
    state:  "HelpShown"
    clip:   true
dogmaphobic's avatar
dogmaphobic committed
22

23 24 25 26
    property alias          text:           helpText.text
    property alias          source:         icon.source
    property bool           checked:        false
    property bool           logo:           false
dogmaphobic's avatar
dogmaphobic committed
27 28 29 30
    property ExclusiveGroup exclusiveGroup:  null

    signal   clicked()

31 32 33 34
    readonly property real _topBottomMargins: ScreenTools.defaultFontPixelHeight / 2

    property real   _helpTextBottomMargin:  0
    property real   _imageBottomMargin:     0
35

dogmaphobic's avatar
dogmaphobic committed
36 37 38 39 40 41
    onExclusiveGroupChanged: {
        if (exclusiveGroup) {
            exclusiveGroup.bindCheckable(_root)
        }
    }

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    QGCPalette { id: qgcPal }

    states: [
        State {
            name: "HelpShown"
        },
        State {
            name: "HelpHidden"
            PropertyChanges { target: imageAnimation; running: true  }
            PropertyChanges { target: helpTextAnimation; running: true  }
        }
    ]

    PropertyAnimation {
        id:             imageAnimation
        target:         _root
        property:       "_imageBottomMargin"
        duration:       1000
        easing.type:    Easing.InOutQuad
        to:             _topBottomMargins
        from:           0
    }

    PropertyAnimation {
        id:             helpTextAnimation
        target:         _root
        property:       "_helpTextBottomMargin"
        duration:       1000
        easing.type:    Easing.InOutQuad
        to:             -helpText.height
        from:           0
    }

    Timer {
        interval:       10000
        running:        true
        onTriggered:    _root.state = "HelpHidden"
    }

    Rectangle {
        anchors.fill:   parent
        visible:        logo
        color:          "#4A2C6D"
    }

87 88 89 90 91 92
    QGCColoredImage {
        id:                     icon
        anchors.left:           parent.left
        anchors.right:          parent.right
        anchors.topMargin:      _topBottomMargins
        anchors.top:            parent.top
93 94
        anchors.bottomMargin:   _imageBottomMargin
        anchors.bottom:         helpText.top
dogmaphobic's avatar
dogmaphobic committed
95
        sourceSize.height:      parent.height
96
        fillMode:               Image.PreserveAspectFit
97
        color:                  logo ? "white" : (checked ? qgcPal.buttonHighlight : qgcPal.buttonText)
98 99
    }

100
    Rectangle {
101 102 103
        anchors.left:   parent.left
        anchors.right:  parent.right
        anchors.bottom: parent.bottom
dogmaphobic's avatar
dogmaphobic committed
104
        height:         _topBottomMargins * 0.25
105 106
        color:          qgcPal.buttonHighlight
        visible:        checked
dogmaphobic's avatar
dogmaphobic committed
107 108
    }

109 110 111 112 113 114 115 116 117 118
    QGCLabel {
        id:                     helpText
        anchors.left:           parent.left
        anchors.right:          parent.right
        anchors.bottomMargin:   _helpTextBottomMargin
        anchors.bottom:         parent.bottom
        horizontalAlignment:    Text.AlignHCenter
        color:                  logo ? "white" : qgcPal.buttonText
    }

dogmaphobic's avatar
dogmaphobic committed
119 120 121 122 123 124 125 126
    MouseArea {
        anchors.fill: parent
        onClicked: {
            checked = true
            _root.clicked()
        }
    }
}