SystemDialog.qml 3.11 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
 *  SPDX-FileCopyrightText: 2021 Devin Lin <espidev@gmail.com>
 *
 *  SPDX-License-Identifier: LGPL-2.0-or-later
 */

import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import QtQuick.Window 2.15
import QtGraphicalEffects 1.12
import org.kde.kirigami 2.18 as Kirigami

/**
 * Dialog used on desktop. Uses SSDs (as opposed to CSDs).
 */
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
17
Item {
18
19
    id: root

Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
20
    property alias mainItem: contentsControl.contentItem
21
    property alias mainText: titleHeading.text
22
23
    property alias subtitle: subtitleLabel.text
    property alias iconName: icon.source
24
    property list<Kirigami.Action> actions
25
    readonly property alias dialogButtonBox: footerButtonBox
26

Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
27
28
29
    property Window window
    implicitHeight: column.implicitHeight
    implicitWidth: column.implicitWidth
Nate Graham's avatar
Nate Graham committed
30
31
    readonly property real minimumHeight: column.Layout.minimumHeight + mainItem.implicitHeight
    readonly property real minimumWidth: column.Layout.minimumWidth + mainItem.implicitWidth
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
32
33
    readonly property int flags: Qt.Dialog
    property alias standardButtons: footerButtonBox.standardButtons
34
    readonly property int spacing: Kirigami.Units.largeSpacing // standard KDE dialog margins
35

Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
36
37
    function present() {
        window.show()
38
39
    }

40
41
    ColumnLayout {
        id: column
42
        anchors.fill: parent
43
44
45
46
47
        anchors.margins: root.spacing

        spacing: root.spacing

        // Header area
48
        RowLayout {
49
50
            spacing: root.spacing

51
            Kirigami.Icon {
52
53
                id: icon
                visible: source
54
55
56
                implicitWidth: Kirigami.Units.iconSizes.large
                implicitHeight: Kirigami.Units.iconSizes.large
            }
57

58
59
            ColumnLayout {
                Layout.fillWidth: true
60
61
62

                spacing: Kirigami.Units.smallSpacing

63
                Kirigami.Heading {
64
                    id: titleHeading
65
                    text: root.title
66
67
68
69
70
                    Layout.fillWidth: true
                    level: 2
                    wrapMode: Text.Wrap
                    elide: Text.ElideRight
                }
71

72
                Label {
73
                    id: subtitleLabel
74
75
76
                    Layout.fillWidth: true
                    wrapMode: Text.Wrap
                    elide: Text.ElideRight
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
77
                    visible: text.length > 0
78
79
80
                }
            }
        }
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
81

82
83
84
85
        // Main content area, to be provided by the implementation
        Control {
            id: contentsControl

Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
86
            Layout.fillWidth: true
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
            Layout.fillHeight: true
            leftPadding: 0
            rightPadding: 0
            bottomPadding: 0
            topPadding: 0
        }

        // Footer area with buttons
        DialogButtonBox {
            id: footerButtonBox

            Layout.fillWidth: true
            leftPadding: 0
            rightPadding: 0
            bottomPadding: 0
            topPadding: 0

            onAccepted: root.window.accept()
            onRejected: root.window.reject()
106

107
108
            Repeater {
                model: root.actions
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
109

110
111
                delegate: Button {
                    action: modelData
112
113
114
115
116
117
                }
            }
        }
    }
}