[pitivi/ges] timeline: Fix the horizontal scrollbar management for zooming



commit f2ff6c3524f81683df927616556ee93830bf9235
Author: Jean-FranÃois Fortin Tam <nekohayo gmail com>
Date:   Thu Apr 26 17:03:28 2012 -0400

    timeline: Fix the horizontal scrollbar management for zooming
    
    Reset the "Zoom Fit" status when the user has fully zoomed out,
    calculate the size from the actual width of surrounding widgets
    and allow inserting clips more easily at the end of the timeline.
    
    Fixes bug #599942

 pitivi/mainwindow.py        |    2 +-
 pitivi/timeline/timeline.py |   31 ++++++++++++++++++++-----------
 2 files changed, 21 insertions(+), 12 deletions(-)
---
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index b605399..05c924e 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -1104,7 +1104,7 @@ class PitiviMainWindow(gtk.Window, Loggable):
                 self.setBestZoomRatio()
             else:
                 self.log("User had changed the zoom, so not autozooming")
-                self.timeline_ui.updateScrollAdjustments()
+                self.timeline_ui.updateHScrollAdjustments()
         else:
             sensitive = False
         self.render_button.set_sensitive(sensitive)
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index a784ac1..1e0dbb2 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -1118,7 +1118,7 @@ class Timeline(gtk.Table, Loggable, Zoomable):
         cur_playhead_offset = self._canvas._playhead.props.x - self.hadj.props.value
         new_pos = Zoomable.nsToPixel(self._position) - cur_playhead_offset
 
-        self.updateScrollAdjustments()
+        self.updateHScrollAdjustments()
         self._scrollToPosition(new_pos)
         self.ruler.queue_resize()
         self.ruler.queue_draw()
@@ -1260,20 +1260,29 @@ class Timeline(gtk.Table, Loggable, Zoomable):
         self.vadj.props.upper = (LAYER_HEIGHT_EXPANDED + LAYER_SPACING
                 + TRACK_SPACING) * 2 * num_layers
 
-    def updateScrollAdjustments(self):
+    def updateHScrollAdjustments(self):
         """
         Recalculate the horizontal scrollbar depending on the timeline duration.
         """
-        a = self.get_allocation()
-        size = Zoomable.nsToPixel(self.app.current.timeline.props.duration)
+        timeline_ui_width = self.get_allocation().width
+        controls_width = self._controls.get_allocation().width
+        scrollbar_width = self._vscrollbar.get_allocation().width
+        contents_size = Zoomable.nsToPixel(self.app.current.timeline.props.duration)
+
+        widgets_width = controls_width + scrollbar_width
+        end_padding = 250  # Provide some space for clip insertion at the end
+
         self.hadj.props.lower = 0
-        # The "+ 200" below compensates the width of the
-        # layers column on the left + vertical scrollbar on the right
-        # FIXME: get those dynamically
-        self.hadj.props.upper = size + 200
-        self.hadj.props.page_size = a.width
-        self.hadj.props.page_increment = size * 0.9
-        self.hadj.props.step_increment = size * 0.1
+        self.hadj.props.upper = contents_size + widgets_width + end_padding
+        self.hadj.props.page_size = timeline_ui_width
+        self.hadj.props.page_increment = contents_size * 0.9
+        self.hadj.props.step_increment = contents_size * 0.1
+
+        if contents_size + widgets_width <= timeline_ui_width:
+            # We're zoomed out completely, re-enable automatic zoom fitting
+            # when adding new clips.
+            self.log("Setting 'zoomed_fitted' to True")
+            self.app.gui.zoomed_fitted = True
 
 ## ToolBar callbacks
     def _zoomFitCb(self, unused_action):



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