Skip to content

Commit

Permalink
Merge pull request OpenShot#3070 from SuslikV/patch-7
Browse files Browse the repository at this point in the history
Prevent accidental properties edit by mouse move
  • Loading branch information
jonoomph authored Nov 17, 2019
2 parents 226c98a + d90c78e commit 69632c1
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions src/windows/views/properties_tableview.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,18 @@ class PropertiesTableView(QTableView):
def mouseMoveEvent(self, event):
# Get data model and selection
model = self.clip_properties_model.model
row = self.indexAt(event.pos()).row()
column = self.indexAt(event.pos()).column()

# Do not change selected row during mouse move
if self.lock_selection:
row = self.prev_row
else:
row = self.indexAt(event.pos()).row()
self.prev_row = row
self.lock_selection = True

if row is None:
return

if model.item(row, 0):
self.selected_label = model.item(row, 0)
self.selected_item = model.item(row, 1)
Expand Down Expand Up @@ -217,10 +227,21 @@ def mouseMoveEvent(self, event):

# Huge range - increment / decrement slowly
if self.previous_x == -1:
# init previous_x for the first time
# Init previous_x for the first time
self.previous_x = event.x()
# calculate # of pixels dragged
self.diff_length = 10
# Calculate # of pixels dragged
drag_diff = self.previous_x - event.x()

if abs(drag_diff) < self.diff_length:
# If threshold exceed then allow any small incriment for the next time
# In few steps, because the first click may has any far position
self.diff_length -= 1
if self.diff_length < 0:
self.diff_length = 0
self.previous_x = event.x()
return

if drag_diff > 0:
# Move to the left by a small amount
self.new_value -= 0.50
Expand All @@ -230,8 +251,21 @@ def mouseMoveEvent(self, event):
# update previous x
self.previous_x = event.x()
else:
if self.previous_x == -1:
# Init previous_x for the first time
self.previous_x = event.x()
self.diff_length = 10
if abs(self.previous_x - event.x()) < self.diff_length:
# If threshold exceeded then allow any small incriment for the next time
# In few steps, because the first click may has any far position
self.diff_length -= 1
if self.diff_length < 0:
self.diff_length = 0
self.previous_x = event.x()
return
# Small range - use cursor % to calculate new value
self.new_value = property_min + (min_max_range * cursor_value_percent)
self.previous_x = event.x()

# Clamp value between min and max (just incase user drags too big)
self.new_value = max(property_min, self.new_value)
Expand Down Expand Up @@ -260,6 +294,10 @@ def mouseReleaseEvent(self, event):
self.selected_label = model.item(row, 0)
self.selected_item = model.item(row, 1)

# Allow new selection and prepare to set minimum move threshold
self.lock_selection = False
self.previous_x = -1

def doubleClickedCB(self, model_index):
"""Double click handler for the property table"""

Expand Down Expand Up @@ -569,6 +607,8 @@ def __init__(self, *args):
self.selected_item = None
self.new_value = None
self.original_data = None
self.lock_selection = False
self.prev_row = None

# Context menu concurrency lock
self.menu_lock = False
Expand Down

0 comments on commit 69632c1

Please sign in to comment.