Restore auto-sizing for preview panel only

Preview: constrains height to video aspect ratio (no bars)
Slideshow: KeepAspectRatio with themed letterbox (centered)
This commit is contained in:
pax 2026-04-05 20:44:10 -05:00
parent 24f8ffff51
commit 3b22538e1a

View File

@ -489,6 +489,8 @@ class VideoPlayer(QWidget):
self._current_file = path
self._error_fired = False
self._ended = False
self._video_sized = False
self._video_widget.setMaximumHeight(16777215)
self._last_pos = 0
self._player.setLoops(QMediaPlayer.Loops.Infinite)
self._player.setSource(QUrl.fromLocalFile(path))
@ -565,8 +567,19 @@ class VideoPlayer(QWidget):
else:
self._play_btn.setText("Play")
_preview_auto_size = False # set True for preview panel, False for slideshow
def _on_video_size(self, frame) -> None:
pass # KeepAspectRatio handles sizing
"""In preview mode, constrain height to match video aspect ratio."""
if not self._preview_auto_size or self._video_sized or not frame.isValid():
return
self._video_sized = True
vw = frame.size().width()
vh = frame.size().height()
if vw > 0 and vh > 0:
parent = self._video_widget.parentWidget()
available_w = parent.width() if parent else self._video_widget.width()
self._video_widget.setMaximumHeight(int(available_w * vh / vw))
def _on_media_status(self, status) -> None:
pass
@ -619,6 +632,7 @@ class ImagePreview(QWidget):
# Video player (index 1)
self._video_player = VideoPlayer()
self._video_player.setFocusPolicy(Qt.FocusPolicy.NoFocus)
self._video_player._preview_auto_size = True # auto-size in preview panel
self._video_player.play_next.connect(lambda: self.navigate.emit(1))
self._stack.addWidget(self._video_player)