Skip to content
ToolStrip.qml 4.28 KiB
Newer Older
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
 * (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.
 *
 ****************************************************************************/

Don Gagne's avatar
 
Don Gagne committed
import QtQuick          2.11
import QtQuick.Controls 2.2
Gus Grubba's avatar
Gus Grubba committed
import QGroundControl               1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0

Rectangle {
    id:         _root
Gus Grubba's avatar
Gus Grubba committed
    color:      qgcPal.globalTheme === QGCPalette.Light ? QGroundControl.corePlugin.options.toolbarBackgroundLight : QGroundControl.corePlugin.options.toolbarBackgroundDark
    width:      _idealWidth < repeater.contentWidth ? repeater.contentWidth : _idealWidth
DonLakeFlyer's avatar
 
DonLakeFlyer committed
    height:     Math.min(maxHeight, toolStripColumn.height + (flickable.anchors.margins * 2))
    radius:     ScreenTools.defaultFontPixelWidth / 2

    property alias  model:              repeater.model
    property real   maxHeight           ///< Maximum height for control, determines whether text is hidden to make control shorter
DoinLakeFlyer's avatar
 
DoinLakeFlyer committed
    property alias  title:              titleLabel.text
DonLakeFlyer's avatar
 
DonLakeFlyer committed
    function simulateClick(buttonIndex) {
DoinLakeFlyer's avatar
 
DoinLakeFlyer committed
        buttonIndex = buttonIndex + 1 // skip over title
DoinLakeFlyer's avatar
 
DoinLakeFlyer committed
        toolStripColumn.children[buttonIndex].clicked()
DonLakeFlyer's avatar
 
DonLakeFlyer committed
    }

    // Ensure we don't get narrower than content
    property real _idealWidth: (ScreenTools.isMobile ? ScreenTools.minTouchPixels : ScreenTools.defaultFontPixelWidth * 8) + toolStripColumn.anchors.margins * 2
DonLakeFlyer's avatar
 
DonLakeFlyer committed
    signal dropped(int index)
DonLakeFlyer's avatar
 
DonLakeFlyer committed
    DeadMouseArea {
        anchors.fill: parent
    }

    QGCFlickable {
DonLakeFlyer's avatar
 
DonLakeFlyer committed
        id:                 flickable
        anchors.margins:    ScreenTools.defaultFontPixelWidth * 0.4
        anchors.top:        parent.top
        anchors.left:       parent.left
        anchors.right:      parent.right
DonLakeFlyer's avatar
 
DonLakeFlyer committed
        height:             parent.height
        contentHeight:      toolStripColumn.height
        flickableDirection: Flickable.VerticalFlick
DoinLakeFlyer's avatar
 
DoinLakeFlyer committed
        clip:               true
DonLakeFlyer's avatar
 
DonLakeFlyer committed

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

DoinLakeFlyer's avatar
 
DoinLakeFlyer committed
            QGCLabel {
                id:                     titleLabel
                anchors.left:           parent.left
                anchors.right:          parent.right
                horizontalAlignment:    Text.AlignHCenter
                font.pointSize:         ScreenTools.smallFontPointSize
                visible:                title != ""
            }

DonLakeFlyer's avatar
 
DonLakeFlyer committed
            Repeater {
                id: repeater

                QGCHoverButton {
                    id:             buttonTemplate

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

DoinLakeFlyer's avatar
 
DoinLakeFlyer committed
                    enabled:        modelData.enabled
                    visible:        modelData.visible
DonLakeFlyer's avatar
 
DonLakeFlyer committed
                    imageSource:    modelData.showAlternateIcon ? modelData.alternateIconSource : modelData.iconSource
DoinLakeFlyer's avatar
 
DoinLakeFlyer committed
                    text:           modelData.text
                    checked:        modelData.checked
                    checkable:      modelData.dropPanelComponent || modelData.checkable
DonLakeFlyer's avatar
 
DonLakeFlyer committed

DoinLakeFlyer's avatar
 
DoinLakeFlyer committed
                    onCheckedChanged: modelData.checked = checked
DonLakeFlyer's avatar
 
DonLakeFlyer committed

                    onClicked: {
DoinLakeFlyer's avatar
 
DoinLakeFlyer committed
                        dropPanel.hide()
                        if (!modelData.dropPanelComponent) {
                            modelData.triggered(this)
DonLakeFlyer's avatar
 
DonLakeFlyer committed
                        } else if (checked) {
                            var panelEdgeTopPoint = mapToItem(_root, width, 0)
DoinLakeFlyer's avatar
 
DoinLakeFlyer committed
                            dropPanel.show(panelEdgeTopPoint, modelData.dropPanelComponent, this)
                            checked = true
DonLakeFlyer's avatar
 
DonLakeFlyer committed
                            _root.dropped(index)
                        }
            }
        }
    }

    DropPanel {
        id:         dropPanel
        toolStrip:  _root
    }
}