[gimp/soc-2011-gimpunitentry: 46/68] app/dialogs: port resolution preference and calibrate dialogs to GimpUnitEntry



commit e3abe3480e4301714d2480673316e0e0f9c3936f
Author: Enrico Schröder <enni schroeder gmail com>
Date:   Mon Jul 11 17:30:49 2011 +0200

    app/dialogs: port resolution preference and calibrate dialogs to GimpUnitEntry

 app/dialogs/preferences-dialog.c          |   66 +++++++++----------
 app/dialogs/resolution-calibrate-dialog.c |   98 ++++++++++++++---------------
 app/dialogs/resolution-calibrate-dialog.h |    2 +-
 3 files changed, 79 insertions(+), 87 deletions(-)
---
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index 7a9c118..7279000 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -94,7 +94,7 @@ static void        prefs_message                  (GtkMessageType  type,
 static void   prefs_resolution_source_callback    (GtkWidget  *widget,
                                                    GObject    *config);
 static void   prefs_resolution_calibrate_callback (GtkWidget  *widget,
-                                                   GtkWidget  *entry);
+                                                   GObject    *entries);
 static void   prefs_input_devices_dialog          (GtkWidget  *widget,
                                                    Gimp       *gimp);
 static void   prefs_keyboard_shortcuts_dialog     (GtkWidget  *widget,
@@ -451,13 +451,18 @@ prefs_resolution_source_callback (GtkWidget *widget,
     }
   else
     {
-      GimpSizeEntry *entry = g_object_get_data (G_OBJECT (widget),
-                                                "monitor_resolution_sizeentry");
-
-      g_return_if_fail (GIMP_IS_SIZE_ENTRY (entry));
-
-      xres = gimp_size_entry_get_refval (entry, 0);
-      yres = gimp_size_entry_get_refval (entry, 1);
+      GimpUnitEntryTable *entries = GIMP_UNIT_ENTRY_TABLE (
+                                    g_object_get_data (G_OBJECT (widget),
+                                                      "monitor_resolution_sizeentry"));
+
+      g_return_if_fail (GIMP_IS_UNIT_ENTRY_TABLE (entries));
+
+      xres = gimp_unit_entry_get_value_in_unit (
+              gimp_unit_entry_table_get_nth_entry (entries, 0),
+              GIMP_UNIT_PIXEL);
+      yres = gimp_unit_entry_get_value_in_unit (
+              gimp_unit_entry_table_get_nth_entry (entries, 1),
+              GIMP_UNIT_PIXEL);                                         
     }
 
   g_object_set (config,
@@ -469,18 +474,19 @@ prefs_resolution_source_callback (GtkWidget *widget,
 
 static void
 prefs_resolution_calibrate_callback (GtkWidget *widget,
-                                     GtkWidget *entry)
+                                     GObject   *unit_entries)
 {
   GtkWidget *dialog;
   GtkWidget *prefs_box;
   GtkWidget *image;
 
-  dialog = gtk_widget_get_toplevel (entry);
+  dialog = gtk_widget_get_toplevel (gimp_unit_entry_table_get_table (
+                                      GIMP_UNIT_ENTRY_TABLE (unit_entries)));
 
   prefs_box = g_object_get_data (G_OBJECT (dialog), "prefs-box");
   image     = gimp_prefs_box_get_image (GIMP_PREFS_BOX (prefs_box));
 
-  resolution_calibrate_dialog (entry, gtk_image_get_pixbuf (GTK_IMAGE (image)));
+  resolution_calibrate_dialog (unit_entries, gtk_image_get_pixbuf (GTK_IMAGE (image)));
 }
 
 static void
@@ -1290,6 +1296,7 @@ prefs_dialog_new (Gimp       *gimp,
   GSList            *group;
   GtkWidget         *editor;
   gint               i;
+  GimpUnitEntryTable *unit_entry_table;
 
   GObject           *object;
   GimpCoreConfig    *core_config;
@@ -2164,35 +2171,24 @@ prefs_dialog_new (Gimp       *gimp,
                            GTK_CONTAINER (vbox), FALSE);
 
   {
-    gchar *pixels_per_unit = g_strconcat (_("Pixels"), "/%s", NULL);
-
-    entry = gimp_prop_coordinates_new (object,
+    unit_entry_table = GIMP_UNIT_ENTRY_TABLE (
+            gimp_prop_coordinates_new2 (object,
                                        "monitor-xresolution",
                                        "monitor-yresolution",
+                                       _("Horizontal"),
+                                       _("Vertical"),
                                        NULL,
-                                       pixels_per_unit,
-                                       GIMP_SIZE_ENTRY_UPDATE_RESOLUTION,
-                                       0.0, 0.0,
-                                       TRUE);
+                                       1.0, 1.0, /* FIXME: UnitEntry needs 1.0 as "resolution of resolution" 
, otherwise calculation is not correct */
+                                       TRUE));
+    gimp_unit_entry_table_set_mode (unit_entry_table, GIMP_UNIT_ENTRY_MODE_RESOLUTION);
 
-    g_free (pixels_per_unit);
   }
 
-  gtk_table_set_col_spacings (GTK_TABLE (entry), 2);
-  gtk_table_set_row_spacings (GTK_TABLE (entry), 2);
-
-  gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (entry),
-                                _("Horizontal"), 0, 1, 0.0);
-  gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (entry),
-                                _("Vertical"), 0, 2, 0.0);
-  gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (entry),
-                                _("ppi"), 1, 4, 0.0);
-
   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
