[pitivi/ges] Only do a "Zoom Fit" when the zoom is already fitted



commit 66d0d68c98f20863b2747e55066fcdeafd2c45bd
Author: Jean-FranÃois Fortin Tam <nekohayo gmail com>
Date:   Thu Apr 26 15:34:00 2012 -0400

    Only do a "Zoom Fit" when the zoom is already fitted
    
    This prevents resetting the zoom if the user had zoomed in.
    This commit also prevents calling setBestZoomRatio too early.
    
    Fixes bug #611964

 pitivi/mainwindow.py        |   20 +++++++++++++-------
 pitivi/timeline/ruler.py    |    4 ++++
 pitivi/timeline/timeline.py |   22 ++++++++++++++++++----
 pitivi/timeline/track.py    |    1 -
 4 files changed, 35 insertions(+), 12 deletions(-)
---
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index 13e2c1d..b605399 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -193,6 +193,7 @@ class PitiviMainWindow(gtk.Window, Loggable):
         self._createUi(instance, allow_full_screen)
         self.recent_manager = RecentManager()
         self._zoom_duration_changed = False
+        self.zoomed_fitted = True
         self._missingUriOnLoading = False
 
         self.app.projectManager.connect("new-project-loading",
@@ -748,10 +749,7 @@ class PitiviMainWindow(gtk.Window, Loggable):
             self._missingUriOnLoading = False
 
         if self.app.current.timeline.props.duration != 0:
-            self.setBestZoomRatio()
             self.render_button.set_sensitive(True)
-        else:
-            self._zoom_duration_changed = True
 
         self._seeker = self.app.current.seeker
         self._seeker.connect("seek", self._timelineSeekCb)
@@ -761,8 +759,10 @@ class PitiviMainWindow(gtk.Window, Loggable):
         # preliminary seek to ensure the project pipeline is configured
         self._seeker.seek(0)
 
-    def setBestZoomRatio(self, p=0):
-        """Set the zoom level so that the entire timeline is in view."""
+    def setBestZoomRatio(self):
+        """
+        Set the zoom level so that the entire timeline is in view.
+        """
         ruler_width = self.timeline_ui.ruler.get_allocation()[2]
         # Add gst.SECOND - 1 to the timeline duration to make sure the
         # last second of the timeline will be in view.
@@ -770,11 +770,15 @@ class PitiviMainWindow(gtk.Window, Loggable):
         timeline_duration = duration + gst.SECOND - 1
         timeline_duration_s = int(timeline_duration / gst.SECOND)
 
+        self.debug("duration: %s, timeline_duration_s: %s" % (duration, timeline_duration_s))
         ideal_zoom_ratio = float(ruler_width) / timeline_duration_s
         nearest_zoom_level = Zoomable.computeZoomLevel(ideal_zoom_ratio)
         Zoomable.setZoomLevel(nearest_zoom_level)
         self.app.current.timeline.props.snapping_distance = \
             Zoomable.pixelToNs(self.app.settings.edgeSnapDeadband)
+        # Only do this at the very end, after updating the other widgets.
+        self.log("Setting 'zoomed_fitted' to True")
+        self.zoomed_fitted = True
 
     def _projectManagerNewProjectLoadingCb(self, projectManager, uri):
         if uri:
@@ -1055,6 +1059,7 @@ class PitiviMainWindow(gtk.Window, Loggable):
         self._settingsChangedCb(self.app.current, None, self.app.current.settings)
         if self.timeline_ui:
             self.timeline_ui.setProject(self.app.current)
+            self.setBestZoomRatio()
             self.clipconfig.project = self.app.current
             #FIXME GES port undo/redo
             #self.app.timelineLogObserver.pipeline = self.app.current.pipeline
@@ -1094,10 +1099,11 @@ class PitiviMainWindow(gtk.Window, Loggable):
         self.debug("Timeline duration changed to %d", timeline.props.duration)
         if timeline.props.duration > 0:
             sensitive = True
-            if self._zoom_duration_changed:
+            if self.zoomed_fitted:
+                self.log("The timeline was zoomed fitted, readjusting to fit again")
                 self.setBestZoomRatio()
-                self._zoom_duration_changed = False
             else:
+                self.log("User had changed the zoom, so not autozooming")
                 self.timeline_ui.updateScrollAdjustments()
         else:
             sensitive = False
diff --git a/pitivi/timeline/ruler.py b/pitivi/timeline/ruler.py
index 634adab..ec400bf 100644
--- a/pitivi/timeline/ruler.py
+++ b/pitivi/timeline/ruler.py
@@ -158,8 +158,12 @@ class ScaleRuler(gtk.DrawingArea, Zoomable, Loggable):
     def do_scroll_event(self, event):
         if event.direction == gtk.gdk.SCROLL_UP:
             Zoomable.zoomIn()
+            self.log("Setting 'zoomed_fitted' to False")
+            self.app.gui.zoomed_fitted = False
         elif event.direction == gtk.gdk.SCROLL_DOWN:
             Zoomable.zoomOut()
+            self.log("Setting 'zoomed_fitted' to False")
+            self.app.gui.zoomed_fitted = False
         # TODO: seek timeline back/forward
         elif event.direction == gtk.gdk.SCROLL_LEFT:
             pass
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 3c62108..a784ac1 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -582,7 +582,7 @@ class Timeline(gtk.Table, Loggable, Zoomable):
         Zoomable.__init__(self)
         self.log("Creating Timeline")
 
-        self._updateZoom = True
+        self._updateZoomSlider = True
         self.ui_manager = ui_manager
         self.app = instance
         self._temp_objects = []
@@ -1052,9 +1052,13 @@ class Timeline(gtk.Table, Loggable, Zoomable):
             # zoom + scroll => zooming (up: zoom in)
             if event.direction == gtk.gdk.SCROLL_UP:
                 Zoomable.zoomIn()
+                self.log("Setting 'zoomed_fitted' to False")
+                self.app.gui.zoomed_fitted = False
                 return True
             elif event.direction == gtk.gdk.SCROLL_DOWN:
                 Zoomable.zoomOut()
+                self.log("Setting 'zoomed_fitted' to False")
+                self.app.gui.zoomed_fitted = False
                 return True
             return False
         else:
@@ -1090,11 +1094,13 @@ class Timeline(gtk.Table, Loggable, Zoomable):
 
     def _zoomAdjustmentChangedCb(self, adjustment):
         # GTK crack
-        self._updateZoom = False
+        self._updateZoomSlider = False
         Zoomable.setZoomLevel(int(adjustment.get_value()))
+        self.log("Setting 'zoomed_fitted' to False")
+        self.app.gui.zoomed_fitted = False
         self._timeline.props.snapping_distance = \
             Zoomable.pixelToNs(self._settings.edgeSnapDeadband)
-        self._updateZoom = True
+        self._updateZoomSlider = True
 
     def _zoomSliderScrollCb(self, unused_widget, event):
         value = self._zoomAdjustment.get_value()
@@ -1104,7 +1110,7 @@ class Timeline(gtk.Table, Loggable, Zoomable):
             self._zoomAdjustment.set_value(value - 1)
 
     def zoomChanged(self):
-        if self._updateZoom:
+        if self._updateZoomSlider:
             self._zoomAdjustment.set_value(self.getCurrentZoomLevel())
 
         # the new scroll position should preserve the current horizontal
@@ -1274,10 +1280,18 @@ class Timeline(gtk.Table, Loggable, Zoomable):
         self.app.gui.setBestZoomRatio()
 
     def _zoomInCb(self, unused_action):
+        # This only handles the button callbacks (from the menus),
+        # not keyboard shortcuts or the zoom slider!
         Zoomable.zoomIn()
+        self.log("Setting 'zoomed_fitted' to False")
+        self.app.gui.zoomed_fitted = False
 
     def _zoomOutCb(self, unused_action):
+        # This only handles the button callbacks (from the menus),
+        # not keyboard shortcuts or the zoom slider!
         Zoomable.zoomOut()
+        self.log("Setting 'zoomed_fitted' to False")
+        self.app.gui.zoomed_fitted = False
 
     def deleteSelected(self, unused_action):
         if self.timeline:
diff --git a/pitivi/timeline/track.py b/pitivi/timeline/track.py
index 39abd1a..45dab3d 100644
--- a/pitivi/timeline/track.py
+++ b/pitivi/timeline/track.py
@@ -772,7 +772,6 @@ class Track(goocanvas.Group, Zoomable, Loggable):
             w = TrackFileSource(self.app, track_object, self.track, self.timeline, self)
             self.widgets[track_object] = w
             self.add_child(w)
-            self.app.gui.setBestZoomRatio()
 
     def _objectRemovedCb(self, unused_timeline, track_object):
         if not isinstance(track_object, ges.TrackEffect):



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