[pitivi/gtktimeline] timeline: Handle reordering layer dragging them around



commit f4710295eff13878bbba9757f4b9810aa0af9ce4
Author: Thibault Saunier <tsaunier gnome org>
Date:   Wed May 20 13:01:18 2015 +0200

    timeline: Handle reordering layer dragging them around
    
    Reviewers: Mathieu_Du
    
    Differential Revision: http://phabricator.freedesktop.org/D194

 pitivi/timeline/layer.py    |   13 ++++++-----
 pitivi/timeline/timeline.py |   46 +++++++++++++++++++++++++++++++++++++-----
 2 files changed, 47 insertions(+), 12 deletions(-)
---
diff --git a/pitivi/timeline/layer.py b/pitivi/timeline/layer.py
index cc956d4..deab26e 100644
--- a/pitivi/timeline/layer.py
+++ b/pitivi/timeline/layer.py
@@ -20,6 +20,7 @@
 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 
+from gi.repository import Gdk
 from gi.repository import Gtk
 from gi.repository import GES
 from gi.repository import Gio
@@ -237,8 +238,6 @@ class LayerControls(Gtk.Bin, Loggable):
 
         menubutton.set_popover(popover)
         menubutton.props.direction = Gtk.ArrowType.RIGHT
-        self.connect("button-release-event", self._ignoreClicksCb)
-        self.connect("button-press-event", self._ignoreClicksCb)
         self._hbox.add(menubutton)
         self._hbox.add(self._vbox)
         popover.props.position = Gtk.PositionType.LEFT
@@ -263,6 +262,11 @@ class LayerControls(Gtk.Bin, Loggable):
         self.bLayer.connect("notify::priority", self.__layerPriorityChangedCb)
         self.__layerPriorityChangedCb(self.bLayer, None)
 
+        ebox.connect("notify::window", self._windowSetCb)
+
+    def _windowSetCb(self, window, pspec):
+        self.props.window.set_cursor(Gdk.Cursor.new(Gdk.CursorType.HAND1))
+
     def __del__(self):
         self.bLayer.disconnect_by_func(self.__layerPriorityChangedCb)
         super(LayerControls, self).__del__()
@@ -314,10 +318,6 @@ class LayerControls(Gtk.Bin, Loggable):
         bTimeline.get_asset().pipeline.commit_timeline()
         self.app.action_log.commit()
 
-    def _ignoreClicksCb(self, unused_widget, event):
-        self.debug("Do not pass event %s to the timeline" % event)
-        return True
-
     def _moveLayerCb(self, unused_simple_action, unused_parametter, step):
         index = self.bLayer.get_priority()
         if abs(step) == 1:
@@ -328,6 +328,7 @@ class LayerControls(Gtk.Bin, Loggable):
             index = len(self.bLayer.get_timeline().get_layers()) - 1
             # if audio, set last position
         self.bLayer.get_timeline().ui.moveLayer(self.bLayer, index)
+        self.app.project_manager.current_project.pipeline.commit_timeline()
 
 
 class LayerLayout(Gtk.Layout, Loggable):
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index e323d29..7e335a8 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -262,6 +262,9 @@ class Timeline(Gtk.EventBox, timelineUtils.Zoomable, Loggable):
         self.__setUpDragAndDrop()
         self.__setupSelectionMarquee()
 
+        # Reorder layers
+        self.__moving_layer = None
+
         self.__button_pressed = False
 
         # Setup our Gtk.Widget properties
@@ -452,10 +455,10 @@ class Timeline(Gtk.EventBox, timelineUtils.Zoomable, Loggable):
 
         parent = widget.get_parent()
         while parent is not None and parent != self:
-            parent = parent.get_parent()
-
             if isinstance(parent, _type):
                 return parent
+
+            parent = parent.get_parent()
         return None
 
     def adjustCoords(self, coords=None, x=None, y=None):
@@ -544,21 +547,34 @@ class Timeline(Gtk.EventBox, timelineUtils.Zoomable, Loggable):
 
             if self.draggingElement is not None:
                 self.__drag_start_x = event.x
-
             else:
-                self.__marquee.setStartPosition(event)
+                layer_controls = self._getParentOfType(event_widget, LayerControls)
+                if not layer_controls:
+                    self.__marquee.setStartPosition(event)
+                else:
+                    self.__moving_layer = layer_controls.bLayer
 
         return False
 
     def __buttonReleaseEventCb(self, unused_widget, event):
         if self.draggingElement:
             self.dragEnd()
+        elif self.__moving_layer:
+            self.__endMovingLayer()
+
+            return False
         else:
             self._selectUnderMarquee()
 
+        event_widget = self.get_event_widget(event)
+        if event_widget and self._getParentOfType(event_widget, LayerControls):
+            # Never seek when the LayerControls box has been clicked
+
+            return False
+
         if self.allowSeek:
             event_widget = self.get_event_widget(event)
-            x, unused_y = event_widget.translate_coordinates(self, event.x, event.y)
+            x, unusedy = event_widget.translate_coordinates(self, event.x, event.y)
             x -= CONTROL_WIDTH
             x += self.hadj.get_value()
 
@@ -583,6 +599,21 @@ class Timeline(Gtk.EventBox, timelineUtils.Zoomable, Loggable):
 
             self.__dragUpdate(self.get_event_widget(event), event.x, event.y)
             self.got_dragged = True
+        elif self.__moving_layer:
+            event_widget = self.get_event_widget(event)
+            unused_x, y = event_widget.translate_coordinates(self, event.x, event.y)
+            priority = self.__moving_layer.get_priority()
+            layer, on_sep = self.__getLayerAt(y)
+
+            if on_sep:
+                if layer.ui.after_sep in on_sep:
+                    priority = layer.get_priority() + 1
+                else:
+                    priority = layer.get_priority() - 1
+            elif layer != self.__moving_layer:
+                priority = layer.get_priority()
+
+            self.moveLayer(self.__moving_layer, priority)
         elif self.__marquee.start_x:
             self.__marquee.move(event)
 
@@ -770,7 +801,6 @@ class Timeline(Gtk.EventBox, timelineUtils.Zoomable, Loggable):
         for layer in layers:
             layer.set_priority(i)
             i += 1
-        self.bTimeline.commit()
 
     def _addLayer(self, bLayer):
         layer_widget = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
@@ -1013,6 +1043,10 @@ class Timeline(Gtk.EventBox, timelineUtils.Zoomable, Loggable):
 
         self.queue_draw()
 
+    def __endMovingLayer(self):
+        self._project.pipeline.commit_timeline()
+        self.__moving_layer = None
+
 
 class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
 


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