QGCTextField.qml 4.15 KB
Newer Older
1 2 3 4
import QtQuick                  2.2
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.2
import QtQuick.Layouts          1.2
5

6 7
import QGroundControl.Palette       1.0
import QGroundControl.ScreenTools   1.0
8 9

TextField {
10 11
    id: root

12 13
    property bool   showUnits:  false
    property bool   showHelp:   false
14
    property string unitsLabel: ""
15

16 17 18 19
    signal helpClicked

    property real _helpLayoutWidth: 0

20 21 22 23 24 25
    Component.onCompleted: {
        if (typeof qgcTextFieldforwardKeysTo !== 'undefined') {
            root.Keys.forwardTo = [qgcTextFieldforwardKeysTo]
        }
    }

26
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
27

28
    textColor:          qgcPal.textFieldText
Don Gagne's avatar
Don Gagne committed
29
    height:             Math.round(Math.max(25, ScreenTools.defaultFontPixelHeight * (ScreenTools.isMobile ? 2.5 : 1.2)))
30

Don Gagne's avatar
Don Gagne committed
31
    QGCLabel {
32 33
        id:             unitsLabelWidthGenerator
        text:           unitsLabel
dogmaphobic's avatar
dogmaphobic committed
34
        width:          contentWidth + parent.__contentHeight * 0.666
35 36
        visible:        false
        antialiasing:   true
Don Gagne's avatar
Don Gagne committed
37
    }
38

Don Gagne's avatar
Don Gagne committed
39
    style: TextFieldStyle {
40
        font.pointSize: ScreenTools.defaultFontPointSize
Don Gagne's avatar
Don Gagne committed
41 42 43
        background: Item {
            id: backgroundItem

44 45
            property bool showHelp: control.showHelp && control.activeFocus

Don Gagne's avatar
Don Gagne committed
46
            Rectangle {
dogmaphobic's avatar
dogmaphobic committed
47 48 49
                anchors.fill:           parent
                anchors.bottomMargin:   -1
                color:                  "#44ffffff"
Don Gagne's avatar
Don Gagne committed
50 51 52
            }

            Rectangle {
dogmaphobic's avatar
dogmaphobic committed
53 54
                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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
            RowLayout {
                id:                     unitsHelpLayout
                anchors.top:            parent.top
                anchors.bottom:         parent.bottom
                anchors.rightMargin:    backgroundItem.showHelp ? 0 : control.__contentHeight * 0.333
                anchors.right:          parent.right
                spacing:                4

                Component.onCompleted:  control._helpLayoutWidth = unitsHelpLayout.width
                onWidthChanged:         control._helpLayoutWidth = unitsHelpLayout.width

                Text {
                    anchors.verticalCenter: parent.verticalCenter
                    text:                   control.unitsLabel
                    font.pointSize:         backgroundItem.showHelp ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize
                    font.family:            ScreenTools.normalFontFamily
                    antialiasing:           true
                    color:                  control.textColor
                    visible:                control.showUnits
                }

                Rectangle {
                    anchors.margins:    2
                    anchors.top:        parent.top
                    anchors.bottom:     parent.bottom
                    anchors.right:      parent.right
                    width:              height * 0.75
                    color:              control.textColor
                    radius:             2
                    visible:            backgroundItem.showHelp

                    QGCLabel {
                        anchors.fill:           parent
                        verticalAlignment:      Text.AlignVCenter
                        horizontalAlignment:    Text.AlignHCenter
                        color:                  qgcPal.textField
                        text:                   "?"
                    }
                }
            }
98

99
            MouseArea {
Don Gagne's avatar
Don Gagne committed
100 101 102 103
                anchors.margins:    ScreenTools.isMobile ? -(ScreenTools.defaultFontPixelWidth * 0.66) : 0 // Larger touch area for mobile
                anchors.fill:       unitsHelpLayout
                enabled:            control.activeFocus
                onClicked:          root.helpClicked()
Don Gagne's avatar
Don Gagne committed
104 105 106
            }
        }

107
        padding.right: control._helpLayoutWidth //control.showUnits ? unitsLabelWidthGenerator.width : control.__contentHeight * 0.333
Don Gagne's avatar
Don Gagne committed
108
    }
Don Gagne's avatar
Don Gagne committed
109 110

    onActiveFocusChanged: {
Don Gagne's avatar
Don Gagne committed
111
        if (!ScreenTools.isMobile && activeFocus) {
Don Gagne's avatar
Don Gagne committed
112 113 114
            selectAll()
        }
    }
115
}