From 7f1da43aa82079176b7964712b1751545fc41a41 Mon Sep 17 00:00:00 2001 From: Eugene Popov Date: Mon, 30 Jan 2023 11:43:45 +0200 Subject: [PATCH] Port away from deprecated API --- contents/ui/FullRepresentation.qml | 34 +++++++++++--------------- contents/ui/MessageDelegate.qml | 39 +++++++----------------------- contents/ui/MessageItem.qml | 15 +++++++++--- contents/ui/main.qml | 4 +-- 4 files changed, 37 insertions(+), 55 deletions(-) diff --git a/contents/ui/FullRepresentation.qml b/contents/ui/FullRepresentation.qml index 8a2d141..d5f46fc 100644 --- a/contents/ui/FullRepresentation.qml +++ b/contents/ui/FullRepresentation.qml @@ -1,44 +1,38 @@ import QtQuick 2.0 import QtQuick.Layouts 1.1 +import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 3.0 as PlasmaComponents3 import org.kde.plasma.extras 2.0 as PlasmaExtras PlasmaComponents3.Page { - Layout.minimumHeight: units.gridUnit * 14 - Layout.minimumWidth: units.gridUnit * 14 + Layout.minimumHeight: PlasmaCore.Units.gridUnit * 14 + Layout.minimumWidth: PlasmaCore.Units.gridUnit * 14 Layout.preferredHeight: Layout.minimumHeight * 1.5 Layout.preferredWidth: Layout.minimumWidth * 1.5 PlasmaExtras.PlaceholderMessage { anchors.centerIn: parent - width: parent.width - 4 * units.largeSpacing + width: parent.width - 4 * PlasmaCore.Units.largeSpacing iconName: "checkmark" text: i18n("No messages") visible: !contentView.visible } - PlasmaExtras.ScrollArea { + PlasmaComponents3.ScrollView { id: contentView anchors.fill: parent - visible: repeater.count > 0 + visible: messageList.length > 0 - ColumnLayout { - spacing: units.smallSpacing - width: contentView.viewport.width + contentItem: ListView { + spacing: PlasmaCore.Units.smallSpacing + model: messageList - Repeater { - id: repeater - - model: messageList - - MessageDelegate { - Layout.fillWidth: true - Layout.leftMargin: units.smallSpacing - Layout.rightMargin: Layout.leftMargin - messageData: modelData - showSeparator: index < repeater.count - 1 - } + delegate: MessageDelegate { + x: PlasmaCore.Units.smallSpacing + width: ListView.view.width - 2 * x + messageData: modelData + showSeparator: index < messageList.length - 1 } } } diff --git a/contents/ui/MessageDelegate.qml b/contents/ui/MessageDelegate.qml index 4069f3a..122b30c 100644 --- a/contents/ui/MessageDelegate.qml +++ b/contents/ui/MessageDelegate.qml @@ -8,7 +8,7 @@ ColumnLayout { property var messageData: undefined property bool showSeparator: false - spacing: units.smallSpacing + spacing: PlasmaCore.Units.smallSpacing MessageItem { Layout.fillWidth: true @@ -16,38 +16,17 @@ ColumnLayout { text: root.messageData.text } - RowLayout { + ColumnLayout { Layout.fillWidth: true - spacing: units.smallSpacing - visible: repeater.count > 0 + spacing: PlasmaCore.Units.smallSpacing - Item { - Layout.fillHeight: true - width: units.iconSizes.small + Repeater { + model: root.messageData.children - PlasmaCore.SvgItem { - anchors.horizontalCenter: parent.horizontalCenter - elementId: "vertical-line" - svg: lineSvg - width: Math.min(parent.width, naturalSize.width * units.devicePixelRatio * 3) - height: parent.height - } - } - - ColumnLayout { - Layout.fillWidth: true - spacing: units.smallSpacing - - Repeater { - id: repeater - - model: root.messageData.children - - MessageItem { - Layout.fillWidth: true - iconSource: modelData.iconSource || "" - text: modelData.text - } + MessageItem { + Layout.fillWidth: true + iconSource: modelData.iconSource || "" + text: modelData.text } } } diff --git a/contents/ui/MessageItem.qml b/contents/ui/MessageItem.qml index 9fa4218..f8d0884 100644 --- a/contents/ui/MessageItem.qml +++ b/contents/ui/MessageItem.qml @@ -1,4 +1,4 @@ -import QtQuick 2.0 +import QtQuick 2.15 import QtQuick.Layouts 1.1 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 3.0 as PlasmaComponents3 @@ -7,13 +7,15 @@ RowLayout { property alias iconSource: iconItem.source property alias text: label.text - spacing: 2 * units.smallSpacing + spacing: 2 * PlasmaCore.Units.smallSpacing PlasmaCore.IconItem { id: iconItem - Layout.preferredWidth: units.iconSizes.smallMedium + Layout.preferredWidth: PlasmaCore.Units.iconSizes.smallMedium Layout.preferredHeight: Layout.preferredWidth + Layout.alignment: label.lineCount > 1 ? Qt.AlignTop : undefined + Layout.topMargin: label.lineCount > 1 ? Math.max(0, (labelTextMetrics.height - Layout.preferredHeight) / 2) : 0 visible: valid } @@ -21,8 +23,15 @@ RowLayout { id: label Layout.fillWidth: true + Layout.topMargin: lineCount > 1 ? Math.max(0, (iconItem.Layout.preferredHeight - labelTextMetrics.height) / 2) : 0 wrapMode: Text.WordWrap elide: Text.ElideRight maximumLineCount: 4 + + TextMetrics { + id: labelTextMetrics + font: label.font + text: label.text + } } } diff --git a/contents/ui/main.qml b/contents/ui/main.qml index a86f2b2..80ce0cd 100644 --- a/contents/ui/main.qml +++ b/contents/ui/main.qml @@ -43,8 +43,8 @@ Item { } Plasmoid.icon: "exception" - Plasmoid.switchWidth: units.gridUnit * 10 - Plasmoid.switchHeight: units.gridUnit * 10 + Plasmoid.switchWidth: PlasmaCore.Units.gridUnit * 10 + Plasmoid.switchHeight: PlasmaCore.Units.gridUnit * 10 Plasmoid.toolTipMainText: i18n("Power Management Inhibition") Plasmoid.compactRepresentation: CompactRepresentation {} Plasmoid.fullRepresentation: FullRepresentation {}