-  gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 24);
-  gtk_widget_show (entry);
-  gtk_widget_set_sensitive (entry, ! display_config->monitor_res_from_gdk);
+  gtk_box_pack_start (GTK_BOX (hbox), unit_entry_table->table, TRUE, TRUE, 24);
+  gtk_widget_show (unit_entry_table->table);
+  gtk_widget_set_sensitive (unit_entry_table->table, ! display_config->monitor_res_from_gdk);
 
   group = NULL;
 
@@ -2214,7 +2210,7 @@ prefs_dialog_new (Gimp       *gimp,
   gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0);
   gtk_widget_show (button);
 
-  g_object_set_data (G_OBJECT (button), "monitor_resolution_sizeentry", entry);
+  g_object_set_data (G_OBJECT (button), "monitor_resolution_sizeentry", unit_entry_table);
 
   g_signal_connect (button, "toggled",
                     G_CALLBACK (prefs_resolution_source_callback),
@@ -2244,7 +2240,7 @@ prefs_dialog_new (Gimp       *gimp,
                             ! display_config->monitor_res_from_gdk);
 
   g_object_bind_property (button, "active",
-                          entry,  "sensitive",
+                          unit_entry_table->table,  "sensitive",
                           G_BINDING_SYNC_CREATE);
   g_object_bind_property (button,           "active",
                           calibrate_button, "sensitive",
@@ -2252,7 +2248,7 @@ prefs_dialog_new (Gimp       *gimp,
 
   g_signal_connect (calibrate_button, "clicked",
                     G_CALLBACK (prefs_resolution_calibrate_callback),
-                    entry);
+                    unit_entry_table);
 
   g_object_unref (size_group);
   size_group = NULL;
diff --git a/app/dialogs/resolution-calibrate-dialog.c b/app/dialogs/resolution-calibrate-dialog.c
index 042d824..55eccf4 100644
--- a/app/dialogs/resolution-calibrate-dialog.c
+++ b/app/dialogs/resolution-calibrate-dialog.c
@@ -28,11 +28,11 @@
 #include "gimp-intl.h"
 
 
-static GtkWidget *calibrate_entry = NULL;
-static gdouble    calibrate_xres  = 1.0;
-static gdouble    calibrate_yres  = 1.0;
-static gint       ruler_width     = 1;
-static gint       ruler_height    = 1;
+static GimpUnitEntryTable  *calibrate_entries = NULL;
+static gdouble              calibrate_xres    = 1.0;
+static gdouble              calibrate_yres    = 1.0;
+static gint                 ruler_width       = 1;
+static gint                 ruler_height      = 1;
 
 
 /**
@@ -45,30 +45,33 @@ static gint       ruler_height    = 1;
  * is connected to a #GimpSizeEntry handling the resolution to be set.
  **/
 void
-resolution_calibrate_dialog (GtkWidget *resolution_entry,
+resolution_calibrate_dialog (GObject   *unit_entry_table,
                              GdkPixbuf *pixbuf)
 {
-  GtkWidget    *dialog;
-  GtkWidget    *table;
-  GtkWidget    *vbox;
-  GtkWidget    *hbox;
-  GtkWidget    *ruler;
-  GtkWidget    *label;
-  GdkScreen    *screen;
-  GdkRectangle  rect;
-  gint          monitor;
-
-  g_return_if_fail (GIMP_IS_SIZE_ENTRY (resolution_entry));
-  g_return_if_fail (gtk_widget_get_realized (resolution_entry));
+  GtkWidget           *dialog;
+  GtkWidget           *table;
+  GtkWidget           *vbox;
+  GtkWidget           *hbox;
+  GtkWidget           *ruler;
+  GtkWidget           *label;
+  GdkScreen           *screen;
+  GdkRectangle         rect;
+  gint                 monitor;
+  GimpUnitEntryTable  *resolution_entries;
+  GimpUnitEntry       *horizontal_entry, *vertical_entry;
+
+  g_return_if_fail (GIMP_IS_UNIT_ENTRY_TABLE (unit_entry_table));
   g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
 
   /*  this dialog can only exist once  */
-  if (calibrate_entry)
+  if (calibrate_entries)
     return;
 
+  resolution_entries = GIMP_UNIT_ENTRY_TABLE (unit_entry_table);
+
   dialog = gimp_dialog_new (_("Calibrate Monitor Resolution"),
                             "gimp-resolution-calibration",
-                            gtk_widget_get_toplevel (resolution_entry),
+                            gtk_widget_get_toplevel (gimp_unit_entry_table_get_table (resolution_entries)),
                             GTK_DIALOG_DESTROY_WITH_PARENT,
                             NULL, NULL,
 
@@ -84,7 +87,7 @@ resolution_calibrate_dialog (GtkWidget *resolution_entry,
 
   screen = gtk_widget_get_screen (dialog);
   monitor = gdk_screen_get_monitor_at_window (screen,
-                                              gtk_widget_get_window (resolution_entry));
+                                              gtk_widget_get_window (gimp_unit_entry_table_get_table 
(resolution_entries)));
   gdk_screen_get_monitor_geometry (screen, monitor, &rect);
 
   ruler_width  = rect.width  - 300 - (rect.width  % 100);
@@ -140,33 +143,28 @@ resolution_calibrate_dialog (GtkWidget *resolution_entry,
   gtk_widget_show (hbox);
 
   calibrate_xres =
-    gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (resolution_entry), 0);
+    gimp_unit_entry_table_get_nth_pixels (resolution_entries, 0);
   calibrate_yres =
-    gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (resolution_entry), 1);
-
-  calibrate_entry =
-    gimp_coordinates_new  (GIMP_UNIT_INCH, "%p",
-                           FALSE, FALSE, 10,
-                           GIMP_SIZE_ENTRY_UPDATE_SIZE,
-                           FALSE,
-                           FALSE,
-                           _("_Horizontal:"),
-                           ruler_width,
-                           calibrate_xres,
-                           1, GIMP_MAX_IMAGE_SIZE,
-                           0, 0,
-                           _("_Vertical:"),
-                           ruler_height,
-                           calibrate_yres,
-                           1, GIMP_MAX_IMAGE_SIZE,
-                           0, 0);
-  gtk_widget_hide (GTK_WIDGET (GIMP_COORDINATES_CHAINBUTTON (calibrate_entry)));
+    gimp_unit_entry_table_get_nth_pixels (resolution_entries, 1);
+
+  calibrate_entries = 
+    GIMP_UNIT_ENTRY_TABLE (gimp_unit_entry_table_new ()); 
+  gimp_unit_entry_table_set_bounds (calibrate_entries, GIMP_UNIT_PIXEL, GIMP_MAX_IMAGE_SIZE, 1);
+  
+  horizontal_entry = 
+    GIMP_UNIT_ENTRY (gimp_unit_entry_table_add_entry_defaults (calibrate_entries, "horizontal", 
_("Horizontal")));  
+  vertical_entry = 
+    GIMP_UNIT_ENTRY (gimp_unit_entry_table_add_entry_defaults (calibrate_entries, "vertical", 
_("Vertical")));                       
+  gimp_unit_entry_set_resolution         (horizontal_entry, calibrate_xres);
+  gimp_unit_entry_set_resolution         (vertical_entry,   calibrate_yres);
+  gimp_unit_entry_set_pixels             (horizontal_entry, ruler_width);
+  gimp_unit_entry_set_pixels             (vertical_entry,   ruler_height);
+
   g_signal_connect (dialog, "destroy",
                     G_CALLBACK (gtk_widget_destroyed),
-                    &calibrate_entry);
+                    &calibrate_entries);
 
-  gtk_box_pack_end (GTK_BOX (hbox), calibrate_entry, FALSE, FALSE, 0);
-  gtk_widget_show (calibrate_entry);
+  gtk_box_pack_end (GTK_BOX (hbox), gimp_unit_entry_table_get_table (calibrate_entries), FALSE, FALSE, 0);
 
   gtk_widget_show (dialog);
 
@@ -177,22 +175,20 @@ resolution_calibrate_dialog (GtkWidget *resolution_entry,
         GtkWidget *chain_button;
         gdouble    x, y;
 
-        x = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (calibrate_entry), 0);
-        y = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (calibrate_entry), 1);
+        x = gimp_unit_entry_get_pixels (horizontal_entry);
+        y = gimp_unit_entry_get_pixels (vertical_entry);
 
         calibrate_xres = (gdouble) ruler_width  * calibrate_xres / x;
         calibrate_yres = (gdouble) ruler_height * calibrate_yres / y;
 
-        chain_button = GIMP_COORDINATES_CHAINBUTTON (resolution_entry);
+        chain_button = gimp_unit_entry_table_get_chain_button (resolution_entries);
 
         if (ABS (x - y) > GIMP_MIN_RESOLUTION)
           gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain_button),
                                         FALSE);
 
-        gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (resolution_entry),
-                                    0, calibrate_xres);
-        gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (resolution_entry),
-                                    1, calibrate_yres);
+        gimp_unit_entry_table_set_nth_pixels (resolution_entries, 0, calibrate_xres);
+        gimp_unit_entry_table_set_nth_pixels (resolution_entries, 1, calibrate_yres);
       }
 
     default:
diff --git a/app/dialogs/resolution-calibrate-dialog.h b/app/dialogs/resolution-calibrate-dialog.h
index 4ac496c..7c9a721 100644
--- a/app/dialogs/resolution-calibrate-dialog.h
+++ b/app/dialogs/resolution-calibrate-dialog.h
@@ -19,7 +19,7 @@
 #define __RESOLUTION_CALIBRATE_DIALOG_H__
 
 
-void  resolution_calibrate_dialog (GtkWidget  *resolution_entry,
+void  resolution_calibrate_dialog (GObject    *resolution_entries,
                                    GdkPixbuf  *pixbuf);
 
 


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