Commit 2f4b27fc authored by Nate Graham's avatar Nate Graham
Browse files

Port to singleton Units

The context property version is slower to access and won't be supported
in Qt6. Let's port away from it and use the singleton version instead.

Here was my full process for making this change:

1. Made the change with `find . -name '*.qml' | xargs perl -pi -e 's/units\./PlasmaCore\.Units\./g'`
2. Verified no more occurrences with `grep -r " units."`
3. Made sure this didn't change any comments in a silly way by inspecting the output of `git diff | grep "+   " | grep "//"`
4. Manually inspected the full git diff to make sure there were no other unintentional or silly changes (there were none)
5. verified that all changed files have the PlasmaCore import with the correct name with `for FILE in `git status | grep modified | cut -d ":" -f 3`; do grep -q "as PlasmaCore" $FILE || echo "$FILE needs the PlasmaCore import"; done`
parent c22feb74
......@@ -30,8 +30,8 @@ import org.kde.plasma.components 3.0 as PlasmaComponents
Item {
id: analogclock
width: units.gridUnit * 15
height: units.gridUnit * 15
width: PlasmaCore.Units.gridUnit * 15
height: PlasmaCore.Units.gridUnit * 15
property int hours
property int minutes
property int seconds
......@@ -82,8 +82,8 @@ Item {
Plasmoid.compactRepresentation: Item {
id: representation
Layout.minimumWidth: plasmoid.formFactor !== PlasmaCore.Types.Vertical ? representation.height : units.gridUnit
Layout.minimumHeight: plasmoid.formFactor === PlasmaCore.Types.Vertical ? representation.width : units.gridUnit
Layout.minimumWidth: plasmoid.formFactor !== PlasmaCore.Types.Vertical ? representation.height : PlasmaCore.Units.gridUnit
Layout.minimumHeight: plasmoid.formFactor === PlasmaCore.Types.Vertical ? representation.width : PlasmaCore.Units.gridUnit
MouseArea {
anchors.fill: parent
......@@ -233,8 +233,8 @@ Item {
}
}
Plasmoid.fullRepresentation: PlasmaCalendar.MonthView {
Layout.minimumWidth: units.gridUnit * 20
Layout.minimumHeight: units.gridUnit * 20
Layout.minimumWidth: PlasmaCore.Units.gridUnit * 20
Layout.minimumHeight: PlasmaCore.Units.gridUnit * 20
today: dataSource.data["Local"]["DateTime"]
}
......
......@@ -71,8 +71,8 @@ Item {
Layout.minimumHeight: implicitHeight
flow: root.vertical ? GridLayout.TopToBottom : GridLayout.LeftToRight
rowSpacing: units.smallSpacing
columnSpacing: units.smallSpacing
rowSpacing: PlasmaCore.Units.smallSpacing
columnSpacing: PlasmaCore.Units.smallSpacing
Component.onCompleted: {
plasmoid.nativeInterface.buttonGrid = buttonGrid
......
......@@ -28,9 +28,9 @@ Rectangle {
property Item icon
color: PlasmaCore.ColorScope.backgroundColor
width: Math.max(units.gridUnit, label.width + units.devicePixelRatio * 2)
width: Math.max(PlasmaCore.Units.gridUnit, label.width + PlasmaCore.Units.devicePixelRatio * 2)
height: label.height
radius: units.devicePixelRatio * 3
radius: PlasmaCore.Units.devicePixelRatio * 3
opacity: 0.9
PlasmaComponents3.Label {
......@@ -43,7 +43,7 @@ Rectangle {
layer.effect: DropShadow {
horizontalOffset: 0
verticalOffset: 0
radius: units.devicePixelRatio * 2
radius: PlasmaCore.Units.devicePixelRatio * 2
samples: radius*2
color: Qt.rgba(0, 0, 0, 0.5)
}
......
......@@ -44,7 +44,7 @@ Item {
id: detailsLayout
property int leftColumnWidth: 0
width: units.gridUnit * 11
width: PlasmaCore.Units.gridUnit * 11
PlasmaComponents3.Label {
id: brokenBatteryLabel
......@@ -61,7 +61,7 @@ Item {
PlasmaComponents3.Label {
id: detailsLabel
width: modelData.value && parent ? parent.width - detailsLayout.leftColumnWidth - units.smallSpacing : detailsLayout.leftColumnWidth + units.smallSpacing
width: modelData.value && parent ? parent.width - detailsLayout.leftColumnWidth - PlasmaCore.Units.smallSpacing : detailsLayout.leftColumnWidth + PlasmaCore.Units.smallSpacing
wrapMode: Text.NoWrap
onPaintedWidthChanged: { // horrible HACK to get a column layout
if (paintedWidth > detailsLayout.leftColumnWidth) {
......@@ -89,7 +89,7 @@ Item {
Column {
width: parent.width
spacing: units.smallSpacing
spacing: PlasmaCore.Units.smallSpacing
PlasmaCore.ToolTipArea {
width: parent.width
......@@ -100,7 +100,7 @@ Item {
mainItem: Row {
id: batteryItemToolTip
property int _s: units.largeSpacing / 2
property int _s: PlasmaCore.Units.largeSpacing / 2
Layout.minimumWidth: implicitWidth + batteryItemToolTip._s
Layout.minimumHeight: implicitHeight + batteryItemToolTip._s * 2
......@@ -114,7 +114,7 @@ Item {
BatteryIcon {
x: batteryItemToolTip._s * 2
y: batteryItemToolTip._s
width: units.iconSizes.desktop // looks weird and small but that's what DefaultTooltip uses
width: PlasmaCore.Units.iconSizes.desktop // looks weird and small but that's what DefaultTooltip uses
height: width
batteryType: batteryIcon.batteryType
percent: batteryIcon.percent
......@@ -142,12 +142,12 @@ Item {
RowLayout {
id: infoRow
width: parent.width
spacing: units.gridUnit
spacing: PlasmaCore.Units.gridUnit
BatteryIcon {
id: batteryIcon
Layout.alignment: Qt.AlignTop
width: units.iconSizes.medium
width: PlasmaCore.Units.iconSizes.medium
height: width
batteryType: model.Type
percent: model.Percent
......@@ -158,11 +158,11 @@ Item {
Column {
Layout.fillWidth: true
Layout.alignment: batteryItem.isPresent ? Qt.AlignTop : Qt.AlignVCenter
spacing: units.smallSpacing
spacing: PlasmaCore.Units.smallSpacing
RowLayout {
width: parent.width
spacing: units.smallSpacing
spacing: PlasmaCore.Units.smallSpacing
PlasmaComponents3.Label {
id: batteryNameLabel
......@@ -201,7 +201,7 @@ Item {
property bool inListView: true
anchors {
left: parent.left
leftMargin: batteryIcon.width + units.gridUnit
leftMargin: batteryIcon.width + PlasmaCore.Units.gridUnit
right: parent.right
}
visible: !!item
......
......@@ -34,12 +34,12 @@ RowLayout {
property alias showPercentage: brightnessPercent.visible
signal moved()
spacing: units.gridUnit
spacing: PlasmaCore.Units.gridUnit
PlasmaCore.IconItem {
id: brightnessIcon
Layout.alignment: Qt.AlignTop
Layout.preferredWidth: units.iconSizes.medium
Layout.preferredWidth: PlasmaCore.Units.iconSizes.medium
Layout.preferredHeight: width
}
......@@ -52,7 +52,7 @@ RowLayout {
RowLayout {
id: infoRow
width: parent.width
spacing: units.smallSpacing
spacing: PlasmaCore.Units.smallSpacing
function percentage(from, to, value) {
return Math.floor(100 * (value - from) / (to - from));
......
......@@ -26,12 +26,12 @@ RowLayout {
property alias iconSource: iconItem.source
property alias text: label.text
spacing: units.smallSpacing
spacing: PlasmaCore.Units.smallSpacing
PlasmaCore.IconItem {
id: iconItem
Layout.preferredWidth: units.iconSizes.small
Layout.preferredHeight: units.iconSizes.small
Layout.preferredWidth: PlasmaCore.Units.iconSizes.small
Layout.preferredHeight: PlasmaCore.Units.iconSizes.small
visible: valid
}
......
......@@ -50,15 +50,15 @@ PlasmaComponents3.Page {
FocusScope {
anchors.fill: parent
anchors.topMargin: units.smallSpacing * 2
anchors.topMargin: PlasmaCore.Units.smallSpacing * 2
focus: true
Column {
id: settingsColumn
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - units.smallSpacing * 2
spacing: Math.round(units.gridUnit / 2)
width: parent.width - PlasmaCore.Units.smallSpacing * 2
spacing: Math.round(PlasmaCore.Units.gridUnit / 2)
BrightnessItem {
id: brightnessSlider
......@@ -113,17 +113,17 @@ PlasmaComponents3.Page {
anchors {
horizontalCenter: parent.horizontalCenter
top: settingsColumn.bottom
topMargin: units.gridUnit
leftMargin: units.smallSpacing
topMargin: PlasmaCore.Units.gridUnit
leftMargin: PlasmaCore.Units.smallSpacing
bottom: parent.bottom
}
width: parent.width - units.smallSpacing * 2
width: parent.width - PlasmaCore.Units.smallSpacing * 2
ListView {
id: batteryList
boundsBehavior: Flickable.StopAtBounds
spacing: Math.round(units.gridUnit / 2)
spacing: Math.round(PlasmaCore.Units.gridUnit / 2)
KeyNavigation.tab: brightnessSlider
KeyNavigation.backtab: pmSwitch
......
......@@ -33,7 +33,7 @@ ColumnLayout {
RowLayout {
Layout.fillWidth: true
Layout.leftMargin: units.smallSpacing
Layout.leftMargin: PlasmaCore.Units.smallSpacing
PlasmaComponents3.CheckBox {
id: pmCheckBox
......@@ -45,8 +45,8 @@ ColumnLayout {
ColumnLayout {
Layout.fillWidth: true
Layout.leftMargin: units.gridUnit + units.smallSpacing // width of checkbox and spacer
spacing: units.smallSpacing
Layout.leftMargin: PlasmaCore.Units.gridUnit + PlasmaCore.Units.smallSpacing // width of checkbox and spacer
spacing: PlasmaCore.Units.smallSpacing
InhibitionHint {
Layout.fillWidth: true
......
......@@ -29,8 +29,8 @@ import "logic.js" as Logic
Item {
id: batterymonitor
Plasmoid.switchWidth: units.gridUnit * 10
Plasmoid.switchHeight: units.gridUnit * 10
Plasmoid.switchWidth: PlasmaCore.Units.gridUnit * 10
Plasmoid.switchHeight: PlasmaCore.Units.gridUnit * 10
LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft
LayoutMirroring.childrenInherit: true
......@@ -209,8 +209,8 @@ Item {
Plasmoid.fullRepresentation: PopupDialog {
id: dialogItem
Layout.minimumWidth: units.iconSizes.medium * 9
Layout.minimumHeight: units.gridUnit * 15
Layout.minimumWidth: PlasmaCore.Units.iconSizes.medium * 9
Layout.minimumHeight: PlasmaCore.Units.gridUnit * 15
// TODO Probably needs a sensible preferredHeight too
model: plasmoid.expanded ? batteries : null
......
......@@ -26,8 +26,8 @@ import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.calendar 2.0
Item {
Plasmoid.switchWidth: units.gridUnit * 12
Plasmoid.switchHeight: units.gridUnit * 12
Plasmoid.switchWidth: PlasmaCore.Units.gridUnit * 12
Plasmoid.switchHeight: PlasmaCore.Units.gridUnit * 12
Plasmoid.toolTipMainText: Qt.formatDate(dataSource.data.Local.DateTime, "dddd")
Plasmoid.toolTipSubText: {
......@@ -41,8 +41,8 @@ Item {
return Qt.formatDate(dataSource.data.Local.DateTime, format)
}
Layout.minimumWidth: units.iconSizes.large
Layout.minimumHeight: units.iconSizes.large
Layout.minimumWidth: PlasmaCore.Units.iconSizes.large
Layout.minimumHeight: PlasmaCore.Units.iconSizes.large
PlasmaCore.DataSource {
id: dataSource
......@@ -114,7 +114,7 @@ Item {
// sizing taken from digital clock
readonly property int _minimumWidth: calendar.showWeekNumbers ? Math.round(_minimumHeight * 1.75) : Math.round(_minimumHeight * 1.5)
readonly property int _minimumHeight: units.gridUnit * 14
readonly property int _minimumHeight: PlasmaCore.Units.gridUnit * 14
Layout.preferredWidth: _minimumWidth
Layout.preferredHeight: Math.round(_minimumHeight * 1.5)
......
......@@ -95,7 +95,7 @@ ColumnLayout {
Item {
Layout.fillWidth: parent
Layout.fillHeight: parent
Layout.topMargin: units.smallSpacing
Layout.topMargin: PlasmaCore.Units.smallSpacing
Prison.Barcode {
id: barcodeItem
......
......@@ -132,7 +132,7 @@ ColumnLayout {
}
Layout.fillWidth: true
Layout.fillHeight: true
Layout.topMargin: units.smallSpacing
Layout.topMargin: PlasmaCore.Units.smallSpacing
onItemSelected: clipboardSource.service(uuid, "select")
onRemove: clipboardSource.service(uuid, "remove")
onEdit: clipboardSource.edit(uuid)
......
......@@ -32,8 +32,8 @@ Item {
signal clearSearchField
Plasmoid.switchWidth: units.gridUnit * 5
Plasmoid.switchHeight: units.gridUnit * 5
Plasmoid.switchWidth: PlasmaCore.Units.gridUnit * 5
Plasmoid.switchHeight: PlasmaCore.Units.gridUnit * 5
Plasmoid.status: isClipboardEmpty ? PlasmaCore.Types.PassiveStatus : PlasmaCore.Types.ActiveStatus
Plasmoid.toolTipMainText: i18n("Clipboard Contents")
Plasmoid.toolTipSubText: isClipboardEmpty ? i18n("Clipboard is empty") : clipboardSource.data["clipboard"]["current"]
......@@ -90,8 +90,8 @@ Item {
Plasmoid.fullRepresentation: PlasmaComponents3.Page {
id: dialogItem
Layout.minimumWidth: units.gridUnit * 5
Layout.minimumHeight: units.gridUnit * 5
Layout.minimumWidth: PlasmaCore.Units.gridUnit * 5
Layout.minimumHeight: PlasmaCore.Units.gridUnit * 5
focus: true
......
......@@ -35,8 +35,8 @@ PlasmaComponents3.Page {
id: fullRep
property bool spontaneousOpen: false
Layout.minimumWidth: units.gridUnit * 12
Layout.minimumHeight: units.gridUnit * 12
Layout.minimumWidth: PlasmaCore.Units.gridUnit * 12
Layout.minimumHeight: PlasmaCore.Units.gridUnit * 12
header: PlasmaExtras.BasicPlasmoidHeading {
visible: !(plasmoid.containmentDisplayHints & PlasmaCore.Types.ContainmentDrawsPlasmoidHeading) || devicenotifier.mountedRemovables > 1
......@@ -159,7 +159,7 @@ PlasmaComponents3.Page {
PlasmaExtras.PlaceholderMessage {
anchors.centerIn: parent
width: parent.width - (units.largeSpacing * 4)
width: parent.width - (PlasmaCore.Units.largeSpacing * 4)
text: plasmoid.configuration.removableDevices ? i18n("No removable devices attached") : i18n("No disks available")
visible: notifierDialog.count === 0 && !devicenotifier.pendingDelegateRemoval
}
......
......@@ -54,8 +54,8 @@ Item {
// causing our "No devices" heading to overlap with the remaining device
property int pendingDelegateRemoval: 0
Plasmoid.switchWidth: units.gridUnit * 10
Plasmoid.switchHeight: units.gridUnit * 10
Plasmoid.switchWidth: PlasmaCore.Units.gridUnit * 10
Plasmoid.switchHeight: PlasmaCore.Units.gridUnit * 10
Plasmoid.toolTipMainText: filterModel.count > 0 && filterModel.get(0) ? i18n("Most Recent Device") : i18n("No Devices Available")
Plasmoid.toolTipSubText: {
......@@ -96,8 +96,8 @@ Item {
Plasmoid.compactRepresentation: PlasmaCore.IconItem {
source: devicenotifier.popupIcon
width: units.iconSizes.medium;
height: units.iconSizes.medium;
width: PlasmaCore.Units.iconSizes.medium;
height: PlasmaCore.Units.iconSizes.medium;
active: compactMouse.containsMouse
MouseArea {
id: compactMouse
......
......@@ -39,7 +39,7 @@ PlasmaComponents3.Page {
Layout.maximumWidth: _minimumWidth
Layout.maximumHeight: _minimumHeight
readonly property int paddings: units.smallSpacing
readonly property int paddings: PlasmaCore.Units.smallSpacing
readonly property bool showAgenda: PlasmaCalendar.EventPluginsManager.enabledPlugins.length > 0
readonly property bool showClocks: plasmoid.configuration.selectedTimeZones.length > 1
......@@ -113,8 +113,8 @@ PlasmaComponents3.Page {
// it, erroneously expecting to never be in a Layout
Item {
Layout.fillWidth: true
Layout.minimumHeight: units.gridUnit * 22
Layout.minimumWidth: units.gridUnit * 22
Layout.minimumHeight: PlasmaCore.Units.gridUnit * 22
Layout.minimumWidth: PlasmaCore.Units.gridUnit * 22
PlasmaCalendar.MonthView {
id: monthView
......@@ -153,7 +153,7 @@ PlasmaComponents3.Page {
visible: calendar.showAgenda || calendar.showClocks
Layout.minimumWidth: units.gridUnit * 14
Layout.minimumWidth: PlasmaCore.Units.gridUnit * 14
// Agenda view stuff
// -----------------
......@@ -177,8 +177,8 @@ PlasmaComponents3.Page {
Layout.fillWidth: true
Layout.fillHeight: true
Layout.minimumHeight: units.gridUnit * 4
Layout.leftMargin: -units.smallSpacing
Layout.minimumHeight: PlasmaCore.Units.gridUnit * 4
Layout.leftMargin: -PlasmaCore.Units.smallSpacing
function formatDateWithoutYear(date) {
// Unfortunatelly Qt overrides ECMA's Date.toLocaleDateString(),
......@@ -312,7 +312,7 @@ PlasmaComponents3.Page {
columns: 3
rows: 2
rowSpacing: 0
columnSpacing: 2 * units.smallSpacing
columnSpacing: 2 * PlasmaCore.Units.smallSpacing
width: parent.width
......@@ -325,7 +325,7 @@ PlasmaComponents3.Page {
Layout.fillHeight: true
color: modelData.eventColor
width: 5 * units.devicePixelRatio
width: 5 * PlasmaCore.Units.devicePixelRatio
visible: modelData.eventColor !== ""
}
......@@ -408,8 +408,8 @@ PlasmaComponents3.Page {
anchors.fill: holidaysView
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
anchors.leftMargin: units.largeSpacing
anchors.rightMargin: units.largeSpacing
anchors.leftMargin: PlasmaCore.Units.largeSpacing
anchors.rightMargin: PlasmaCore.Units.largeSpacing
text: monthView.isToday(monthView.currentDate) ? i18n("No events for today")
: i18n("No events for this day");
level: 3
......@@ -467,7 +467,7 @@ PlasmaComponents3.Page {
Layout.fillWidth: true
Layout.fillHeight: !agenda.visible
Layout.leftMargin: -units.smallSpacing
Layout.leftMargin: -PlasmaCore.Units.smallSpacing
ListView {
id: clocksList
......@@ -493,7 +493,7 @@ PlasmaComponents3.Page {
separatorVisible: false
width: clocksList.width
height: units.gridUnit + units.smallSpacing
height: PlasmaCore.Units.gridUnit + PlasmaCore.Units.smallSpacing
RowLayout {
anchors.fill: parent
......
......@@ -114,7 +114,7 @@ Item {
height: timeLabel.height + (main.showDate || timezoneLabel.visible ? 0.8 * timeLabel.height : 0)
width: Math.max(timeLabel.paintedWidth + (main.showDate ? timezoneLabel.paintedWidth : 0),
timezoneLabel.paintedWidth, dateLabel.paintedWidth) + units.smallSpacing * 2
timezoneLabel.paintedWidth, dateLabel.paintedWidth) + PlasmaCore.Units.smallSpacing * 2
}
PropertyChanges {
......@@ -343,8 +343,8 @@ Item {
target: main
Layout.fillHeight: false
Layout.fillWidth: false
Layout.minimumWidth: units.gridUnit * 3
Layout.minimumHeight: units.gridUnit * 3
Layout.minimumWidth: PlasmaCore.Units.gridUnit * 3
Layout.minimumHeight: PlasmaCore.Units.gridUnit * 3
}
PropertyChanges {
......@@ -384,7 +384,7 @@ Item {
height: 0.7 * timeLabel.height
font.pixelSize: 1024
width: Math.max(timeLabel.contentWidth, units.gridUnit * 3)
width: Math.max(timeLabel.contentWidth, PlasmaCore.Units.gridUnit * 3)
verticalAlignment: Text.AlignVCenter
fontSizeMode: Text.Fit
......@@ -478,7 +478,7 @@ Item {
verticalItemAlignment: Grid.AlignVCenter
flow: Grid.TopToBottom
columnSpacing: units.smallSpacing
columnSpacing: PlasmaCore.Units.smallSpacing
Rectangle {
height: 0.8 * sizehelper.height
......
......@@ -26,10 +26,10 @@ import org.kde.plasma.extras 2.0 as PlasmaExtras
Item {
id: tooltipContentItem
property int preferredTextWidth: units.gridUnit * 20
property int preferredTextWidth: PlasmaCore.Units.gridUnit * 20
width: childrenRect.width + units.gridUnit
height: childrenRect.height + units.gridUnit
width: childrenRect.width + PlasmaCore.Units.gridUnit
height: childrenRect.height + PlasmaCore.Units.gridUnit
LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
LayoutMirroring.childrenInherit: true
......@@ -40,7 +40,7 @@ Item {
anchors {
left: parent.left
top: parent.top
margins: units.gridUnit / 2
margins: PlasmaCore.Units.gridUnit / 2
}
spacing: 0
......
......@@ -28,8 +28,8 @@ import org.kde.plasma.calendar 2.0 as PlasmaCalendar
Item {
id: root
width: units.gridUnit * 10
height: units.gridUnit * 4
width: PlasmaCore.Units.gridUnit * 10
height: PlasmaCore.Units.gridUnit * 4
property string dateFormatString: setDateFormatString()
Plasmoid.backgroundHints: PlasmaCore.Types.ShadowBackground | PlasmaCore.Types.ConfigurableBackground
property date tzDate: {
......
......@@ -39,14 +39,14 @@ MouseArea {
readonly property bool constrained: plasmoid.formFactor === PlasmaCore.Types.Vertical || plasmoid.formFactor === PlasmaCore.Types.Horizontal
property bool containsAcceptableDrag: false
height: Math.round(units.iconSizes.desktop + 2 * theme.mSize(theme.defaultFont).height)
width: Math.round(units.iconSizes.desktop * 1.5)
height: Math.round(PlasmaCore.Units.iconSizes.desktop + 2 * theme.mSize(theme.defaultFont).height)
width: Math.round(PlasmaCore.Units.iconSizes.desktop * 1.5)
Layout.minimumWidth: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? height : units.iconSizes.small
Layout.minimumHeight: plasmoid.formFactor === PlasmaCore.Types.Vertical ? width : (units.iconSizes.small + 2 * theme.mSize(theme.defaultFont).height)
Layout.minimumWidth: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? height : PlasmaCore.Units.iconSizes.small
Layout.minimumHeight: plasmoid.formFactor === PlasmaCore.Types.Vertical ? width : (PlasmaCore.Units.iconSizes.small + 2 * theme.mSize(theme.defaultFont).height)
Layout.maximumWidth: inPanel ? units.iconSizeHints.panel : -1
Layout.maximumHeight: inPanel ? units.iconSizeHints.panel : -1
Layout.maximumWidth: inPanel ? PlasmaCore.Units.iconSizeHints.panel : -1
Layout.maximumHeight: inPanel ? PlasmaCore.Units.iconSizeHints.panel : -1
hoverEnabled: true
......
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