Skip to content

Commit 8d2b9c4

Browse files
committed
fix: icons stuck together caused by listview add animation
由于 QTBUG-133953, 任务栏添加 icon 时新元素的加入动画一定会导致其 布局计算得到的位置是一个错误的位置.原本的修复是通过延时强制重新触发 布局实现的,但延时重新触发不一定可靠,导致仍可能概率性发生. 尽管 QTBUG-133953 并未得以解决,此处通过将动画时机进行调整,使相关位置计算 问题不再发生. PMS: BUG-308927 Log:
1 parent 70db0bb commit 8d2b9c4

File tree

1 file changed

+12
-29
lines changed

1 file changed

+12
-29
lines changed

panels/dock/taskmanager/package/TaskManager.qml

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,17 @@ ContainmentItem {
1414
property bool useColumnLayout: Panel.position % 2
1515
property int dockOrder: 16
1616
property int remainingSpacesForTaskManager: Panel.itemAlignment === Dock.LeftAlignment ? Panel.rootObject.dockLeftSpaceForCenter : Panel.rootObject.dockRemainingSpaceForCenter
17-
property int forceRelayoutWorkaround: 0
1817

1918
property int remainingSpacesForSplitWindow: Panel.rootObject.dockLeftSpaceForCenter - (Panel.rootObject.dockCenterPartCount - 1) * Panel.rootObject.dockItemMaxSize * 9 / 14
2019
// 用于居中计算的实际应用区域尺寸
21-
property int appContainerWidth: useColumnLayout ? Panel.rootObject.dockSize : (appContainer.implicitWidth + forceRelayoutWorkaround)
22-
property int appContainerHeight: useColumnLayout ? (appContainer.implicitHeight + forceRelayoutWorkaround) : Panel.rootObject.dockSize
20+
property int appContainerWidth: useColumnLayout ? Panel.rootObject.dockSize : appContainer.implicitWidth
21+
property int appContainerHeight: useColumnLayout ? appContainer.implicitHeight : Panel.rootObject.dockSize
2322

2423
// 动态字符限制数组,存储每个应用的最大显示字符数
2524
property var dynamicCharLimits: []
2625

27-
Timer {
28-
// FIXME: dockItemMaxSize(visualModel.cellWidth,actually its implicitWidth/Height) change will cause all delegate item's position change, but
29-
// the newly added item will using the old cellWidth to calculate its position, thus it will be placed in the wrong position. Also it
30-
// seems forceLayout() simply doesn't work, so we use a workaround here to force relayout the ListView inside the OverflowContainer.
31-
// See: QTBUG-133953
32-
id: relayoutWorkaroundTimer
33-
interval: 250 // should longer than OverflowContainer.add duration
34-
repeat: false
35-
onTriggered: {
36-
taskmanager.forceRelayoutWorkaround = visualModel.count % 2 + 1
37-
console.log("force relayout", taskmanager.forceRelayoutWorkaround)
38-
}
39-
}
40-
41-
implicitWidth: useColumnLayout ? Panel.rootObject.dockSize : (Math.max(remainingSpacesForTaskManager, appContainer.implicitWidth) + forceRelayoutWorkaround)
42-
implicitHeight: useColumnLayout ? (Math.max(remainingSpacesForTaskManager, appContainer.implicitHeight) + forceRelayoutWorkaround) : Panel.rootObject.dockSize
26+
implicitWidth: useColumnLayout ? Panel.rootObject.dockSize : Math.max(remainingSpacesForTaskManager, appContainer.implicitWidth)
27+
implicitHeight: useColumnLayout ? Math.max(remainingSpacesForTaskManager, appContainer.implicitHeight) : Panel.rootObject.dockSize
4328

4429
// Helper function to find the current index of an app by its appId in the visualModel
4530
function findAppIndex(appId) {
@@ -238,14 +223,6 @@ ContainmentItem {
238223
anchors.fill: parent
239224
useColumnLayout: taskmanager.useColumnLayout
240225
spacing: Panel.rootObject.itemSpacing + visualModel.count % 2
241-
add: Transition {
242-
NumberAnimation {
243-
properties: "scale,opacity"
244-
from: 0
245-
to: 1
246-
duration: 200
247-
}
248-
}
249226
remove: Transition {
250227
NumberAnimation {
251228
properties: "scale,opacity"
@@ -277,7 +254,6 @@ ContainmentItem {
277254
// 1:4 the distance between app : dock height; get width/height≈0.8
278255
property real cellWidth: Panel.rootObject.dockItemMaxSize * 0.8
279256
onCountChanged: function() {
280-
relayoutWorkaroundTimer.start()
281257
DS.singleShot(300, updateDynamicCharLimits)
282258
}
283259
delegate: Item {
@@ -312,6 +288,14 @@ ContainmentItem {
312288
return false
313289
}
314290

291+
ListView.onAdd: NumberAnimation {
292+
target: delegateRoot
293+
properties: "scale,opacity"
294+
from: 0
295+
to: 1
296+
duration: 200
297+
}
298+
315299
states: [
316300
State {
317301
name: "item-visible"
@@ -472,7 +456,6 @@ ContainmentItem {
472456
repeat: false
473457
onTriggered: {
474458
updateDynamicCharLimits()
475-
taskmanager.forceRelayoutWorkaround = (visualModel.count + 1) % 2 + 1
476459
}
477460
}
478461

0 commit comments

Comments
 (0)