ToolStrip.qml.orig 21.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 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 132 133 134 135 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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
/****************************************************************************
 *
 * (c) 2009-2020 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.11
<<<<<<< HEAD
<<<<<<< HEAD
import QtQuick.Controls 1.4
import QtQuick.Layouts  1.11
=======
import QtQuick.Controls 2.2
>>>>>>> upstream_merge
=======
import QtQuick.Controls 2.2
>>>>>>> upstream_merge

import QGroundControl               1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0

// Tool Strip not tested for mobile devices!
Rectangle {
    id:         _root
<<<<<<< HEAD
<<<<<<< HEAD
    color:      qgcPal.window
    width:      toolStripGrid.width + (toolStripGrid.anchors.margins * 2)
    height:     toolStripGrid.height + (toolStripGrid.anchors.margins * 2)
    radius:     _radius
    border.width:   1
    border.color:   qgcPal.globalTheme === QGCPalette.Light ? Qt.rgba(0,0,0,0.35) : Qt.rgba(1,1,1,0.35)

    property string title:              "Title"
    property alias  model:              repeater.model
    property var    showAlternateIcon                   ///< List of bool values, one for each button in strip - true: show alternate icon, false: show normal icon
    property var    rotateImage                         ///< List of bool values, one for each button in strip - true: animation rotation, false: static image
    property var    animateImage                        ///< List of bool values, one for each button in strip - true: animate image, false: static image
    property var    buttonEnabled                       ///< List of bool values, one for each button in strip - true: button enabled, false: button disabled
    property var    buttonVisible                       ///< List of bool values, one for each button in strip - true: button visible, false: button invisible
    property var    maxHeight                           /// legacy parameter, does not have any impact
    property bool   horizontal:         false           /// toolstrip horizontal or vertical ?
    property bool   enableSwitchButton: false           /// enable horizontal vertical button ?



    signal clicked(int index, bool checked)

    readonly property real  _radius:                ScreenTools.defaultFontPixelWidth / 2
    readonly property real  _margin:                ScreenTools.defaultFontPixelWidth / 2
    readonly property real  _buttonSpacing:         ScreenTools.defaultFontPixelHeight / 4

    readonly property real _buttonWidthHeight: ScreenTools.isMobile ? ScreenTools.minTouchPixels : ScreenTools.defaultFontPixelWidth * 6

    Component.onCompleted: toolStripGrid.horizontal = _root.horizontal

    onHorizontalChanged: toolStripGrid.horizontal = _root.horizontal

    QGCPalette { id: qgcPal }
    ExclusiveGroup { id: dropButtonsExclusiveGroup }

    function uncheckAll() {
        dropButtonsExclusiveGroup.current = null
        // Signal all toggles as off
        for (var i=0; i<model.length; i++) {
            if (model[i].toggle === true) {
                _root.clicked(i, false)
            }
        }
=======
    color:      qgcPal.toolbarBackground
    width:      _idealWidth < repeater.contentWidth ? repeater.contentWidth : _idealWidth
    height:     Math.min(maxHeight, toolStripColumn.height + (flickable.anchors.margins * 2))
    radius:     ScreenTools.defaultFontPixelWidth / 2

    property alias  model:              repeater.model
=======
    color:      qgcPal.toolbarBackground
    width:      _idealWidth < repeater.contentWidth ? repeater.contentWidth : _idealWidth
    height:     Math.min(maxHeight, toolStripColumn.height + (flickable.anchors.margins * 2))
    radius:     ScreenTools.defaultFontPixelWidth / 2

    property alias  model:              repeater.model
>>>>>>> upstream_merge
    property real   maxHeight           ///< Maximum height for control, determines whether text is hidden to make control shorter
    property alias  title:              titleLabel.text

    function simulateClick(buttonIndex) {
        buttonIndex = buttonIndex + 1 // skip over title
        toolStripColumn.children[buttonIndex].clicked()
<<<<<<< HEAD
>>>>>>> upstream_merge
=======
>>>>>>> upstream_merge
    }

    // Ensure we don't get narrower than content
    property real _idealWidth: (ScreenTools.isMobile ? ScreenTools.minTouchPixels : ScreenTools.defaultFontPixelWidth * 8) + toolStripColumn.anchors.margins * 2

    signal dropped(int index)

    DeadMouseArea {
        anchors.fill: parent
    }

<<<<<<< HEAD
<<<<<<< HEAD
    Grid {
        id:                 toolStripGrid
        anchors.margins:    ScreenTools.defaultFontPixelWidth  / 2
        anchors.top:        parent.top
        anchors.left:       parent.left
        columnSpacing:      _buttonSpacing
        rowSpacing:         _buttonSpacing

        // Lable + Separator + GridLayout + Spearator + Switch Button
        property int numItems: enableSwitchButton ? 5 : 3
        rows:               toolStripGrid.horizontal ? 1 : numItems
        columns:            toolStripGrid.horizontal ? numItems : 1

        horizontalItemAlignment:    Grid.AlignHCenter
        verticalItemAlignment:      Grid.AlignVCenter

        property bool horizontal

        QGCLabel {
            text:                       title
            font.pointSize:             ScreenTools.mobile ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize
        }


        // separator
        Rectangle {
            height:             toolStripGrid.horizontal ? _buttonWidthHeight : 1
            width:              toolStripGrid.horizontal ? 1 : _buttonWidthHeight
            color:              qgcPal.text
        }
=======
    QGCFlickable {
        id:                 flickable
        anchors.margins:    ScreenTools.defaultFontPixelWidth * 0.4
        anchors.top:        parent.top
        anchors.left:       parent.left
        anchors.right:      parent.right
        height:             parent.height
        contentHeight:      toolStripColumn.height
        flickableDirection: Flickable.VerticalFlick
        clip:               true
>>>>>>> upstream_merge

        GridLayout {
            id:             modelButtonsGrid
            rows:           toolStripGrid.horizontal ?            1 : model.length
            columns:        toolStripGrid.horizontal ? model.length : 1
            columnSpacing:  _buttonSpacing
            rowSpacing:     _buttonSpacing


=======
    QGCFlickable {
        id:                 flickable
        anchors.margins:    ScreenTools.defaultFontPixelWidth * 0.4
        anchors.top:        parent.top
        anchors.left:       parent.left
        anchors.right:      parent.right
        height:             parent.height
        contentHeight:      toolStripColumn.height
        flickableDirection: Flickable.VerticalFlick
        clip:               true

        Column {
            id:             toolStripColumn
            anchors.left:   parent.left
            anchors.right:  parent.right
            spacing:        ScreenTools.defaultFontPixelWidth * 0.25

            QGCLabel {
                id:                     titleLabel
                anchors.left:           parent.left
                anchors.right:          parent.right
                horizontalAlignment:    Text.AlignHCenter
                font.pointSize:         ScreenTools.smallFontPointSize
                visible:                title != ""
            }
<<<<<<< HEAD
>>>>>>> upstream_merge
=======
>>>>>>> upstream_merge

            Repeater {
                id: repeater

<<<<<<< HEAD
<<<<<<< HEAD
                delegate: FocusScope {
                    id:         scope
                    width:      buttonRect.width
                    height:     buttonRect.height
                    visible:    _root.buttonVisible ? _root.buttonVisible[index] : true
                    Layout.alignment: toolStripGrid.horizontal ? Qt.AlignVCenter : Qt.AlignHCenter

                    property bool checked: false
                    property ExclusiveGroup exclusiveGroup: dropButtonsExclusiveGroup

                    property bool   _buttonEnabled:         _root.buttonEnabled ? _root.buttonEnabled[index] : true
                    property var    _iconSource:            modelData.iconSource
                    property var    _alternateIconSource:   modelData.alternateIconSource
                    property var    _source:                (_root.showAlternateIcon && _root.showAlternateIcon[index]) ? _alternateIconSource : _iconSource
                    property bool   rotateImage:            _root.rotateImage ? _root.rotateImage[index] : false
                    property bool   animateImage:           _root.animateImage ? _root.animateImage[index] : false
                    property bool   _hovered:               false
                    property bool   _showHighlight:         checked || (_buttonEnabled && _hovered)

                    QGCPalette { id: _repeaterPal; colorGroupEnabled: _buttonEnabled }

                    onExclusiveGroupChanged: {
                        if (exclusiveGroup) {
                            exclusiveGroup.bindCheckable(scope)
                        }
                    }

                    onRotateImageChanged: {
                        if (rotateImage) {
                            imageRotation.running = true
                        } else {
                            imageRotation.running = false
                            buttonImage.rotation = 0
                        }
                    }

                    onAnimateImageChanged: {
                        if (animateImage) {
                            opacityAnimation.running = true
                        } else {
                            opacityAnimation.running = false
                            buttonImage.opacity = 1
                        }
                    }

                    Rectangle {
                        id:             buttonRect
                        height:         _buttonWidthHeight
                        width:          _buttonWidthHeight
                        color:          _showHighlight ? _repeaterPal.buttonHighlight : _repeaterPal.window
                        clip:           true
                        radius:         ScreenTools.defaultFontPixelWidth/2

                        Column {

                            anchors.horizontalCenter: parent.horizontalCenter

                            QGCColoredImage {
                                id:             buttonImage
                                height:             _buttonWidthHeight-buttonLabel.height
                                width:              _buttonWidthHeight-buttonLabel.height
                                source:             _source
                                anchors.horizontalCenter: parent.horizontalCenter
                                sourceSize.height:  _buttonWidthHeight-buttonLabel.height
                                sourceSize.width:   _buttonWidthHeight-buttonLabel.height
                                fillMode:           Image.PreserveAspectCrop
                                mipmap:             true
                                smooth:             true
                                color:              _showHighlight ? _repeaterPal.buttonHighlightText : _repeaterPal.text

                                RotationAnimation on rotation {
                                    id:             imageRotation
                                    loops:          Animation.Infinite
                                    from:           0
                                    to:             360
                                    duration:       500
                                    running:        false
                                }

                                NumberAnimation on opacity {
                                    id:         opacityAnimation
                                    running:    false
                                    from:       0
                                    to:         1.0
                                    loops:      Animation.Infinite
                                    duration:   2000
                                }
                            }

                            QGCLabel {
                                id:                         buttonLabel

                                anchors.horizontalCenter:   parent.horizontalCenter
                                font.pointSize:             ScreenTools.smallFontPointSize
                                text:                       modelData.name
                                color:                      _showHighlight ? _repeaterPal.buttonHighlightText : _repeaterPal.text
                                enabled:                    _buttonEnabled
                            }
                        }

                        QGCMouseArea {
                            anchors.fill:       parent
                            visible:            _buttonEnabled
                            hoverEnabled:       true
                            preventStealing:    true

                            onContainsMouseChanged: _hovered = containsMouse
                            onContainsPressChanged: _hovered = containsPress

                            onClicked: {
                                scope.focus = true
                                if (modelData.dropPanelComponent === undefined) {
                                    dropPanel.hide()
                                    if (modelData.toggle === true) {
                                        checked = !checked
                                    } else {
                                        // dropPanel.hide above will close panel, but we need to do this to clear toggles
                                        uncheckAll()
                                    }
                                    _root.clicked(index, checked)
                                } else {
                                    if (checked) {
                                        dropPanel.hide()    // hide affects checked, so this needs to be duplicated inside not outside if
                                    } else {
                                        dropPanel.hide()    // hide affects checked, so this needs to be duplicated inside not outside if
                                        uncheckAll()
                                        checked = true
                                        var panelEdgeTopPoint = mapToItem(_root, width, 0)
                                        dropPanel.show(panelEdgeTopPoint, height, modelData.dropPanelComponent)
                                    }
                                }
                            }
                        }
                    } // Rectangle
                } // FocusScope
            } // Repeater
        } // GridLayout

        // separator
        Rectangle {
            height:             toolStripGrid.horizontal ? _buttonWidthHeight : 1
            width:              toolStripGrid.horizontal ? 1 : _buttonWidthHeight
            color:              qgcPal.text
            visible:            enableSwitchButton
=======
                QGCHoverButton {
                    id:             buttonTemplate

                    anchors.left:   toolStripColumn.left
                    anchors.right:  toolStripColumn.right
                    height:         width
                    radius:         ScreenTools.defaultFontPixelWidth / 2
                    fontPointSize:  ScreenTools.smallFontPointSize
                    autoExclusive:  true

                    enabled:        modelData.enabled
                    visible:        modelData.visible
                    imageSource:    modelData.showAlternateIcon ? modelData.alternateIconSource : modelData.iconSource
                    text:           modelData.text
                    checked:        modelData.checked
                    checkable:      modelData.dropPanelComponent || modelData.checkable

                    onCheckedChanged: modelData.checked = checked

                    onClicked: {
                        dropPanel.hide()
                        if (!modelData.dropPanelComponent) {
                            modelData.triggered(this)
                        } else if (checked) {
                            var panelEdgeTopPoint = mapToItem(_root, width, 0)
                            dropPanel.show(panelEdgeTopPoint, modelData.dropPanelComponent, this)
                            checked = true
                            _root.dropped(index)
                        }
                    }
=======
                QGCHoverButton {
                    id:             buttonTemplate

                    anchors.left:   toolStripColumn.left
                    anchors.right:  toolStripColumn.right
                    height:         width
                    radius:         ScreenTools.defaultFontPixelWidth / 2
                    fontPointSize:  ScreenTools.smallFontPointSize
                    autoExclusive:  true

                    enabled:        modelData.enabled
                    visible:        modelData.visible
                    imageSource:    modelData.showAlternateIcon ? modelData.alternateIconSource : modelData.iconSource
                    text:           modelData.text
                    checked:        modelData.checked
                    checkable:      modelData.dropPanelComponent || modelData.checkable

                    onCheckedChanged: modelData.checked = checked

                    onClicked: {
                        dropPanel.hide()
                        if (!modelData.dropPanelComponent) {
                            modelData.triggered(this)
                        } else if (checked) {
                            var panelEdgeTopPoint = mapToItem(_root, width, 0)
                            dropPanel.show(panelEdgeTopPoint, modelData.dropPanelComponent, this)
                            checked = true
                            _root.dropped(index)
                        }
                    }
>>>>>>> upstream_merge
                }
            }
>>>>>>> upstream_merge
        }

        // switch button, tool strip horizontal <-> vertical
        Rectangle {
            id:             switchButtonRect
            height:         enableSwitchButton ? _buttonWidthHeight : 0
            width:          enableSwitchButton ? _buttonWidthHeight : 0
            color:          _showHighlight ? _switchButtonPal.buttonHighlight : _switchButtonPal.window
            visible:        enableSwitchButton
            radius:         ScreenTools.defaultFontPixelWidth/2
            clip:           true

            property bool   _hovered:               false
            property bool   _showHighlight:         (enableSwitchButton && _hovered)

            QGCPalette { id: _switchButtonPal; colorGroupEnabled: enableSwitchButton }

            Column {
                anchors.horizontalCenter: parent.horizontalCenter
                QGCColoredImage {
                    id:             switchButtonImage
                    height:             _buttonWidthHeight-switchButtonLabel.height
                    width:              _buttonWidthHeight-switchButtonLabel.height
                    source:             "/res/clockwise-arrow.svg"
                    anchors.horizontalCenter: parent.horizontalCenter
                    sourceSize.height:  _buttonWidthHeight-switchButtonLabel.height
                    sourceSize.width:   _buttonWidthHeight-switchButtonLabel.height
                    fillMode:           Image.PreserveAspectCrop
                    mipmap:             true
                    smooth:             true
                    color:              switchButtonRect._showHighlight ? _switchButtonPal.buttonHighlightText : _switchButtonPal.text
                }

                QGCLabel {
                    id:                         switchButtonLabel
                    anchors.horizontalCenter:   parent.horizontalCenter
                    font.pointSize:             ScreenTools.smallFontPointSize
                    text:                       toolStripGrid.horizontal ? "Vert" : "Hor"
                    color:                      switchButtonRect._showHighlight ? _switchButtonPal.buttonHighlightText : _switchButtonPal.text
                    enabled:                    enableSwitchButton
                }
            }

            QGCMouseArea {
                anchors.fill:       parent
                visible:            enableSwitchButton
                hoverEnabled:       true
                preventStealing:    true

                onContainsMouseChanged: switchButtonRect._hovered = containsMouse
                onContainsPressChanged: switchButtonRect._hovered = containsPress

                onClicked: {
                    dropPanel.hide()    // hide affects checked, so this needs to be duplicated inside not outside if
                    if (toolStripGrid.horizontal === true) {
                        toolStripGrid.horizontal = false
                    } else {
                        toolStripGrid.horizontal = true
                    }
                }
            }
        } // switchButton Rectangle
    } // GridLayout

    DropPanel {
        id:         dropPanel
        toolStrip:  _root
    }
}