Skip to content

Commit e728227

Browse files
committed
Merge branch 'effect-parenting-fix' into effect-parenting
2 parents 3b08209 + ea93464 commit e728227

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

src/windows/process_effect.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ def rect_select_clicked(self, widget, param):
255255
topLeft = win.videoPreview.regionTopLeftHandle
256256
bottomRight = win.videoPreview.regionBottomRightHandle
257257
viewPortSize = win.viewport_rect
258+
curr_frame_size = win.videoPreview.curr_frame_size
259+
260+
x1 = topLeft.x() / curr_frame_size.width()
261+
y1 = topLeft.y() / curr_frame_size.height()
262+
x2 = bottomRight.x() / curr_frame_size.width()
263+
y2 = bottomRight.y() / curr_frame_size.height()
258264

259265
# Get QImage of region
260266
if win.videoPreview.region_qimage:
@@ -275,13 +281,10 @@ def rect_select_clicked(self, widget, param):
275281

276282
# If data found, add to context
277283
if topLeft and bottomRight:
278-
self.context[param["setting"]].update({"x": topLeft.x(), "y": topLeft.y(),
279-
"width": bottomRight.x() - topLeft.x(),
280-
"height": bottomRight.y() - topLeft.y(),
281-
"scaled_x": topLeft.x() / viewPortSize.width(), "scaled_y": topLeft.y() / viewPortSize.height(),
282-
"scaled_width": (bottomRight.x() - topLeft.x()) / viewPortSize.width(),
283-
"scaled_height": (bottomRight.y() - topLeft.y()) / viewPortSize.height(),
284-
"first-frame": win.current_frame
284+
self.context[param["setting"]].update({"normalized_x": x1, "normalized_y": y1,
285+
"normalized_width": x2-x1,
286+
"normalized_height": y2-y1,
287+
"first-frame": win.current_frame,
285288
})
286289
log.info(self.context)
287290

src/windows/video_widget.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def drawTransformHandler(self, painter, sx, sy, source_width, source_height, ori
104104
x1=None, y1=None, x2=None, y2=None, rotation = None):
105105
# Draw transform corners and center origin circle
106106
# Corner size
107-
cs = 14.0
107+
cs = self.cs
108108
os = 12.0
109109

110110
# Rotate the transform handler
@@ -206,6 +206,7 @@ def paintEvent(self, event, *args):
206206
# Calculate new frame image size, maintaining aspect ratio
207207
pixSize = self.current_image.size()
208208
pixSize.scale(event.rect().width(), event.rect().height(), Qt.KeepAspectRatio)
209+
self.curr_frame_size = pixSize
209210

210211
# Scale image
211212
scaledPix = self.current_image.scaled(pixSize, Qt.KeepAspectRatio, Qt.SmoothTransformation)
@@ -374,7 +375,7 @@ def paintEvent(self, event, *args):
374375

375376
# Draw transform corners and center origin circle
376377
# Corner size
377-
cs = 14.0
378+
cs = self.cs
378379

379380
if self.regionTopLeftHandle and self.regionBottomRightHandle:
380381
# Draw 2 corners and bounding box
@@ -805,7 +806,7 @@ def mouseMoveEvent(self, event):
805806
if self.region_enabled:
806807
# Modify region selection (x, y, width, height)
807808
# Corner size
808-
cs = 14.0
809+
cs = self.cs
809810

810811
# Adjust existing region coordinates (if any)
811812
if not self.mouse_dragging and self.resize_button.isVisible() and self.resize_button.rect().contains(event.pos()):
@@ -1001,15 +1002,13 @@ def updateEffectProperty(self, effect_id, frame_number, property_key, new_value,
10011002
found_point = False
10021003
effect_updated = False
10031004

1004-
raw_properties = json.loads(self.transforming_effect_object.Json())
1005-
10061005
c = Effect.get(id=effect_id)
10071006

10081007
if not c:
10091008
# No clip found
10101009
return
10111010

1012-
for point in raw_properties[property_key]["Points"]:
1011+
for point in c.data[property_key]["Points"]:
10131012
log.info("looping points: co.X = %s" % point["co"]["X"])
10141013

10151014
if point["co"]["X"] == frame_number:
@@ -1021,18 +1020,17 @@ def updateEffectProperty(self, effect_id, frame_number, property_key, new_value,
10211020
if not found_point and new_value != None:
10221021
effect_updated = True
10231022
log.info("Created new point at X=%s" % frame_number)
1024-
raw_properties[property_key]["Points"].append({'co': {'X': frame_number, 'Y': new_value}, 'interpolation': openshot.BEZIER})
1023+
c.data[property_key]["Points"].append({'co': {'X': frame_number, 'Y': new_value}, 'interpolation': openshot.BEZIER})
10251024

1026-
raw_properties_string = json.dumps(raw_properties)
1025+
# Reduce # of clip properties we are saving (performance boost)
1026+
c.data = {property_key: c.data.get(property_key)}
10271027

10281028
if effect_updated:
10291029
c.save()
10301030
# Update the preview
10311031
if refresh:
10321032
get_app().window.refreshFrameSignal.emit()
10331033

1034-
self.transforming_effect_object.SetJson(raw_properties_string)
1035-
10361034
def refreshTriggered(self):
10371035
"""Signal to refresh viewport (i.e. a property might have changed that effects the preview)"""
10381036

@@ -1202,7 +1200,9 @@ def __init__(self, watch_project=True, *args):
12021200
self.region_mode = None
12031201
self.regionTopLeftHandle = None
12041202
self.regionBottomRightHandle = None
1203+
self.curr_frame_size = None # Frame size
12051204
self.zoom = 1.0 # Zoom of widget (does not affect video, only workspace)
1205+
self.cs = 14.0 # Corner size of Transform Handler rectangles
12061206
self.resize_button = QPushButton(_('Reset Zoom'), self)
12071207
self.resize_button.hide()
12081208
self.resize_button.setStyleSheet('QPushButton { margin: 10px; padding: 2px; }')

0 commit comments

Comments
 (0)