[pitivi] viewer: Set title props when dragging the viewer



commit 8430a1ad6c9ba1f7622260dde98de7be68a8c474
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Fri Nov 6 08:52:46 2015 +0100

    viewer: Set title props when dragging the viewer
    
    When draging the viewer we currently change the clip transformation:
    posx, posy. But for TitleClipss we want to change xpos and ypos which
    represent the text position.
    
    Also fixes https://phabricator.freedesktop.org/T3181
    
    Reviewed-by: Thibault Saunier <tsaunier gnome org>
    Differential Revision: https://phabricator.freedesktop.org/D558

 pitivi/titleeditor.py |   64 -------------------------------------------------
 pitivi/viewer.py      |   31 ++++++++++++++++++-----
 2 files changed, 24 insertions(+), 71 deletions(-)
---
diff --git a/pitivi/titleeditor.py b/pitivi/titleeditor.py
index 3c574c0..1226fdd 100644
--- a/pitivi/titleeditor.py
+++ b/pitivi/titleeditor.py
@@ -22,11 +22,9 @@
 import os
 
 from gi.repository import Gtk
-from gi.repository import Gdk
 from gi.repository import Pango
 from gi.repository import GES
 from gi.repository import Gst
-from gi.repository import GLib
 
 from gettext import gettext as _
 from xml.sax.saxutils import escape, unescape
@@ -62,9 +60,6 @@ class TitleEditor(Loggable):
         self.seeker = Seeker()
         self._selection = None
 
-        # Drag attributes
-        self._drag_events = []
-        self._signals_connected = False
         self._setting_props = False
         self._children_props_handler = None
 
@@ -305,71 +300,12 @@ class TitleEditor(Loggable):
         if self.source and not self._children_props_handler:
             self._children_props_handler = self.source.connect('deep-notify',
                                                                self._propertyChangedCb)
-        if not self._signals_connected:
-            widget = self.app.gui.viewer.target
-            widget.connect("motion-notify-event", self.viewerDragNotifyCb)
-            widget.connect("button-press-event", self.viewerDragPressCb)
-            widget.connect("button-release-event", self.viewerDragReleaseCb)
-            self._signals_connected = True
 
     def _disconnect_signals(self):
         if self._children_props_handler is not None:
             self.source.disconnect(self._children_props_handler)
             self._children_props_handler = None
 
-        if not self._signals_connected:
-            return
-        self.app.gui.viewer.target.disconnect_by_func(self.viewerDragNotifyCb)
-        self.app.gui.viewer.target.disconnect_by_func(self.viewerDragPressCb)
-        self.app.gui.viewer.target.disconnect_by_func(self.viewerDragReleaseCb)
-        self._signals_connected = False
-
-    def viewerDragPressCb(self, unused_widget, event):
-        if event.button == 1:
-            self._drag_events = [(event.x, event.y)]
-            # Update drag by drag event change, but not too often
-            self.timeout = GLib.timeout_add(100, self.drag_update_event)
-            # If drag goes out for 0.3 second, and do not come back, consider
-            # drag end
-            self._drag_updated = True
-            self.timeout = GLib.timeout_add(1000, self.drag_possible_end_event)
-
-    def drag_possible_end_event(self):
-        if self._drag_updated:
-            # Updated during last timeout, wait more
-            self._drag_updated = False
-            return True
-        else:
-            # Not updated - posibly out of bounds, stop drag
-            self.log("Drag timeout")
-            self._drag_events = []
-            return False
-
-    def drag_update_event(self):
-        if len(self._drag_events) > 0:
-            st = self._drag_events[0]
-            self._drag_events = [self._drag_events[-1]]
-            e = self._drag_events[0]
-            xdiff = e[0] - st[0]
-            ydiff = e[1] - st[1]
-            xdiff /= self.app.gui.viewer.target.get_allocated_width()
-            ydiff /= self.app.gui.viewer.target.get_allocated_height()
-            newxpos = self.settings["xpos"].get_value() + xdiff
-            newypos = self.settings["ypos"].get_value() + ydiff
-            self.settings["xpos"].set_value(newxpos)
-            self.settings["ypos"].set_value(newypos)
-            return True
-        else:
-            return False
-
-    def viewerDragNotifyCb(self, unused_widget, event):
-        if len(self._drag_events) > 0 and event.get_state() & Gdk.ModifierType.BUTTON1_MASK:
-            self._drag_updated = True
-            self._drag_events.append((event.x, event.y))
-
-    def viewerDragReleaseCb(self, unused_widget, unused_event):
-        self._drag_events = []
-
     def _newProjectLoadedCb(self, app, project, unused_fully_loaded):
         if self._selection is not None:
             self._selection.disconnect_by_func(self._selectionChangedCb)
diff --git a/pitivi/viewer.py b/pitivi/viewer.py
index f548856..1392bdc 100644
--- a/pitivi/viewer.py
+++ b/pitivi/viewer.py
@@ -538,16 +538,35 @@ class TransformationBox(Gtk.EventBox, Loggable):
                     x, y = event_widget.translate_coordinates(self, event.x, event.y)
                     self.__startEditSourcePosition = (current_x, current_y)
                     self.__startDraggingPosition = (x, y)
+                    if type(self.__editSource) == GES.TitleSource:
+                        res_x, xpos = self.__editSource.get_child_property("xpos")
+                        res_y, ypos = self.__editSource.get_child_property("ypos")
+                        assert res_x
+                        assert res_y
+                        self.__startDraggingTitlePos = (xpos, ypos)
         elif event.type == Gdk.EventType.MOTION_NOTIFY:
             if self.__startDraggingPosition and self.__editSource:
                 event_widget = Gtk.get_event_widget(event)
                 x, y = event_widget.translate_coordinates(self, event.x, event.y)
-                self.__editSource.set_child_property("posx",
-                                                     self.__startEditSourcePosition[0] +
-                                                     (x - self.__startDraggingPosition[0]))
+                delta_x = x - self.__startDraggingPosition[0]
+                delta_y = y - self.__startDraggingPosition[1]
+                if type(self.__editSource) == GES.TitleSource:
+                    self.__editSource.set_child_property("halignment", GES.TextHAlign.POSITION)
+                    self.__editSource.set_child_property("valignment", GES.TextVAlign.POSITION)
+                    alloc = self.get_allocation()
+                    delta_xpos = delta_x / alloc.width
+                    delta_ypos = delta_y / alloc.height
+                    xpos = max(0, min(self.__startDraggingTitlePos[0] + delta_xpos, 1))
+                    ypos = max(0, min(self.__startDraggingTitlePos[1] + delta_ypos, 1))
+                    self.__editSource.set_child_property("xpos", xpos)
+                    self.__editSource.set_child_property("ypos", ypos)
+                else:
+                    self.__editSource.set_child_property("posx",
+                                                         self.__startEditSourcePosition[0] +
+                                                         delta_x)
 
-                self.__editSource.set_child_property("posy", self.__startEditSourcePosition[1] +
-                                                     (y - self.__startDraggingPosition[1]))
+                    self.__editSource.set_child_property("posy", self.__startEditSourcePosition[1] +
+                                                         delta_y)
                 self.app.project_manager.current_project.pipeline.commit_timeline()
         elif event.type == Gdk.EventType.SCROLL:
             if self.__editSource:
@@ -630,8 +649,6 @@ class ViewerWidget(Gtk.AspectFrame, Loggable):
         self.area = None
         self.zoom = 1.0
         self.sink = sink
-        self.pixbuf = None
-        self.pipeline = None
         self.transformation_properties = None
         self._setting_ratio = False
         self.__startDraggingPosition = None


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