OfflineMapButton.qml 4.88 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

10 11
import QtQuick          2.3
import QtQuick.Controls 1.2
dogmaphobic's avatar
dogmaphobic committed
12 13 14 15

import QGroundControl.Palette       1.0
import QGroundControl.ScreenTools   1.0

16 17 18 19 20 21
Rectangle {
    id:             mapButton
    anchors.margins: ScreenTools.defaultFontPixelWidth
    color:          _showHighlight ? qgcPal.buttonHighlight : qgcPal.button
    border.width:   _showBorder ? 1: 0
    border.color:   qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
22

23 24
    property var    tileSet:    null
    property var    currentSet: null
dogmaphobic's avatar
dogmaphobic committed
25 26 27
    property bool   checked:    false
    property bool   complete:   false
    property alias  text:       nameLabel.text
dogmaphobic's avatar
dogmaphobic committed
28 29
    property int    tiles:      0
    property string size:       ""
dogmaphobic's avatar
dogmaphobic committed
30

31 32 33 34 35 36 37 38 39
    property bool   _showHighlight: (_pressed | _hovered | checked) && !_forceHoverOff
    property bool   _showBorder:    qgcPal.globalTheme === QGCPalette.Light

    property bool   _forceHoverOff:    false
    property int    _lastGlobalMouseX: 0
    property int    _lastGlobalMouseY: 0
    property bool   _pressed:          false
    property bool   _hovered:          false

dogmaphobic's avatar
dogmaphobic committed
40 41
    signal clicked()

42 43 44 45 46 47 48 49 50 51 52 53 54
    property ExclusiveGroup exclusiveGroup:  null
    onExclusiveGroupChanged: {
        if (exclusiveGroup) {
            checked = false
            exclusiveGroup.bindCheckable(mapButton)
        }
    }
    onCheckedChanged: {
        if(checked) {
            currentSet = tileSet
        }
    }

55 56
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }

dogmaphobic's avatar
dogmaphobic committed
57 58 59 60
    Row {
        anchors.centerIn: parent
        QGCLabel {
            id:     nameLabel
61 62
            width:  mapButton.width * 0.4
            color:  _showHighlight ? qgcPal.buttonHighlightText : qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
63 64 65 66
            anchors.verticalCenter: parent.verticalCenter
        }
        QGCLabel {
            id:     sizeLabel
67
            width:  mapButton.width * 0.4
dogmaphobic's avatar
dogmaphobic committed
68 69
            horizontalAlignment: Text.AlignRight
            anchors.verticalCenter: parent.verticalCenter
70 71
            color:  _showHighlight ? qgcPal.buttonHighlightText : qgcPal.buttonText
            text:   mapButton.size + (tiles > 0 ? " (" + tiles + " tiles)" : "")
dogmaphobic's avatar
dogmaphobic committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
        }
        Item {
            width:  ScreenTools.defaultFontPixelWidth * 2
            height: 1
        }
        Rectangle {
            width:   sizeLabel.height * 0.5
            height:  sizeLabel.height * 0.5
            radius:  width / 2
            color:   complete ? "#31f55b" : "#fc5656"
            opacity: sizeLabel.text.length > 0 ? 1 : 0
            anchors.verticalCenter: parent.verticalCenter
        }
        Item {
            width:  ScreenTools.defaultFontPixelWidth * 2
            height: 1
        }
        QGCColoredImage {
            width:      sizeLabel.height * 0.8
            height:     sizeLabel.height * 0.8
dogmaphobic's avatar
dogmaphobic committed
92
            sourceSize.height:  height
dogmaphobic's avatar
dogmaphobic committed
93 94 95
            source:     "/res/buttonRight.svg"
            mipmap:     true
            fillMode:   Image.PreserveAspectFit
96
            color:      _showHighlight ? qgcPal.buttonHighlightText : qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
97 98 99 100 101 102
            anchors.verticalCenter: parent.verticalCenter
        }
    }

    MouseArea {
        anchors.fill: parent
103
        hoverEnabled: !ScreenTools.isMobile
dogmaphobic's avatar
dogmaphobic committed
104
        onMouseXChanged: {
105 106 107 108
            if(!ScreenTools.isMobile) {
                _lastGlobalMouseX = ScreenTools.mouseX()
                _lastGlobalMouseY = ScreenTools.mouseY()
            }
dogmaphobic's avatar
dogmaphobic committed
109 110
        }
        onMouseYChanged: {
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
            if(!ScreenTools.isMobile) {
                _lastGlobalMouseX = ScreenTools.mouseX()
                _lastGlobalMouseY = ScreenTools.mouseY()
            }
        }
        onEntered:  {
            if(!ScreenTools.isMobile) {
                _hovered = true
                _forceHoverOff = false
                hoverTimer.start()
            }
        }
        onExited:   {
            if(!ScreenTools.isMobile) {
                _hovered = false
                _forceHoverOff = false
                hoverTimer.stop()
            }
        }
        onPressed:  {
            if(!ScreenTools.isMobile) {
                _pressed = true
            }
        }
        onReleased: {
            if(!ScreenTools.isMobile) {
                _pressed = false
            }
        }
        onClicked: {
            checked = true
            mapButton.clicked()
        }
dogmaphobic's avatar
dogmaphobic committed
144 145 146 147 148
    }

    Timer {
        id:         hoverTimer
        interval:   250
149
        repeat:     !ScreenTools.isMobile
dogmaphobic's avatar
dogmaphobic committed
150
        onTriggered: {
151 152
            if (_lastGlobalMouseX !== ScreenTools.mouseX() || _lastGlobalMouseY !== ScreenTools.mouseY()) {
                _forceHoverOff = true
dogmaphobic's avatar
dogmaphobic committed
153
            } else {
154
                _forceHoverOff = false
dogmaphobic's avatar
dogmaphobic committed
155 156 157 158
            }
        }
    }
}