99@file: Widgets.Skins.PictureWidget
1010@description:
1111"""
12+ from PyQt5 .QtCore import QObject , pyqtSignal , pyqtProperty , Qt , QRectF ,\
13+ QSequentialAnimationGroup , QPauseAnimation , QParallelAnimationGroup ,\
14+ QPropertyAnimation
15+ from PyQt5 .QtGui import QColor , QPainter
16+
1217from Utils .CommonUtil import Signals
1318from Utils .ThemeThread import GetAllCategoryRunnable
1419from Widgets .Skins .SkinBaseWidget import SkinBaseWidget , SkinBaseItemWidget
1722__Author__ = 'Irony'
1823__Copyright__ = 'Copyright (c) 2019'
1924
25+
26+ class CircleItem (QObject ):
27+
28+ _x = 0 # x坐标
29+ _opacity = 1 # 透明度0~1
30+ valueChanged = pyqtSignal ()
31+
32+ @pyqtProperty (float )
33+ def x (self ):
34+ return self ._x
35+
36+ @x .setter
37+ def x (self , x ):
38+ self ._x = x
39+ self .valueChanged .emit ()
40+
41+ @pyqtProperty (float )
42+ def opacity (self ):
43+ return self ._opacity
44+
45+ @opacity .setter
46+ def opacity (self , opacity ):
47+ self ._opacity = opacity
48+
49+
2050class PictureWidget (SkinBaseWidget ):
2151
52+ _waiting = False
53+ _circleRadius = 3 # 半径
54+ _circleColor = QColor (39 , 174 , 97 ) # 圆圈颜色
55+
2256 def __init__ (self , category , * args , ** kwargs ):
2357 super (PictureWidget , self ).__init__ (* args , ** kwargs )
2458 self .category = category
59+ self ._items = []
60+
61+ def showWaiting (self , show = True ):
62+ self .setEnabled (not show )
63+ self ._waiting = show
64+ if show :
65+ self ._items .clear ()
66+ self ._initAnimations ()
67+ for _ , animation in self ._items :
68+ animation .start ()
69+ else :
70+ for _ , animation in self ._items :
71+ animation .stop ()
2572
2673 def addItem (self , index , title , path ):
2774 # 计算行列
@@ -36,3 +83,91 @@ def init(self):
3683 if self .gridLayout .count () > 0 :
3784 return
3885 return GetAllCategoryRunnable (self .category , self )
86+
87+ def paintEvent (self , event ):
88+ if not self ._waiting :
89+ # 交给原来的绘制
90+ super (PictureWidget , self ).paintEvent (event )
91+ return
92+ # 自定义绘制
93+ painter = QPainter (self )
94+ painter .setRenderHint (QPainter .Antialiasing )
95+ painter .setRenderHint (QPainter .SmoothPixmapTransform )
96+ painter .setPen (Qt .NoPen )
97+
98+ for item , _ in self ._items :
99+ painter .save ()
100+ color = self ._circleColor .toRgb ()
101+ color .setAlphaF (item .opacity )
102+ painter .setBrush (color )
103+ diameter = 2 * self ._circleRadius
104+ painter .drawRoundedRect (
105+ QRectF (
106+ item .x / 100 * self .width () - diameter ,
107+ self ._circleRadius / 2 ,
108+ # (self.height() - self._circleRadius) / 2,
109+ diameter , diameter
110+ ), self ._circleRadius , self ._circleRadius )
111+ painter .restore ()
112+
113+ def _initAnimations (self ):
114+ for index in range (5 ): # 5个小圆
115+ item = CircleItem (self )
116+ item .valueChanged .connect (self .update )
117+ # 串行动画组
118+ seqAnimation = QSequentialAnimationGroup (self )
119+ seqAnimation .setLoopCount (- 1 )
120+ self ._items .append ((item , seqAnimation ))
121+
122+ # 暂停延迟动画
123+ seqAnimation .addAnimation (QPauseAnimation (150 * index , self ))
124+
125+ # 加速,并行动画组1
126+ parAnimation1 = QParallelAnimationGroup (self )
127+ # 透明度
128+ parAnimation1 .addAnimation (QPropertyAnimation (
129+ item , b'opacity' , self , duration = 400 , startValue = 0 , endValue = 1.0 ))
130+ # x坐标
131+ parAnimation1 .addAnimation (QPropertyAnimation (
132+ item , b'x' , self , duration = 400 , startValue = 0 , endValue = 25.0 ))
133+ seqAnimation .addAnimation (parAnimation1 )
134+ ##
135+
136+ # 匀速
137+ seqAnimation .addAnimation (QPropertyAnimation (
138+ item , b'x' , self , duration = 2000 , startValue = 25.0 , endValue = 75.0 ))
139+
140+ # 加速,并行动画组2
141+ parAnimation2 = QParallelAnimationGroup (self )
142+ # 透明度
143+ parAnimation2 .addAnimation (QPropertyAnimation (
144+ item , b'opacity' , self , duration = 400 , startValue = 1.0 , endValue = 0 ))
145+ # x坐标
146+ parAnimation2 .addAnimation (QPropertyAnimation (
147+ item , b'x' , self , duration = 400 , startValue = 75.0 , endValue = 100.0 ))
148+ seqAnimation .addAnimation (parAnimation2 )
149+ ##
150+
151+ # 暂停延迟动画
152+ seqAnimation .addAnimation (
153+ QPauseAnimation ((5 - index - 1 ) * 150 , self ))
154+
155+ @pyqtProperty (int )
156+ def circleRadius (self ):
157+ return self ._circleRadius
158+
159+ @circleRadius .setter
160+ def circleRadius (self , radius ):
161+ if self ._circleRadius != radius :
162+ self ._circleRadius = radius
163+ self .update ()
164+
165+ @pyqtProperty (QColor )
166+ def circleColor (self ):
167+ return self ._circleColor
168+
169+ @circleColor .setter
170+ def circleColor (self , color ):
171+ if self ._circleColor != color :
172+ self ._circleColor = color
173+ self .update ()
0 commit comments