[pdfmod] Add zoom slider/buttons in bottom-right (bgo#614378, bgo#628437)



commit 848351ead3399db0179da5035698c4e1b742ffb8
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Wed Sep 15 12:18:18 2010 -0500

    Add zoom slider/buttons in bottom-right (bgo#614378, bgo#628437)

 src/Makefile.am                    |    1 +
 src/PdfMod.mdp                     |    3 +-
 src/PdfMod/Gui/Client.cs           |   16 +++++--
 src/PdfMod/Gui/DocumentIconView.cs |    7 +++-
 src/PdfMod/Gui/ZoomSlider.cs       |   82 ++++++++++++++++++++++++++++++++++++
 5 files changed, 103 insertions(+), 6 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 6574599..69ae223 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -40,6 +40,7 @@ FILES =  \
 	PdfMod/Gui/PageCell.cs \
 	PdfMod/Gui/PageListStore.cs \
 	PdfMod/Gui/SelectMatchingBox.cs \
+	PdfMod/Gui/ZoomSlider.cs \
 	PdfMod/Main.cs \
 	PdfMod/Pdf/Actions/BaseAction.cs \
 	PdfMod/Pdf/Actions/BasePageAction.cs \
diff --git a/src/PdfMod.mdp b/src/PdfMod.mdp
index 5b0b84c..55c0128 100644
--- a/src/PdfMod.mdp
+++ b/src/PdfMod.mdp
@@ -52,6 +52,7 @@
     <File subtype="Code" buildaction="Compile" name="PdfMod/Core/Configuration.cs" />
     <File subtype="Code" buildaction="Compile" name="PdfMod/Pdf/PageLabels.cs" />
     <File subtype="Code" buildaction="Compile" name="PdfMod/Gui/BookmarkView.cs" />
+    <File subtype="Code" buildaction="Compile" name="PdfMod/Gui/ZoomSlider.cs" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
@@ -69,4 +70,4 @@
     <ProjectReference type="Gac" localcopy="True" refto="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
     <ProjectReference type="Project" localcopy="True" refto="poppler-sharp" />
   </References>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/src/PdfMod/Gui/Client.cs b/src/PdfMod/Gui/Client.cs
index 754c69b..d5d635c 100644
--- a/src/PdfMod/Gui/Client.cs
+++ b/src/PdfMod/Gui/Client.cs
@@ -98,17 +98,25 @@ namespace PdfMod.Gui
             query_box = new QueryBox (this) { NoShowAll = true };
             query_box.Hide ();
 
+            // ActionManager
+            ActionManager = new Hyena.Gui.ActionManager ();
+            Window.AddAccelGroup (ActionManager.UIManager.AccelGroup);
+            Actions = new Actions (this, ActionManager);
+
             // Status bar
             StatusBar = new Gtk.Statusbar () { HasResizeGrip = true };
             status_label = new Label () { Xalign = 0.0f };
             StatusBar.PackStart (status_label, true, true, 6);
             StatusBar.ReorderChild (status_label, 0);
 
-            // ActionManager
-            ActionManager = new Hyena.Gui.ActionManager ();
-            Window.AddAccelGroup (ActionManager.UIManager.AccelGroup);
-            Actions = new Actions (this, ActionManager);
+            var zoom_align = new Alignment (1f, 0.5f, 0f, 0f) { RightPadding = 24 };
+            var zoom_box = new HBox () { Spacing = 6 };
+
+            var zoom_slider = new ZoomSlider (this);
+            StatusBar.PackEnd (zoom_slider, false, false, 0);
+            StatusBar.ReorderChild (zoom_slider, 1);
 
+            // Properties editor box
             EditorBox = new MetadataEditorBox (this) { NoShowAll = true };
             EditorBox.Hide ();
 
diff --git a/src/PdfMod/Gui/DocumentIconView.cs b/src/PdfMod/Gui/DocumentIconView.cs
index 68ec587..ff08710 100644
--- a/src/PdfMod/Gui/DocumentIconView.cs
+++ b/src/PdfMod/Gui/DocumentIconView.cs
@@ -459,6 +459,11 @@ namespace PdfMod.Gui
         bool zoom_manually_set;
         public void Zoom (int pixels)
         {
+            Zoom (pixels, false);
+        }
+
+        public void Zoom (int pixels, bool absolute)
+        {
             CanZoomIn = CanZoomOut = true;
 
             if (!zoom_manually_set) {
@@ -466,7 +471,7 @@ namespace PdfMod.Gui
                 (app.Actions["ZoomFit"] as ToggleAction).Active = false;
             }
 
-            int new_width = ItemSize + pixels;
+            int new_width = absolute ? pixels : ItemSize + pixels;
             if (new_width <= MIN_WIDTH) {
                 CanZoomOut = false;
                 new_width = MIN_WIDTH;
diff --git a/src/PdfMod/Gui/ZoomSlider.cs b/src/PdfMod/Gui/ZoomSlider.cs
new file mode 100644
index 0000000..b144ac0
--- /dev/null
+++ b/src/PdfMod/Gui/ZoomSlider.cs
@@ -0,0 +1,82 @@
+// Copyright (C) 2010 Novell, Inc.
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+using System;
+using System.Linq;
+using System.Collections.Generic;
+using System.IO;
+
+using Gtk;
+using Mono.Unix;
+
+using Hyena;
+using Hyena.Gui;
+
+using PdfSharp;
+using PdfSharp.Pdf;
+using PdfSharp.Pdf.IO;
+
+using PdfMod.Pdf;
+
+namespace PdfMod.Gui
+{
+    public class ZoomSlider : Alignment
+    {
+        public ZoomSlider (Client app) : base (1f, 0.5f, 0f, 0f)
+        {
+            RightPadding = 16;
+
+            var box = new HBox () { Spacing = 2 };
+
+            // Zoom in/out buttons
+            var zoom_out = new Button (new Image (Stock.ZoomOut, IconSize.Button)) { Relief = ReliefStyle.None };
+            app.Actions["ZoomOut"].ConnectProxy (zoom_out);
+
+            var zoom_in  = new Button (new Image (Stock.ZoomIn, IconSize.Button)) { Relief = ReliefStyle.None };
+            app.Actions["ZoomIn"].ConnectProxy (zoom_in);
+
+            // Slider
+            var slider = new HScale (DocumentIconView.MIN_WIDTH, DocumentIconView.MAX_WIDTH, 1) {
+                WidthRequest = 100,
+                DrawValue = false,
+                Sensitive = false
+            };
+
+            bool setting_via_slider = false;
+            slider.ValueChanged += (o, a) => {
+                if (!setting_via_slider) {
+                    setting_via_slider = true;
+                    app.IconView.Zoom ((int)slider.Value, true);
+                    setting_via_slider = false;
+                }
+            };
+
+            app.IconView.ZoomChanged += () => {
+                if (!setting_via_slider) {
+                    setting_via_slider = true;
+                    slider.Value = app.IconView.ItemSize;
+                    setting_via_slider = false;
+                }
+            };
+
+            app.DocumentLoaded += (o, a) => slider.Sensitive = app.Document != null;
+            box.PackStart (zoom_out, false, false, 0);
+            box.PackStart (slider,   false, false, 0);
+            box.PackStart (zoom_in,  false, false, 0);
+            Child = box;
+        }
+    }
+}



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