Skip to content

Commit a49989d

Browse files
committed
Protect cursor when transform is happening, so it doesn't keep switching cursors during a drag. Fix shear_left and shear_top to take scale into account.
1 parent 3af06b7 commit a49989d

File tree

1 file changed

+44
-24
lines changed

1 file changed

+44
-24
lines changed

src/windows/video_widget.py

+44-24
Original file line numberDiff line numberDiff line change
@@ -376,72 +376,86 @@ def mouseMoveEvent(self, event):
376376

377377
# Determine if cursor is over a handle
378378
if self.transform.mapToPolygon(self.topRightHandle.toRect()).containsPoint(event.pos(), Qt.OddEvenFill):
379-
self.setCursor(self.rotateCursor(self.cursors.get('resize_bdiag'), rotation, shear_x, shear_y))
379+
if not self.transform_mode or self.transform_mode == 'scale_top_right':
380+
self.setCursor(self.rotateCursor(self.cursors.get('resize_bdiag'), rotation, shear_x, shear_y))
380381
# Set the transform mode
381382
if self.mouse_dragging and not self.transform_mode:
382383
self.transform_mode = 'scale_top_right'
383384
elif self.transform.mapToPolygon(self.topHandle.toRect()).containsPoint(event.pos(), Qt.OddEvenFill):
384-
self.setCursor(self.rotateCursor(self.cursors.get('resize_y'), rotation, shear_x, shear_y))
385+
if not self.transform_mode or self.transform_mode == 'scale_top':
386+
self.setCursor(self.rotateCursor(self.cursors.get('resize_y'), rotation, shear_x, shear_y))
385387
# Set the transform mode
386388
if self.mouse_dragging and not self.transform_mode:
387389
self.transform_mode = 'scale_top'
388390
elif self.transform.mapToPolygon(self.topLeftHandle.toRect()).containsPoint(event.pos(), Qt.OddEvenFill):
389-
self.setCursor(self.rotateCursor(self.cursors.get('resize_fdiag'), rotation, shear_x, shear_y))
391+
if not self.transform_mode or self.transform_mode == 'scale_top_left':
392+
self.setCursor(self.rotateCursor(self.cursors.get('resize_fdiag'), rotation, shear_x, shear_y))
390393
# Set the transform mode
391394
if self.mouse_dragging and not self.transform_mode:
392395
self.transform_mode = 'scale_top_left'
393396
elif self.transform.mapToPolygon(self.leftHandle.toRect()).containsPoint(event.pos(), Qt.OddEvenFill):
394-
self.setCursor(self.rotateCursor(self.cursors.get('resize_x'), rotation, shear_x, shear_y))
397+
if not self.transform_mode or self.transform_mode == 'scale_left':
398+
self.setCursor(self.rotateCursor(self.cursors.get('resize_x'), rotation, shear_x, shear_y))
395399
# Set the transform mode
396400
if self.mouse_dragging and not self.transform_mode:
397401
self.transform_mode = 'scale_left'
398402
elif self.transform.mapToPolygon(self.rightHandle.toRect()).containsPoint(event.pos(), Qt.OddEvenFill):
399-
self.setCursor(self.rotateCursor(self.cursors.get('resize_x'), rotation, shear_x, shear_y))
403+
if not self.transform_mode or self.transform_mode == 'scale_right':
404+
self.setCursor(self.rotateCursor(self.cursors.get('resize_x'), rotation, shear_x, shear_y))
400405
# Set the transform mode
401406
if self.mouse_dragging and not self.transform_mode:
402407
self.transform_mode = 'scale_right'
403408
elif self.transform.mapToPolygon(self.bottomLeftHandle.toRect()).containsPoint(event.pos(), Qt.OddEvenFill):
404-
self.setCursor(self.rotateCursor(self.cursors.get('resize_bdiag'), rotation, shear_x, shear_y))
409+
if not self.transform_mode or self.transform_mode == 'scale_bottom_left':
410+
self.setCursor(self.rotateCursor(self.cursors.get('resize_bdiag'), rotation, shear_x, shear_y))
405411
# Set the transform mode
406412
if self.mouse_dragging and not self.transform_mode:
407413
self.transform_mode = 'scale_bottom_left'
408414
elif self.transform.mapToPolygon(self.bottomHandle.toRect()).containsPoint(event.pos(), Qt.OddEvenFill):
409-
self.setCursor(self.rotateCursor(self.cursors.get('resize_y'), rotation, shear_x, shear_y))
415+
if not self.transform_mode or self.transform_mode == 'scale_bottom':
416+
self.setCursor(self.rotateCursor(self.cursors.get('resize_y'), rotation, shear_x, shear_y))
410417
# Set the transform mode
411418
if self.mouse_dragging and not self.transform_mode:
412419
self.transform_mode = 'scale_bottom'
413420
elif self.transform.mapToPolygon(self.bottomRightHandle.toRect()).containsPoint(event.pos(), Qt.OddEvenFill):
414-
self.setCursor(self.rotateCursor(self.cursors.get('resize_fdiag'), rotation, shear_x, shear_y))
421+
if not self.transform_mode or self.transform_mode == 'scale_bottom_right':
422+
self.setCursor(self.rotateCursor(self.cursors.get('resize_fdiag'), rotation, shear_x, shear_y))
415423
# Set the transform mode
416424
if self.mouse_dragging and not self.transform_mode:
417425
self.transform_mode = 'scale_bottom_right'
418426
elif self.transform.mapToPolygon(self.topShearHandle.toRect()).containsPoint(event.pos(), Qt.OddEvenFill):
419-
self.setCursor(self.rotateCursor(self.cursors.get('shear_x'), rotation, shear_x, shear_y))
427+
if not self.transform_mode or self.transform_mode == 'shear_top':
428+
self.setCursor(self.rotateCursor(self.cursors.get('shear_x'), rotation, shear_x, shear_y))
420429
# Set the transform mode
421430
if self.mouse_dragging and not self.transform_mode:
422431
self.transform_mode = 'shear_top'
423432
elif self.transform.mapToPolygon(self.leftShearHandle.toRect()).containsPoint(event.pos(), Qt.OddEvenFill):
424-
self.setCursor(self.rotateCursor(self.cursors.get('shear_y'), rotation, shear_x, shear_y))
433+
if not self.transform_mode or self.transform_mode == 'shear_left':
434+
self.setCursor(self.rotateCursor(self.cursors.get('shear_y'), rotation, shear_x, shear_y))
425435
# Set the transform mode
426436
if self.mouse_dragging and not self.transform_mode:
427437
self.transform_mode = 'shear_left'
428438
elif self.transform.mapToPolygon(self.rightShearHandle.toRect()).containsPoint(event.pos(), Qt.OddEvenFill):
429-
self.setCursor(self.rotateCursor(self.cursors.get('shear_y'), rotation, shear_x, shear_y))
439+
if not self.transform_mode or self.transform_mode == 'shear_right':
440+
self.setCursor(self.rotateCursor(self.cursors.get('shear_y'), rotation, shear_x, shear_y))
430441
# Set the transform mode
431442
if self.mouse_dragging and not self.transform_mode:
432443
self.transform_mode = 'shear_right'
433444
elif self.transform.mapToPolygon(self.bottomShearHandle.toRect()).containsPoint(event.pos(), Qt.OddEvenFill):
434-
self.setCursor(self.rotateCursor(self.cursors.get('shear_x'), rotation, shear_x, shear_y))
445+
if not self.transform_mode or self.transform_mode == 'shear_bottom':
446+
self.setCursor(self.rotateCursor(self.cursors.get('shear_x'), rotation, shear_x, shear_y))
435447
# Set the transform mode
436448
if self.mouse_dragging and not self.transform_mode:
437449
self.transform_mode = 'shear_bottom'
438450
elif self.transform.mapToPolygon(self.clipBounds.toRect()).containsPoint(event.pos(), Qt.OddEvenFill):
439-
self.setCursor(self.rotateCursor(self.cursors.get('move'), rotation, shear_x, shear_y))
451+
if not self.transform_mode or self.transform_mode == 'location':
452+
self.setCursor(self.rotateCursor(self.cursors.get('move'), rotation, shear_x, shear_y))
440453
# Set the transform mode
441454
if self.mouse_dragging and not self.transform_mode:
442455
self.transform_mode = 'location'
443456
elif not self.transform.mapToPolygon(self.clipBounds.toRect()).containsPoint(event.pos(), Qt.OddEvenFill):
444-
self.setCursor(self.rotateCursor(self.cursors.get('rotate'), rotation, shear_x, shear_y))
457+
if not self.transform_mode or self.transform_mode == 'rotation':
458+
self.setCursor(self.rotateCursor(self.cursors.get('rotate'), rotation, shear_x, shear_y))
445459
# Set the transform mode
446460
if self.mouse_dragging and not self.transform_mode:
447461
self.transform_mode = 'rotation'
@@ -457,24 +471,26 @@ def mouseMoveEvent(self, event):
457471
location_y = raw_properties.get('location_y').get('value')
458472

