/*SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>SPDX-License-Identifier: GPL-2.0-or-later*/pragma ComponentBehavior: Boundimport QtQuickimport QtQuick.Layoutsimport QtQuick.Windowimport QtQuick.Controls as QQC2import org.kde.plasma.core as PlasmaCoreimport org.kde.plasma.components as PC3import org.kde.kirigami as Kirigamiimport org.kde.plasma.plasmoidPlasmoidItem {id: rootenum LayoutType {HorizontalPanel,VerticalPanel,Desktop,DesktopCompact}property var errorInformationreadonly property real minimumPreferredWidth: Kirigami.Units.gridUnit * 12readonly property real minimumPreferredHeight: Kirigami.Units.gridUnit * 12// To properly show the error message in panelreadonly property int layoutForm: {if (fullRepresentationItem.width >= root.minimumPreferredWidth) {if (fullRepresentationItem.height >= root.minimumPreferredHeight) {return AppletError.Desktop;} else if (fullRepresentationItem.height >= Kirigami.Units.iconSizes.huge + root.fullRepresentationItem.buttonLayout.implicitHeight) {return AppletError.DesktopCompact;}}return Plasmoid.formFactor === PlasmaCore.Types.Vertical ? AppletError.VerticalPanel : AppletError.HorizontalPanel;}preloadFullRepresentation: truefullRepresentation: GridLayout {id: fullRepproperty alias buttonLayout: buttonLayoutLayout.minimumWidth: {switch (root.layoutForm) {case AppletError.Desktop:case AppletError.DesktopCompact:// [Icon] [Text]// [Button]// [Information]return Math.max(root.minimumPreferredWidth, buttonLayout.implicitWidth);case AppletError.VerticalPanel:// [Icon]// [Copy]// [Open]return Math.max(headerIcon.implicitWidth, buttonLayout.implicitWidth);case AppletError.HorizontalPanel:// [Icon] [Copy] [Open]return headingLayout.implicitWidth + rowSpacing + buttonLayout.implicitWidth;}}Layout.minimumHeight: {switch (root.layoutForm) {case AppletError.Desktop:return headingLayout.implicitHeight + fullRep.columnSpacing + buttonLayout.implicitHeight + fullRep.columnSpacing + fullContentView.implicitHeight;case AppletError.DesktopCompact:return Math.max(headingLayout.implicitHeight, buttonLayout.implicitHeight);case AppletError.VerticalPanel:return headingLayout.implicitHeight + fullRep.columnSpacing + buttonLayout.implicitHeight;case AppletError.HorizontalPanel:return Math.max(headingLayout.implicitHeight, buttonLayout.implicitHeight);}}// Same as systray popupsLayout.preferredWidth: Kirigami.Units.gridUnit * 24Layout.preferredHeight: Kirigami.Units.gridUnit * 24Layout.maximumWidth: Kirigami.Units.gridUnit * 34Layout.maximumHeight: Kirigami.Units.gridUnit * 34rowSpacing: textArea.topPaddingcolumnSpacing: rowSpacingflow: {switch (root.layoutForm) {case AppletError.HorizontalPanel:return GridLayout.LeftToRight;default:return GridLayout.TopToBottom;}}RowLayout {id: headingLayoutLayout.margins: root.layoutForm !== AppletError.Desktop ? 0 : Kirigami.Units.gridUnitLayout.maximumWidth: fullRep.widthspacing: 0Layout.fillWidth: trueKirigami.Icon {id: headerIconimplicitWidth: Math.min(Kirigami.Units.iconSizes.huge, fullRep.width, fullRep.height)implicitHeight: implicitWidthactiveFocusOnTab: truesource: "dialog-error"Accessible.description: heading.textPlasmaCore.ToolTipArea {anchors.fill: parentenabled: !heading.visible || heading.truncatedmainText: heading.texttextFormat: Text.PlainText}}Kirigami.Heading {id: headingvisible: root.layoutForm !== AppletError.VerticalPanel// Descent is equal to the amount of space above and below capital letters.// Add descent to the sides to make the spacing around Latin text look more even.leftPadding: headingFontMetrics.descentrightPadding: headingFontMetrics.descenttext: root.errorInformation ? root.errorInformation.compactError : "No error information."textFormat: Text.PlainTextlevel: 2wrapMode: Text.WraphorizontalAlignment: Text.AlignHCenterverticalAlignment: Text.AlignVCenterelide: Text.ElideRightLayout.fillWidth: trueLayout.maximumHeight: headerIcon.implicitHeightFontMetrics {id: headingFontMetricsfont: heading.font}}}GridLayout {id: buttonLayoutLayout.alignment: Qt.AlignCenterrowSpacing: fullRep.rowSpacingcolumnSpacing: parent.columnSpacingflow: {switch (root.layoutForm) {case AppletError.HorizontalPanel:case AppletError.VerticalPanel:return fullRep.flow;default:return GridLayout.LeftToRight;}}PC3.Button {id: copyButtondisplay: root.layoutForm === AppletError.HorizontalPanel || root.layoutForm === AppletError.VerticalPanel ? PC3.AbstractButton.IconOnly : PC3.AbstractButton.TextBesideIcontext: i18ndc("plasma_shell_org.kde.plasma.desktop", "@action:button", "Copy to Clipboard")icon.name: "edit-copy"onClicked: {textArea.selectAll()textArea.copy()textArea.deselect()}PlasmaCore.ToolTipArea {anchors.fill: parentenabled: parent.display === PC3.AbstractButton.IconOnlymainText: parent.texttextFormat: Text.PlainText}}Loader {id: compactContentLoaderactive: root.layoutForm !== AppletError.Desktopvisible: activesourceComponent: PC3.Button {display: copyButton.displayicon.name: "window-new"text: i18ndc("plasma_shell_org.kde.plasma.desktop", "@action:button opens dialog", "View Error Detailsβ¦")checked: dialog.visibleonClicked: dialog.visible = !dialog.visiblePlasmaCore.ToolTipArea {anchors.fill: parentenabled: parent.display === PC3.AbstractButton.IconOnlymainText: parent.texttextFormat: Text.PlainText}QQC2.ApplicationWindow {id: dialogflags: Qt.Dialog | Qt.WindowStaysOnTopHint | Qt.WindowMinMaxButtonsHint | Qt.WindowCloseButtonHintminimumWidth: dialogFontMetrics.height * 12+ dialogTextArea.leftPadding + dialogTextArea.rightPaddingminimumHeight: dialogFontMetrics.height * 12+ dialogTextArea.topPadding + dialogTextArea.bottomPaddingwidth: Kirigami.Units.gridUnit * 24height: Kirigami.Units.gridUnit * 24color: palette.baseQQC2.ScrollView {id: dialogScrollViewanchors.fill: parentQQC2.TextArea {id: dialogTextArea// HACK: silence binding loop warnings.// contentWidth seems to be causing the binding loop,// but contentWidth is read-only and we have no control// over how it is calculated.implicitWidth: 0wrapMode: TextEdit.Wraptext: textArea.textfont.family: "monospace"readOnly: trueselectByMouse: truebackground: nullFontMetrics {id: dialogFontMetricsfont: dialogTextArea.font}}background: null}}}}}PC3.ScrollView {id: fullContentView// Not handled by a Loader because we need// TextEdit::copy() to copy to clipboard.visible: !compactContentLoader.activeLayout.fillHeight: trueLayout.fillWidth: truePC3.TextArea {id: textArea// HACK: silence binding loop warnings.// contentWidth seems to be causing the binding loop,// but contentWidth is read-only and we have no control// over how it is calculated.implicitWidth: 0wrapMode: TextEdit.Wraptext: root.errorInformation && root.errorInformation.errors ?root.errorInformation.errors.join("\n\n")// This is just to suppress warnings. Users should never see this.: "No error information."font.family: "monospace"readOnly: trueselectByMouse: true}}}}