Skip to content

Commit

Permalink
feat: allow seek while dragging cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhd1701 committed Nov 22, 2021
1 parent 0193ee8 commit a3a7024
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
3 changes: 2 additions & 1 deletion gridplayer/player/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ def __init__(self, **kwargs):
("files_opened", "playlist.process_arguments")
]

self.global_event_filters.append("mouse_hide")

self.event_filters = [
"window_state",
"mouse_hide",
"drag_n_drop",
"active_block",
"single_mode",
Expand Down
4 changes: 2 additions & 2 deletions gridplayer/widgets/video_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def ui_connect(self): # noqa: WPS213
(self.progress_bar.mouse_left, self.floating_progress.on_mouse_left),
(self.exit_button.clicked, self.exit),
(self.play_pause_button.clicked, self.play_pause),
(self.progress_bar.emit_new_position, self.emit_position),
(self.progress_bar.position_changed, self.emit_position),
(self.volume_button.clicked, self.mute_unmute),
(self.volume_bar.emit_new_position, self.emit_volume_position),
(self.volume_bar.position_changed, self.emit_volume_position),
)

def ui_setup(self): # noqa: WPS213
Expand Down
62 changes: 45 additions & 17 deletions gridplayer/widgets/video_overlay_elements.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import math

from PyQt5.QtCore import QPoint, Qt, pyqtSignal
from PyQt5.QtGui import QFontMetrics, QPainter, QPainterPath, QRegion
from PyQt5.QtGui import QFontMetrics, QGuiApplication, QPainter, QPainterPath, QRegion
from PyQt5.QtWidgets import QSizePolicy, QWidget

from gridplayer.utils.time_txt import get_time_txt_short
Expand Down Expand Up @@ -188,7 +188,7 @@ def update_visuals(self):


class OverlayProgressBar(OverlayWidget):
emit_new_position = pyqtSignal(float)
position_changed = pyqtSignal(float)

mouse_over = pyqtSignal(QPoint, float)
mouse_left = pyqtSignal()
Expand All @@ -212,16 +212,20 @@ def leaveEvent(self, event):
event.ignore()

def mouseMoveEvent(self, event):
self.progress_select_x = event.pos().x()
self.update()
self.progress_select_x = self._get_x_within_bounds(event.pos().x())

top_edge = self.mapToParent(event.pos())
top_edge.setY(self.pos().y())
self.update()

top_edge = self.mapToParent(QPoint(self.progress_select_x, 0))
mouse_position = self.progress_select_x / self.width()

self.mouse_over.emit(top_edge, mouse_position)

event.ignore()
if QGuiApplication.mouseButtons() == Qt.LeftButton:
self._update_position(self.progress_select_x)
event.accept()
else:
event.ignore()

def mouseReleaseEvent(self, event):
"""Consume mouse release to avoid pausing from parent event"""
Expand All @@ -233,9 +237,7 @@ def mouseReleaseEvent(self, event):

def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.progress_select_x = event.pos().x()
new_position = self.progress_select_x / self.width()
self.emit_new_position.emit(new_position)
self._update_position(event.pos().x())

event.ignore()

Expand Down Expand Up @@ -313,9 +315,21 @@ def loop_end(self, loop_end):
self._loop_end = loop_end
self.update()

def _update_position(self, x):
self.progress_select_x = x
new_position = self.progress_select_x / self.width()
self.position_changed.emit(new_position)

def _get_x_within_bounds(self, x):
if x < 0:
return 0
elif x > self.width():
return self.width()
return x


class OverlayVolumeBar(OverlayWidget):
emit_new_position = pyqtSignal(float)
position_changed = pyqtSignal(float)

def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand All @@ -336,20 +350,22 @@ def leaveEvent(self, event):
event.ignore()

def mouseMoveEvent(self, event):
self.progress_select_y = event.pos().y()
self.progress_select_y = self._get_y_within_bounds(event.pos().y())

self.update()

event.ignore()
if QGuiApplication.mouseButtons() == Qt.LeftButton:
self._update_position(self.progress_select_y)
event.accept()
else:
event.ignore()

def mouseReleaseEvent(self, event):
event.accept()

def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.progress_select_y = event.pos().y()
new_position = 1.0 - (self.progress_select_y / self.height())
self.emit_new_position.emit(new_position)

self._update_position(event.pos().y())
event.accept()
else:
event.ignore()
Expand Down Expand Up @@ -395,3 +411,15 @@ def position(self):
def position(self, position):
self._position = position
self.update()

def _update_position(self, y):
self.progress_select_y = y
new_position = 1.0 - (self.progress_select_y / self.height())
self.position_changed.emit(new_position)

def _get_y_within_bounds(self, y):
if y < 0:
return 0
elif y > self.height():
return self.height()
return y

0 comments on commit a3a7024

Please sign in to comment.