459473
# Calculate new location coordinates
460-
location_x += (event.pos().x() - self.mouse_position.x()) / self.clipBounds.width()
461-
location_y += (event.pos().y() - self.mouse_position.y()) / self.clipBounds.height()
474+
location_x += (event.pos().x() - self.mouse_position.x()) / viewport_rect.width()
475+
location_y += (event.pos().y() - self.mouse_position.y()) / viewport_rect.height()
462476

463477
# Update keyframe value (or create new one)
464-
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'location_x', location_x)
478+
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'location_x', location_x, refresh=False)
465479
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'location_y', location_y)
466480

467481
elif self.transform_mode == 'shear_top':
468482
# Get current keyframe shear value
469483
shear_x = raw_properties.get('shear_x').get('value')
484+
scale_x = raw_properties.get('scale_x').get('value')
470485
location_x = raw_properties.get('location_x').get('value')
471486

472487
# Calculate new location coordinates
488+
aspect_ratio = self.clipBounds.width() / self.clipBounds.height()
473489
shear_x -= (event.pos().x() - self.mouse_position.x()) / self.clipBounds.width()
474-
location_x += (event.pos().x() - self.mouse_position.x()) / (self.clipBounds.width() * 2.0)
490+
location_x += (event.pos().x() - self.mouse_position.x()) / ((viewport_rect.width() * aspect_ratio) / scale_x)
475491

