QGCComboBox.qml 2.47 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
/****************************************************************************
 *
 * (c) 2009-2019 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.
 *
 * @file
 *   @author Gus Grubba <gus@auterion.com>
 */

import QtQuick                      2.11
import QtQuick.Controls             2.4
import QtQuick.Layouts              1.11

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

ComboBox {
    id:         control
    padding:    ScreenTools.comboBoxPadding

    property bool centeredLabel:  false

Don Gagne's avatar
Don Gagne committed
26 27 28 29
    property var _qgcPal: QGCPalette { colorGroupEnabled: enabled }

    Component.onCompleted: indicator.color = Qt.binding(function() { return _qgcPal.text })

30 31 32
    background: Rectangle {
        implicitWidth:                  ScreenTools.implicitComboBoxWidth
        implicitHeight:                 ScreenTools.implicitComboBoxHeight
Don Gagne's avatar
Don Gagne committed
33
        color:                          _qgcPal.window
34 35
        border.width:                   enabled ? 1 : 0
        border.color:                   "#999"
36
    }
Yasen's avatar
Yasen committed
37 38 39

    /*! Adding the Combobox list item to the theme.  */

40 41 42 43
    delegate: ItemDelegate {
            width:                      control.width

            contentItem: Text {
44
                text:                   control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData
Don Gagne's avatar
Don Gagne committed
45
                color:                  control.currentIndex === index ? _qgcPal.buttonHighlightText : _qgcPal.buttonText
46 47
                verticalAlignment:      Text.AlignVCenter
            }
Yasen's avatar
Yasen committed
48

49
            background: Rectangle {
Don Gagne's avatar
Don Gagne committed
50
                color:                  control.currentIndex === index ? _qgcPal.buttonHighlight : _qgcPal.button
Yasen's avatar
Yasen committed
51
            }
52 53 54

            highlighted:                control.highlightedIndex === index
        }
55

56 57 58 59
    /*! This defines the label of the button.  */
    contentItem: Item {
        implicitWidth:                  text.implicitWidth
        implicitHeight:                 text.implicitHeight
Yasen's avatar
Yasen committed
60

61 62 63 64 65
        QGCLabel {
            id:                         text
            anchors.verticalCenter:     parent.verticalCenter
            anchors.horizontalCenter:   centeredLabel ? parent.horizontalCenter : undefined
            text:                       control.currentText
Don Gagne's avatar
Don Gagne committed
66
            color:                      _qgcPal.text
67 68
        }
    }
69
}