Commit 8f747d61 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`

(unrelated formatting changes to layout.js were forced by clang-tidy)
parent bdf8e6fe
......@@ -25,13 +25,13 @@ import org.kde.plasma.core 2.0 as PlasmaCore
Item {
id: main
readonly property real w1: (main.height-5*units.smallSpacing)*dots/4
readonly property real w1: (main.height-5*PlasmaCore.Units.smallSpacing)*dots/4
Layout.minimumWidth: w1 < 20 ? 20 : w1
Layout.maximumWidth: Infinity
Layout.preferredWidth: Layout.minimumWidth
Layout.minimumHeight: 16+(units.smallSpacing*5)
Layout.minimumHeight: 16+(PlasmaCore.Units.smallSpacing*5)
//Layout.maximumHeight: vertical ? Layout.minimumHeight : Infinity
//Layout.preferredHeight: Layout.minimumHeight
......@@ -56,9 +56,9 @@ Item {
readonly property color offColor: plasmoid.configuration.useCustomColorForInactive ? plasmoid.configuration.customColorForInactive : Qt.rgba(onColor.r, onColor.g, onColor.b, 0.4)
readonly property color gridColor: plasmoid.configuration.useCustomColorForGrid ? plasmoid.configuration.customColorForGrid : Qt.rgba(onColor.r, onColor.g, onColor.b, 0.6)
readonly property int dotSize: Math.min((height-5*units.smallSpacing)/4, (width-(dots+1)*units.smallSpacing)/dots)
readonly property real displayTop: (height - 4*dotSize-3*units.smallSpacing)/2
readonly property real displayLeft: (width - dots*dotSize-(dots-1)*units.smallSpacing)/2
readonly property int dotSize: Math.min((height-5*PlasmaCore.Units.smallSpacing)/4, (width-(dots+1)*PlasmaCore.Units.smallSpacing)/dots)
readonly property real displayTop: (height - 4*dotSize-3*PlasmaCore.Units.smallSpacing)/2
readonly property real displayLeft: (width - dots*dotSize-(dots-1)*PlasmaCore.Units.smallSpacing)/2
/* displaying calendar after clicking binary clock applet */
MouseArea {
......@@ -75,32 +75,32 @@ Item {
val: hours/base
}
DotColumn {
x: displayLeft+(dotSize+units.smallSpacing)
x: displayLeft+(dotSize+PlasmaCore.Units.smallSpacing)
y: displayTop
val: hours%base
}
/* minutes */
DotColumn {
x: displayLeft+(dotSize+units.smallSpacing)*2
x: displayLeft+(dotSize+PlasmaCore.Units.smallSpacing)*2
y: displayTop
val: minutes/base
}
DotColumn {
x: displayLeft+(dotSize+units.smallSpacing)*3
x: displayLeft+(dotSize+PlasmaCore.Units.smallSpacing)*3
y: displayTop
val: minutes%base
}
/* seconds */
DotColumn {
x: displayLeft+(dotSize+units.smallSpacing)*4
x: displayLeft+(dotSize+PlasmaCore.Units.smallSpacing)*4
y: displayTop
val: seconds/base
visible: showSeconds
}
DotColumn {
x: displayLeft+(dotSize+units.smallSpacing)*5
x: displayLeft+(dotSize+PlasmaCore.Units.smallSpacing)*5
y: displayTop
val: seconds%base
visible: showSeconds
......@@ -108,20 +108,20 @@ Item {
/* upper grid border */
Rectangle {
x: displayLeft-units.smallSpacing
y: displayTop-units.smallSpacing
width: dots*(dotSize+units.smallSpacing)+units.smallSpacing
height: units.smallSpacing
x: displayLeft-PlasmaCore.Units.smallSpacing
y: displayTop-PlasmaCore.Units.smallSpacing
width: dots*(dotSize+PlasmaCore.Units.smallSpacing)+PlasmaCore.Units.smallSpacing
height: PlasmaCore.Units.smallSpacing
visible: showGrid
color: gridColor
}
/* left grid border */
Rectangle {
x: displayLeft-units.smallSpacing
x: displayLeft-PlasmaCore.Units.smallSpacing
y: displayTop
width: units.smallSpacing
height: 4*(dotSize+units.smallSpacing)
width: PlasmaCore.Units.smallSpacing
height: 4*(dotSize+PlasmaCore.Units.smallSpacing)
visible: showGrid
color: gridColor
}
......
......@@ -25,8 +25,8 @@ Item {
property int hours
property int minutes
property int seconds
width: units.gridUnit * 10
height: units.gridUnit * 4
width: PlasmaCore.Units.gridUnit * 10
height: PlasmaCore.Units.gridUnit * 4
Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
......@@ -53,8 +53,8 @@ Item {
Plasmoid.compactRepresentation: BinaryClock { }
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"]
}
......
......@@ -26,8 +26,8 @@ QQC2.Control {
Layout.minimumWidth: 150
Layout.minimumHeight: 225
width: units.gridSize * 3
height: units.gridSize * 4
width: PlasmaCore.Units.gridSize * 3
height: PlasmaCore.Units.gridSize * 4
// Make the buttons' text labels scale with the widget's size
// This is propagated down to all child controls with text
......
......@@ -102,8 +102,8 @@ Item {
columns: root.isVertical ? 1 : 3
rows: root.isVertical ? 3 : 1
Layout.minimumWidth: isVertical ? units.iconSizes.small : ((height * 2) + spacer.width)
Layout.minimumHeight: isVertical ? ((width * 2) + spacer.height) : units.iconSizes.small
Layout.minimumWidth: isVertical ? PlasmaCore.Units.iconSizes.small : ((height * 2) + spacer.width)
Layout.minimumHeight: isVertical ? ((width * 2) + spacer.height) : PlasmaCore.Units.iconSizes.small
// TODO: Still PC2 for now because:
// - It never loses visible focus despite panel widgets never getting focus anyway: https://bugs.kde.org/show_bug.cgi?id=424446
......@@ -127,7 +127,7 @@ Item {
Item { // spacer
id: spacer
readonly property int thickness: Math.ceil(Math.min(parent.width, parent.height) / units.iconSizes.small)
readonly property int thickness: Math.ceil(Math.min(parent.width, parent.height) / PlasmaCore.Units.iconSizes.small)
width: root.isVertical ? parent.width : thickness
height: root.isVertical ? thickness : parent.height
......@@ -186,8 +186,8 @@ Item {
id: colorCircle
anchors.centerIn: parent
// try to match the color-picker icon in size
width: units.roundToIconSize(pickerIcon.width) * 0.75
height: units.roundToIconSize(pickerIcon.height) * 0.75
width: PlasmaCore.Units.roundToIconSize(pickerIcon.width) * 0.75
height: PlasmaCore.Units.roundToIconSize(pickerIcon.height) * 0.75
radius: width / 2
color: root.recentColor
......@@ -215,7 +215,7 @@ Item {
if (contrast > 3 && colorCircle.color.a > 0.5) {
return 0;
} else {
return Math.round(Math.max(units.devicePixelRatio, width / 20));
return Math.round(Math.max(PlasmaCore.Units.devicePixelRatio, width / 20));
}
}
}
......@@ -247,7 +247,7 @@ Item {
readonly property int columns: 3
Layout.minimumWidth: columns * units.gridUnit * 6
Layout.minimumWidth: columns * PlasmaCore.Units.gridUnit * 6
Layout.minimumHeight: Layout.minimumWidth
Layout.maximumWidth: Layout.minimumWidth
Layout.maximumHeight: Layout.minimumHeight
......@@ -296,11 +296,11 @@ Item {
id: dragImageDummy
border {
color: theme.textColor
width: Math.round(units.devicePixelRatio)
width: Math.round(PlasmaCore.Units.devicePixelRatio)
}
radius: width
width: units.iconSizes.large
height: units.iconSizes.large
width: PlasmaCore.Units.iconSizes.large
height: PlasmaCore.Units.iconSizes.large
visible: false
}
......@@ -355,14 +355,14 @@ Item {
anchors {
fill: parent
margins: units.smallSpacing
margins: PlasmaCore.Units.smallSpacing
}
color: delegateMouse.currentColor
border {
color: theme.textColor
width: Math.round(units.devicePixelRatio)
width: Math.round(PlasmaCore.Units.devicePixelRatio)
}
Rectangle {
......@@ -372,7 +372,7 @@ Item {
right: parent.right
margins: rect.border.width
}
height: colorLabel.contentHeight + 2 * units.smallSpacing
height: colorLabel.contentHeight + 2 * PlasmaCore.Units.smallSpacing
color: theme.backgroundColor
opacity: 0.8
......
......@@ -12,8 +12,8 @@ import org.kde.kquickcontrolsaddons 2.0
Item {
id: root
width: units.gridUnit
height: units.gridUnit
width: PlasmaCore.Units.gridUnit
height: PlasmaCore.Units.gridUnit
property variant comicData
......
......@@ -16,21 +16,21 @@ import org.kde.kquickcontrolsaddons 2.0
Item {
id: mainWindow
readonly property int implicitWidth: units.gridUnit * 40
readonly property int implicitHeight: units.gridUnit * 15
readonly property int implicitWidth: PlasmaCore.Units.gridUnit * 40
readonly property int implicitHeight: PlasmaCore.Units.gridUnit * 15
Plasmoid.backgroundHints: PlasmaCore.Types.DefaultBackground | PlasmaCore.Types.ConfigurableBackground
Plasmoid.switchWidth: {
if (centerLayout.comicData.image) {
return Math.max(minimumWidth, Math.min(centerLayout.comicData.image.nativeWidth * 0.6, implicitWidth));
} else {
return units.gridUnit * 8;
return PlasmaCore.Units.gridUnit * 8;
}
}
Plasmoid.switchHeight: {
if (centerLayout.comicData.image) {
return Math.max(minimumHeight, Math.min(centerLayout.comicData.image.nativeHeight * 0.6, implicitHeight));
} else {
return units.gridUnit * 8;
return PlasmaCore.Units.gridUnit * 8;
}
}
Plasmoid.icon: "face-laughing"
......@@ -38,8 +38,8 @@ Item {
width: implicitWidth
height: implicitHeight
readonly property int minimumWidth: units.gridUnit * 8
readonly property int minimumHeight: units.gridUnit * 8
readonly property int minimumWidth: PlasmaCore.Units.gridUnit * 8
readonly property int minimumHeight: PlasmaCore.Units.gridUnit * 8
readonly property bool showComicAuthor: plasmoid.nativeInterface.showComicAuthor
readonly property bool showComicTitle: plasmoid.nativeInterface.showComicTitle
readonly property bool showErrorPicture: plasmoid.nativeInterface.showErrorPicture
......
......@@ -26,7 +26,7 @@ ColumnLayout {
PlasmaComponents3.TextField {
id: input
placeholderText: i18nc("@info:placeholder", "Enter word to define here")
implicitWidth: units.gridUnit * 40
implicitWidth: PlasmaCore.Units.gridUnit * 40
onAccepted: {
if (input.text === "") {
web.visible = false;
......@@ -48,7 +48,7 @@ ColumnLayout {
Layout.fillWidth: true
//Layout.fillHeight: true
Layout.preferredHeight: 400
zoomFactor: units.devicePixelRatio
zoomFactor: PlasmaCore.Units.devicePixelRatio
profile: dict.webProfile
}
......
......@@ -37,12 +37,12 @@ PlasmaComponents.ListItem {
RowLayout {
id: contents
width: parent.width
spacing: units.gridUnit
spacing: PlasmaCore.Units.gridUnit
PlasmaCore.IconItem {
source: iconName
Layout.alignment: Qt.AlignTop
width: units.iconSizes.medium
width: PlasmaCore.Units.iconSizes.medium
height: width
}
......
......@@ -17,8 +17,8 @@ import org.kde.plasma.private.diskquota 1.0
Item {
id: quotaApplet
Layout.minimumWidth: units.gridUnit * 10
Layout.minimumHeight: units.gridUnit * 2
Layout.minimumWidth: PlasmaCore.Units.gridUnit * 10
Layout.minimumHeight: PlasmaCore.Units.gridUnit * 2
Plasmoid.status: {
switch (diskQuota.status) {
......@@ -31,8 +31,8 @@ Item {
return PlasmaCore.Types.PassiveStatus
}
Plasmoid.switchWidth: units.gridUnit * 10
Plasmoid.switchHeight: units.gridUnit * 10
Plasmoid.switchWidth: PlasmaCore.Units.gridUnit * 10
Plasmoid.switchHeight: PlasmaCore.Units.gridUnit * 10
Plasmoid.icon: diskQuota.iconName
Plasmoid.toolTipMainText: diskQuota.toolTip
......@@ -47,8 +47,8 @@ Item {
Plasmoid.fullRepresentation: Item {
id: root
width: units.gridUnit * 20
height: units.gridUnit * 14
width: PlasmaCore.Units.gridUnit * 20
height: PlasmaCore.Units.gridUnit * 14
// HACK: connection to reset currentIndex to -1. Without this, when
// uninstalling filelight, the selection highlight remains fixed (which is wrong)
......
......@@ -164,14 +164,14 @@ Item {
left: parent.left
right: parent.right
bottom: controlsRow.top
bottomMargin: units.smallSpacing
bottomMargin: PlasmaCore.Units.smallSpacing
}
}
RowLayout {
id: controlsRow
anchors {
margins: units.smallSpacing
margins: PlasmaCore.Units.smallSpacing
bottom: parent.bottom
horizontalCenter: parent.horizontalCenter
}
......
......@@ -31,7 +31,7 @@ Rectangle {
signal activated(int position)
readonly property int boardSize: plasmoid.configuration.boardSize
readonly property int margin: units.smallSpacing
readonly property int margin: PlasmaCore.Units.smallSpacing
readonly property int pieceWidth: (parent.width - (margin * boardSize)) / boardSize
readonly property int pieceHeight: (parent.height - (margin * boardSize)) / boardSize
readonly property int boardColumn: (position % boardSize)
......@@ -42,13 +42,13 @@ Rectangle {
Behavior on x {
NumberAnimation {
duration: units.longDuration
duration: PlasmaCore.Units.longDuration
easing.type: Easing.InOutQuad
}
}
Behavior on y {
NumberAnimation {
duration: units.longDuration
duration: PlasmaCore.Units.longDuration
easing.type: Easing.InOutQuad
}
}
......
......@@ -22,8 +22,8 @@ Item {
Layout.minimumWidth: width
Layout.minimumHeight: height
width: units.gridUnit * 16
height: units.gridUnit * 16
width: PlasmaCore.Units.gridUnit * 16
height: PlasmaCore.Units.gridUnit * 16
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
......
......@@ -16,11 +16,11 @@ import org.kde.plasma.components 3.0 as PlasmaComponents3
Item {
id: main
Layout.minimumWidth: vertical ? 0 : sizehelper.paintedWidth + (units.smallSpacing * 2)
Layout.minimumWidth: vertical ? 0 : sizehelper.paintedWidth + (PlasmaCore.Units.smallSpacing * 2)
Layout.maximumWidth: vertical ? Infinity : Layout.minimumWidth
Layout.preferredWidth: vertical ? undefined : Layout.minimumWidth
Layout.minimumHeight: vertical ? sizehelper.paintedHeight + (units.smallSpacing * 2) : 0
Layout.minimumHeight: vertical ? sizehelper.paintedHeight + (PlasmaCore.Units.smallSpacing * 2) : 0
Layout.maximumHeight: vertical ? Layout.minimumHeight : Infinity
Layout.preferredHeight: vertical ? Layout.minimumHeight : theme.mSize(theme.defaultFont).height * 2
......@@ -267,8 +267,8 @@ Item {
width: 0
anchors {
fill: parent
leftMargin: units.smallSpacing
rightMargin: units.smallSpacing
leftMargin: PlasmaCore.Units.smallSpacing
rightMargin: PlasmaCore.Units.smallSpacing
}
}
......@@ -294,8 +294,8 @@ Item {
visible: false
anchors {
fill: parent
leftMargin: units.smallSpacing
rightMargin: units.smallSpacing
leftMargin: PlasmaCore.Units.smallSpacing
rightMargin: PlasmaCore.Units.smallSpacing
}
}
}
......@@ -18,8 +18,8 @@ Item {
readonly property date currentDateTime: dataSource.data.Local ? dataSource.data.Local.DateTime : new Date()
width: units.gridUnit * 10
height: units.gridUnit * 4
width: PlasmaCore.Units.gridUnit * 10
height: PlasmaCore.Units.gridUnit * 4
Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
......@@ -39,8 +39,8 @@ Item {
Plasmoid.compactRepresentation: FuzzyClock { }
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: currentDateTime
}
......
......@@ -18,8 +18,8 @@ Item {
id: root
//be at least the same size as the system tray popup
Layout.minimumWidth: units.gridUnit * 24
Layout.minimumHeight: units.gridUnit * 21
Layout.minimumWidth: PlasmaCore.Units.gridUnit * 24
Layout.minimumHeight: PlasmaCore.Units.gridUnit * 21
Layout.preferredWidth: Layout.minimumWidth
Layout.preferredHeight: Layout.minimumHeight * 1.5
......
......@@ -14,11 +14,11 @@ import org.kde.plasma.extras 2.0 as PlasmaExtras
FocusScope {
id: konsoleProfiles
Plasmoid.switchWidth: units.gridUnit * 11
Plasmoid.switchHeight: units.gridUnit * 9
Plasmoid.switchWidth: PlasmaCore.Units.gridUnit * 11
Plasmoid.switchHeight: PlasmaCore.Units.gridUnit * 9
Layout.minimumWidth: units.gridUnit * 12
Layout.minimumHeight: units.gridUnit * 10
Layout.minimumWidth: PlasmaCore.Units.gridUnit * 12
Layout.minimumHeight: PlasmaCore.Units.gridUnit * 10
Plasmoid.onExpandedChanged: {
if (plasmoid.expanded) {
......@@ -60,8 +60,8 @@ FocusScope {
PlasmaCore.IconItem {
id: appIcon
source: "utilities-terminal"
width: units.iconSizes.medium
height: units.iconSizes.medium
width: PlasmaCore.Units.iconSizes.medium
height: PlasmaCore.Units.iconSizes.medium
}
PlasmaComponents3.Label {
......@@ -90,7 +90,7 @@ FocusScope {
}
PlasmaExtras.ScrollArea {
anchors { left: parent.left; right: parent.right; bottom: parent.bottom; top: separator.bottom; topMargin: units.smallSpacing}
anchors { left: parent.left; right: parent.right; bottom: parent.bottom; top: separator.bottom; topMargin: PlasmaCore.Units.smallSpacing}
ListView {
id: view
......
......@@ -29,13 +29,13 @@ Item {
Plasmoid.preferredRepresentation: plasmoid.fullRepresentation
Plasmoid.switchWidth: units.gridUnit * 5
Plasmoid.switchHeight: units.gridUnit * 5
Plasmoid.switchWidth: PlasmaCore.Units.gridUnit * 5
Plasmoid.switchHeight: PlasmaCore.Units.gridUnit * 5
Plasmoid.backgroundHints: plasmoid.configuration.useBackground ? PlasmaCore.Types.DefaultBackground : PlasmaCore.Types.NoBackground
width: units.gridUnit * 20
height: units.gridUnit * 13
width: PlasmaCore.Units.gridUnit * 20
height: PlasmaCore.Units.gridUnit * 13
property string activeSource: ""
property string transitionSource: ""
......@@ -328,7 +328,7 @@ Item {
Row {
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottomMargin: units.smallSpacing
anchors.bottomMargin: PlasmaCore.Units.smallSpacing
/*
PlasmaComponents3.Button {
......@@ -389,7 +389,7 @@ Item {
color: "transparent"
implicitWidth: units.gridUnit
implicitWidth: PlasmaCore.Units.gridUnit
implicitHeight: implicitWidth
Rectangle {
......
......@@ -32,7 +32,7 @@ KCM.GridView {
thumbnailAvailable: true
thumbnail: PlasmaCore.SvgItem {
anchors.fill: parent
anchors.margins: units.gridUnit / 2
anchors.margins: PlasmaCore.Units.gridUnit / 2
svg: noteSvg
elementId: modelData + "-notes"
......
......@@ -30,12 +30,12 @@ PlasmaCore.SvgItem {
}
elementId: plasmoid.configuration.color + "-notes"
width: units.gridUnit * 15
height: units.gridUnit * 15
Layout.minimumWidth: units.iconSizes.medium
Layout.minimumHeight: units.iconSizes.medium
Plasmoid.switchWidth: units.gridUnit * 5
Plasmoid.switchHeight: units.gridUnit * 5
width: PlasmaCore.Units.gridUnit * 15
height: PlasmaCore.Units.gridUnit * 15
Layout.minimumWidth: PlasmaCore.Units.iconSizes.medium
Layout.minimumHeight: PlasmaCore.Units.iconSizes.medium
Plasmoid.switchWidth: PlasmaCore.Units.gridUnit * 5
Plasmoid.switchHeight: PlasmaCore.Units.gridUnit * 5
Plasmoid.backgroundHints: PlasmaCore.Types.NoBackground
......@@ -140,7 +140,7 @@ PlasmaCore.SvgItem {
left: parent.left
right: parent.right
bottom: fontButtons.top
bottomMargin: Math.round(units.largeSpacing / 2)
bottomMargin: Math.round(PlasmaCore.Units.largeSpacing / 2)
}
clip: true
......@@ -336,7 +336,7 @@ PlasmaCore.SvgItem {
RowLayout {
id: fontButtons
spacing: units.smallSpacing
spacing: PlasmaCore.Units.smallSpacing
anchors {
bottom: parent.bottom
left: parent.left
......@@ -345,14 +345,14 @@ PlasmaCore.SvgItem {
visible: opacity > 0
opacity: focusScope.activeFocus ? 1 : 0