shift-shell/lookandfeel/contents/systemdialog/SystemDialog.qml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

166 lines
5.5 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: 2021-2024 Devin Lin <devin@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
2021-12-21 18:38:12 +00:00
import QtQuick
import QtQuick.Controls as QQC2
2024-07-27 03:47:44 +00:00
import QtQuick.Layouts
import QtQuick.Window
2023-03-03 05:48:24 +00:00
import Qt5Compat.GraphicalEffects
import QtQuick.Templates as T
import org.kde.kirigami as Kirigami
2021-12-21 18:38:12 +00:00
Item {
id: root
2024-07-27 03:47:44 +00:00
// -- public API: should match plasma-workspace implementation --
2021-12-21 18:38:12 +00:00
default property Item mainItem
property string mainText: ""
property string subtitle: ""
property string iconName
property list<T.Action> actions
readonly property alias dialogButtonBox: footerButtonBox
2021-12-21 18:38:12 +00:00
required property Window window
2021-12-21 18:38:12 +00:00
readonly property real minimumHeight: implicitWidth
readonly property real minimumWidth: implicitHeight
readonly property int flags: Qt.FramelessWindowHint | Qt.Dialog
property var standardButtons // footerButtonBox standardButtons
readonly property int spacing: Kirigami.Units.gridUnit
2024-07-27 03:47:44 +00:00
2021-12-21 18:38:12 +00:00
function present() {
window.showMaximized();
2021-12-21 18:38:12 +00:00
}
onWindowChanged: {
if (window) {
window.color = Qt.rgba(0, 0, 0, 0.5);
}
2021-12-21 18:38:12 +00:00
}
Item {
id: windowItem
2021-12-21 18:38:12 +00:00
anchors.centerIn: parent
// margins for shadow
implicitWidth: Math.min(Screen.width, control.implicitWidth + 2 * Kirigami.Units.gridUnit)
implicitHeight: Math.min(Screen.height, control.implicitHeight + 2 * Kirigami.Units.gridUnit)
// shadow
RectangularGlow {
id: glow
anchors.topMargin: 1
anchors.fill: control
cached: true
glowRadius: 2
cornerRadius: Kirigami.Units.gridUnit
spread: 0.1
color: Qt.rgba(0, 0, 0, 0.4)
}
2021-12-21 18:38:12 +00:00
// actual window
QQC2.Control {
id: control
anchors.fill: parent
anchors.margins: glow.cornerRadius
topPadding: root.spacing
bottomPadding: root.spacing
rightPadding: root.spacing
leftPadding: root.spacing
implicitWidth: Kirigami.Units.gridUnit * 22
background: Item {
Rectangle { // border
anchors.fill: parent
anchors.margins: -1
radius: Kirigami.Units.largeSpacing + 1
color: Qt.darker(Kirigami.Theme.backgroundColor, 1.5)
}
Rectangle { // background colour
anchors.fill: parent
radius: Kirigami.Units.largeSpacing
color: Kirigami.Theme.backgroundColor
2021-12-21 18:38:12 +00:00
}
}
contentItem: ColumnLayout {
id: column
spacing: 0
2021-12-21 18:38:12 +00:00
// header
2021-12-21 18:38:12 +00:00
Kirigami.Heading {
Layout.fillWidth: true
Layout.maximumWidth: root.window.maximumWidth
level: 3
font.weight: Font.Bold
2021-12-21 18:38:12 +00:00
text: root.mainText
wrapMode: Text.Wrap
elide: Text.ElideRight
horizontalAlignment: Text.AlignHCenter
}
QQC2.Label {
Layout.topMargin: Kirigami.Units.largeSpacing
Layout.bottomMargin: Kirigami.Units.largeSpacing
Layout.maximumWidth: root.window.maximumWidth
Layout.fillWidth: true
2021-12-21 18:38:12 +00:00
text: root.subtitle
visible: text.length > 0
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
2021-12-21 18:38:12 +00:00
}
Kirigami.Icon {
Layout.topMargin: Kirigami.Units.largeSpacing
Layout.alignment: Qt.AlignCenter
source: root.iconName
implicitWidth: Kirigami.Units.iconSizes.large
implicitHeight: Kirigami.Units.iconSizes.large
2021-12-21 18:38:12 +00:00
}
// content
QQC2.Control {
id: content
2021-12-21 18:38:12 +00:00
Layout.fillHeight: true
Layout.fillWidth: true
Layout.topMargin: Kirigami.Units.gridUnit
Layout.maximumWidth: root.window.maximumWidth
2021-12-21 18:38:12 +00:00
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
2021-12-21 18:38:12 +00:00
contentItem: root.mainItem
background: Item {}
2021-12-21 18:38:12 +00:00
}
QQC2.DialogButtonBox {
id: footerButtonBox
// ensure we never have no buttons, we always must have the cancel button available
standardButtons: (root.standardButtons === QQC2.DialogButtonBox.NoButton) ? QQC2.DialogButtonBox.Cancel : root.standardButtons
2024-07-27 03:47:44 +00:00
Layout.topMargin: Kirigami.Units.largeSpacing
2021-12-21 18:38:12 +00:00
Layout.fillWidth: true
Layout.maximumWidth: root.window.maximumWidth
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
onAccepted: root.window.accept()
onRejected: root.window.reject()
Repeater {
model: root.actions
delegate: QQC2.Button {
action: modelData
}
}
2021-12-21 18:38:12 +00:00
}
}
}
}
}