Skip to content

Commit

Permalink
Port away from deprecated API
Browse files Browse the repository at this point in the history
  • Loading branch information
popov895 committed Jan 31, 2023
1 parent c04b619 commit 7f1da43
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 55 deletions.
34 changes: 14 additions & 20 deletions contents/ui/FullRepresentation.qml
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Expand Down
39 changes: 9 additions & 30 deletions contents/ui/MessageDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,25 @@ ColumnLayout {
property var messageData: undefined
property bool showSeparator: false

spacing: units.smallSpacing
spacing: PlasmaCore.Units.smallSpacing

MessageItem {
Layout.fillWidth: true
iconSource: root.messageData.iconSource || ""
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
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions contents/ui/MessageItem.qml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,22 +7,31 @@ 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
}

PlasmaComponents3.Label {
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
}
}
}
4 changes: 2 additions & 2 deletions contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down

0 comments on commit 7f1da43

Please sign in to comment.