17 |
17 |
18 class EricAnimatedWidget(QWidget): |
18 class EricAnimatedWidget(QWidget): |
19 """ |
19 """ |
20 Class implementing an animated widget. |
20 Class implementing an animated widget. |
21 """ |
21 """ |
|
22 |
22 DirectionDown = 0 |
23 DirectionDown = 0 |
23 DirectionUp = 1 |
24 DirectionUp = 1 |
24 |
25 |
25 def __init__(self, direction=DirectionDown, duration=300, parent=None): |
26 def __init__(self, direction=DirectionDown, duration=300, parent=None): |
26 """ |
27 """ |
27 Constructor |
28 Constructor |
28 |
29 |
29 @param direction direction of the animation |
30 @param direction direction of the animation |
30 @type int (one of DirectionDown or DirectionUp) |
31 @type int (one of DirectionDown or DirectionUp) |
31 @param duration duration of the animation |
32 @param duration duration of the animation |
32 @type int |
33 @type int |
33 @param parent reference to the parent widget |
34 @param parent reference to the parent widget |
34 @type QWidget |
35 @type QWidget |
35 """ |
36 """ |
36 super().__init__(parent) |
37 super().__init__(parent) |
37 |
38 |
38 self.__direction = direction |
39 self.__direction = direction |
39 self.__stepHeight = 0.0 |
40 self.__stepHeight = 0.0 |
40 self.__stepY = 0.0 |
41 self.__stepY = 0.0 |
41 self.__startY = 0 |
42 self.__startY = 0 |
42 self.__widget = QWidget(self) |
43 self.__widget = QWidget(self) |
43 |
44 |
44 self.__timeline = QTimeLine(duration) |
45 self.__timeline = QTimeLine(duration) |
45 self.__timeline.setFrameRange(0, 100) |
46 self.__timeline.setFrameRange(0, 100) |
46 self.__timeline.frameChanged.connect(self.__animateFrame) |
47 self.__timeline.frameChanged.connect(self.__animateFrame) |
47 |
48 |
48 self.setMaximumHeight(0) |
49 self.setMaximumHeight(0) |
49 |
50 |
50 def widget(self): |
51 def widget(self): |
51 """ |
52 """ |
52 Public method to get a reference to the animated widget. |
53 Public method to get a reference to the animated widget. |
53 |
54 |
54 @return reference to the animated widget |
55 @return reference to the animated widget |
55 @rtype QWidget |
56 @rtype QWidget |
56 """ |
57 """ |
57 return self.__widget |
58 return self.__widget |
58 |
59 |
59 @pyqtSlot() |
60 @pyqtSlot() |
60 def startAnimation(self): |
61 def startAnimation(self): |
61 """ |
62 """ |
62 Public slot to start the animation. |
63 Public slot to start the animation. |
63 """ |
64 """ |
64 if self.__timeline.state() == QTimeLine.State.Running: |
65 if self.__timeline.state() == QTimeLine.State.Running: |
65 return |
66 return |
66 |
67 |
67 shown = 0 |
68 shown = 0 |
68 hidden = 0 |
69 hidden = 0 |
69 |
70 |
70 if self.__direction == self.DirectionDown: |
71 if self.__direction == self.DirectionDown: |
71 shown = 0 |
72 shown = 0 |
72 hidden = -self.__widget.height() |
73 hidden = -self.__widget.height() |
73 |
74 |
74 self.__widget.move(QPoint(self.__widget.pos().x(), hidden)) |
75 self.__widget.move(QPoint(self.__widget.pos().x(), hidden)) |
75 |
76 |
76 self.__stepY = (hidden - shown) / 100.0 |
77 self.__stepY = (hidden - shown) / 100.0 |
77 self.__startY = hidden |
78 self.__startY = hidden |
78 self.__stepHeight = self.__widget.height() / 100.0 |
79 self.__stepHeight = self.__widget.height() / 100.0 |
79 |
80 |
80 self.__timeline.setDirection(QTimeLine.Direction.Forward) |
81 self.__timeline.setDirection(QTimeLine.Direction.Forward) |
81 self.__timeline.start() |
82 self.__timeline.start() |
82 |
83 |
83 @pyqtSlot(int) |
84 @pyqtSlot(int) |
84 def __animateFrame(self, frame): |
85 def __animateFrame(self, frame): |
85 """ |
86 """ |
86 Private slot to animate the next frame. |
87 Private slot to animate the next frame. |
87 |
88 |
88 @param frame frame number |
89 @param frame frame number |
89 @type int |
90 @type int |
90 """ |
91 """ |
91 self.setFixedHeight(frame * self.__stepHeight) |
92 self.setFixedHeight(frame * self.__stepHeight) |
92 self.__widget.move(self.pos().x(), |
93 self.__widget.move(self.pos().x(), self.__startY - frame * self.__stepY) |
93 self.__startY - frame * self.__stepY) |
94 |
94 |
|
95 @pyqtSlot() |
95 @pyqtSlot() |
96 def hide(self): |
96 def hide(self): |
97 """ |
97 """ |
98 Public slot to hide the animated widget. |
98 Public slot to hide the animated widget. |
99 """ |
99 """ |
100 if self.__timeline.state() == QTimeLine.State.Running: |
100 if self.__timeline.state() == QTimeLine.State.Running: |
101 return |
101 return |
102 |
102 |
103 self.__timeline.setDirection(QTimeLine.Direction.Backward) |
103 self.__timeline.setDirection(QTimeLine.Direction.Backward) |
104 self.__timeline.finished.connect(self.close) |
104 self.__timeline.finished.connect(self.close) |
105 self.__timeline.start() |
105 self.__timeline.start() |
106 |
106 |
107 p = self.parentWidget() |
107 p = self.parentWidget() |
108 if p is not None: |
108 if p is not None: |
109 p.setFocus() |
109 p.setFocus() |
110 |
110 |
111 def resizeEvent(self, evt): |
111 def resizeEvent(self, evt): |
112 """ |
112 """ |
113 Protected method to handle a resize event. |
113 Protected method to handle a resize event. |
114 |
114 |
115 @param evt reference to the event object |
115 @param evt reference to the event object |
116 @type QResizeEvent |
116 @type QResizeEvent |
117 """ |
117 """ |
118 if evt.size().width() != self.__widget.width(): |
118 if evt.size().width() != self.__widget.width(): |
119 self.__widget.resize(evt.size().width(), self.__widget.height()) |
119 self.__widget.resize(evt.size().width(), self.__widget.height()) |
120 |
120 |
121 super().resizeEvent(evt) |
121 super().resizeEvent(evt) |