Skip to content
Snippets Groups Projects
QGCTextField.qml 1.82 KiB
Newer Older
  • Learn to ignore specific revisions
  • 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: ""
    
        property var __qgcPal: QGCPalette { colorGroupEnabled: enabled }
    
        textColor: __qgcPal.textFieldText
    
        height: ScreenTools.isMobile ? ScreenTools.defaultFontPixelHeight * 3 * 0.75 : implicitHeight
    
    Don Gagne's avatar
    Don Gagne committed
        Label {
            id: unitsLabelWidthGenerator
    
            text: unitsLabel
    
    Don Gagne's avatar
    Don Gagne committed
            width: contentWidth + ((parent.__contentHeight/3)*2)
            visible: false
    
            antialiasing: true
    
    Don Gagne's avatar
    Don Gagne committed
        }
    
    Don Gagne's avatar
    Don Gagne committed
        style: TextFieldStyle {
            background: Item {
                id: backgroundItem
    
                Rectangle {
                    anchors.fill: parent
                    anchors.bottomMargin: -1
                    color: "#44ffffff"
                }
    
                Rectangle {
                    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
                    anchors.bottom: parent.bottom
    
                    verticalAlignment: Text.AlignVCenter
                    horizontalAlignment: Text.AlignHCenter
    
                    x: parent.width - width
                    width: unitsLabelWidthGenerator.width
    
    
                    text: control.unitsLabel
    
    Don Gagne's avatar
    Don Gagne committed
                    font.pixelSize: ScreenTools.defaultFontPixelSize
    
                    antialiasing:   true
    
    Don Gagne's avatar
    Don Gagne committed
                    color: control.textColor
                    visible: control.showUnits
                }
            }
    
            padding.right: control.showUnits ? unitsLabelWidthGenerator.width : control.__contentHeight/3
        }
    
    Don Gagne's avatar
    Don Gagne committed
    
        onActiveFocusChanged: {
            if (activeFocus) {
                selectAll()
            }
        }