ModeSwitchDisplay.qml 7.84 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.
 *
 ****************************************************************************/
Don Gagne's avatar
Don Gagne committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32


import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

import QGroundControl.Palette 1.0
import QGroundControl.ScreenTools 1.0

Rectangle {
    property string flightModeName          ///< User visible name for this  flight mode
    property string flightModeDescription
    property real   rcValue                 ///< Current rcValue to show in Monitor display, range: 0.0 - 1.0
    property int    modeChannelIndex        ///< Index into channel list for this mode
    property bool   modeChannelEnabled      ///< true: Channel combo box is enabled
    property bool   modeSelected            ///< true: This mode is currently selected
    property real   thresholdValue          ///< Treshold setting for this mode, show in Threshold display, range 0.0 - 1.0
    property bool   thresholdDragEnabled    ///< true: Threshold value indicator can be dragged to modify value

    anchors.leftMargin:     ScreenTools.defaultFontPixelWidth
    anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
    anchors.left:           parent.left
    anchors.right:          parent.right
    height:                 column.height + (ScreenTools.defaultFontPixelWidth * 2)
33
    color:                  _qgcPal.window
Don Gagne's avatar
Don Gagne committed
34

Don Gagne's avatar
Don Gagne committed
35 36
    signal modeChannelIndexSelected(int index)

Don Gagne's avatar
Don Gagne committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
    QGCPalette { id: _qgcPal; colorGroupEnabled: enabled }

    Item {
        anchors.margins:    ScreenTools.defaultFontPixelWidth
        anchors.fill:       parent

        Column {
            id:         column
            width:      parent.width
            spacing:    ScreenTools.defaultFontPixelHeight / 4

            Row {
                width:      parent.width
                spacing:    ScreenTools.defaultFontPixelWidth

                Rectangle {
                    width:  modeLabel.width
54
                    height: channelCombo.height
Don Gagne's avatar
Don Gagne committed
55
                    color:  modeSelected ? _qgcPal.buttonHighlight : _qgcPal.button
Don Gagne's avatar
Don Gagne committed
56 57 58 59

                    QGCLabel {
                        id:                     modeLabel
                        width:                  ScreenTools.defaultFontPixelWidth * 18
60 61
                        anchors.top:            parent.top
                        anchors.bottom:         parent.bottom
Don Gagne's avatar
Don Gagne committed
62 63
                        color:                  modeSelected ? _qgcPal.buttonHighlightText : _qgcPal.text
                        horizontalAlignment:    Text.AlignHCenter
64
                        verticalAlignment:      Text.AlignVCenter
Don Gagne's avatar
Don Gagne committed
65 66 67 68 69 70 71 72 73 74 75
                        text:                   flightModeName
                    }
                }

                QGCComboBox {
                    id:             channelCombo
                    width:          ScreenTools.defaultFontPixelWidth * 15
                    model:          controller.channelListModel
                    currentIndex:   modeChannelIndex
                    enabled:        modeChannelEnabled

Don Gagne's avatar
Don Gagne committed
76
                    onActivated: modeChannelIndexSelected(index)
Don Gagne's avatar
Don Gagne committed
77 78 79 80 81 82
                }

                QGCLabel {
                    width:      parent.width - x
                    wrapMode:   Text.WordWrap
                    text:       flightModeDescription
Don Gagne's avatar
Don Gagne committed
83
                    visible:    !ScreenTools.isTinyScreen
Don Gagne's avatar
Don Gagne committed
84 85 86 87 88 89 90 91
                }
            }

            Row {
                width:      parent.width
                spacing:    ScreenTools.defaultFontPixelWidth * 2

                QGCLabel {
92
                    id:                 monitorLabel
Don Gagne's avatar
Don Gagne committed
93 94
                    height:             ScreenTools.defaultFontPixelHeight
                    verticalAlignment:  Text.AlignVCenter
95
                    text:               qsTr("Monitor:")
Don Gagne's avatar
Don Gagne committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
                }

                Item {
                    height: ScreenTools.defaultFontPixelHeight
                    width:  parent.width - x

                    // Won't be able to pull these properties, need to reference parent.
                    property int            __lastRcValue:      1500
                    readonly property int   __rcValueMaxJitter: 2

                    // Bar
                    Rectangle {
                        id:                     bar
                        anchors.verticalCenter: parent.verticalCenter
                        width:                  parent.width
                        height:                 parent.height / 2
                        color:                  _qgcPal.windowShadeDark
                    }

                    // RC Indicator
                    Rectangle {
                        anchors.verticalCenter: parent.verticalCenter
                        width:                  parent.height * 0.75
                        height:                 width
                        x:                      (parent.width * rcValue) - (width / 2)
                        radius:                 width / 2
                        color:                  _qgcPal.text
                    }
                } // Item
            }

            Row {
                width:      parent.width
                spacing:    ScreenTools.defaultFontPixelWidth * 2

                QGCLabel {
132
                    id:                 thresholdLabel
Don Gagne's avatar
Don Gagne committed
133 134
                    height:             ScreenTools.defaultFontPixelHeight
                    verticalAlignment:  Text.AlignVCenter
135
                    text:               qsTr("Threshold:")
Don Gagne's avatar
Don Gagne committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
                }

                Item {
                    id:     thresholdContainer
                    height: ScreenTools.defaultFontPixelHeight
                    width:  parent.width - x

                    // Bar
                    Rectangle {
                        anchors.verticalCenter: parent.verticalCenter
                        width:                  parent.width
                        height:                 parent.height / 2
                        color:                  _qgcPal.windowShadeDark
                    }

                    // Threshold Indicator
                    Rectangle {
                        id:                     thresholdIndicator
                        anchors.verticalCenter: parent.verticalCenter
                        width:                  parent.height * 0.75
                        height:                 width
                        x:                      (parent.width * thresholdValue) - (width / 2)
                        radius:                 width / 2
                        color:                  thresholdDragEnabled ? _qgcPal.buttonHighlight : _qgcPal.text

                        Drag.active:    thresholdDrag.drag.active
                        Drag.hotSpot.x: width / 2
                        Drag.hotSpot.y: height / 2

                        MouseArea {
                            id:             thresholdDrag
                            anchors.fill:   parent
                            cursorShape:    Qt.SizeHorCursor
                            drag.target:    thresholdDragEnabled ? parent : null
                            drag.minimumX:  - (width / 2)
                            drag.maximumX:  thresholdContainer.width - (width / 2)
                            drag.axis:      Drag.XAxis

                            property bool dragActive: drag.active

                            onDragActiveChanged: {
                                if (!drag.active) {
                                    thresholdValue = (thresholdIndicator.x + (thresholdIndicator.width / 2)) / thresholdContainer.width
                                }
                            }
                        }
                    }
                } // Item
            } // Row
        } // Column
    } // Item
} // Rectangle