[f-spot] Adjustable filmstrip placement (hor/vert).



commit 3af0a8a5ce8133656e8aa8826a016924c495ba7f
Author: Lorenzo Milesi <maxxer yetopen it>
Date:   Fri Jul 3 08:11:59 2009 +0200

    Adjustable filmstrip placement (hor/vert).
    
    The current patch allows placing filmstrip in horizontal or
    vertical position by right clicking on the filmstrip itself.

 src/MainWindow.cs        |   22 +++++-
 src/PhotoView.cs         |   77 ++++++++++++++++++---
 src/Preferences.cs       |    4 +
 src/Widgets/Filmstrip.cs |  175 +++++++++++++++++++++++++++++++++++-----------
 4 files changed, 225 insertions(+), 53 deletions(-)
---
diff --git a/src/MainWindow.cs b/src/MainWindow.cs
index c91182b..4f93833 100644
--- a/src/MainWindow.cs
+++ b/src/MainWindow.cs
@@ -474,6 +474,7 @@ public class MainWindow {
 		group_selector.Adaptor.GlassSet += HandleAdaptorGlassSet;
 		group_selector.Adaptor.Changed += HandleAdaptorChanged;
 		LoadPreference (Preferences.GROUP_ADAPTOR_ORDER_ASC);
+		LoadPreference (Preferences.FILMSTRIP_POSITION);
 
 		this.selection = new MainSelection (this);
 		this.selection.Changed += HandleSelectionChanged;
@@ -1606,7 +1607,23 @@ public class MainWindow {
 			Preferences.Set (Preferences.TAG_ICON_SIZE, TagsIconSize);
 		}
 	}
