Commit f4cd31e7 authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

desktoppackage: improve applet error message in panel

1. Hide button text when there is not enough space
2. Use different flows for vertical panels and horizontal panels
parent 8fd8101b
Pipeline #230913 canceled with stage
in 1 minute and 20 seconds
......@@ -11,40 +11,110 @@ import QtQuick.Controls 2.15 as QQC2
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PC3
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.plasmoid 2.0
ColumnLayout {
GridLayout {
id: root
enum LayoutType {
HorizontalPanel,
VerticalPanel,
Desktop,
DesktopCompact
}
property var reason
property var errorInformation: {}
readonly property real minimumPreferredWidth: PlasmaCore.Units.gridUnit * 12
readonly property real minimumPreferredHeight: PlasmaCore.Units.gridUnit * 12
Layout.minimumWidth: Math.max(buttonLayout.implicitWidth, headerIcon.implicitWidth + PlasmaCore.Units.gridUnit * 2)
Layout.minimumHeight: headingLayout.implicitHeight + spacing + buttonLayout.implicitHeight + PlasmaCore.Units.gridUnit * 2
// To properly show the error message in panel
readonly property int layoutForm: {
if (root.width >= root.minimumPreferredWidth) {
if (root.height >= root.minimumPreferredHeight) {
return AppletError.Desktop;
} else if (root.height >= PlasmaCore.Units.iconSizes.huge + buttonLayout.implicitHeight) {
return AppletError.DesktopCompact;
}
}
return Plasmoid.formFactor === PlasmaCore.Types.Vertical ? AppletError.VerticalPanel : AppletError.HorizontalPanel;
}
Layout.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 + root.rowSpacing + buttonLayout.implicitWidth;
}
}
Layout.minimumHeight: {
switch (root.layoutForm) {
case AppletError.Desktop:
return headingLayout.implicitHeight + root.columnSpacing + buttonLayout.implicitHeight + root.columnSpacing + fullContentView.implicitHeight;
case AppletError.DesktopCompact:
return Math.max(headingLayout.implicitHeight, buttonLayout.implicitHeight);
case AppletError.VerticalPanel:
return headingLayout.implicitHeight + root.columnSpacing + buttonLayout.implicitHeight;
case AppletError.HorizontalPanel:
return Math.max(headingLayout.implicitHeight, buttonLayout.implicitHeight);
}
}
// Same as systray popups
Layout.preferredWidth: PlasmaCore.Units.gridUnit * 24
Layout.preferredHeight: PlasmaCore.Units.gridUnit * 24
spacing: textArea.topPadding
rowSpacing: textArea.topPadding
columnSpacing: rowSpacing
flow: {
switch (root.layoutForm) {
case AppletError.HorizontalPanel:
return GridLayout.LeftToRight;
default:
return GridLayout.TopToBottom;
}
}
RowLayout {
id: headingLayout
Layout.margins: root.layoutForm !== AppletError.Desktop ? 0 : PlasmaCore.Units.gridUnit
Layout.maximumWidth: root.width
spacing: 0
Layout.margins: PlasmaCore.Units.gridUnit
Layout.minimumWidth: headerIcon.implicitWidth
Layout.minimumHeight: headerIcon.implicitHeight
Layout.maximumHeight: headerIcon.implicitHeight
Layout.fillWidth: true
PlasmaCore.IconItem {
id: headerIcon
implicitWidth: PlasmaCore.Units.iconSizes.huge
implicitHeight: PlasmaCore.Units.iconSizes.huge
implicitWidth: Math.min(PlasmaCore.Units.iconSizes.huge, root.width, root.height)
implicitHeight: implicitWidth
activeFocusOnTab: true
source: "dialog-error"
Accessible.description: heading.text
PlasmaCore.ToolTipArea {
anchors.fill: parent
enabled: !heading.visible || heading.truncated
mainText: heading.text
textFormat: Text.PlainText
}
}
PlasmaExtras.Heading {
id: heading
visible: 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.descent
......@@ -60,6 +130,7 @@ ColumnLayout {
elide: Text.ElideRight
Layout.fillWidth: true
Layout.maximumHeight: headerIcon.implicitHeight
FontMetrics {
id: headingFontMetrics
font: heading.font
......@@ -67,12 +138,26 @@ ColumnLayout {
}
}
RowLayout {
GridLayout {
id: buttonLayout
spacing: parent.spacing
Layout.alignment: Qt.AlignCenter
rowSpacing: parent.rowSpacing
columnSpacing: parent.columnSpacing
flow: {
switch (root.layoutForm) {
case AppletError.HorizontalPanel:
case AppletError.VerticalPanel:
return root.flow;
default:
return GridLayout.LeftToRight;
}
}
PC3.Button {
id: copyButton
display: root.layoutForm === AppletError.HorizontalPanel || root.layoutForm === AppletError.VerticalPanel ? PC3.AbstractButton.IconOnly : PC3.AbstractButton.TextBesideIcon
text: i18nd("plasma_shell_org.kde.plasma.desktop", "Copy to Clipboard")
icon.name: "edit-copy"
onClicked: {
......@@ -80,17 +165,33 @@ ColumnLayout {
textArea.copy()
textArea.deselect()
}
PlasmaCore.ToolTipArea {
anchors.fill: parent
enabled: parent.display === PC3.AbstractButton.IconOnly
mainText: parent.text
textFormat: Text.PlainText
}
}
Loader {
id: compactContentLoader
active: root.width < root.minimumPreferredWidth
|| root.height < root.minimumPreferredHeight
active: root.layoutForm !== AppletError.Desktop
visible: active
sourceComponent: PC3.Button {
display: copyButton.display
icon.name: "window-new"
text: i18nd("plasma_shell_org.kde.plasma.desktop", "View Error Details…")
checked: dialog.visible
onClicked: dialog.visible = !dialog.visible
PlasmaCore.ToolTipArea {
anchors.fill: parent
enabled: parent.display === PC3.AbstractButton.IconOnly
mainText: parent.text
textFormat: Text.PlainText
}
QQC2.ApplicationWindow {
id: dialog
flags: Qt.Dialog | Qt.WindowStaysOnTopHint | Qt.WindowMinMaxButtonsHint | Qt.WindowCloseButtonHint
......@@ -134,7 +235,7 @@ ColumnLayout {
id: fullContentView
// Not handled by a Loader because we need
// TextEdit::copy() to copy to clipboard.
visible: !compactContentLoader.visible
visible: !compactContentLoader.active
Layout.fillHeight: true
Layout.fillWidth: true
PC3.ScrollBar.horizontal.policy: PC3.ScrollBar.AlwaysOff
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment