diff --git a/vspreview/main/settings.py b/vspreview/main/settings.py index 12609a1b..e111e08e 100644 --- a/vspreview/main/settings.py +++ b/vspreview/main/settings.py @@ -28,8 +28,8 @@ class MainSettings(AbstractToolbarSettings): 'png_compressing_spinbox', 'statusbar_timeout_control', 'timeline_notches_margin_spinbox', 'usable_cpus_spinbox', 'zoom_levels_combobox', 'zoom_levels_lineedit', 'zoom_level_default_combobox', - 'azerty_keyboard_checkbox', 'dragnavigator_timeout_spinbox', 'color_management_checkbox', - 'plugins_save_position_combobox' + 'azerty_keyboard_checkbox', 'dragnavigator_timeout_spinbox', 'dragtimeline_timeout_spinbox', + 'color_management_checkbox', 'plugins_save_position_combobox' ) INSTANT_FRAME_UPDATE = False @@ -75,6 +75,7 @@ def setup_ui(self) -> None: self.zoom_level_default_combobox = ComboBox[int]() self.dragnavigator_timeout_spinbox = SpinBox(self, 0, 1000 * 60 * 5) + self.dragtimeline_timeout_spinbox = SpinBox(self, 0, 500) self.primaries_combobox = ComboBox[str]( model=GeneralModel[str]([ @@ -121,6 +122,8 @@ def setup_ui(self) -> None: HBoxLayout(self.vlayout, [QLabel('Drag Navigator Timeout (ms)'), self.dragnavigator_timeout_spinbox]) + HBoxLayout(self.vlayout, [QLabel('Drag Timeline Timeout (ms)'), self.dragtimeline_timeout_spinbox]) + HBoxLayout(self.vlayout, [QLabel('Output Primaries'), self.primaries_combobox]) HBoxLayout(self.vlayout, [QLabel('Save Plugins Bar Position'), self.plugins_save_position_combobox]) @@ -141,6 +144,7 @@ def set_defaults(self) -> None: self.azerty_keyboard_checkbox.setChecked(False) self.usable_cpus_spinbox.setValue(self.get_usable_cpus_count()) self.dragnavigator_timeout_spinbox.setValue(250) + self.dragtimeline_timeout_spinbox.setValue(40) self.zoom_levels = [ 25, 50, 68, 75, 85, 100, 150, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 2000, 3200 @@ -256,6 +260,10 @@ def get_usable_cpus_count() -> int: def dragnavigator_timeout(self) -> int: return self.dragnavigator_timeout_spinbox.value() + @property + def dragtimeline_timeout(self) -> int: + return self.dragtimeline_timeout_spinbox.value() + def zoom_levels_combobox_on_add(self) -> None: try: new_value = int(self.zoom_levels_lineedit.text()) @@ -319,6 +327,7 @@ def __getstate__(self) -> Mapping[str, Any]: 'zoom_default_index': self.zoom_default_index, 'output_primaries_index': self.primaries_combobox.currentIndex(), 'dragnavigator_timeout': self.dragnavigator_timeout, + 'dragtimeline_timeout': self.dragtimeline_timeout, 'plugins_bar_save_behaviour_index': self.plugins_bar_save_behaviour, 'color_management': self.color_management } @@ -336,6 +345,7 @@ def _setstate_(self, state: Mapping[str, Any]) -> None: try_load(state, 'zoom_levels', list, self) try_load(state, 'zoom_default_index', int, self.zoom_level_default_combobox.setCurrentIndex) try_load(state, 'dragnavigator_timeout', int, self.dragnavigator_timeout_spinbox.setValue) + try_load(state, 'dragtimeline_timeout', int, self.dragtimeline_timeout_spinbox.setValue) try_load(state, 'output_primaries_index', int, self.primaries_combobox.setCurrentIndex) try_load(state, 'plugins_bar_save_behaviour_index', int, self.plugins_save_position_combobox.setCurrentIndex) try_load(state, 'color_management', bool, self.color_management_checkbox.setChecked) diff --git a/vspreview/main/timeline.py b/vspreview/main/timeline.py index c1db7f67..696b4c0f 100644 --- a/vspreview/main/timeline.py +++ b/vspreview/main/timeline.py @@ -3,6 +3,7 @@ from copy import deepcopy from math import floor from typing import Any, Iterable, Sequence, cast +from time import perf_counter_ns from PyQt6.QtCore import QEvent, QLineF, QRectF, Qt, pyqtSignal from PyQt6.QtGui import QMouseEvent, QMoveEvent, QPainter, QPaintEvent, QPalette, QPen, QResizeEvent @@ -54,6 +55,9 @@ def __init__(self, parent: QWidget, **kwargs: Any) -> None: self.main.reload_before_signal.connect(lambda: self.__setattr__('_after_reload', True)) + self.mousepressed = False + self.lastpaint = perf_counter_ns() + @property def cursor_x(self) -> int: return self.c_to_x(self._cursor_x) @@ -222,18 +226,29 @@ def moveEvent(self, event: QMoveEvent) -> None: super().moveEvent(event) self.update() + def mouseReleaseEvent(self, event: QMouseEvent) -> None: + self.mousepressed = False + def mousePressEvent(self, event: QMouseEvent) -> None: super().mousePressEvent(event) - pos = event.pos().toPointF() - - if self.notches_cache[self.mode][1][0].contains(pos): - self.cursor_x = int(pos.x()) - self.clicked.emit(self.x_to_f(self.cursor_x), self.x_to_t(self.cursor_x)) + self.mousepressed = True + self.mouseMoveEvent(event) def mouseMoveEvent(self, event: QMouseEvent) -> None: super().mouseMoveEvent(event) + if self.mousepressed and ( + (perf_counter_ns() - self.lastpaint) / 100000 > self.main.settings.dragtimeline_timeout + ): + pos = event.pos().toPointF() + pos.setY(self.notches_cache[self.mode][1][0].top() + 1) + + if self.notches_cache[self.mode][1][0].contains(pos): + self.cursor_x = int(pos.x()) + self.clicked.emit(self.x_to_f(self.cursor_x), self.x_to_t(self.cursor_x)) + self.lastpaint = perf_counter_ns() + for provider, notches in self.notches.items(): if not provider.is_notches_visible: continue