QGCComboBox.qml 2.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
/****************************************************************************
 *
 * (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

    background: Rectangle {
        implicitWidth:                  ScreenTools.implicitComboBoxWidth
        implicitHeight:                 ScreenTools.implicitComboBoxHeight
Yasen's avatar
Yasen committed
29
        color:                          qgcPal.window
30 31
        border.width:                   enabled ? 1 : 0
        border.color:                   "#999"
32
    }
Yasen's avatar
Yasen committed
33 34 35

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

36 37 38 39
    delegate: ItemDelegate {
            width:                      control.width

            contentItem: Text {
40
                text:                   control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData
Yasen's avatar
Yasen committed
41
                color:                  control.currentIndex === index ? qgcPal.buttonHighlightText : qgcPal.buttonText
42 43
                verticalAlignment:      Text.AlignVCenter
            }
Yasen's avatar
Yasen committed
44

45
            background: Rectangle {
Yasen's avatar
Yasen committed
46 47
                color:                  control.currentIndex === index ? qgcPal.buttonHighlight : qgcPal.button
            }
48 49 50

            highlighted:                control.highlightedIndex === index
        }
51

52 53 54 55
    /*! This defines the label of the button.  */
    contentItem: Item {
        implicitWidth:                  text.implicitWidth
        implicitHeight:                 text.implicitHeight
Yasen's avatar
Yasen committed
56

57 58 59 60 61
        QGCLabel {
            id:                         text
            anchors.verticalCenter:     parent.verticalCenter
            anchors.horizontalCenter:   centeredLabel ? parent.horizontalCenter : undefined
            text:                       control.currentText
Yasen's avatar
Yasen committed
62
            color:                      qgcPal.text
63 64
        }
    }
65
}