[cheese] thumbview: let iconview pick up its optimal size



commit 9ceb674e523a358c9d46b986a7af26baeef55015
Author: Filippo Argiolas <filippo argiolas gmail com>
Date:   Mon Aug 10 11:31:20 2009 +0200

    thumbview: let iconview pick up its optimal size
    
    Remove hard coded size constraints for the icon view so that it picks up
    the best size for the current children (i.e. centered items, even with
    no selection, with every thumbnail size).
    It's almost an hack but seems to work pretty well here. The alternative
    is to keep the current size request but it's quite ugly.
    Remove also extra spacing between and around thumbnails.

 src/cheese-thumb-view.c |   11 ++----
 src/cheese-window.c     |   89 +++++++++++++++++++++++++++++++++++++----------
 src/eog-thumb-nav.c     |   30 +++++++---------
 3 files changed, 87 insertions(+), 43 deletions(-)
---
diff --git a/src/cheese-thumb-view.c b/src/cheese-thumb-view.c
index 7ed76e2..acedfe7 100644
--- a/src/cheese-thumb-view.c
+++ b/src/cheese-thumb-view.c
@@ -39,7 +39,6 @@
 
 G_DEFINE_TYPE (CheeseThumbView, cheese_thumb_view, GTK_TYPE_ICON_VIEW);
 
-
 typedef struct
 {
   GtkListStore *store;
@@ -536,9 +535,7 @@ cheese_thumb_view_fill (CheeseThumbView *thumb_view)
 static void
 cheese_thumb_view_finalize (GObject *object)
 {
-  CheeseThumbView *thumb_view;
-
-  thumb_view = CHEESE_THUMB_VIEW (object);
+  CheeseThumbView *thumb_view = CHEESE_THUMB_VIEW (object);
   CheeseThumbViewPrivate *priv = CHEESE_THUMB_VIEW_GET_PRIVATE (thumb_view);
 
   g_object_unref (priv->store);
@@ -568,8 +565,6 @@ cheese_thumb_view_init (CheeseThumbView *thumb_view)
   char *path_videos = NULL, *path_photos = NULL;
 
   GFile    *file;
-  const int THUMB_VIEW_HEIGHT = 120;
-  const int THUMB_VIEW_WIDTH  = 172;
 
   eog_thumbnail_init ();
 
@@ -579,7 +574,9 @@ cheese_thumb_view_init (CheeseThumbView *thumb_view)
 
   gtk_icon_view_set_model (GTK_ICON_VIEW (thumb_view), GTK_TREE_MODEL (priv->store));
 
-  gtk_widget_set_size_request (GTK_WIDGET (thumb_view), THUMB_VIEW_WIDTH, THUMB_VIEW_HEIGHT);
+  gtk_icon_view_set_margin (GTK_ICON_VIEW (thumb_view), 0);
+  gtk_icon_view_set_row_spacing (GTK_ICON_VIEW (thumb_view), 0);
+  gtk_icon_view_set_column_spacing (GTK_ICON_VIEW (thumb_view), 0);
 
   path_videos = cheese_fileutil_get_video_path (priv->fileutil);
   path_photos = cheese_fileutil_get_photo_path (priv->fileutil);
diff --git a/src/cheese-window.c b/src/cheese-window.c
index 54fbdda..258631f 100644
--- a/src/cheese-window.c
+++ b/src/cheese-window.c
@@ -181,6 +181,7 @@ typedef struct
 
   gint repeat_count;
   gboolean is_bursting;
+  gboolean needs_resizing;
 
   CheeseFlash *flash;
 } CheeseWindow;
@@ -324,12 +325,71 @@ cheese_window_fullscreen_motion_notify_cb (GtkWidget      *widget,
 }
 
 static void
+cheese_window_queue_size_negotiation (CheeseWindow *cheese_window)
+{
+  gtk_widget_queue_resize_no_redraw (GTK_WIDGET (cheese_window->thumb_view));
+  cheese_window->needs_resizing = TRUE;
+}
+
+static void
+cheese_window_window_size_req_cb (GtkWidget      *widget,
+                                  GtkRequisition *req,
+                                  CheeseWindow   *cheese_window)
+{
+  gtk_window_resize (widget, req->width, req->height);
+  g_signal_handlers_disconnect_by_func (widget, G_CALLBACK (cheese_window_window_size_req_cb), cheese_window);
+  gtk_widget_set_size_request (cheese_window->notebook, -1, -1);
+}
+
+static void
+cheese_window_thumb_view_size_req_cb (GtkWidget      *widget,
+                                      GtkRequisition *req,
+                                      CheeseWindow   *cheese_window)
+{
+
+  CheeseThumbView *thumbview = CHEESE_THUMB_VIEW (widget);
+
+  /* at this time the toplevel window has still no size requisition,
+   * wait for its next size-request */
+  if (cheese_window->needs_resizing) {
+    g_signal_connect (G_OBJECT (cheese_window->window),
+                      "size-request",
+                      G_CALLBACK (cheese_window_window_size_req_cb),
+                      cheese_window);
+    cheese_window->needs_resizing = FALSE;
+  }
+}
+
+static void
 cheese_window_toggle_wide_mode (GtkWidget *widget, CheeseWindow *cheese_window)
 {
   gboolean toggled = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (widget));
 
+  /* 1. set a size request on the notebook to keep the video area size
+   *    while switching mode. So it feels like the thumbview is moving
+   *    from the bottom to the left (well it actually is..)
+   *
+   * 2. trigger a resize on the thumbview and set needs_resizing
+   *
+   * 3. wait for next icon view size-request, at this time the icon view
+   *    has reached its definitive size and we can:
+   *    - resize the window to its minimum requisition
+   *    - remove size contraints on the netbook
+   *
+   * This eventually works for setting default window size at startup
+   * too since it prevents the video screen to shrink down without any
+   * need of a permanent size request
+   */
+  gtk_widget_set_size_request (cheese_window->notebook, GTK_WIDGET
+                               (cheese_window->notebook)->allocation.width,
+                               GTK_WIDGET (cheese_window->notebook)->allocation.height);
+  cheese_window_queue_size_negotiation (cheese_window);
+
+  /* set a single column in wide mode */
   gtk_icon_view_set_columns (GTK_ICON_VIEW (cheese_window->thumb_view), toggled ? 1 : G_MAXINT);
+  /* switch thumb_nav mode */
   eog_thumb_nav_set_vertical (cheese_window->thumb_nav, toggled);
+  /* reparent thumb_view */
   g_object_ref (cheese_window->thumb_scrollwindow);
   if (toggled) {
     gtk_container_remove (GTK_CONTAINER (cheese_window->video_vbox), cheese_window->thumb_scrollwindow);
@@ -363,19 +423,6 @@ cheese_window_toggle_wide_mode (GtkWidget *widget, CheeseWindow *cheese_window)
     g_object_set (G_OBJECT (cheese_window->netbook_alignment),
                   "left-padding", 0, NULL);
   }
-
-  /* try to keep video screen size while switching to and from wide mode */
-
-  GtkRequisition req;
-  gint w, h;
-
-  gtk_widget_set_size_request (cheese_window->notebook,
-                               GTK_WIDGET (cheese_window->notebook)->allocation.width,
-                               GTK_WIDGET (cheese_window->notebook)->allocation.height);
-  gtk_window_resize (cheese_window->window, 1, 1);
-  gtk_widget_size_request (cheese_window->window, &req);
-  gtk_window_resize (GTK_WINDOW (cheese_window->window), req.width, req.height);
-  gtk_widget_set_size_request (cheese_window->notebook, -1, -1);
 }
 
 static void
