InstrumentSwipeView.qml 3.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
import QtQuick                  2.5
import QtQuick.Controls         1.4

import QGroundControl.Palette       1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.FlightMap     1.0

Item {
    id: _root
    clip: true
    height: valuesPage.height + pageIndicatorRow.anchors.topMargin + pageIndicatorRow.height

    property var    qgcView     ///< QGCView to use for showing dialogs
    property color  textColor
    property color  backgroundColor
    property var    maxHeight   ///< Maximum height that should be taken, smaller than this is ok

18 19 20 21
    property real   _margins:           ScreenTools.defaultFontPixelWidth / 2
    property real   _pageWidth:         _root.width
    property int    _currentPage:       0
    property int    _maxPage:           2
22

Don Gagne's avatar
Don Gagne committed
23 24 25 26
    function showPicker() {
        valuesPage.showPicker()
    }

27 28 29 30 31
    function showPage(pageIndex) {
        _root.height = Qt.binding(function() { return _root.children[pageIndex].height + pageIndicatorRow.anchors.topMargin + pageIndicatorRow.height } )
        _root.children[0].x = -(pageIndex * _pageWidth)
    }

32 33
    ValuesWidget {
        id:         valuesPage
34
        width:      _pageWidth
35 36 37 38 39
        qgcView:    _root.qgcView
        textColor:  _root.textColor
        maxHeight:  _root.maxHeight
    }

40 41 42 43 44 45 46 47 48
    VehicleHealthWidget {
        id:             healthPage
        anchors.left:   valuesPage.right
        width:          _pageWidth
        qgcView:        _root.qgcView
        textColor:      _root.textColor
        maxHeight:      _root.maxHeight
    }

49 50
    VibrationWidget {
        id:                 vibrationPage
51 52
        anchors.left:       healthPage.right
        width:              _pageWidth
53 54 55 56 57 58 59 60 61 62 63
        textColor:          _root.textColor
        backgroundColor:    _root.backgroundColor
        maxHeight:          _root.maxHeight
    }

    Row {
        id:                         pageIndicatorRow
        anchors.bottom:             parent.bottom
        anchors.horizontalCenter:   parent.horizontalCenter
        spacing:                    _margins

64 65
        Repeater {
            model: _maxPage + 1
66

67 68 69
            Rectangle {
                height:         radius * 2
                width:          radius * 2
70
                radius:         ScreenTools.defaultFontPixelWidth / 3
71 72 73 74
                border.color:   textColor
                border.width:   1
                color:          _currentPage == index ? textColor : "transparent"
            }
75 76 77
        }
    }

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    MouseArea {
        anchors.fill: parent

        onClicked: {
            if (_currentPage == _maxPage) {
                _currentPage = 0
            } else {
                _currentPage++
            }
            showPage(_currentPage)
        }
    }

    /*
      Switching from swipe to click to change pages. Keeping swipe code for now in case of change back.
93 94 95 96
    MouseArea {
        anchors.fill: parent

        property real xDragStart
97
        property real xFirstPageSave
98 99 100 101 102

        onPressed: {
            if (mouse.button == Qt.LeftButton) {
                mouse.accepted = true
                xDragStart = mouse.x
103
                xFirstPageSave = _root.children[0].x
104 105 106 107
            }
        }

        onPositionChanged: {
108
            _root.children[0].x = xFirstPageSave + mouse.x - xDragStart
109 110 111 112
        }

        onReleased: {
            if (mouse.x < xDragStart) {
113 114
                // Swipe left
                _currentPage = Math.min(_currentPage + 1, _maxPage)
115
            } else {
116 117
                // Swipe right
                _currentPage = Math.max(_currentPage - 1, 0)
118
            }
119
            showPage(_currentPage)
120 121
        }
    }
122
    */
123
}