Warning, /libraries/kirigami-addons/src/components/MessageDialog.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com>
0002 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
0003 // SPDX-License-Identifier: LGPL-2.1-or-later
0004 
0005 import QtQuick
0006 import QtQuick.Controls as QQC2
0007 import QtQuick.Templates as T
0008 import QtQuick.Layouts
0009 import org.kde.kirigami as Kirigami
0010 import org.kde.kirigamiaddons.components as Components
0011 import org.kde.kirigamiaddons.delegates as Delegates
0012 
0013 T.Dialog {
0014     id: root
0015 
0016     enum DialogType {
0017         Sucess,
0018         Warning,
0019         Error,
0020         Information
0021     }
0022 
0023     property int dialogType: MessageDialog.Sucess
0024 
0025     property string iconName: ''
0026 
0027     x: Math.round((parent.width - width) / 2)
0028     y: Math.round((parent.height - height) / 2)
0029 
0030     parent: applicationWindow().QQC2.Overlay.overlay
0031 
0032     width: Math.min(parent.width - Kirigami.Units.gridUnit * 4, Kirigami.Units.gridUnit * 30)
0033     height: Math.min(parent.height - Kirigami.Units.gridUnit * 4, Kirigami.Units.gridUnit * 30)
0034 
0035     z: Kirigami.OverlayZStacking.z
0036 
0037     implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
0038                             contentWidth + leftPadding + rightPadding,
0039                             implicitHeaderWidth,
0040                             implicitFooterWidth)
0041     implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
0042                              contentHeight + topPadding + bottomPadding
0043                              + (implicitHeaderHeight > 0 ? implicitHeaderHeight + spacing : 0)
0044                              + (implicitFooterHeight > 0 ? implicitFooterHeight + spacing : 0))
0045 
0046     padding: Kirigami.Units.gridUnit
0047 
0048     header: ColumnLayout {
0049         spacing: Kirigami.Units.largeSpacing
0050         Kirigami.Icon {
0051             source: {
0052                 if (root.iconName.length > 0) {
0053                     return root.iconName
0054                 }
0055                 switch (root.dialogType) {
0056                 case MessageDialog.Sucess:
0057                     return "data-sucess";
0058                 case MessageDialog.Warning:
0059                     return "data-warning";
0060                 case MessageDialog.Error:
0061                     return "data-error";
0062                 case MessageDialog.Information:
0063                     return "data-information";
0064                 default:
0065                     return "data-warning";
0066                 }
0067             }
0068             Layout.preferredWidth: Kirigami.Units.iconSizes.huge
0069             Layout.preferredHeight: Kirigami.Units.iconSizes.huge
0070             Layout.topMargin: Kirigami.Units.gridUnit
0071             Layout.alignment: Qt.AlignHCenter
0072         }
0073 
0074         Kirigami.Heading {
0075             text: root.title
0076             visible: root.title
0077             elide: QQC2.Label.ElideRight
0078             bottomPadding: 0
0079             horizontalAlignment: Text.AlignHCenter
0080 
0081             Layout.fillWidth: true
0082         }
0083     }
0084 
0085     enter: Transition {
0086         NumberAnimation {
0087             property: "opacity"
0088             from: 0
0089             to: 1
0090             easing.type: Easing.InOutQuad
0091             duration: Kirigami.Units.longDuration
0092         }
0093     }
0094 
0095     exit: Transition {
0096         NumberAnimation {
0097             property: "opacity"
0098             from: 1
0099             to: 0
0100             easing.type: Easing.InOutQuad
0101             duration: Kirigami.Units.longDuration
0102         }
0103     }
0104 
0105     modal: true
0106     focus: true
0107 
0108     background: Components.DialogRoundedBackground {}
0109     footer: Components.MessageDialogButtonBox {}
0110 
0111     // black background, fades in and out
0112     QQC2.Overlay.modal: Rectangle {
0113         color: Qt.rgba(0, 0, 0, 0.3)
0114 
0115         // the opacity of the item is changed internally by QQuickPopup on open/close
0116         Behavior on opacity {
0117             OpacityAnimator {
0118                 duration: Kirigami.Units.longDuration
0119                 easing.type: Easing.InOutQuad
0120             }
0121         }
0122     }
0123 }