[gimp] app: display the screenshot in the extension details GUI.



commit 9fa49af470ac0ad6554a60cab7d656cb2fad00e2
Author: Jehan <jehan girinstud io>
Date:   Mon May 27 17:26:25 2019 +0200

    app: display the screenshot in the extension details GUI.
    
    Further improvements should load screenshots in a thread, especially
    since we are loading from a URL taken from metadata, so it makes the GUI
    non-responsive for a bit too long. But this is a first working version
    for now.

 app/widgets/gimpextensiondetails.c | 71 +++++++++++++++++++++++++++++++++++---
 1 file changed, 66 insertions(+), 5 deletions(-)
---
diff --git a/app/widgets/gimpextensiondetails.c b/app/widgets/gimpextensiondetails.c
index cc7c442aaa..59c585390e 100644
--- a/app/widgets/gimpextensiondetails.c
+++ b/app/widgets/gimpextensiondetails.c
@@ -37,8 +37,15 @@
 struct _GimpExtensionDetailsPrivate
 {
   GimpExtension *extension;
+
+  gint           screenshot_width;
+  gint           screenshot_height;
 };
 
+static void gimp_extension_details_size_allocate (GimpExtensionDetails *details,
+                                                  GdkRectangle         *allocation,
+                                                  GtkGrid              *data);
+
 G_DEFINE_TYPE_WITH_PRIVATE (GimpExtensionDetails, gimp_extension_details,
                             GTK_TYPE_FRAME)
 
@@ -67,7 +74,7 @@ void
 gimp_extension_details_set (GimpExtensionDetails *details,
                             GimpExtension        *extension)
 {
-  GtkWidget     *box;
+  GtkWidget     *grid;
   GtkWidget     *widget;
   GtkTextBuffer *buffer;
 
@@ -76,6 +83,7 @@ gimp_extension_details_set (GimpExtensionDetails *details,
   if (details->p->extension)
     g_object_unref (details->p->extension);
   details->p->extension  = g_object_ref (extension);
+  details->p->screenshot_width = details->p->screenshot_height = 0;
 
   gtk_container_foreach (GTK_CONTAINER (details),
                          (GtkCallback) gtk_widget_destroy,
@@ -84,22 +92,41 @@ gimp_extension_details_set (GimpExtensionDetails *details,
   gtk_frame_set_label (GTK_FRAME (details),
                        extension ? gimp_extension_get_name (extension) : NULL);
 
-  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
-  gtk_container_add (GTK_CONTAINER (details), box);
-  gtk_widget_show (box);
+  grid = gtk_grid_new ();
+  gtk_grid_set_column_homogeneous (GTK_GRID (grid), FALSE);
+  gtk_grid_set_row_homogeneous (GTK_GRID (grid), FALSE);
+  gtk_container_add (GTK_CONTAINER (details), grid);
+  gtk_widget_show (grid);
 
   if (extension)
     {
       gchar       *desc;
       GtkTextIter  iter;
 
+      /* Screenshots. */
+      if (gtk_widget_get_realized (GTK_WIDGET (details)))
+        {
+          GtkAllocation allocation;
+          gint          baseline   = 0;
+
+          gtk_widget_get_allocated_size (GTK_WIDGET (details),
+                                         &allocation, &baseline);
+          gimp_extension_details_size_allocate (details, &allocation, GTK_GRID (grid));
+        }
+      g_signal_connect (details, "size-allocate",
+                        G_CALLBACK (gimp_extension_details_size_allocate),
+                        grid);
+
+      /* Description. */
       desc = gimp_extension_get_markup_description (extension);
       widget = gtk_text_view_new ();
+      gtk_widget_set_vexpand (widget, TRUE);
+      gtk_widget_set_hexpand (widget, TRUE);
       gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (widget), GTK_WRAP_WORD_CHAR);
       gtk_text_view_set_editable (GTK_TEXT_VIEW (widget), FALSE);
       gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (widget), FALSE);
       gtk_text_view_set_justification (GTK_TEXT_VIEW (widget), GTK_JUSTIFY_FILL);
-      gtk_box_pack_start (GTK_BOX (box), widget, TRUE, TRUE, 0);
+      gtk_grid_attach (GTK_GRID (grid), widget, 0, 1, 3, 3);
       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
       gtk_text_buffer_get_start_iter (buffer, &iter);
       if (desc)
@@ -110,3 +137,37 @@ gimp_extension_details_set (GimpExtensionDetails *details,
       gtk_widget_show (widget);
     }
 }
+
+/* Private functions. */
+
+static void
+gimp_extension_details_size_allocate (GimpExtensionDetails *details,
+                                      GdkRectangle         *allocation,
+                                      GtkGrid              *grid)
+{
+  GtkWidget *widget;
+
+  if (allocation->width > 0 && allocation->height > 0 &&
+      allocation->width * 2 / 3 != details->p->screenshot_width &&
+      allocation->height * 2 / 3 != details->p->screenshot_height)
+    {
+      GdkPixbuf *pixbuf;
+
+      details->p->screenshot_width  = allocation->width * 2 / 3;
+      details->p->screenshot_height = allocation->height * 2 / 3;
+
+      pixbuf = gimp_extension_get_screenshot (details->p->extension,
+                                              details->p->screenshot_width, details->p->screenshot_height,
+                                              NULL);
+      if (pixbuf)
+        {
+          widget = gtk_image_new_from_pixbuf (pixbuf);
+          gtk_widget_set_vexpand (widget, FALSE);
+          gtk_widget_set_hexpand (widget, FALSE);
+          gtk_grid_attach (grid, widget, 1, 0, 1, 1);
+          gtk_widget_show (widget);
+
+          g_object_unref (pixbuf);
+        }
+    }
+}


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