Skip to content

Commit

Permalink
fix: improve overlay workarounds for Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhd1701 committed Jul 16, 2022
1 parent f5b8164 commit 70963b5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 28 deletions.
7 changes: 6 additions & 1 deletion gridplayer/widgets/video_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ def __init__(self, video_driver, context, **kwargs):
self.ui_setup()

self.video_status.show()
self.overlay.raise_()
self.overlay.hide()

def init_video_driver(self) -> VideoFrameVLC:
Expand Down Expand Up @@ -387,6 +386,12 @@ def wheelEvent(self, event):

event.ignore()

def mousePressEvent(self, event) -> None:
if Settings().get("internal/fake_overlay_invisibility"):
self.window().raise_()

super().mousePressEvent(event)

@only_initialized
def mouseReleaseEvent(self, event) -> None:
if self._ctx.is_disable_click_pause:
Expand Down
38 changes: 23 additions & 15 deletions gridplayer/widgets/video_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,20 +339,15 @@ def paintEvent(self, event):
# 0 coord to keep children from sliding off
mask = QRegion(QRect(0, 0, 1, 1))

if self.border_widget.isVisible():
frame_width = 5
frame = QRegion(self.rect())
frame -= QRegion(
QRect(
frame_width,
frame_width,
self.width() - frame_width * 2,
self.height() - frame_width * 2,
)
)
mask = mask.united(frame)

mask = mask.united(self.control_widget.childrenRegion())
for child in self.findChildren(OverlayWidget):
if child.isVisible():
if child.mask():
mask += child.mask().translated(child.pos())
else:
mask += QRegion(child.geometry())

if not self.border_widget.isVisible():
mask -= QRegion(QRect(0, 0, 1, 1))

self.setMask(mask)

Expand Down Expand Up @@ -400,21 +395,34 @@ def __init__(self, parent=None):

def show(self):
if not self.isVisible():
super().show()
self.setVisible(True)

self._is_visible = True

self.setAttribute(Qt.WA_TransparentForMouseEvents, False)
self.update()

def hide(self):
if not self.isVisible():
self.setVisible(True)

self._is_visible = False

self.setAttribute(Qt.WA_TransparentForMouseEvents)
self.update()

def move_beyond_screen(self):
self.move(QPoint(-self.width(), -self.height()))

def move_to_parent(self):
if not self._is_visible:
return self.move_beyond_screen()

super().move_to_parent()

def paintEvent(self, event):
if not self._is_visible and self.windowOpacity() != 0:
self.move_beyond_screen()
self.setMask(QRegion(0, 0, 1, 1))
self.setWindowOpacity(0)
return
Expand Down
36 changes: 24 additions & 12 deletions gridplayer/widgets/video_overlay_elements.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import math

from PyQt5.QtCore import QEvent, QPoint, Qt, pyqtSignal
from PyQt5.QtCore import QEvent, QPoint, QRect, Qt, pyqtSignal
from PyQt5.QtGui import (
QBrush,
QColor,
QFontMetrics,
QGuiApplication,
QPainter,
QPainterPath,
QPen,
QRegion,
)
from PyQt5.QtWidgets import QSizePolicy, QWidget
Expand All @@ -31,6 +31,11 @@ def __init__(self, **kwargs):
def color(self):
return self._color

@color.setter
def color(self, color):
self._color = QColor(color)
self.update()

@property
def color_contrast(self):
lightness = 0 if self.color.lightness() > 127 else 255 # noqa: WPS432
Expand All @@ -46,11 +51,6 @@ def color_contrast_mid(self):

return QColor.fromHsl(self.color.hue(), self.color.saturation(), lightness)

@color.setter
def color(self, color):
self._color = QColor(color)
self.update()


class OverlayLabel(OverlayWidget):
def __init__(self, **kwargs):
Expand Down Expand Up @@ -480,17 +480,29 @@ def _get_y_within_bounds(self, y):


class OverlayBorder(OverlayWidget):
border_width = 5

def __init__(self, **kwargs):
super().__init__(**kwargs)

self.setAttribute(Qt.WA_TransparentForMouseEvents)

def resizeEvent(self, event) -> None:
border = QRegion(self.rect())
border -= QRegion(
QRect(
self.border_width,
self.border_width,
self.width() - self.border_width * 2,
self.height() - self.border_width * 2,
)
)

self.setMask(border)

def paintEvent(self, event) -> None:
painter = QPainter(self)

pen = QPen(self.color)
pen.setWidth(10)

painter.setPen(pen)
painter.setBrush(Qt.NoBrush)
painter.setPen(Qt.NoPen)
painter.setBrush(QBrush(self.color))
painter.drawRect(self.rect())

0 comments on commit 70963b5

Please sign in to comment.