-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimelineWidget.py
More file actions
55 lines (39 loc) · 1.8 KB
/
TimelineWidget.py
File metadata and controls
55 lines (39 loc) · 1.8 KB
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
from PySide6.QtCore import Qt, QRectF, Signal
from PySide6.QtGui import QPainter, QPen
from PySide6.QtWidgets import QWidget, QVBoxLayout, QGraphicsView, QGraphicsScene
class TimelineWidget(QWidget):
cursor_positions_changed = Signal(int, int)
def __init__(self, range_max, parent=None):
super().__init__(parent)
self.range_max = range_max
self.head_position = 0
self.tail_position = 0
self.init_ui()
def init_ui(self):
layout = QVBoxLayout(self)
self.timeline_view = QGraphicsView()
self.timeline_scene = QGraphicsScene()
self.timeline_view.setScene(self.timeline_scene)
layout.addWidget(self.timeline_view)
self.setStyleSheet("background-color: #333;")
def update_timeline(self):
self.timeline_scene.clear()
# Draw the timeline
pen = QPen(Qt.SolidLine)
pen.setColor(Qt.white)
timeline_height = 30
timeline_rect = QRectF(0, 0, self.width(), timeline_height)
self.timeline_scene.addRect(timeline_rect, pen)
# Draw the head cursor
head_rect = QRectF(self.head_position, 0, 2, timeline_height)
self.timeline_scene.addRect(head_rect, pen)
# Draw the tail cursor
tail_rect = QRectF(self.tail_position, 0, 2, timeline_height)
self.timeline_scene.addRect(tail_rect, pen)
self.timeline_view.setSceneRect(self.timeline_scene.itemsBoundingRect())
def set_cursor_positions(self, head_position, tail_position):
if head_position != self.head_position or tail_position != self.tail_position:
self.head_position = head_position
self.tail_position = tail_position
self.update_timeline()
self.cursor_positions_changed.emit(self.head_position, self.tail_position)