-	
+
+	public void HandleFilmstripHorizontal (object sender, EventArgs args)
+	{
+		if (photo_view.FilmstripOrientation == Orientation.Horizontal)
+			return;
+		(sender as Gtk.CheckMenuItem).Active = false;
+		photo_view.PlaceFilmstrip (Orientation.Horizontal);
+	}
+
+	public void HandleFilmstripVertical (object sender, EventArgs args)
+	{
+		if (photo_view.FilmstripOrientation == Orientation.Vertical)
+			return;
+		(sender as Gtk.CheckMenuItem).Active = false;
+		photo_view.PlaceFilmstrip (Orientation.Vertical);
+	}
+
 	public void HandleReverseOrder (object sender, EventArgs args)
 	{
 		ToggleAction item = sender as ToggleAction;
@@ -2479,8 +2496,9 @@ public class MainWindow {
 			break;
 		
 		case Preferences.SHOW_FILMSTRIP:
-			if (display_filmstrip.Active != Preferences.Get<bool> (key))
+			if (display_filmstrip.Active != Preferences.Get<bool> (key)) {
 				display_filmstrip.Active = Preferences.Get<bool> (key);
+			}
 			break;
 		
 		case Preferences.SHOW_TAGS:
diff --git a/src/PhotoView.cs b/src/PhotoView.cs
index 7210e3b..5f86863 100644
--- a/src/PhotoView.cs
+++ b/src/PhotoView.cs
@@ -33,6 +33,8 @@ namespace FSpot {
 		private EventBox background;
 		
 		private Filmstrip filmstrip;
+		VBox inner_vbox;
+		HBox inner_hbox;
 	
 		private Widgets.TagView tag_view;
 		
@@ -54,6 +56,10 @@ namespace FSpot {
 
 		public event EventHandler<BrowsableEventArgs> DoubleClicked;
 	
+		public Orientation FilmstripOrientation {
+			get { return filmstrip.Orientation; }
+		}
+	
 		public PhotoImageView View {
 			get { return photo_view; }
 		}
@@ -240,6 +246,56 @@ namespace FSpot {
 			Dispose ();
 		}
 	
+		private void OnPreferencesChanged (object sender, NotifyEventArgs args)
+		{
+			LoadPreference (args.Key);
+		}
+
+		private void LoadPreference (String key)
+		{
+			switch (key) {
+			case Preferences.FILMSTRIP_POSITION:
+				PlaceFilmstrip ((Orientation) Preferences.Get<int> (key));
+				break;
+			}
+		}
+
+		public void PlaceFilmstrip (Orientation pos)
+		{
+			PlaceFilmstrip (pos, false);
+		}
+
+		public void PlaceFilmstrip (Orientation pos, bool force)
+		{
+			if (!force && filmstrip.Orientation == pos)
+				return;
+			filmstrip.Orientation = pos;
+
+			System.Collections.IEnumerator widgets;
+			switch (pos) {
+			case Orientation.Horizontal:
+				widgets = inner_hbox.AllChildren.GetEnumerator ();
+				while (widgets.MoveNext ())
+					if (widgets.Current == filmstrip) {
+						inner_hbox.Remove (filmstrip);
+						break;
+					}
+				inner_vbox.PackStart (filmstrip, false, false, 0); 
+				inner_vbox.ReorderChild (filmstrip, 0);
+				break;
+			case Orientation.Vertical:
+				widgets = inner_vbox.AllChildren.GetEnumerator ();
+				while (widgets.MoveNext ())
+					if (widgets.Current == filmstrip) {
+						inner_vbox.Remove (filmstrip);
+						break;
+					}
+				inner_hbox.PackEnd (filmstrip, false, false, 0);
+				break;
+			}
+			Preferences.Set (Preferences.FILMSTRIP_POSITION, (int) pos);
+		}
+	
 		public bool FilmStripVisibility {
 			get { return filmstrip.Visible; }
 			set { filmstrip.Visible = value; }
@@ -266,9 +322,10 @@ namespace FSpot {
 			frame.ShadowType = ShadowType.In;
 			vbox.PackStart (background, true, true, 0);
 			
-			Box inner_vbox = new VBox (false , 2);
+			inner_vbox = new VBox (false , 2);
+			inner_hbox = new HBox (false , 2);
 	
-			frame.Add (inner_vbox);
+			frame.Add (inner_hbox);
 			
 			BrowsablePointer bp = new BrowsablePointer (query, -1);
 			photo_view = new PhotoImageView (bp);
@@ -279,7 +336,7 @@ namespace FSpot {
 			filmstrip.BackgroundTile = bg;
 			filmstrip.ThumbOffset = 1;
 			filmstrip.Spacing = 4;
-			inner_vbox.PackStart (filmstrip, false, false, 0);
+			PlaceFilmstrip ((Orientation) Preferences.Get <int> (Preferences.FILMSTRIP_POSITION), true);
 	
 			photo_view.PhotoChanged += HandlePhotoChanged;
 	
@@ -291,30 +348,32 @@ namespace FSpot {
 			photo_view_scrolled.Child.ButtonPressEvent += HandleButtonPressEvent;
 			photo_view.AddEvents ((int) EventMask.KeyPressMask);
 			inner_vbox.PackStart (photo_view_scrolled, true, true, 0);
+			inner_hbox.PackStart (inner_vbox, true, true, 0);
 			
-			HBox inner_hbox = new HBox (false, 2);
+			HBox lower_hbox = new HBox (false, 2);
 			//inner_hbox.BorderWidth = 6;
 	
 			tag_view = new Widgets.TagView (MainWindow.ToolTips);
-			inner_hbox.PackStart (tag_view, false, true, 0);
+			lower_hbox.PackStart (tag_view, false, true, 0);
 	
 			Label comment = new Label (Catalog.GetString ("Comment:"));
-			inner_hbox.PackStart (comment, false, false, 0);
+			lower_hbox.PackStart (comment, false, false, 0);
 			description_entry = new Entry ();
-			inner_hbox.PackStart (description_entry, true, true, 0);
+			lower_hbox.PackStart (description_entry, true, true, 0);
 			description_entry.Changed += HandleDescriptionChanged;
 	
 			rating = new Widgets.Rating();
-			inner_hbox.PackStart (rating, false, false, 0);
+			lower_hbox.PackStart (rating, false, false, 0);
 			rating.Changed += HandleRatingChanged;
 	
 			SetColors ();
 			
-			inner_vbox.PackStart (inner_hbox, false, true, 0);
+			inner_vbox.PackStart (lower_hbox, false, true, 0);
 	
 			vbox.ShowAll ();
 	
 			Realized += delegate (object o, EventArgs e) {SetColors ();};
+			Preferences.SettingChanged += OnPreferencesChanged;
 		}
 
 		~PhotoView ()
diff --git a/src/Preferences.cs b/src/Preferences.cs
index d4c0669..fbdeeee 100644
--- a/src/Preferences.cs
+++ b/src/Preferences.cs
@@ -41,6 +41,7 @@ namespace FSpot
 		public const string SHOW_SIDEBAR = APP_FSPOT + "ui/show_sidebar";
 		public const string SHOW_TIMELINE = APP_FSPOT + "ui/show_timeline";
 		public const string SHOW_FILMSTRIP = APP_FSPOT + "ui/show_filmstrip";
+		public const string FILMSTRIP_POSITION = APP_FSPOT + "ui/filmstrip_position";
 		public const string SHOW_TAGS = APP_FSPOT + "ui/show_tags";
 		public const string SHOW_DATES = APP_FSPOT + "ui/show_dates";
 		public const string EXPANDED_TAGS = APP_FSPOT + "ui/expanded_tags";
@@ -108,11 +109,14 @@ namespace FSpot
 			case IMPORT_WINDOW_HEIGHT:
 			case IMPORT_WINDOW_WIDTH:
 			case IMPORT_WINDOW_PANE_POSITION:
+			case FILMSTRIP_POSITION:
 				return 0;
 					
 			case METADATA_EMBED_IN_IMAGE:
 			case MAIN_WINDOW_MAXIMIZED:
 			case GROUP_ADAPTOR_ORDER_ASC:
+			case COLOR_MANAGEMENT_ENABLED:
+			case COLOR_MANAGEMENT_USE_X_PROFILE:
 				return false;
 
 			case GLASS_POSITION:
diff --git a/src/Widgets/Filmstrip.cs b/src/Widgets/Filmstrip.cs
index 4427a74..5a68528 100644
--- a/src/Widgets/Filmstrip.cs
+++ b/src/Widgets/Filmstrip.cs
@@ -44,11 +44,12 @@ namespace FSpot.Widgets
 				if (orientation == value)
 					return;
 
-				throw new NotImplementedException ();
+				BackgroundPixbuf = null;
+				orientation = value;
 //				if (OrientationChanged != null) {
 //					OrientationChangedArgs args = new OrientationChangedArgs ();
-//					//args.Orientation = value;
-//					//OrientationChanged (this, args);
+//					args.Orientation = value;
+//					OrientationChanged (this, args);
 //				}
 			}
 		}
@@ -198,10 +199,12 @@ namespace FSpot.Widgets
 		public Pixbuf BackgroundTile {
 			get {
 				if (background_tile == null)
-					if (orientation == Orientation.Horizontal)
-						background_tile = new Pixbuf(film_100_xpm);
-					else
-						throw new NotImplementedException ("doesn't support Vertical orientation yet");
+					background_tile = new Pixbuf(film_100_xpm);
+
+				if (Orientation == Orientation.Horizontal && background_tile.Height < background_tile.Width) 
+					background_tile = background_tile.RotateSimple (PixbufRotation.Counterclockwise); 
+				else if (Orientation == Orientation.Vertical && background_tile.Width < background_tile.Height) 
+					background_tile = background_tile.RotateSimple (PixbufRotation.Clockwise); 
 				return background_tile;
 			}
 			set { 
@@ -309,32 +312,63 @@ namespace FSpot.Widgets
 		}
 	
 		int min_length = 400;
+		int min_height = 200;
 		protected override void OnSizeRequested (ref Gtk.Requisition requisition)
 		{
 			base.OnSizeRequested (ref requisition);
-			requisition.Width = Math.Max (min_length + 2 * x_offset, requisition.Width);
-			if (min_length % BackgroundTile.Width != 0)
-				requisition.Width += BackgroundTile.Width - min_length % BackgroundTile.Width;	
-
-			requisition.Height = Math.Max (requisition.Height, BackgroundTile.Height + (2 * y_offset));
+			requisition.Width = (Orientation == Orientation.Horizontal ? min_length : BackgroundTile.Width) + 2 * x_offset;
+			requisition.Height = (Orientation == Orientation.Vertical ? min_height : BackgroundTile.Height) + 2 * y_offset;
+			switch (Orientation) {
+			case Orientation.Horizontal:
+				if (min_length % BackgroundTile.Width != 0)
+					requisition.Width += BackgroundTile.Width - min_length % BackgroundTile.Width;
+				break;
+			case Orientation.Vertical:
+				if (min_height % BackgroundTile.Height != 0)
+					requisition.Height += BackgroundTile.Height - min_height % BackgroundTile.Height;
+				break;
+			}
 		}
 
 		Pixbuf background_pixbuf;
 		protected Pixbuf BackgroundPixbuf {
 			get {
 				if (background_pixbuf == null) {
-					int length;
-					if (Allocation.Width < min_length || !extendable)
-						length = min_length;
-					else
-						length = Allocation.Width;
-
-					length = length - length % BackgroundTile.Width;
-
-					background_pixbuf = new Pixbuf (Gdk.Colorspace.Rgb, true, 8, length, BackgroundTile.Height);
-					for (int i = 0; i < length; i += BackgroundTile.Width) {
-						BackgroundTile.CopyArea (0, 0, BackgroundTile.Width, BackgroundTile.Height, 
-								background_pixbuf, i, 0);
+					int length = BackgroundTile.Width;
+					int height = BackgroundTile.Height;
+					switch (Orientation) {
+					case Orientation.Horizontal:
+						if (Allocation.Width < min_length || !extendable)
+							length = min_length;
+						else
+							length = Allocation.Width;
+
+						length = length - length % BackgroundTile.Width;
+						break;
+					case Orientation.Vertical:
+						if (Allocation.Height < min_height || !extendable)
+							height = min_height;
+						else
+							height = Allocation.Height;
+
+						height = height - height % BackgroundTile.Height;
+						break;
+					}
+
+					background_pixbuf = new Pixbuf (Gdk.Colorspace.Rgb, true, 8, length, height);
+					switch (Orientation) {
+					case Orientation.Horizontal:
+						for (int i = 0; i < length; i += BackgroundTile.Width) {
+							BackgroundTile.CopyArea (0, 0, BackgroundTile.Width, BackgroundTile.Height, 
+									background_pixbuf, i, 0);
+						}
+						break;
+					case Orientation.Vertical:
+						for (int i = 0; i < height; i += BackgroundTile.Height) {
+							BackgroundTile.CopyArea (0, 0, BackgroundTile.Width, BackgroundTile.Height, 
+									background_pixbuf, 0, i);
+						}
+						break;
 					}
 				}
 				return background_pixbuf;
@@ -357,10 +391,12 @@ namespace FSpot.Widgets
 			if (selection.Collection.Count == 0)
 				return true;
 
-			if (extendable && Allocation.Width >= BackgroundPixbuf.Width + (2 * x_offset) + BackgroundTile.Width)
+			if (Orientation == Orientation.Horizontal && (extendable && Allocation.Width >= BackgroundPixbuf.Width + (2 * x_offset) + BackgroundTile.Width) ||
+				Orientation == Orientation.Vertical && (extendable && Allocation.Height >= BackgroundPixbuf.Height + (2 * y_offset) + BackgroundTile.Height) )
 				BackgroundPixbuf = null;
 
-			if (extendable && Allocation.Width < BackgroundPixbuf.Width + (2 * x_offset))
+			if ( Orientation == Orientation.Horizontal && (extendable && Allocation.Width < BackgroundPixbuf.Width + (2 * x_offset) ) || 
+				Orientation == Orientation.Vertical && ( extendable && Allocation.Height < BackgroundPixbuf.Height + (2 * y_offset) ))
 				BackgroundPixbuf = null;
 
 			int xpad = 0, ypad = 0;
@@ -377,31 +413,54 @@ namespace FSpot.Widgets
 			//drawing the icons...
 			start_indexes = new Hashtable ();
 
-			Pixbuf icon_pixbuf = new Pixbuf (Gdk.Colorspace.Rgb, true, 8, BackgroundPixbuf.Width, thumb_size);
+			Pixbuf icon_pixbuf = null;
+			if (Orientation == Orientation.Horizontal)
+				icon_pixbuf = new Pixbuf (Gdk.Colorspace.Rgb, true, 8, BackgroundPixbuf.Width, thumb_size);
+			else if (Orientation == Orientation.Vertical)
+				icon_pixbuf = new Pixbuf (Gdk.Colorspace.Rgb, true, 8, thumb_size, BackgroundPixbuf.Height);
 			icon_pixbuf.Fill (0x00000000);
 
 			Pixbuf current = GetPixbuf ((int) Math.Round (Position));
 			int ref_x = (int)(icon_pixbuf.Width / 2.0 - current.Width * (Position + 0.5f - Math.Round (Position))); //xpos of the reference icon
+			int ref_y = (int)(icon_pixbuf.Height / 2.0 - current.Height * (Position + 0.5f - Math.Round (Position))); 
 
-			int start_x = ref_x;
+			int start_x = Orientation == Orientation.Horizontal ? ref_x : 0;
+			int start_y = Orientation == Orientation.Vertical ? ref_y : 0;
 			for (int i = (int) Math.Round (Position); i < selection.Collection.Count; i++) {
 				current = GetPixbuf (i, ActiveItem == i);
-				current.CopyArea (0, 0, Math.Min (current.Width, icon_pixbuf.Width - start_x) , current.Height, icon_pixbuf, start_x, 0);
-				start_indexes [start_x] = i; 
-				start_x += current.Width + spacing;
-				if (start_x > icon_pixbuf.Width)
-					break;
+				if (Orientation == Orientation.Horizontal) {
+					current.CopyArea (0, 0, Math.Min (current.Width, icon_pixbuf.Width - start_x) , current.Height, icon_pixbuf, start_x, start_y);	
+					start_indexes [start_x] = i; 
+					start_x += current.Width + spacing;
+					if (start_x > icon_pixbuf.Width)
+						break;
+				} else if (Orientation == Orientation.Vertical) {
+					current.CopyArea (0, 0, current.Width, Math.Min (current.Height, icon_pixbuf.Height - start_y), icon_pixbuf, start_x, start_y);	
+					start_indexes [start_y] = i; 
+					start_y += current.Height + spacing;
+					if (start_y > icon_pixbuf.Height)
+						break;
+				}
 			}
-			filmstrip_end_pos = start_x;
+			filmstrip_end_pos = (Orientation == Orientation.Horizontal ? start_x : start_y);
 
-			start_x = ref_x;
+			start_x = Orientation == Orientation.Horizontal ? ref_x : 0;
+			start_y = Orientation == Orientation.Vertical ? ref_y : 0;
 			for (int i = (int) Math.Round (Position) - 1; i >= 0; i--) {
 				current = GetPixbuf (i, ActiveItem == i);
-				start_x -= (current.Width + spacing);
-				current.CopyArea (Math.Max (0, -start_x), 0, Math.Min (current.Width, current.Width + start_x), current.Height, icon_pixbuf, Math.Max (start_x, 0), 0);
-				start_indexes [Math.Max (0, start_x)] = i; 
-				if (start_x < 0)
-					break;
+				if (Orientation == Orientation.Horizontal) {
+					start_x -= (current.Width + spacing);
+					current.CopyArea (Math.Max (0, -start_x), 0, Math.Min (current.Width, current.Width + start_x), current.Height, icon_pixbuf, Math.Max (start_x, 0), 0);
+					start_indexes [Math.Max (0, start_x)] = i; 
+					if (start_x < 0)
+						break;
+				} else if (Orientation == Orientation.Vertical) {
+					start_y -= (current.Height + spacing);
+					current.CopyArea (0, Math.Max (0, -start_y), current.Width, Math.Min (current.Height, current.Height + start_y), icon_pixbuf, 0, Math.Max (start_y, 0));
+					start_indexes [Math.Max (0, start_y)] = i; 
+					if (start_y < 0)
+						break;
+				}
 			}
 			
 			GdkWindow.DrawPixbuf (Style.BackgroundGC (StateType.Normal), icon_pixbuf,
@@ -497,15 +556,47 @@ namespace FSpot.Widgets
 			
 
 		}
+		
+		protected override bool OnPopupMenu ()
+		{
+			DrawOrientationMenu (null);
+			return true;
+		}
+
+		private bool DrawOrientationMenu (Gdk.EventButton args)
+		{
+			Gtk.Menu placement_menu = new Gtk.Menu ();
+			GtkUtil.MakeCheckMenuItem (placement_menu, 
+							Mono.Unix.Catalog.GetString ("_Horizontal"), 
+							MainWindow.Toplevel.HandleFilmstripHorizontal, 
+							true, Orientation == Orientation.Horizontal, true);
+			GtkUtil.MakeCheckMenuItem (placement_menu, 
+							Mono.Unix.Catalog.GetString ("_Vertical"), 
+							MainWindow.Toplevel.HandleFilmstripVertical, 
+							true, Orientation == Orientation.Vertical, true);
+
+			if (args != null)
+				placement_menu.Popup (null, null, null, args.Button, args.Time);
+			else
+				placement_menu.Popup (null, null, null, 0, Gtk.Global.CurrentEventTime);
+			
+			return true;
+		}
 
 		protected override bool OnButtonPressEvent (EventButton evnt)
 		{
-			if(evnt.Button != 1 || evnt.X > filmstrip_end_pos) 
+			if (evnt.Button == 3)
+				return DrawOrientationMenu (evnt); 
+
+			if (evnt.Button != 1 || (
+				(Orientation == Orientation.Horizontal && evnt.X > filmstrip_end_pos) || 
+				(Orientation == Orientation.Vertical && evnt.Y > filmstrip_end_pos) 
+				))
 				return false;
 			HasFocus = true;
 			int pos = -1;
 			foreach (int key in start_indexes.Keys)
-				if (key <= evnt.X && key > pos)
+				if (key <= (Orientation == Orientation.Horizontal ? evnt.X : evnt.Y) && key > pos)
 					pos = key;
 			ActiveItem = (int)start_indexes [pos];
 			return true;



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