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

import QtQuick          2.5
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 25

    property bool   checked:    false
    property bool   complete:   false
    property alias  text:       nameLabel.text
dogmaphobic's avatar
dogmaphobic committed
26 27
    property int    tiles:      0
    property string size:       ""
dogmaphobic's avatar
dogmaphobic committed
28

29 30 31 32 33 34 35 36 37
    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
38 39
    signal clicked()

40 41
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }

dogmaphobic's avatar
dogmaphobic committed
42 43 44 45
    Row {
        anchors.centerIn: parent
        QGCLabel {
            id:     nameLabel
46 47
            width:  mapButton.width * 0.4
            color:  _showHighlight ? qgcPal.buttonHighlightText : qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
48 49 50 51
            anchors.verticalCenter: parent.verticalCenter
        }
        QGCLabel {
            id:     sizeLabel
52
            width:  mapButton.width * 0.4
dogmaphobic's avatar
dogmaphobic committed
53 54
            horizontalAlignment: Text.AlignRight
            anchors.verticalCenter: parent.verticalCenter
55 56
            color:  _showHighlight ? qgcPal.buttonHighlightText : qgcPal.buttonText
            text:   mapButton.size + (tiles > 0 ? " (" + tiles + " tiles)" : "")
dogmaphobic's avatar
dogmaphobic committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
        }
        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
77
            sourceSize.height:  height
dogmaphobic's avatar
dogmaphobic committed
78 79 80
            source:     "/res/buttonRight.svg"
            mipmap:     true
            fillMode:   Image.PreserveAspectFit
81
            color:      _showHighlight ? qgcPal.buttonHighlightText : qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
82 83 84 85 86 87 88 89
            anchors.verticalCenter: parent.verticalCenter
        }
    }

    MouseArea {
        anchors.fill: parent
        hoverEnabled: true
        onMouseXChanged: {
90 91
            _lastGlobalMouseX = ScreenTools.mouseX()
            _lastGlobalMouseY = ScreenTools.mouseY()
dogmaphobic's avatar
dogmaphobic committed
92 93
        }
        onMouseYChanged: {
94 95
            _lastGlobalMouseX = ScreenTools.mouseX()
            _lastGlobalMouseY = ScreenTools.mouseY()
dogmaphobic's avatar
dogmaphobic committed
96
        }
97 98 99 100 101
        onEntered:  { _hovered = true;  _forceHoverOff = false; hoverTimer.start() }
        onExited:   { _hovered = false; _forceHoverOff = false; hoverTimer.stop()  }
        onPressed:  { _pressed = true;  }
        onReleased: { _pressed = false; }
        onClicked:  mapButton.clicked()
dogmaphobic's avatar
dogmaphobic committed
102 103 104 105 106 107 108
    }

    Timer {
        id:         hoverTimer
        interval:   250
        repeat:     true
        onTriggered: {
109 110
            if (_lastGlobalMouseX !== ScreenTools.mouseX() || _lastGlobalMouseY !== ScreenTools.mouseY()) {
                _forceHoverOff = true
dogmaphobic's avatar
dogmaphobic committed
111
            } else {
112
                _forceHoverOff = false
dogmaphobic's avatar
dogmaphobic committed
113 114 115 116
            }
        }
    }
}