Skip to content

Commit d947446

Browse files
sync: from linuxdeepin/dtkdeclarative
Synchronize source files from linuxdeepin/dtkdeclarative. Source-pull-request: linuxdeepin/dtkdeclarative#554
1 parent f08200e commit d947446

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)