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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223 | def drawWidget(self, painter: QPainter) -> None:
setup_key = (self.rect_f, self.main.current_output.index)
curr_key, (scroll_rect, labels_notches, rects_to_draw) = self.notches_cache[self.mode]
if setup_key != curr_key:
lnotch_y, lnotch_x = self.rect_f.top() + self.font_height + self.notch_height + 5, self.rect_f.left()
lnotch_top = lnotch_y - self.notch_height
labels_notches = Notches()
if self.mode == self.Mode.TIME:
max_value = self.main.current_output.total_time
notch_interval = self.calculate_notch_interval_t(self.notch_interval_target_x)
label_format = self.generate_label_format(notch_interval, max_value)
label_notch = Time()
elif self.mode == self.Mode.FRAME:
max_value = self.main.current_output.total_frames - 1 # type: ignore
notch_interval = self.calculate_notch_interval_f(self.notch_interval_target_x) # type: ignore
label_notch = Frame() # type: ignore
while (lnotch_x < self.rect_f.right() and label_notch <= max_value):
labels_notches.add(
Notch(deepcopy(label_notch), line=QLineF(lnotch_x, lnotch_y, lnotch_x, lnotch_top))
)
label_notch += notch_interval
lnotch_x = self.c_to_x(label_notch)
labels_notches.add(
Notch(max_value, line=QLineF(self.rect_f.right() - 1, lnotch_y, self.rect_f.right() - 1, lnotch_top))
)
scroll_rect = QRectF(
self.rect_f.left(), lnotch_y + self.notch_scroll_interval, self.rect_f.width(), self.scroll_height
)
cursor_line = QLineF(
self.cursor_x, scroll_rect.top(), self.cursor_x, scroll_rect.top() + scroll_rect.height() - 1
)
for provider, notches in self.notches.items():
if not provider.is_notches_visible:
continue
notches.norm_lines(self, scroll_rect)
painter.fillRect(self.rect_f, self.palette().color(QPalette.ColorRole.Window))
painter.setPen(QPen(self.palette().color(QPalette.ColorRole.WindowText)))
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
if setup_key != curr_key:
rects_to_draw = []
for i, notch in enumerate(labels_notches):
anchor_rect = QRectF(notch.line.x2(), notch.line.y2(), 0, 0)
if self.mode == self.Mode.TIME:
time = cast(Time, notch.data)
label = strfdelta(time, label_format)
elif self.mode == self.Mode.FRAME:
label = str(notch.data)
if i == 0:
rect = painter.boundingRect(
anchor_rect, Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignLeft, label
)
if self.mode == self.Mode.TIME:
rect.moveLeft(-2.5)
elif i == (len(labels_notches) - 1):
rect = painter.boundingRect(
anchor_rect, Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignRight, label
)
elif i == (len(labels_notches) - 2):
rect = painter.boundingRect(
anchor_rect, Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignHCenter, label
)
last_notch = labels_notches[-1]
if self.mode == self.Mode.TIME:
last_label = strfdelta(cast(Time, last_notch.data), label_format)
elif self.mode == self.Mode.FRAME:
last_label = str(last_notch.data)
anchor_rect = QRectF(last_notch.line.x2(), last_notch.line.y2(), 0, 0)
last_rect = painter.boundingRect(
anchor_rect, Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignRight, last_label
)
if last_rect.left() - rect.right() < self.notch_interval_target_x / 10:
labels_notches.items.pop(-2)
rects_to_draw.append((last_rect, last_label))
break
else:
rect = painter.boundingRect(
anchor_rect, Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignHCenter, label
)
rects_to_draw.append((rect, label))
self.notches_cache[self.mode] = (setup_key, (scroll_rect, labels_notches, rects_to_draw))
for rect, text in rects_to_draw:
painter.drawText(rect, text)
painter.setRenderHint(QPainter.RenderHint.Antialiasing, False)
painter.drawLines([notch.line for notch in labels_notches]) # type: ignore
painter.fillRect(scroll_rect, Qt.GlobalColor.gray)
for provider, notches in self.notches.items():
if not provider.is_notches_visible:
continue
for notch in notches:
painter.setPen(notch.color)
painter.drawLine(notch.line)
painter.setPen(Qt.GlobalColor.black)
painter.drawLine(cursor_line)
|