QGCMouseArea.qml 1.57 KB
Newer Older
1
import QtQuick 2.11
2

3 4
import QGroundControl               1.0
import QGroundControl.ScreenTools   1.0
5

6 7 8
/// Works just like a regular MouseArea except:
///     1) It supports the ability to show touch extents based on QGroundControl.showTouchAreas
///     2) You can specify fillItem and it will automatically fill to the size and adjust touch areas on mobile
9
MouseArea {
10 11 12 13 14 15
    anchors.leftMargin:     fillItem ? -_touchMarginHorizontal : 0
    anchors.rightMargin:    fillItem ? -_touchMarginHorizontal : 0
    anchors.topMargin:      fillItem ? -_touchMarginVertical : 0
    anchors.bottomMargin:   fillItem ? -_touchMarginVertical : 0
    anchors.fill:           fillItem ? fillItem : undefined

DonLakeFlyer's avatar
DonLakeFlyer committed
16 17
    property var    fillItem
    property bool   debugMobile:    false   ///< Allows you to debug mobile sizing on desktop builds
18 19 20 21 22

    property real _itemWidth:               fillItem ? fillItem.width : width
    property real _itemHeight:              fillItem ? fillItem.height : height
    property real _touchWidth:              Math.max(_itemWidth, ScreenTools.minTouchPixels)
    property real _touchHeight:             Math.max(_itemHeight, ScreenTools.minTouchPixels)
DonLakeFlyer's avatar
DonLakeFlyer committed
23 24
    property real _touchMarginHorizontal:   debugMobile || ScreenTools.isMobile ? (_touchWidth - _itemWidth) / 2 : 0
    property real _touchMarginVertical:     debugMobile || ScreenTools.isMobile ? (_touchHeight - _itemHeight) / 2 : 0
25

26 27 28
    Rectangle {
        anchors.fill:   parent
        border.color:   "red"
29
        border.width:   QGroundControl.corePlugin.showTouchAreas ? 1 : 0
30 31 32
        color:          "transparent"
    }
}