QGCTextField.qml 1.54 KB
Newer Older
1 2 3
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
4 5

import QGroundControl.Palette 1.0
6 7

TextField {
Don Gagne's avatar
Don Gagne committed
8
    property bool showUnits: false
9
    property string unitsLabel: ""
10

11
    property var __qgcPal: QGCPalette { colorGroupEnabled: enabled }
12

13
    textColor: __qgcPal.textFieldText
14

Don Gagne's avatar
Don Gagne committed
15 16
    Label {
        id: unitsLabelWidthGenerator
17
        text: unitsLabel
Don Gagne's avatar
Don Gagne committed
18 19 20
        width: contentWidth + ((parent.__contentHeight/3)*2)
        visible: false
    }
21

Don Gagne's avatar
Don Gagne committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35
    style: TextFieldStyle {
        background: Item {
            id: backgroundItem

            Rectangle {
                anchors.fill: parent
                anchors.bottomMargin: -1
                color: "#44ffffff"
            }

            Rectangle {
                anchors.fill: parent

                border.color: control.activeFocus ? "#47b" : "#999"
36
                color: __qgcPal.textField
Don Gagne's avatar
Don Gagne committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50
            }

            Text {
                id: unitsLabel

                anchors.top: parent.top
                anchors.bottom: parent.bottom

                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter

                x: parent.width - width
                width: unitsLabelWidthGenerator.width

51
                text: control.unitsLabel
52 53
                font.pointSize: __qgcPal.dpiAdjustedDefaultFontPointSize

Don Gagne's avatar
Don Gagne committed
54 55 56 57 58 59 60
                color: control.textColor
                visible: control.showUnits
            }
        }

        padding.right: control.showUnits ? unitsLabelWidthGenerator.width : control.__contentHeight/3
    }
61
}