QGCTextField.qml 2.08 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
    style: TextFieldStyle {
dogmaphobic's avatar
dogmaphobic committed
34
        font.pixelSize: ScreenTools.defaultFontPixelSize
Don Gagne's avatar
Don Gagne committed
35 36 37 38 39 40 41 42 43 44 45 46
        background: Item {
            id: backgroundItem

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

            Rectangle {
                anchors.fill: parent
                border.color: control.activeFocus ? "#47b" : "#999"
47
                color: __qgcPal.textField
Don Gagne's avatar
Don Gagne committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61
            }

            Text {
                id: unitsLabel

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

                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter

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

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

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

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

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