QGCTextField.qml 2.03 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 {
9 10
    id: root

Don Gagne's avatar
Don Gagne committed
11
    property bool showUnits: false
12
    property string unitsLabel: ""
13

14 15 16 17 18 19
    Component.onCompleted: {
        if (typeof qgcTextFieldforwardKeysTo !== 'undefined') {
            root.Keys.forwardTo = [qgcTextFieldforwardKeysTo]
        }
    }

20
    property var __qgcPal: QGCPalette { colorGroupEnabled: enabled }
21

22
    textColor: __qgcPal.textFieldText
23
    height: ScreenTools.isMobile ? ScreenTools.defaultFontPixelHeight * 3 * 0.75 : implicitHeight
24

Don Gagne's avatar
Don Gagne committed
25 26
    Label {
        id: unitsLabelWidthGenerator
27
        text: unitsLabel
Don Gagne's avatar
Don Gagne committed
28 29
        width: contentWidth + ((parent.__contentHeight/3)*2)
        visible: false
30
        antialiasing: true
Don Gagne's avatar
Don Gagne committed
31
    }
32

Don Gagne's avatar
Don Gagne committed
33 34 35 36 37 38 39 40 41 42 43 44 45
    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"
46
                color: __qgcPal.textField
Don Gagne's avatar
Don Gagne committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60
            }

            Text {
                id: unitsLabel

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

                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter

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

61
                text: control.unitsLabel
Don Gagne's avatar
Don Gagne committed
62
                font.pixelSize: ScreenTools.defaultFontPixelSize
63
                antialiasing:   true
64

Don Gagne's avatar
Don Gagne committed
65 66 67 68 69 70 71
                color: control.textColor
                visible: control.showUnits
            }
        }

        padding.right: control.showUnits ? unitsLabelWidthGenerator.width : control.__contentHeight/3
    }
Don Gagne's avatar
Don Gagne committed
72 73

    onActiveFocusChanged: {
Don Gagne's avatar
Don Gagne committed
74
        if (!ScreenTools.isMobile && activeFocus) {
Don Gagne's avatar
Don Gagne committed
75 76 77
            selectAll()
        }
    }
78
}