QGCTextField.qml 2.34 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
Don Gagne's avatar
Don Gagne committed
23
    height:             Math.round(Math.max(25, ScreenTools.defaultFontPixelHeight * (ScreenTools.isMobile ? 2.5 : 1.2)))
24

Don Gagne's avatar
Don Gagne committed
25
    QGCLabel {
26 27
        id:             unitsLabelWidthGenerator
        text:           unitsLabel
dogmaphobic's avatar
dogmaphobic committed
28
        width:          contentWidth + parent.__contentHeight * 0.666
29 30
        visible:        false
        antialiasing:   true
Don Gagne's avatar
Don Gagne committed
31
    }
32

Don Gagne's avatar
Don Gagne committed
33
    style: TextFieldStyle {
34
        font.pointSize: ScreenTools.defaultFontPointSize
Don Gagne's avatar
Don Gagne committed
35 36 37 38
        background: Item {
            id: backgroundItem

            Rectangle {
dogmaphobic's avatar
dogmaphobic committed
39 40 41
                anchors.fill:           parent
                anchors.bottomMargin:   -1
                color:                  "#44ffffff"
Don Gagne's avatar
Don Gagne committed
42 43 44
            }

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

            Text {
                id: unitsLabel

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

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

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

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

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

dogmaphobic's avatar
dogmaphobic committed
72
        padding.right: control.showUnits ? unitsLabelWidthGenerator.width : control.__contentHeight * 0.333
Don Gagne's avatar
Don Gagne committed
73
    }
Don Gagne's avatar
Don Gagne committed
74 75

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