applets/panelspacer: Fix optimal size calculation

Get rid of the delayed optimal size calculation caused by Qt.callLater
and calculate optimal size immediately when an applet's size changes.
This removes the unnecessary jumping of applets that are centered between 2
spacers.

BUG: 431668
FIXED-IN: 5.24.2
wilder-5.25
Martin Seher 4 years ago committed by Nate Graham
parent 61e935ea51
commit 5824e63620
  1. 30
      applets/panelspacer/package/contents/ui/main.qml

@ -55,12 +55,9 @@ Item {
plasmoid.removeAction("configure");
}
property real leftItemsSizeHint: 0
property real rightItemsSizeHint: 0
property real middleItemsSizeHint: {
// Every time this binding gets reevaluated we want to queue a recomputation of the size hints
Qt.callLater(root.updateHints)
if (!twinSpacer || !panelLayout || !leftTwin || !rightTwin) {
optimalSize = horizontal ? plasmoid.nativeInterface.containment.width : plasmoid.nativeInterface.containment.height;
return 0;
}
@ -105,8 +102,13 @@ Item {
}
}
rightItemsSizeHint = rightItemsHint;
leftItemsSizeHint = leftItemsHint;
var halfContainment = root.horizontal ?plasmoid.nativeInterface.containment.width/2 : plasmoid.nativeInterface.containment.height/2;
if (leftTwin == plasmoid) {
optimalSize = Math.max(PlasmaCore.Units.smallSpacing, halfContainment - middleItemsHint/2 - leftItemsHint)
} else {
optimalSize = Math.max(PlasmaCore.Units.smallSpacing, halfContainment - middleItemsHint/2 - rightItemsHint)
}
return middleItemsHint;
}
@ -134,22 +136,6 @@ Item {
}
}
function updateHints() {
if (!twinSpacer || !panelLayout || !leftTwin || !rightTwin) {
root.optimalSize = root.horizontal ? plasmoid.nativeInterface.containment.width : plasmoid.nativeInterface.containment.height;
return;
}
var halfContainment = root.horizontal ?plasmoid.nativeInterface.containment.width/2 : plasmoid.nativeInterface.containment.height/2;
if (leftTwin == plasmoid) {
root.optimalSize = Math.max(PlasmaCore.Units.smallSpacing, halfContainment - middleItemsSizeHint/2 - leftItemsSizeHint)
} else {
root.optimalSize = Math.max(PlasmaCore.Units.smallSpacing, halfContainment - middleItemsSizeHint/2 - rightItemsSizeHint)
}
}
Rectangle {
anchors.fill: parent
color: PlasmaCore.Theme.highlightColor

Loading…
Cancel
Save