[cheese/three-point-oh] Added code to properly toggle between wide mode and normal mode



commit 4c5d2e7b01225160a529ca5cf877f54e9452bac0
Author: Yuvaraj Pandian T <yuvipanda gmail com>
Date:   Tue Jun 1 15:53:40 2010 +0530

    Added code to properly toggle between wide mode and normal mode

 data/cheese-main-window.ui |   13 +++++++-
 valasrc/cheese-window.vala |   73 +++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 77 insertions(+), 9 deletions(-)
---
diff --git a/data/cheese-main-window.ui b/data/cheese-main-window.ui
index 1cc101a..6551e58 100644
--- a/data/cheese-main-window.ui
+++ b/data/cheese-main-window.ui
@@ -143,7 +143,7 @@
 	  </object>
 	</child>
 	<child>
-	  <object class="GtkFrame" id="thumbnails">
+	  <object class="GtkFrame" id="thumbnails_right">
 	    <child>
 	      <placeholder />
 	    </child>
@@ -154,6 +154,17 @@
 	</child>
       </object>
     </child>
+    <child>
+      <object class="GtkFrame" id="thumbnails_bottom">
+	<property name="visible">False</property>
+	<child>
+	    <placeholder />	    
+	</child>
+      </object>
+      	<packing>
+	  <property name="expand">False</property>
+	</packing>
+    </child>
   </object>
 
 </interface>
\ No newline at end of file
diff --git a/valasrc/cheese-window.vala b/valasrc/cheese-window.vala
index fa8361d..ed3b86f 100644
--- a/valasrc/cheese-window.vala
+++ b/valasrc/cheese-window.vala
@@ -15,6 +15,11 @@ public class Cheese.MainWindow : Gtk.Window {
 	private Widget thumbnails;
 	private GtkClutter.Embed viewport_widget;
 	private Clutter.Stage viewport;
+	private Eog.ThumbNav thumb_nav;
+	private Cheese.ThumbView thumb_view;
+	private Gtk.Frame thumbnails_right;
+	private Gtk.Frame thumbnails_bottom;
+	
 	[CCode (instance_pos = -1)]
 	internal void on_quit (Action action ) {
 		destroy();
@@ -35,7 +40,59 @@ public class Cheese.MainWindow : Gtk.Window {
 		about_dialog = (Gtk.AboutDialog) builder.get_object("aboutdialog");
 		about_dialog.version = Config.VERSION;
 		about_dialog.show_all();
-	}		
+	}
+
+	[CCode (instance_pos = -1)]
+	internal void on_layout_wide_mode (ToggleAction action ) {
+		set_wide_mode(action.active);
+	}
+
+
+	private void set_wide_mode(bool wide_mode, bool initialize=false) {
+
+		if (!initialize) {
+			// Sets requested size of the viewport_widget to be it's current size
+			// So it does not grow smaller with each toggle
+			Gtk.Allocation alloc;
+			viewport_widget.get_allocation(out alloc);
+			viewport_widget.set_size_request(alloc.width, alloc.height);
+		}
+		
+		if (wide_mode) {
+			thumb_view.set_columns(1);
+			thumb_nav.set_vertical(true);
+			if (thumbnails_bottom.get_child() != null)
+			{
+				thumbnails_bottom.remove(thumb_nav);
+			}
+			thumbnails_right.add(thumb_nav);
+			thumbnails_right.resize_children();
+			thumbnails_right.show_all();
+			thumbnails_bottom.hide_all();
+			
+		}
+		else {
+			thumb_view.set_columns(5000);
+			thumb_nav.set_vertical(false);
+			if (thumbnails_right.get_child() != null)
+			{
+				thumbnails_right.remove(thumb_nav);
+			}
+			thumbnails_bottom.add(thumb_nav);
+			thumbnails_bottom.resize_children();
+			thumbnails_right.hide_all();
+			thumbnails_bottom.show_all();
+
+		}
+		
+		if(!initialize) {
+			// Makes sure that the window is the size it ought to be, and no bigger/smaller
+			// Used to make sure that the viewport_widget does not keep growing with each toggle
+			Gtk.Requisition req;
+			this.size_request(out req);
+			this.resize(req.width, req.height);
+		}
+	}				
 	
 	public	void setup_ui () {
 		builder = new Builder();
@@ -49,6 +106,8 @@ public class Cheese.MainWindow : Gtk.Window {
 		thumbnails = (Widget) builder.get_object("thumbnails");
 		viewport_widget = (GtkClutter.Embed) builder.get_object("viewport");
 		viewport = (Clutter.Stage) viewport_widget.get_stage();
+		thumbnails_right = (Frame) builder.get_object("thumbnails_right");
+		thumbnails_bottom = (Frame) builder.get_object("thumbnails_bottom");
 
 		Clutter.Rectangle r = new Clutter.Rectangle();
 		r.width = 200;
@@ -57,14 +116,12 @@ public class Cheese.MainWindow : Gtk.Window {
 		r.y = 0;
 		r.color = Clutter.Color.from_string("Red");
 		viewport.add_actor(r);
-					
+
+		thumb_view = new Cheese.ThumbView();
+		thumb_nav = new Eog.ThumbNav(thumb_view, false);
+		
 		viewport.show_all();
-		Cheese.ThumbView tv = new Cheese.ThumbView();
-		Eog.ThumbNav tnav = new Eog.ThumbNav(tv, false);
-		tv.set_columns(1);
-		tnav.set_vertical(true);
-		Gtk.Frame tf = (Gtk.Frame) builder.get_object("thumbnails");		
-		tf.add(tnav);
+		set_wide_mode(false, true);
 		this.add(main_vbox);
 			
 	}



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