Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

quickshell/nuguland/PopupTextField.qml

Raw
import QtQuick
import QtQuick.Templates as T

Rectangle {
    id: root

    required property Theme theme
    property alias text: fieldInput.text
    property alias echoMode: fieldInput.echoMode
    property alias inputMethodHints: fieldInput.inputMethodHints
    // Local editors may consume Escape before a host WindowShortcut.
    property bool localEscape: false
    property string placeholderText: ""
    property string accessibleName: placeholderText
    property string icon: ""
    property string fontFamily: theme.fontSans
    property int fontPixelSize: theme.textBody
    property alias input: fieldInput
    readonly property bool hintVisible: hint.visible
    signal accepted
    signal cancelled
    signal edited(string text)

    implicitWidth: 220
    implicitHeight: 38
    radius: theme.radiusControl
    opacity: enabled ? 1 : 0.48
    color: theme.withAlpha(theme.content.backdrop, fieldInput.activeFocus ? 0.9 : 0.68)
    border.width: fieldInput.activeFocus ? 2 : 1
    border.color: fieldInput.activeFocus ? theme.content.focus : theme.withAlpha(theme.ui.minor, 0.3)

    T.TextField {
        id: fieldInput

        anchors.fill: parent
        leftPadding: root.icon.length > 0 ? 34 : root.theme.spaceMd
        rightPadding: root.theme.spaceMd
        topPadding: 0
        bottomPadding: 0
        verticalAlignment: TextInput.AlignVCenter
        color: root.theme.content.normal
        selectionColor: root.theme.ui.accent
        selectedTextColor: root.theme.content.backdrop
        font.family: root.fontFamily
        font.pixelSize: root.fontPixelSize
        activeFocusOnTab: true
        selectByMouse: true
        clip: true
        Accessible.name: root.accessibleName
        onAccepted: root.accepted()
        onTextEdited: root.edited(text)
        Keys.onPressed: event => {
            if (event.isAutoRepeat && (event.key === Qt.Key_Return || event.key === Qt.Key_Enter))
                event.accepted = true;
        }
        Keys.onShortcutOverride: event => {
            if (root.localEscape && event.key === Qt.Key_Escape)
                event.accepted = true;
        }
        Keys.onEscapePressed: event => {
            event.accepted = true;
            if (!event.isAutoRepeat)
                root.cancelled();
        }
    }

    Text {
        visible: root.icon.length > 0
        anchors.left: parent.left
        anchors.leftMargin: root.theme.spaceMd
        anchors.verticalCenter: parent.verticalCenter
        color: root.theme.ui.minor
        font.family: root.theme.fontIcon
        font.pixelSize: 13
        text: root.icon
        Accessible.ignored: true
    }

    NuguText {
        id: hint

        anchors.left: parent.left
        anchors.right: parent.right
        anchors.leftMargin: fieldInput.leftPadding
        anchors.rightMargin: fieldInput.rightPadding
        anchors.verticalCenter: parent.verticalCenter
        visible: fieldInput.text.length === 0
        theme: root.theme
        variant: "meta"
        text: root.placeholderText
        Accessible.ignored: true
    }
}