@@ -1759,6 +1806,7 @@ cheese_window_create_window (CheeseWindow *cheese_window)
 
   cheese_window->thumb_view = cheese_thumb_view_new ();
   cheese_window->thumb_nav  = eog_thumb_nav_new (cheese_window->thumb_view, FALSE);
+
   gtk_container_add (GTK_CONTAINER (cheese_window->thumb_scrollwindow), cheese_window->thumb_nav);
 
   /* show the scroll window to get it included in the size requisition done later */
@@ -2082,6 +2130,7 @@ cheese_window_init (char *hal_dev_udi, CheeseDbus *dbus_server)
   cheese_window->audio_play_counter  = 0;
   cheese_window->isFullscreen        = FALSE;
   cheese_window->is_bursting         = FALSE;
+  cheese_window->needs_resizing      = FALSE;
 
   cheese_window->server = dbus_server;
 
@@ -2101,13 +2150,15 @@ cheese_window_init (char *hal_dev_udi, CheeseDbus *dbus_server)
   cheese_window->recording   = FALSE;
 
   /* handy trick to set default size of the drawing area while not
-   * limiting its minimum size, thanks Owen! */
-  GtkRequisition req;
-  gtk_widget_set_size_request (cheese_window->screen,
+   * limiting its minimum size, thanks Owen! -- slightly modified, see
+   * comment in toggle_wide_mode to understand how it works -- */
+
+  g_signal_connect (cheese_window->thumb_view, "size-request",
+                    G_CALLBACK (cheese_window_thumb_view_size_req_cb),
+                    cheese_window);
+  gtk_widget_set_size_request (cheese_window->notebook,
                                DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
-  gtk_widget_size_request (cheese_window->window, &req);
-  gtk_window_set_default_size (GTK_WINDOW (cheese_window->window), req.width, req.height);
-  gtk_widget_set_size_request (cheese_window->screen, -1, -1);
+  cheese_window_queue_size_negotiation (cheese_window);
 
   gtk_widget_show_all (cheese_window->window);
 
diff --git a/src/eog-thumb-nav.c b/src/eog-thumb-nav.c
index ff3d67a..7907fef 100644
--- a/src/eog-thumb-nav.c
+++ b/src/eog-thumb-nav.c
@@ -122,7 +122,6 @@ eog_thumb_nav_vadj_changed (GtkAdjustment *vadj, gpointer user_data)
                 "upper", &upper,
                 "page_size", &page_size,
                 NULL);
-
   gtk_widget_set_sensitive (priv->button_up, value > 0);
 
   gtk_widget_set_sensitive (priv->button_down,
@@ -347,18 +346,24 @@ eog_thumb_nav_constructor (GType type,
                            GObjectConstructParam *construct_params)
 {
   GObject *object;
+  EogThumbNav *nav;
   EogThumbNavPrivate *priv;
 
   object = G_OBJECT_CLASS (eog_thumb_nav_parent_class)->constructor
     (type, n_construct_properties, construct_params);
 
-  priv = EOG_THUMB_NAV (object)->priv;
+  nav = EOG_THUMB_NAV (object);
+  priv = EOG_THUMB_NAV_GET_PRIVATE (object);
 
   if (priv->thumbview != NULL) {
     gtk_container_add (GTK_CONTAINER (priv->sw), priv->thumbview);
     gtk_widget_show_all (priv->sw);
   }
 
+   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->sw),
+                                   GTK_POLICY_AUTOMATIC,
+                                   GTK_POLICY_NEVER);
+
   return object;
 }
 