476492
# Update keyframe value (or create new one)
477-
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'shear_x', shear_x)
493+
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'shear_x', shear_x, refresh=False)
478494
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'location_x', location_x)
479495

480496
elif self.transform_mode == 'shear_bottom':
@@ -490,14 +506,16 @@ def mouseMoveEvent(self, event):
490506
elif self.transform_mode == 'shear_left':
491507
# Get current keyframe shear value
492508
shear_y = raw_properties.get('shear_y').get('value')
509+
scale_y = raw_properties.get('scale_y').get('value')
493510
location_y = raw_properties.get('location_y').get('value')
494511

495512
# Calculate new location coordinates
513+
aspect_ratio = self.clipBounds.height() / self.clipBounds.width()
496514
shear_y -= (event.pos().y() - self.mouse_position.y()) / self.clipBounds.height()
497-
location_y += (event.pos().y() - self.mouse_position.y()) / self.clipBounds.height()
515+
location_y += (event.pos().y() - self.mouse_position.y()) / ((viewport_rect.height() * aspect_ratio) / scale_y)
498516

499517
# Update keyframe value (or create new one)
500-
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'shear_y', shear_y)
518+
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'shear_y', shear_y, refresh=False)
501519
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'location_y', location_y)
502520

503521
elif self.transform_mode == 'shear_right':
@@ -567,8 +585,9 @@ def mouseMoveEvent(self, event):
567585
scale_y = scale_x
568586

569587
# Update keyframe value (or create new one)
588+
both_scaled = scale_x != 0.001 and scale_y != 0.001
570589
if scale_x != 0.001:
571-
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'scale_x', scale_x)
590+
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'scale_x', scale_x, refresh=(not both_scaled))
572591
if scale_y != 0.001:
573592
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'scale_y', scale_y)
574593

@@ -580,7 +599,7 @@ def mouseMoveEvent(self, event):
580599

581600
self.mutex.unlock()
582601

583-
def updateProperty(self, id, frame_number, property_key, new_value):
602+
def updateProperty(self, id, frame_number, property_key, new_value, refresh=True):
584603
"""Update a keyframe property to a new value, adding or updating keyframes as needed"""
585604
found_point = False
586605
clip_updated = False
@@ -613,7 +632,8 @@ def updateProperty(self, id, frame_number, property_key, new_value):
613632
c.save()
614633

615634
# Update the preview
616-
get_app().window.refreshFrameSignal.emit()
635+
if refresh:
636+
get_app().window.refreshFrameSignal.emit()
617637

618638
def refreshTriggered(self):
619639
"""Signal to refresh viewport (i.e. a property might have changed that effects the preview)"""

0 commit comments

Comments
 (0)