InputSheet.qml 2.64 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/***************************************************************************
 *                                                                         *
 *   Copyright 2019 Jonah Brüchert                                         *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 *                                                                         *
 ***************************************************************************/

import QtQuick.Controls 2.1 as Controls
import QtQuick.Layouts 1.7
import QtQuick 2.7

import org.kde.kirigami 2.5 as Kirigami

Kirigami.OverlaySheet {
    id: inputSheet
    property string placeholderText
    property string description
    property string title
    property string text

    signal accepted

37 38 39 40 41 42
    function accept() {
        inputSheet.text = sheetTextField.text
        inputSheet.close()
        accepted()
    }

43 44 45
    header: Kirigami.Heading {
        text: title
    }
46

47
    ColumnLayout {
48 49 50 51 52 53 54 55 56 57
        Controls.Label {
            Layout.fillWidth: true
            text: inputSheet.description
            wrapMode: Text.WordWrap
        }

        Controls.TextField {
            id: sheetTextField
            Layout.fillWidth: true
            placeholderText: inputSheet.placeholderText
Rinigus Saar's avatar
Rinigus Saar committed
58
            text: inputSheet.text
59
            focus: true
Rinigus Saar's avatar
Rinigus Saar committed
60
            onAccepted: accept()
61 62 63
        }

        Controls.Button {
Pino Toscano's avatar
Pino Toscano committed
64
            text: i18n("OK")
65
            Layout.alignment: Qt.AlignRight
66
            onClicked: accept()
67 68
        }
    }
69 70 71 72 73

    onSheetOpenChanged: {
        if (sheetOpen)
            sheetTextField.forceActiveFocus()
    }
74
}