Skip to content
QGCTextField.qml 2.44 KiB
Newer Older
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

import QGroundControl.Palette 1.0
import QGroundControl.ScreenTools 1.0
Don Gagne's avatar
Don Gagne committed
    property bool showUnits: false
    property string unitsLabel: ""
    Component.onCompleted: {
        if (typeof qgcTextFieldforwardKeysTo !== 'undefined') {
            root.Keys.forwardTo = [qgcTextFieldforwardKeysTo]
        }
    }

    property var __qgcPal: QGCPalette { colorGroupEnabled: enabled }
dogmaphobic's avatar
dogmaphobic committed
    textColor:          __qgcPal.textFieldText
dogmaphobic's avatar
dogmaphobic committed
    height:             ScreenTools.isMobile ? Math.max(25, Math.round(ScreenTools.defaultFontPixelHeight * 2)) : Math.max(25, Math.round(ScreenTools.defaultFontPixelHeight * 1.2))
Don Gagne's avatar
Don Gagne committed
    Label {
        id:             unitsLabelWidthGenerator
        text:           unitsLabel
dogmaphobic's avatar
dogmaphobic committed
        width:          contentWidth + parent.__contentHeight * 0.666
        visible:        false
        antialiasing:   true
        font.family:    ScreenTools.normalFontFamily
Don Gagne's avatar
Don Gagne committed
    }
Don Gagne's avatar
Don Gagne committed
    style: TextFieldStyle {
dogmaphobic's avatar
dogmaphobic committed
        font.pointSize: ScreenTools.defaultFontPointSize
Don Gagne's avatar
Don Gagne committed
        background: Item {
            id: backgroundItem

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

            Rectangle {
dogmaphobic's avatar
dogmaphobic committed
                anchors.fill:           parent
                border.color:           control.activeFocus ? "#47b" : "#999"
                color:                  __qgcPal.textField
Don Gagne's avatar
Don Gagne committed
            }

            Text {
                id: unitsLabel

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

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

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

                text:           control.unitsLabel
dogmaphobic's avatar
dogmaphobic committed
                font.pointSize: ScreenTools.defaultFontPointSize
                font.family:    ScreenTools.normalFontFamily
                antialiasing:   true
                color:          control.textColor
                visible:        control.showUnits
Don Gagne's avatar
Don Gagne committed
            }
        }

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

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