[gnome-screenshot/wip/christopherdavis/screenshot-redesign: 9/12] screenshot-dialog: Redesign "Save Screenshot" dialog



commit b32edf6a08b38eb0338cfffba17b53c8b4a2c1b1
Author: Christopher Davis <brainblasted disroot org>
Date:   Thu Jan 3 20:30:28 2019 -0500

    screenshot-dialog: Redesign "Save Screenshot" dialog
    
    This has been changed to look like a normal dialog, with
    the preview image being above the name and folder.

 src/screenshot-dialog.c  |  79 ++++-------------
 src/screenshot-dialog.h  |   2 +-
 src/screenshot-dialog.ui | 221 ++++++++++++++++++++---------------------------
 3 files changed, 113 insertions(+), 189 deletions(-)
---
diff --git a/src/screenshot-dialog.c b/src/screenshot-dialog.c
index 76757d2..306ebe3 100644
--- a/src/screenshot-dialog.c
+++ b/src/screenshot-dialog.c
@@ -37,38 +37,6 @@ static GtkTargetEntry drag_types[] =
   { "image/png", 0, TYPE_IMAGE_PNG },
 };
 
-static void
-on_preview_draw (GtkWidget      *drawing_area,
-                 cairo_t        *cr,
-                 gpointer        data)
-{
-  ScreenshotDialog *dialog = data;
-  GtkStyleContext *context;
-  int width, height;
-
-  width = gtk_widget_get_allocated_width (drawing_area);
-  height = gtk_widget_get_allocated_height (drawing_area);
-
-  if (!dialog->preview_image ||
-      gdk_pixbuf_get_width (dialog->preview_image) != width ||
-      gdk_pixbuf_get_height (dialog->preview_image) != height)
-    {
-      g_clear_object (&dialog->preview_image);
-      dialog->preview_image = gdk_pixbuf_scale_simple (dialog->screenshot,
-                                                       width,
-                                                       height,
-                                                       GDK_INTERP_BILINEAR);
-    }
-
-  context = gtk_widget_get_style_context (drawing_area);
-  gtk_style_context_save (context);
-
-  gtk_style_context_set_state (context, gtk_widget_get_state_flags (drawing_area));
-  gtk_render_icon (context, cr, dialog->preview_image, 0, 0);
-
-  gtk_style_context_restore (context);
-}
-
 static gboolean
 on_preview_button_press_event (GtkWidget      *drawing_area,
                                GdkEventButton *event,
@@ -114,7 +82,7 @@ drag_begin (GtkWidget        *widget,
             GdkDragContext   *context,
             ScreenshotDialog *dialog)
 {
-  gtk_drag_set_icon_pixbuf (context, dialog->preview_image,
+  gtk_drag_set_icon_pixbuf (context, dialog->screenshot,
                             dialog->drag_x, dialog->drag_y);
 }
 
@@ -154,45 +122,36 @@ button_clicked (GtkWidget *button, ScreenshotDialog *dialog)
 }
 
 static void
-setup_drawing_area (ScreenshotDialog *dialog, GtkBuilder *ui)
+setup_preview_img (ScreenshotDialog *dialog, GtkBuilder *ui)
 {
-  GtkWidget *preview_darea;
-  GtkWidget *aspect_frame;
-  gint width, height, scale_factor;
+  GtkWidget *preview_img;
+  GdkPixbuf *preview_buf;
+  GdkInterpType mode;
+  gint width, height, ratio;
 
-  aspect_frame = GTK_WIDGET (gtk_builder_get_object (ui, "aspect_frame"));
-  preview_darea = GTK_WIDGET (gtk_builder_get_object (ui, "preview_darea"));
+  preview_img = GTK_WIDGET (gtk_builder_get_object (ui, "preview_img"));
 
-  width = gdk_pixbuf_get_width (dialog->screenshot);
+  mode = GDK_INTERP_BILINEAR;
   height = gdk_pixbuf_get_height (dialog->screenshot);
-  scale_factor = gtk_widget_get_scale_factor (dialog->dialog);
-
-  width /= 5 * scale_factor;
-  height /= 5 * scale_factor;
-
-  gtk_widget_set_size_request (preview_darea, width, height);
-  gtk_aspect_frame_set (GTK_ASPECT_FRAME (aspect_frame), 0.0, 0.5,
-                        (gfloat) width / (gfloat) height,
-                        FALSE);
+  width = gdk_pixbuf_get_width (dialog->screenshot);
+  ratio = width / 400;
 
-  if (screenshot_config->take_window_shot)
-    gtk_frame_set_shadow_type (GTK_FRAME (aspect_frame), GTK_SHADOW_NONE);
-  else
-    gtk_frame_set_shadow_type (GTK_FRAME (aspect_frame), GTK_SHADOW_IN);
+  preview_buf = gdk_pixbuf_scale_simple (dialog->screenshot, 400, height / ratio, mode);
+  gtk_image_set_from_pixbuf (GTK_IMAGE (preview_img),  preview_buf);
+  dialog->preview_image = GTK_IMAGE (preview_img);
 
-  g_signal_connect (preview_darea, "draw", G_CALLBACK (on_preview_draw), dialog);
-  g_signal_connect (preview_darea, "button_press_event", G_CALLBACK (on_preview_button_press_event), dialog);
-  g_signal_connect (preview_darea, "button_release_event", G_CALLBACK (on_preview_button_release_event), 
dialog);
+  g_signal_connect (preview_img, "button_press_event", G_CALLBACK (on_preview_button_press_event), dialog);
+  g_signal_connect (preview_img, "button_release_event", G_CALLBACK (on_preview_button_release_event), 
dialog);
 
   /* setup dnd */
-  gtk_drag_source_set (preview_darea,
+  gtk_drag_source_set (preview_img,
                        GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
                        drag_types, G_N_ELEMENTS (drag_types),
                        GDK_ACTION_COPY);
 
-  g_signal_connect (G_OBJECT (preview_darea), "drag_begin",
+  g_signal_connect (G_OBJECT (preview_img), "drag_begin",
                     G_CALLBACK (drag_begin), dialog);
-  g_signal_connect (G_OBJECT (preview_darea), "drag_data_get",
+  g_signal_connect (G_OBJECT (preview_img), "drag_data_get",
                     G_CALLBACK (drag_data_get), dialog);
 }
 
@@ -248,7 +207,7 @@ screenshot_dialog_new (GdkPixbuf              *screenshot,
   dialog->back_button = GTK_WIDGET (gtk_builder_get_object (ui, "back_button"));
   g_signal_connect (dialog->back_button, "clicked", G_CALLBACK (button_clicked), dialog);
 
-  setup_drawing_area (dialog, ui);
+  setup_preview_img (dialog, ui);
 
   gtk_widget_show_all (dialog->dialog);
 
diff --git a/src/screenshot-dialog.h b/src/screenshot-dialog.h
index d9b07a5..3393b96 100644
--- a/src/screenshot-dialog.h
+++ b/src/screenshot-dialog.h
@@ -33,7 +33,7 @@ typedef void (*SaveScreenshotCallback) (ScreenshotResponse response, gpointer *u
 
 typedef struct {
   GdkPixbuf *screenshot;
-  GdkPixbuf *preview_image;
+  GtkImage *preview_image;
 
   GtkWidget *dialog;
   GtkWidget *save_widget;
diff --git a/src/screenshot-dialog.ui b/src/screenshot-dialog.ui
index ed2d620..87ddd87 100644
--- a/src/screenshot-dialog.ui
+++ b/src/screenshot-dialog.ui
@@ -1,49 +1,111 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.0 -->
 <interface>
-  <!-- interface-requires gtk+ 3.8 -->
+  <requires lib="gtk+" version="3.22"/>
   <object class="GtkApplicationWindow" id="toplevel">
     <property name="can_focus">False</property>
-    <property name="border_width">5</property>
-    <property name="title" translatable="yes">Save Screenshot</property>
-    <property name="resizable">False</property>
     <property name="window_position">center</property>
-    <child type="titlebar">
-      <object class="GtkHeaderBar" id="headerbar1">
+    <child>
+      <object class="GtkBox">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="show_close_button">True</property>
+        <property name="halign">center</property>
+        <property name="valign">center</property>
+        <property name="border_width">12</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
         <child>
-          <object class="GtkButton" id="back_button">
-            <property name="tooltip_text" translatable="yes">Back</property>
+          <object class="GtkImage" id="preview_img">
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">True</property>
-            <property name="use_underline">True</property>
-            <style>
-              <class name="image-button"/>
-            </style>
+            <property name="can_focus">False</property>
+            <property name="pixel_size">256</property>
+            <property name="icon_name">image-x-generic-symbolic</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">center</property>
+            <property name="row_spacing">6</property>
+            <property name="column_spacing">12</property>
             <child>
-              <object class="GtkImage">
+              <object class="GtkLabel">
                 <property name="visible">True</property>
-                <property name="icon_name">go-previous-symbolic</property>
+                <property name="can_focus">False</property>
+                <property name="halign">end</property>
+                <property name="label" translatable="yes">_Name:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">filename_entry</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">end</property>
+                <property name="label" translatable="yes">_Folder:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">save_widget</property>
               </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="filename_entry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="width_chars">35</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkFileChooserButton" id="save_widget">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="action">select-folder</property>
+                <property name="local_only">False</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+              </packing>
             </child>
           </object>
           <packing>
-            <property name="pack-type">start</property>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
           </packing>
         </child>
+      </object>
+    </child>
+    <child type="titlebar">
+      <object class="GtkHeaderBar">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
         <child>
-          <object class="GtkButton" id="copy_button">
-            <property name="label" translatable="yes">C_opy to Clipboard</property>
+          <object class="GtkButton" id="back_button">
+            <property name="label" translatable="yes">_Cancel</property>
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="receives_default">True</property>
             <property name="use_underline">True</property>
           </object>
-          <packing>
-            <property name="pack-type">start</property>
-          </packing>
         </child>
         <child>
           <object class="GtkButton" id="save_button">
@@ -59,121 +121,24 @@
             </style>
           </object>
           <packing>
-            <property name="pack-type">end</property>
-          </packing>
-        </child>
-      </object>
-    </child>
-    <child>
-      <object class="GtkGrid" id="grid1">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="margin_left">5</property>
-        <property name="margin_right">5</property>
-        <property name="margin_top">5</property>
-        <property name="margin_bottom">5</property>
-        <property name="row_spacing">8</property>
-        <property name="column_spacing">8</property>
-        <child>
-          <object class="GtkAlignment" id="alignment1">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="vexpand">True</property>
-            <child>
-              <object class="GtkAspectFrame" id="aspect_frame">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label_xalign">0</property>
-                <property name="shadow_type">none</property>
-                <child>
-                  <object class="GtkDrawingArea" id="preview_darea">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                  </object>
-                </child>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">0</property>
-            <property name="width">1</property>
-            <property name="height">2</property>
+            <property name="pack_type">end</property>
+            <property name="position">1</property>
           </packing>
         </child>
         <child>
-          <object class="GtkLabel" id="label1">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="halign">start</property>
-            <property name="valign">start</property>
-            <property name="label" translatable="yes">_Name:</property>
-            <property name="use_underline">True</property>
-            <property name="mnemonic_widget">filename_entry</property>
-          </object>
-          <packing>
-            <property name="left_attach">1</property>
-            <property name="top_attach">0</property>
-            <property name="width">1</property>
-            <property name="height">1</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label2">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="halign">start</property>
-            <property name="valign">start</property>
-            <property name="label" translatable="yes">Save in _folder:</property>
-            <property name="use_underline">True</property>
-            <property name="mnemonic_widget">save_widget</property>
-          </object>
-          <packing>
-            <property name="left_attach">1</property>
-            <property name="top_attach">1</property>
-            <property name="width">1</property>
-            <property name="height">1</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkEntry" id="filename_entry">
+          <object class="GtkButton" id="copy_button">
+            <property name="label" translatable="yes">C_opy to Clipboard</property>
             <property name="visible">True</property>
             <property name="can_focus">True</property>
-            <property name="valign">start</property>
-            <property name="activates_default">True</property>
-            <property name="width_chars">32</property>
-          </object>
-          <packing>
-            <property name="left_attach">2</property>
-            <property name="top_attach">0</property>
-            <property name="width">1</property>
-            <property name="height">1</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkFileChooserButton" id="save_widget">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="valign">start</property>
-            <property name="vexpand">True</property>
-            <property name="action">select-folder</property>
-            <property name="local_only">False</property>
+            <property name="receives_default">True</property>
+            <property name="use_underline">True</property>
           </object>
           <packing>
-            <property name="left_attach">2</property>
-            <property name="top_attach">1</property>
-            <property name="width">1</property>
-            <property name="height">1</property>
+            <property name="pack_type">end</property>
+            <property name="position">2</property>
           </packing>
         </child>
       </object>
     </child>
   </object>
-  <object class="GtkSizeGroup" id="header_bar_size_group">
-    <property name="mode">horizontal</property>
-    <widgets>
-      <widget name="copy_button"/>
-      <widget name="save_button"/>
-    </widgets>
-  </object>
 </interface>


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