Skip to content

Commit 0419124

Browse files
committed
fix: refactor progress bar animation and visual effects
1. Replaced manual timer-based animation with a reusable lightSweepAnimation component 2. Fixed BoxShadow positioning to use anchors instead of manual calculations 3. Added OpacityMask layers to handle corner radius clipping properly 4. Restructured gradient animation to use ColorAnimation for smoother transitions 5. Fixed indeterminate mode animation to respect animationStop control 6. Improved visual consistency between determinate and indeterminate modes Log: Improved progress bar visual effects with smoother animations and better corner handling Influence: 1. Test progress bar in both determinate and indeterminate modes 2. Verify smooth gradient animation without visual glitches 3. Check corner radius rendering at different progress values 4. Test animation stop/start functionality in indeterminate mode 5. Verify BoxShadow positioning and visibility at progress boundaries 6. Test performance with multiple progress bars simultaneously fix: 重构进度条动画和视觉效果 1. 将基于定时器的手动动画替换为可复用的 lightSweepAnimation 组件 2. 修复 BoxShadow 定位,使用锚点替代手动计算 3. 添加 OpacityMask 层以正确处理圆角裁剪 4. 重构渐变动画,使用 ColorAnimation 实现更平滑的过渡 5. 修复不确定模式动画以遵守 animationStop 控制 6. 改进确定模式和不确定模式之间的视觉一致性 Log: 改进了进度条的视觉效果,动画更平滑,圆角处理更好 Influence: 1. 测试确定模式和不确定模式下的进度条 2. 验证平滑的渐变动画,无视觉故障 3. 检查不同进度值下的圆角渲染 4. 测试不确定模式下的动画停止/开始功能 5. 验证进度边界处的 BoxShadow 定位和可见性 6. 测试同时显示多个进度条时的性能表现 pms: BUG-341547
1 parent 22f8682 commit 0419124

1 file changed

Lines changed: 98 additions & 45 deletions

File tree

qt6/src/qml/private/ProgressBarImpl.qml

