QGCTextField.qml 1.69 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
import QGroundControl.ScreenTools 1.0
7 8

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

12
    property var __qgcPal: QGCPalette { colorGroupEnabled: enabled }
13
    property ScreenTools __screenTools: ScreenTools { }
14

15
    textColor: __qgcPal.textFieldText
16

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

Don Gagne's avatar
Don Gagne committed
25 26 27 28 29 30 31 32 33 34 35 36 37
    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"
38
                color: __qgcPal.textField
Don Gagne's avatar
Don Gagne committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52
            }

            Text {
                id: unitsLabel

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

                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter

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

53
                text: control.unitsLabel
54 55
                font.pointSize: __screenTools.defaultFontPointSize
                antialiasing:   true
56

Don Gagne's avatar
Don Gagne committed
57 58 59 60 61 62 63
                color: control.textColor
                visible: control.showUnits
            }
        }

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