Skip to content

Commit

Permalink
starting to add new timeline ozmartian#3
Browse files Browse the repository at this point in the history
  • Loading branch information
morzhakovanton committed Dec 16, 2023
1 parent 58232c1 commit 9242072
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 21 deletions.
28 changes: 28 additions & 0 deletions components/ScalableTimeline/lauoyt_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys

from PyQt5.QtWidgets import (
QApplication,
QHBoxLayout,
QPushButton,
QWidget,
)

class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("QHBoxLayout Example")
# Create a QHBoxLayout instance
layout = QHBoxLayout()
# Add widgets to the layout
layout.addWidget(QPushButton("Left-Most"))
layout.addWidget(QPushButton("Center"), 1)
layout.addWidget(QPushButton("Right-Most"), 2)
# Set the layout on the application's window
self.setLayout(layout)
print(self.children())

if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
9 changes: 5 additions & 4 deletions components/ScalableTimeline/scalable_timeline_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@


class ScalableTimeLineWindow(QWidget):
def __init__(self, duration, parent=None):
super().__init__(parent)
def __init__(self):
super().__init__()
self.factor = 1
self.factorMaximum = 16
self.mediaAvailable = True
Expand All @@ -20,7 +20,7 @@ def __init__(self, duration, parent=None):
scrollAreaLayout.addWidget(self.timeline)
# scrollAreaLayout.setContentsMargins(0, 0, 0, 0)

buttonLayout = QHBoxLayout(self)
buttonLayout = QHBoxLayout()
buttonPlus = QPushButton()
buttonPlus.setText('+')

Expand Down Expand Up @@ -92,9 +92,10 @@ def setFixedWidth(self, w):
super().setFixedWidth(w + 36)
self.timeline.setFixedWidth(w)


def main():
app = QApplication(sys.argv)
scalable_timeline = ScalableTimeLineWindow(12.5)
scalable_timeline = ScalableTimeLineWindow()
scalable_timeline.timeline.setFixedWidth(800)
scalable_timeline.timeline.timeline.duration = 15.5
# scalable_timeline.setFixedHeight(102)
Expand Down
34 changes: 17 additions & 17 deletions vidcutter/widgets/scalable_timeline_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TimeLine(QWidget):
positionChanged = pyqtSignal(int)

def __init__(self, parent=None):
super(QWidget, self).__init__()
super().__init__()
self.duration = -1.0
self.length = 400
self.parent = parent
Expand All @@ -34,6 +34,7 @@ def __init__(self, parent=None):
self.minorTicksHeight = 10
self.timeLineHeight = 100
self.theme = 'dark'
self.setObjectName('videoslider')

# Set variables
self.backgroundColor = __backgroudColor__
Expand Down Expand Up @@ -73,7 +74,7 @@ def drawTicks_(self, painter: QStylePainter):
x = i + self.sliderAreaHorizontalOffset
if i % timeTickStep == 0:
h, w, z = 30, 1, 10
if self.parent.parent.mediaAvailable and i < self.width() - (tickStep * 5):
if i < self.width() - (tickStep * 5):
painter.setPen(Qt.white if self.theme == 'dark' else Qt.black)
timecode = self.getTimeString(i * scale, millisecondsFlag)
painter.drawText(x + 5, y + 25, timecode)
Expand Down Expand Up @@ -115,8 +116,10 @@ def paintEvent(self, event):
painter.drawRoundedRect(self.sliderAreaHorizontalOffset, self.sliderAreaTopOffset,
self.width() - 2 * self.sliderAreaHorizontalOffset, self.sliderAreaHeight,
3, 3)
self.drawTicks_(painter)
self.drawSlider_(painter)

if self.parent.parent.mediaAvailable:
self.drawTicks_(painter)
self.drawSlider_(painter)
painter.end()

# Mouse movement
Expand Down Expand Up @@ -200,19 +203,16 @@ def __init__(self, parent=None):
self.restrictValue = 0

self.timeline = TimeLine(self)
self.scrollArea = QScrollArea()
self.scrollArea.setWidget(self.timeline)
self.scrollArea.setContentsMargins(0, 0, 0, 0)
self.scrollArea.setAlignment(Qt.AlignVCenter)
self.scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.scrollArea.setFixedHeight(self.timeline.timeLineHeight + 16)
self.setWidget(self.scrollArea)
self.setWidget(self.timeline)
self.setAlignment(Qt.AlignVCenter)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)


def value(self):
return 0
return self.timeline.pointerTimePosition

def setRange(self, start, end):
pass
self.timeline.duration = end

def setValue(self, seconds: int):
try:
Expand All @@ -225,10 +225,10 @@ def setValue(self, seconds: int):

def setEnabled(self, flag):
self.timeline.setEnabled(flag)
self.scrollArea.setEnabled(flag)
super().setEnabled(flag)

def setRestrictValue(self, value, force=False):
pass
self.restrictValue = value

def update(self):
self.timeline.update()
Expand All @@ -254,10 +254,10 @@ def width(self):
return self.width()

def setFixedWidth(self, width):
self.scrollArea.setFixedWidth(width)
super().setFixedWidth(width)
self.timeline.setFixedWidth(width - 2)

def setFixedHeight(self, height):
self.scrollArea.setFixedHeight(height)
super().setFixedHeight(height)
self.timeline.setFixedHeight(height - 2)

0 comments on commit 9242072

Please sign in to comment.