Skip to content

Commit 43c762b

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

1 file changed

Lines changed: 87 additions & 46 deletions

File tree

qt6/src/qml/private/ProgressBarImpl.qml

Lines changed: 87 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,59 @@ 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+
LightSweepAnimation {
59+
targetItem: rect
60+
running: !control.animationStop && rect.visible
61+
}
62+
63+
radius: DS.Style.control.radius
64+
layer.enabled: true
65+
clip: true
66+
layer.effect: OpacityMask {
67+
maskSource: Rectangle {
68+
width: rect.width
69+
height: rect.height
70+
radius: DS.Style.control.radius
6471
}
65-
rect.count += 1
66-
rect.lightPosition = rect.count * 0.01
72+
}
73+
}
74+
layer.enabled: true
75+
layer.effect: OpacityMask {
76+
maskSource: Item {
77+
width: item.width
78+
height: item.height
79+
Rectangle {
80+
anchors.fill: parent
81+
anchors.leftMargin: -item.x
82+
radius: DS.Style.control.radius
6783
}
6884
}
6985
}
@@ -121,28 +137,16 @@ Item {
121137
id: indeterminateRect
122138
anchors.fill: parent
123139
radius: indeterminateProgressContent.cornerRadius
124-
property int count
125-
property real lightPosition
140+
property real lightPosition: 0
141+
property color gradientColor: control.D.ColorSelector.handleGradientColor
126142
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 }
143+
GradientStop { position: 0; color: progressBar.palette.highlight }
144+
GradientStop { position: indeterminateRect.lightPosition; color: indeterminateRect.gradientColor }
145+
GradientStop { position: 1; color: progressBar.palette.highlight }
130146
}
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
145-
}
147+
LightSweepAnimation {
148+
targetItem: indeterminateRect
149+
running: progressBar.indeterminate && !control.animationStop && indeterminateRect.visible
146150
}
147151
}
148152

@@ -224,4 +228,41 @@ Item {
224228
}
225229
}
226230
}
231+
232+
component LightSweepAnimation: SequentialAnimation{
233+
id: anim
234+
property Item targetItem: null
235+
loops: Animation.Infinite
236+
237+
ParallelAnimation {
238+
SequentialAnimation {
239+
ColorAnimation {
240+
target: anim.targetItem
241+
property: "gradientColor"
242+
from: progressBar.palette.highlight
243+
to: control.D.ColorSelector.handleGradientColor
244+
duration: 500
245+
}
246+
PauseAnimation { duration: 2000 }
247+
ColorAnimation {
248+
target: anim.targetItem
249+
property: "gradientColor"
250+
from: control.D.ColorSelector.handleGradientColor
251+
to: progressBar.palette.highlight
252+
duration: 500
253+
}
254+
}
255+
256+
NumberAnimation {
257+
target: anim.targetItem
258+
property: "lightPosition"
259+
from: 0
260+
to: 1
261+
duration: 3000
262+
easing.type: Easing.InOutSine
263+
}
264+
}
265+
266+
PauseAnimation { duration: 2000 }
267+
}
227268
}

0 commit comments

Comments
 (0)