Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++
1.2 KB
Raw Blame
/*
 *  SPDX-FileCopyrightText: 2024 Deif Lou <[email protected]>
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 */
/*
    \qmltype TextInputWithPrefixAndSuffix
    This is a Text Input which holds a prefix and a suffix.

 */
TextInputWithSelectionRange {
    /*
        \qmlproperty prefix
        A string that will be prefixed to the current input.
    */
    property string prefix: ""
    /*
        \qmlproperty suffix
        A string that will be suffixed to the current input.
    */
    property string suffix: ""
    /*
        \qmlproperty contentsText
        The current input text.
    */
    property string contentsText: ""

    selectionRangeStart: prefix.length
    selectionRangeEnd: text.length - suffix.length

    text: prefix + contentsText + suffix

    onTextChanged: {
        const startPos = text.startsWith(prefix) ? prefix.length : 0;
        const endPos = text.endsWith(suffix) ? text.length - suffix.length : text.length;
        contentsText = text.slice(startPos, endPos);
    }

    function selectContents() {
        const startPos = text.startsWith(prefix) ? prefix.length : 0;
        const endPos = text.endsWith(suffix) ? text.length - suffix.length : text.length;
        select(startPos, endPos);
    }
}