QGCTextField.qml 2.28 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 23
    textColor:          __qgcPal.textFieldText
    height:             Math.max(25, Math.round(TextSingleton.implicitHeight * 1.2))
24

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

Don Gagne's avatar
Don Gagne committed
34
    style: TextFieldStyle {
35
        font.pointSize: ScreenTools.defaultFontPointSize
Don Gagne's avatar
Don Gagne committed
36 37 38 39 40 41 42 43 44 45 46 47
        background: Item {
            id: backgroundItem

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

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

            Text {
                id: unitsLabel

54
                anchors.top:    parent.top
Don Gagne's avatar
Don Gagne committed
55 56
                anchors.bottom: parent.bottom

57 58
                verticalAlignment:  Text.AlignVCenter
                horizontalAlignment:Text.AlignHCenter
Don Gagne's avatar
Don Gagne committed
59

60 61
                x:              parent.width - width
                width:          unitsLabelWidthGenerator.width
Don Gagne's avatar
Don Gagne committed
62

63
                text:           control.unitsLabel
64
                font.pointSize: ScreenTools.defaultFontPointSize
65
                font.family:    ScreenTools.normalFontFamily
66
                antialiasing:   true
67

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

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

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