Lines changed: 98 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,63 @@ Item {
2727

2828
Item {
2929
BoxShadow {
30-
y: (parent.height - height) / 2
31-
x: -y
32-
width: progressBar.height
33-
height: progressBar.visualPosition * progressBar.width
34-
shadowOffsetX: -4
30+
anchors.fill: parent
31+
anchors.rightMargin: (1 - progressBar.visualPosition) * progressBar.width
32+
shadowOffsetY: 4
3533
shadowBlur: 6
36-
rotation: -90
3734
cornerRadius: DS.Style.control.radius
3835
shadowColor: control.D.ColorSelector.shadowPaletteColor
3936
visible: progressBar.visualPosition > 0
37+
}
4038

39+
Item {
40+
id: item
41+
// 向左偏移height显示,避免宽度过窄时产生的圆角显示问题
42+
x: - height
43+
width: progressBar.width + height
44+
height: progressBar.height
4145
Rectangle {
4246
id: rect
43-
anchors.fill: parent
44-
radius: parent.cornerRadius
45-
property int count
46-
property real lightPosition
47-
gradient: Gradient {
47+
property color gradientColor: progressBar.palette.highlight
48+
property real lightPosition: 0
49+
width: progressBar.width * progressBar.visualPosition + height
50+
height: progressBar.height
51+
gradient: Gradient {
52+
orientation: Gradient.Horizontal
4853
GradientStop { position: 0; color: progressBar.palette.highlight }
49-
GradientStop { position: rect.lightPosition; color: control.D.ColorSelector.handleGradientColor }
54+
GradientStop { position: rect.lightPosition; color: rect.gradientColor }
5055
GradientStop { position: 1; color: progressBar.palette.highlight }
5156
}
52-
Timer {
53-
id: moveTimer
54-
interval: 10
55-
repeat: true
56-
running: rect.visible
57-
onTriggered: {
58-
moveTimer.interval = 10
59-
if (rect.count === 100) {
60-
rect.count = 0
61-
rect.lightPosition = 0.0
62-
moveTimer.interval = 2000
63-
return;
57+
58+
Loader {
59+
id: lightAnimLoader
60+
sourceComponent: lightSweepAnimation
61+
onLoaded: {
62+
lightAnimLoader.item.targetItem = rect
63+
lightAnimLoader.item.running = true
64+
}
65+
}
66+
67+
radius: DS.Style.control.radius
68+
layer.enabled: true
69+
clip: true
70+
layer.effect: OpacityMask {
71+
maskSource: Rectangle {
72+
width: rect.width
73+
height: rect.height
74+
radius: DS.Style.control.radius
6475
}
65-
rect.count += 1
66-
rect.lightPosition = rect.count * 0.01
76+
}
77+
}
78+
layer.enabled: true
79+
layer.effect: OpacityMask {
80+
maskSource: Item {
81+
width: item.width
82+
height: item.height
83+
Rectangle {
84+
anchors.fill: parent
85+
anchors.leftMargin: -item.x
86+
radius: DS.Style.control.radius
6787
}
6888
}
6989
}
@@ -121,27 +141,19 @@ Item {
121141
id: indeterminateRect
122142
anchors.fill: parent
123143
radius: indeterminateProgressContent.cornerRadius
124-
property int count
125-
property real lightPosition
144+
property real lightPosition: 0
145+
property color gradientColor: control.D.ColorSelector.handleGradientColor
126146
gradient: Gradient {
127-
GradientStop { position: 0.0; color: progressBar.palette.highlight }
128-
GradientStop { position: indeterminateRect.lightPosition; color: control.D.ColorSelector.handleGradientColor }
129-
GradientStop { position: 1.0; color: progressBar.palette.highlight }
147+
GradientStop { position: 0; color: progressBar.palette.highlight }
148+
GradientStop { position: indeterminateRect.lightPosition; color: indeterminateRect.gradientColor }
149+
GradientStop { position: 1; color: progressBar.palette.highlight }
130150
}
131-
Timer {
132-
id: indeterminateMoveTimer
133-
interval: 50
134-
repeat: true
135-
running: indeterminateRect.visible
136-
onTriggered: {
137-
indeterminateMoveTimer.interval = 50
138-
if (indeterminateRect.count === 100) {
139-
indeterminateRect.count = 0
140-
indeterminateMoveTimer.interval = 2000
141-
return;
142-
}
143-
indeterminateRect.count += 5
144-
indeterminateRect.lightPosition = indeterminateRect.count * 0.01
151+
Loader {
152+
id: lightAnimLoader
153+
sourceComponent: lightSweepAnimation
154+
onLoaded: {
155+
lightAnimLoader.item.targetItem = indeterminateRect
156+
lightAnimLoader.item.running = progressBar.indeterminate && !control.animationStop
145157
}
146158
}
147159
}
@@ -224,4 +236,45 @@ Item {
224236
}
225237
}
226238
}
239+
240+
Component {
241+
id: lightSweepAnimation
242+
243+
SequentialAnimation {
244+
id: anim
245+
property Item targetItem: null
246+
loops: Animation.Infinite
247+
248+
ParallelAnimation {
249+
SequentialAnimation {
250+
ColorAnimation {
251+
target: anim.targetItem
252+
property: "gradientColor"
253+
from: progressBar.palette.highlight
254+
to: control.D.ColorSelector.handleGradientColor
255+
duration: 500
256+
}
257+
PauseAnimation { duration: 2000 }
258+
ColorAnimation {
259+
target: anim.targetItem
260+
property: "gradientColor"
261+
from: control.D.ColorSelector.handleGradientColor
262+
to: progressBar.palette.highlight
263+
duration: 500
264+
}
265+
}
266+
267+
NumberAnimation {
268+
target: anim.targetItem
269+
property: "lightPosition"
270+
from: 0
271+
to: 1
272+
duration: 3000
273+
easing.type: Easing.InOutSine
274+
}
275+
}
276+
277+
PauseAnimation { duration: 2000 }
278+
}
279+
}
227280
}

0 commit comments

Comments
 (0)