Skip to content

Commit 3b38903

Browse files
authored
Merge pull request #3994 from OpenShot/improved-resize-video-widget
Improving video widget resize logic (by width, or height)
2 parents c4cf27e + c84cabf commit 3b38903

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/windows/video_widget.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
Qt, QCoreApplication, QPointF, QPoint, QRect, QRectF, QSize, QMutex, QTimer
3030
)
3131
from PyQt5.QtGui import (
32-
QTransform, QPainter, QPixmap, QColor, QPen, QBrush, QCursor,
32+
QTransform, QPainter, QPixmap, QColor, QPen, QBrush, QCursor, QImage, QRegion
3333
)
3434
from PyQt5.QtWidgets import QSizePolicy, QWidget, QPushButton
3535

@@ -977,7 +977,7 @@ def regionTriggered(self, clip_id):
977977
self.region_enabled = False
978978
else:
979979
self.region_enabled = True
980-
980+
981981
get_app().window.refreshFrameSignal.emit()
982982

983983
def resizeEvent(self, event):
@@ -995,16 +995,18 @@ def delayed_resize_callback(self):
995995
# Trying to find the closest even number to the requested aspect ratio
996996
# so that both width and height are divisible by 2. This is to prevent some
997997
# strange phantom scaling lines on the edges of the preview window.
998-
ratio = float(get_app().project.get("width")) / float(get_app().project.get("height"))
999-
width = round(self.delayed_size.width() / 2.0) * 2
1000-
height = (round(width / ratio) / 2.0) * 2
1001998

1002-
# Override requested size
1003-
self.delayed_size.setWidth(width)
1004-
self.delayed_size.setHeight(height)
999+
# Scale project size (with aspect ratio) to the delayed widget size
1000+
project_size = QSize(get_app().project.get("width"), get_app().project.get("height"))
1001+
project_size.scale(self.delayed_size, Qt.KeepAspectRatio)
1002+
1003+
# Calculate height/width divisible by 2
1004+
ratio = float(project_size.width()) / float(project_size.height())
1005+
width = round(project_size.width() / 2.0) * 2
1006+
height = (round(width / ratio) / 2.0) * 2
10051007

10061008
# Emit signal that video widget changed size
1007-
self.win.MaxSizeChanged.emit(self.delayed_size)
1009+
self.win.MaxSizeChanged.emit(project_size)
10081010

10091011
# Capture wheel event to alter zoom/scale of widget
10101012
def wheelEvent(self, event):

0 commit comments

Comments
 (0)