This repository has been archived by the owner on Jan 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
progress.py
204 lines (154 loc) · 6.22 KB
/
progress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
from .core._core import *
class QMaterialCircularProgressDelegate(QObject):
def __init__(self, parent: "QMaterialCircularProgress") -> None:
QObject.__init__(self, parent)
self.m_progress = parent
self.m_dashOffset = float(0)
self.m_dashLength = float(89)
self.m_angle = int(0)
def setDashOffset(self, offset: float) -> None:
self.m_dashOffset = offset
self.m_progress.update()
def dashOffset(self) -> float:
return self.m_dashOffset
def setDashLength(self, length: float) -> None:
self.m_dashLength = length
self.m_progress.update()
def dashLength(self) -> float:
return self.m_dashLength
def setAngle(self, angle: int) -> None:
self.m_angle = angle
self.m_progress.update()
def angle(self) -> int:
return self.m_angle
_dashOffset = Property(float, fset=setDashOffset, fget=dashOffset)
_dashLength = Property(float, fset=setDashLength, fget=dashLength)
_angle = Property(int, fset=setAngle, fget=angle)
class QMaterialCircularProgress(QProgressBar):
def __init__(self, parent: QWidget = None):
QProgressBar.__init__(self, parent)
self.m_delegate = QMaterialCircularProgressDelegate(self)
self.m_progressType = Material.IndeterminateProgress
self.m_penWidth = 6.25
self.m_size = 64
self.m_useThemeColors = True
self.setSizePolicy(
QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
)
group = QParallelAnimationGroup(self)
group.setLoopCount(-1)
animation = QPropertyAnimation(self)
animation.setPropertyName(b"_dashLength")
animation.setTargetObject(self.delegate)
animation.setEasingCurve(QEasingCurve.InOutQuad)
animation.setStartValue(0.1)
animation.setKeyValueAt(0.15, 0.2)
animation.setKeyValueAt(0.6, 20)
animation.setKeyValueAt(0.7, 20)
animation.setEndValue(20)
animation.setDuration(2050)
group.addAnimation(animation)
animation = QPropertyAnimation(self)
animation.setPropertyName(b"_dashOffset")
animation.setTargetObject(self.m_delegate)
animation.setEasingCurve(QEasingCurve.InOutSine)
animation.setStartValue(0)
animation.setKeyValueAt(0.15, 0)
animation.setKeyValueAt(0.6, -7)
animation.setKeyValueAt(0.7, -7)
animation.setEndValue(-25)
animation.setDuration(2050)
group.addAnimation(animation)
animation = QPropertyAnimation(self)
animation.setPropertyName(b"_angle")
animation.setTargetObject(self.m_delegate)
animation.setStartValue(0)
animation.setEndValue(719)
animation.setDuration(2050)
group.addAnimation(animation)
group.start()
def setProgressType(self, type: Material.ProgressType) -> None:
self.m_progressType = type
self.update()
def progressType(self) -> Material.ProgressType:
return self.m_progressType
def setUseThemeColors(self, value: bool) -> None:
if self.m_useThemeColors == value:
return
self.m_useThemeColors = value
self.update()
def useThemeColors(self) -> bool:
return self.m_useThemeColors
def setLineWidth(self, width: float) -> None:
self.m_penWidth = width
self.update()
self.updateGeometry()
def lineWidth(self) -> float:
return self.m_penWidth
def setSize(self, size: int) -> None:
self.m_size = size
self.update()
self.updateGeometry()
def size(self) -> int:
return self.m_size
def setColor(self, color: QColor) -> None:
self.m_color = color
MATERIAL_DISABLE_THEME_COLORS(self)
self.update()
def color(self) -> QColor:
if self.m_useThemeColors or not self.m_color.isValid():
return QMaterialStyle.instance().themeColor("primary1")
else:
return self.m_color
def sizeHint(self) -> QSize:
s: float = self.m_size + self.m_penWidth + 8
return QSize(s, s)
def paintEvent(self, event: QPaintEvent) -> None:
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
pen = QPen()
if not self.isEnabled():
pen.setCapStyle(Qt.RoundCap)
pen.setWidthF(self.m_penWidth)
pen.setColor(QMaterialStyle.instance().themeColor("border"))
painter.setPen(pen)
painter.drawLine(
self.rect().center() - QPointF(20, 20),
self.rect().center() + QPointF(20, 20),
)
painter.drawLine(
self.rect().center() + QPointF(20, -20),
self.rect().center() - QPointF(20, -20),
)
return
if Material.IndeterminateProgress == self.m_progressType:
painter.translate(self.width() / 2, self.height() / 2)
painter.rotate(self.m_delegate.angle())
pen.setCapStyle(Qt.RoundCap)
pen.setWidthF(self.m_penWidth)
pen.setColor(self.color())
if Material.IndeterminateProgress == self.m_progressType:
pattern: List[float] = [
self.m_delegate.dashLength() * self.m_size / 50,
30 * self.m_size / 50,
]
pen.setDashOffset(self.m_delegate.dashOffset() * self.m_size / 50)
pen.setDashPattern(pattern)
painter.setPen(pen)
painter.drawEllipse(QPoint(0, 0), self.m_size / 2, self.m_size / 2)
else:
painter.setPen(pen)
x: float = (self.width() - self.m_size) / 2
y: float = (self.height() - self.m_size) / 2
a: float = (
360
* (self.value() - self.minimum())
/ (self.maximum() - self.minimum())
)
path = QPainterPath()
path.arcMoveTo(x, y, self.m_size, self.m_size, 0)
path.arcTo(x, y, self.m_size, self.m_size, 0, a)
painter.drawPath(path)
_lineWidth = Property(float, fset=setLineWidth, fget=lineWidth)
_size = Property(float, fset=setSize, fget=size)
_color = Property(QColor, fset=setColor, fget=color)