QGCTextField.qml 2.42 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 24 25 26 27 28 29 30
    textColor:  __qgcPal.textFieldText

    height: {
        if(ScreenTools.isTinyScreen)
            return ScreenTools.defaultFontPixelHeight * 3.5
        if(ScreenTools.isMobile)
            return ScreenTools.defaultFontPixelHeight * 2.5
        return implicitHeight
    }
31

Don Gagne's avatar
Don Gagne committed
32
    Label {
33 34 35 36 37 38
        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
39
    }
40

Don Gagne's avatar
Don Gagne committed
41
    style: TextFieldStyle {
dogmaphobic's avatar
dogmaphobic committed
42
        font.pixelSize: ScreenTools.defaultFontPixelSize
Don Gagne's avatar
Don Gagne committed
43 44 45 46 47 48 49 50 51 52 53 54
        background: Item {
            id: backgroundItem

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

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

            Text {
                id: unitsLabel

61
                anchors.top:    parent.top
Don Gagne's avatar
Don Gagne committed
62 63
                anchors.bottom: parent.bottom

64 65
                verticalAlignment:  Text.AlignVCenter
                horizontalAlignment:Text.AlignHCenter
Don Gagne's avatar
Don Gagne committed
66

67 68
                x:              parent.width - width
                width:          unitsLabelWidthGenerator.width
Don Gagne's avatar
Don Gagne committed
69

70
                text:           control.unitsLabel
Don Gagne's avatar
Don Gagne committed
71
                font.pixelSize: ScreenTools.defaultFontPixelSize
72
                font.family:    ScreenTools.normalFontFamily
73
                antialiasing:   true
74

75 76
                color:          control.textColor
                visible:        control.showUnits
Don Gagne's avatar
Don Gagne committed
77 78 79 80 81
            }
        }

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

    onActiveFocusChanged: {
Don Gagne's avatar
Don Gagne committed
84
        if (!ScreenTools.isMobile && activeFocus) {
Don Gagne's avatar
Don Gagne committed
85 86 87
            selectAll()
        }
    }
88
}