[pitivi] timeline: Use Widget.translate_coordinates instead of custom operations



commit 416e37830ca0d1005ee394c23de26d85846e3ee4
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Thu Oct 13 10:38:22 2016 +0200

    timeline: Use Widget.translate_coordinates instead of custom operations
    
    This way it's clear beyond doubt what we're using and is consistent with
    the other coordinates translations done in the timeline since two
    commits ago.
    
    Reviewed-by: Thibault Saunier <tsaunier gnome org>
    Differential Revision: https://phabricator.freedesktop.org/D1386

 pitivi/timeline/timeline.py |   48 ++++++++++++++++++++++++------------------
 tests/test_undo_timeline.py |    2 +-
 2 files changed, 28 insertions(+), 22 deletions(-)
---
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 78bbe30..3bb4ca3 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -534,7 +534,6 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
                 return False
 
         event_widget = Gtk.get_event_widget(event)
-        x, y = event_widget.translate_coordinates(self, event.x, event.y)
         if event.get_state() & Gdk.ModifierType.SHIFT_MASK:
             if delta_y > 0:
                 # Scroll down.
@@ -545,22 +544,24 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         elif event.get_state() & (Gdk.ModifierType.CONTROL_MASK |
                                   Gdk.ModifierType.MOD1_MASK):
             # Zoom.
-            x -= self.controls_width
+            x, unused_y = event_widget.translate_coordinates(self.layers_vbox, event.x, event.y)
             # Figure out first where to scroll at the end.
             if event.get_state() & Gdk.ModifierType.CONTROL_MASK:
                 # The time at the mouse cursor.
-                position = self.pixelToNs(x + self.hadj.get_value())
+                position = self.pixelToNs(x)
             else:
                 # The time at the playhead.
                 position = self.__last_position
             if delta_y > 0:
                 Zoomable.zoomOut()
-            elif delta_y < 0:
+            else:
                 Zoomable.zoomIn()
             self.__setLayoutSize()
             if delta_y:
+                # The zoom level changed.
                 self.queue_draw()
-                # Scroll so position is at the current mouse cursor position.
+                # Scroll so position remains in place.
+                x, unused_y = event_widget.translate_coordinates(self.layout, event.x, event.y)
                 self.hadj.set_value(self.nsToPixel(position) - x)
         else:
             if delta_y > 0:
@@ -686,7 +687,9 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
                 return False
 
             if self.got_dragged or self.__drag_start_x != event.x:
-                self.__dragUpdate(Gtk.get_event_widget(event), event.x, event.y)
+                event_widget = Gtk.get_event_widget(event)
+                x, y = event_widget.translate_coordinates(self.layers_vbox, event.x, event.y)
+                self.__drag_update(x, y)
                 self.got_dragged = True
         elif self.__moving_layer:
             event_widget = Gtk.get_event_widget(event)
@@ -708,9 +711,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
 
     def _seek(self, event):
         event_widget = Gtk.get_event_widget(event)
-        x, unused_y = event_widget.translate_coordinates(self, event.x, event.y)
-        x -= self.controls_width
-        x += self.hadj.get_value()
+        x, unused_y = event_widget.translate_coordinates(self.layers_vbox, event.x, event.y)
         position = max(0, self.pixelToNs(x))
         self._project.pipeline.simple_seek(position)
 
@@ -737,10 +738,13 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         for layer in self._layers:
             layer.updatePosition()
 
-    def __createClips(self, x, y):
-        x += self.hadj.props.value
-        x -= self.controls_width
+    def __create_clips(self, x, y):
+        """Creates the clips for an asset drag operation.
 
+        Args:
+            x (int): The x coordinate relative to the layers box.
+            y (int): The y coordinate relative to the layers box.
+        """
         placement = 0
         self.draggingElement = None
         self.resetSelectionGroup()
@@ -782,7 +786,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
 
         return True
 
-    def _drag_motion_cb(self, unused_widget, context, x, y, timestamp):
+    def _drag_motion_cb(self, widget, context, x, y, timestamp):
         target = self.drag_dest_find_target(context, None)
         if not target:
             Gdk.drag_status(context, 0, timestamp)
@@ -793,10 +797,11 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
             # Ask for the details.
             self.drag_get_data(context, target, timestamp)
         elif target.name() == URI_TARGET_ENTRY.target:
+            x, y = widget.translate_coordinates(self.layers_vbox, x, y)
             if not self.dropping_clips:
                 # The preview clips have not been created yet.
-                self.__createClips(x, y)
-            self.__dragUpdate(self, x, y)
+                self.__create_clips(x, y)
+            self.__drag_update(x, y)
 
         Gdk.drag_status(context, Gdk.DragAction.COPY, timestamp)
         return True
@@ -1023,7 +1028,13 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
             else:
                 unset_children_state_recurse(sep, Gtk.StateFlags.PRELIGHT)
 
-    def __dragUpdate(self, event_widget, x, y):
+    def __drag_update(self, x, y):
+        """Updates a clip or asset drag operation.
+
+        Args:
+            x (int): The x coordinate relative to the layers box.
+            y (int): The y coordinate relative to the layers box.
+        """
         if not self.draggingElement:
             return
 
@@ -1043,11 +1054,6 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
                                                   self.app,
                                                   not self.dropping_clips)
 
-        x, y = event_widget.translate_coordinates(self, x, y)
-        x -= self.controls_width
-        x += self.hadj.get_value()
-        y += self.vadj.get_value()
-
         mode = self.__getEditingMode()
         self.editing_context.setMode(mode)
 
diff --git a/tests/test_undo_timeline.py b/tests/test_undo_timeline.py
index 1ddcfe1..de2306b 100644
--- a/tests/test_undo_timeline.py
+++ b/tests/test_undo_timeline.py
@@ -766,7 +766,7 @@ class TestDragDropUndo(BaseTestUndoTimeline):
                 def translate_coordinates(widget, x, y):
                     return x, y
                 timeline_ui.translate_coordinates = translate_coordinates
-                timeline_ui._drag_motion_cb(None, None, 0, LAYER_HEIGHT * 2, 0)
+                timeline_ui._drag_motion_cb(timeline_ui, None, 0, LAYER_HEIGHT * 2, 0)
                 self.assertFalse(timeline_ui.drag_get_data.called)
                 self.assertIsNotNone(timeline_ui.draggingElement)
                 self.assertTrue(timeline_ui.dropping_clips)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]