@@ -461,9 +466,7 @@ eog_thumb_nav_init (EogThumbNav *nav)
   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->sw),
                                        GTK_SHADOW_IN);
 
-  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->sw),
-                                  GTK_POLICY_AUTOMATIC,
-                                  GTK_POLICY_NEVER);
+
 
   g_signal_connect (priv->sw,
                     "scroll-event",
@@ -600,12 +603,6 @@ eog_thumb_nav_new (GtkWidget       *thumbview,
 
   priv = nav->priv;
 
-  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->sw),
-                                  GTK_POLICY_AUTOMATIC,
-                                  GTK_POLICY_NEVER);
-
-  eog_thumb_nav_set_show_buttons (nav, priv->show_buttons);
-
   return GTK_WIDGET (nav);
 }
 
@@ -669,7 +666,6 @@ eog_thumb_nav_set_vertical (EogThumbNav *nav, gboolean vertical)
   /* show/hide doesn't work because of a mandatory show_all in cheese-window */
 
   if (vertical) {
-    g_print ("setting vertical mode\n");
     g_return_if_fail (!gtk_widget_get_parent (priv->button_up));
     g_return_if_fail (!gtk_widget_get_parent (priv->button_down));
     g_return_if_fail (gtk_widget_get_parent (priv->button_left));
@@ -685,13 +681,12 @@ eog_thumb_nav_set_vertical (EogThumbNav *nav, gboolean vertical)
     gtk_container_remove (GTK_CONTAINER (nav), priv->button_left);
     g_object_ref (priv->button_right);
     gtk_container_remove (GTK_CONTAINER (nav), priv->button_right);
+    gtk_adjustment_value_changed (priv->vadj);
+    priv->vertical = TRUE;
     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->sw),
                                     GTK_POLICY_NEVER,
                                     GTK_POLICY_AUTOMATIC);
-    gtk_adjustment_value_changed (priv->vadj);
-    priv->vertical = TRUE;
   } else {
-    g_print ("setting horizontal mode\n");
     g_return_if_fail (!gtk_widget_get_parent (priv->button_left));
     g_return_if_fail (!gtk_widget_get_parent (priv->button_right));
     g_return_if_fail (gtk_widget_get_parent (priv->button_up));
@@ -707,11 +702,12 @@ eog_thumb_nav_set_vertical (EogThumbNav *nav, gboolean vertical)
     gtk_container_remove (GTK_CONTAINER (priv->vbox), priv->button_up);
     g_object_ref (priv->button_down);
     gtk_container_remove (GTK_CONTAINER (priv->vbox), priv->button_down);
+    gtk_adjustment_value_changed (priv->hadj);
+    priv->vertical = FALSE;
     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->sw),
                                     GTK_POLICY_AUTOMATIC,
                                     GTK_POLICY_NEVER);
-    gtk_adjustment_value_changed (priv->hadj);
-    priv->vertical = FALSE;
   }
   gtk_widget_show_all (GTK_WIDGET (nav));
 }
+



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