[gthumb] [crop tool] allow to force dimesions as multiple of 8 or other sizes



commit 5a71a013bc1cf035c911ceaaddf31c8df8ef69ef
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Jul 25 18:40:06 2010 +0200

    [crop tool] allow to force dimesions as multiple of 8 or other sizes
    
    [bug #622385]

 .../file_tools/data/gthumb_crop_options.schemas.in |   24 +++
 extensions/file_tools/data/ui/crop-options.ui      |  177 +++++++++++---------
 extensions/file_tools/gth-file-tool-crop.c         |   54 ++++++-
 extensions/file_tools/preferences.h                |    2 +
 gthumb/gth-image-selector.c                        |   40 +++++-
 gthumb/gth-image-selector.h                        |    3 +
 6 files changed, 212 insertions(+), 88 deletions(-)
---
diff --git a/extensions/file_tools/data/gthumb_crop_options.schemas.in b/extensions/file_tools/data/gthumb_crop_options.schemas.in
index 900c933..84d38e8 100644
--- a/extensions/file_tools/data/gthumb_crop_options.schemas.in
+++ b/extensions/file_tools/data/gthumb_crop_options.schemas.in
@@ -61,5 +61,29 @@
 	</locale>
       </schema>
 
+      <schema>
+	<key>/schemas/apps/gthumb/ext/crop/bind_dimensions</key>
+	<applyto>/apps/gthumb/ext/crop/bind_dimensions</applyto>
+	<owner>gthumb</owner>
+	<type>bool</type>
+	<default>false</default>
+	<locale name="C">
+	  <short></short>
+	  <long></long>
+	</locale>
+      </schema>
+
+      <schema>
+	<key>/schemas/apps/gthumb/ext/crop/bind_factor</key>
+	<applyto>/apps/gthumb/ext/crop/bind_factor</applyto>
+	<owner>gthumb</owner>
+	<type>int</type>
+	<default>8</default>
+	<locale name="C">
+	  <short></short>
+	  <long></long>
+	</locale>
+      </schema>
+
     </schemalist>
 </gconfschemafile>
diff --git a/extensions/file_tools/data/ui/crop-options.ui b/extensions/file_tools/data/ui/crop-options.ui
index e88e2b0..7735609 100644
--- a/extensions/file_tools/data/ui/crop-options.ui
+++ b/extensions/file_tools/data/ui/crop-options.ui
@@ -31,7 +31,7 @@
                         <child>
                           <object class="GtkTable" id="table2">
                             <property name="visible">True</property>
-                            <property name="n_rows">5</property>
+                            <property name="n_rows">3</property>
                             <property name="n_columns">2</property>
                             <property name="column_spacing">6</property>
                             <property name="row_spacing">6</property>
@@ -39,7 +39,7 @@
                               <object class="GtkLabel" id="crop_x_label">
                                 <property name="visible">True</property>
                                 <property name="xalign">0</property>
-                                <property name="label" translatable="yes">_X:</property>
+                                <property name="label" translatable="yes">_Position:</property>
                                 <property name="use_underline">True</property>
                                 <property name="mnemonic_widget">crop_x_spinbutton</property>
                               </object>
@@ -49,46 +49,16 @@
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkLabel" id="crop_y_label">
-                                <property name="visible">True</property>
-                                <property name="xalign">0</property>
-                                <property name="label" translatable="yes">_Y:</property>
-                                <property name="use_underline">True</property>
-                                <property name="mnemonic_widget">crop_y_spinbutton</property>
-                              </object>
-                              <packing>
-                                <property name="top_attach">1</property>
-                                <property name="bottom_attach">2</property>
-                                <property name="x_options">GTK_FILL</property>
-                                <property name="y_options"></property>
-                              </packing>
-                            </child>
-                            <child>
                               <object class="GtkLabel" id="crop_width_label">
                                 <property name="visible">True</property>
                                 <property name="xalign">0</property>
-                                <property name="label" translatable="yes">_Width:</property>
+                                <property name="label" translatable="yes">Size:</property>
                                 <property name="use_underline">True</property>
                                 <property name="mnemonic_widget">crop_width_spinbutton</property>
                               </object>
                               <packing>
-                                <property name="top_attach">2</property>
-                                <property name="bottom_attach">3</property>
-                                <property name="x_options">GTK_FILL</property>
-                                <property name="y_options"></property>
-                              </packing>
-                            </child>
-                            <child>
-                              <object class="GtkLabel" id="crop_height_label">
-                                <property name="visible">True</property>
-                                <property name="xalign">0</property>
-                                <property name="label" translatable="yes">Heigh_t:</property>
-                                <property name="use_underline">True</property>
-                                <property name="mnemonic_widget">crop_height_spinbutton</property>
-                              </object>
-                              <packing>
-                                <property name="top_attach">3</property>
-                                <property name="bottom_attach">4</property>
+                                <property name="top_attach">1</property>
+                                <property name="bottom_attach">2</property>
                                 <property name="x_options">GTK_FILL</property>
                                 <property name="y_options"></property>
                               </packing>
@@ -96,11 +66,13 @@
                             <child>
                               <object class="GtkHBox" id="hbox5">
                                 <property name="visible">True</property>
+                                <property name="spacing">6</property>
                                 <child>
                                   <object class="GtkSpinButton" id="crop_x_spinbutton">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="invisible_char">&#x25CF;</property>
+                                    <property name="width_chars">5</property>
                                     <property name="adjustment">crop_x_adjustment</property>
                                     <property name="climb_rate">1</property>
                                   </object>
@@ -109,36 +81,34 @@
                                     <property name="position">0</property>
                                   </packing>
                                 </child>
-                              </object>
-                              <packing>
-                                <property name="left_attach">1</property>
-                                <property name="right_attach">2</property>
-                                <property name="x_options">GTK_FILL</property>
-                                <property name="y_options">GTK_FILL</property>
-                              </packing>
-                            </child>
-                            <child>
-                              <object class="GtkHBox" id="hbox6">
-                                <property name="visible">True</property>
+                                <child>
+                                  <object class="GtkLabel" id="label1">
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes">&#xD7;</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
                                 <child>
                                   <object class="GtkSpinButton" id="crop_y_spinbutton">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="invisible_char">&#x25CF;</property>
+                                    <property name="width_chars">5</property>
                                     <property name="adjustment">crop_y_adjustment</property>
                                     <property name="climb_rate">1</property>
                                   </object>
                                   <packing>
                                     <property name="expand">False</property>
-                                    <property name="position">0</property>
+                                    <property name="position">2</property>
                                   </packing>
                                 </child>
                               </object>
                               <packing>
                                 <property name="left_attach">1</property>
                                 <property name="right_attach">2</property>
-                                <property name="top_attach">1</property>
-                                <property name="bottom_attach">2</property>
                                 <property name="x_options">GTK_FILL</property>
                                 <property name="y_options">GTK_FILL</property>
                               </packing>
@@ -146,11 +116,13 @@
                             <child>
                               <object class="GtkHBox" id="hbox7">
                                 <property name="visible">True</property>
+                                <property name="spacing">6</property>
                                 <child>
                                   <object class="GtkSpinButton" id="crop_width_spinbutton">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="invisible_char">&#x25CF;</property>
+                                    <property name="width_chars">5</property>
                                     <property name="adjustment">crop_width_adjustment</property>
                                     <property name="climb_rate">1</property>
                                   </object>
@@ -160,78 +132,65 @@
                                     <property name="position">0</property>
                                   </packing>
                                 </child>
-                              </object>
-                              <packing>
-                                <property name="left_attach">1</property>
-                                <property name="right_attach">2</property>
-                                <property name="top_attach">2</property>
-                                <property name="bottom_attach">3</property>
-                                <property name="x_options">GTK_FILL</property>
-                                <property name="y_options">GTK_FILL</property>
-                              </packing>
-                            </child>
-                            <child>
-                              <object class="GtkHBox" id="hbox8">
-                                <property name="visible">True</property>
+                                <child>
+                                  <object class="GtkLabel" id="label2">
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes" comments="this is used to separate the dimensions, for example: 120 &#xD7; 250">&#xD7;</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
                                 <child>
                                   <object class="GtkSpinButton" id="crop_height_spinbutton">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="invisible_char">&#x25CF;</property>
+                                    <property name="width_chars">5</property>
                                     <property name="adjustment">crop_height_adjustment</property>
                                     <property name="climb_rate">1</property>
                                   </object>
                                   <packing>
                                     <property name="expand">False</property>
                                     <property name="fill">False</property>
-                                    <property name="position">0</property>
+                                    <property name="position">2</property>
                                   </packing>
                                 </child>
                               </object>
                               <packing>
                                 <property name="left_attach">1</property>
                                 <property name="right_attach">2</property>
-                                <property name="top_attach">3</property>
-                                <property name="bottom_attach">4</property>
+                                <property name="top_attach">1</property>
+                                <property name="bottom_attach">2</property>
                                 <property name="x_options">GTK_FILL</property>
                                 <property name="y_options">GTK_FILL</property>
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkHBox" id="hbox1">
+                              <object class="GtkHBox" id="grid_type_combobox_box">
                                 <property name="visible">True</property>
                                 <child>
-                                  <object class="GtkHBox" id="grid_type_combobox_box">
-                                    <property name="visible">True</property>
-                                    <child>
-                                      <placeholder/>
-                                    </child>
-                                  </object>
-                                  <packing>
-                                    <property name="position">0</property>
-                                  </packing>
+                                  <placeholder/>
                                 </child>
                               </object>
                               <packing>
                                 <property name="left_attach">1</property>
                                 <property name="right_attach">2</property>
-                                <property name="top_attach">4</property>
-                                <property name="bottom_attach">5</property>
+                                <property name="top_attach">2</property>
+                                <property name="bottom_attach">3</property>
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkLabel" id="crop_grid_label">
+                              <object class="GtkLabel" id="grid_label">
                                 <property name="visible">True</property>
                                 <property name="xalign">0</property>
                                 <property name="label" translatable="yes">_Grid:</property>
                                 <property name="use_underline">True</property>
-                                <property name="mnemonic_widget">crop_x_spinbutton</property>
                               </object>
                               <packing>
-                                <property name="top_attach">4</property>
-                                <property name="bottom_attach">5</property>
-                                <property name="x_options">GTK_FILL</property>
-                                <property name="y_options"></property>
+                                <property name="top_attach">2</property>
+                                <property name="bottom_attach">3</property>
                               </packing>
                             </child>
                           </object>
@@ -351,6 +310,52 @@
                             <property name="position">2</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkHBox" id="hbox1">
+                            <property name="visible">True</property>
+                            <property name="spacing">6</property>
+                            <child>
+                              <object class="GtkCheckButton" id="bind_dimensions_checkbutton">
+                                <property name="label" translatable="yes" comments="after the colon there is a control to select the size in pixels">M_ultiple of:</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="draw_indicator">True</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkSpinButton" id="bind_factor_spinbutton">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="invisible_char">&#x25CF;</property>
+                                <property name="width_chars">5</property>
+                                <property name="adjustment">bind_factor_adjustment</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="label3">
+                                <property name="visible">True</property>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes" comments="abbreviation of pixel">px</property>
+                              </object>
+                              <packing>
+                                <property name="position">2</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">3</property>
+                          </packing>
+                        </child>
                       </object>
                     </child>
                   </object>
@@ -455,4 +460,10 @@
     <property name="upper">999999</property>
     <property name="step_increment">1</property>
   </object>
+  <object class="GtkAdjustment" id="bind_factor_adjustment">
+    <property name="value">1</property>
+    <property name="lower">1</property>
+    <property name="upper">100000</property>
+    <property name="step_increment">1</property>
+  </object>
 </interface>
diff --git a/extensions/file_tools/gth-file-tool-crop.c b/extensions/file_tools/gth-file-tool-crop.c
index 0659d24..6b61a3d 100644
--- a/extensions/file_tools/gth-file-tool-crop.c
+++ b/extensions/file_tools/gth-file-tool-crop.c
@@ -325,6 +325,39 @@ grid_type_changed_cb (GtkComboBox     *combobox,
 }
 
 
+static void
+update_sensitivity (GthFileToolCrop *self)
+{
+	gtk_widget_set_sensitive (GET_WIDGET ("bind_factor_spinbutton"), gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET("bind_dimensions_checkbutton"))));
+}
+
+
+static void
+bind_dimensions_checkbutton_toggled_cb (GtkToggleButton *togglebutton,
+					 gpointer         user_data)
+{
+	GthFileToolCrop *self = user_data;
+
+	gth_image_selector_bind_dimensions (self->priv->selector,
+					    gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET("bind_dimensions_checkbutton"))),
+					    gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("bind_factor_spinbutton"))));
+	update_sensitivity (self);
+}
+
+
+static void
+bind_factor_spinbutton_value_changed_cb (GtkSpinButton *spinbutton,
+					 gpointer       user_data)
+{
+	GthFileToolCrop *self = user_data;
+
+	gth_image_selector_bind_dimensions (self->priv->selector,
+					    gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET("bind_dimensions_checkbutton"))),
+					    gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("bind_factor_spinbutton"))));
+	update_sensitivity (self);
+}
+
+
 static GtkWidget *
 gth_file_tool_crop_get_options (GthFileTool *base)
 {
@@ -394,6 +427,9 @@ gth_file_tool_crop_get_options (GthFileTool *base)
 	gtk_combo_box_set_active (GTK_COMBO_BOX (self->priv->grid_type_combobox), eel_gconf_get_enum (PREF_CROP_GRID_TYPE, GTH_TYPE_GRID_TYPE, GTH_GRID_THIRDS));
 	gtk_widget_show (self->priv->grid_type_combobox);
 	gtk_box_pack_start (GTK_BOX (GET_WIDGET ("grid_type_combobox_box")), self->priv->grid_type_combobox, FALSE, FALSE, 0);
+	gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("grid_label")), self->priv->grid_type_combobox);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("bind_dimensions_checkbutton")), eel_gconf_get_boolean (PREF_CROP_BIND_DIMENSIONS, FALSE));
+	gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("bind_factor_spinbutton")), eel_gconf_get_integer (PREF_CROP_BIND_FACTOR, 8));
 
 	g_signal_connect (GET_WIDGET ("crop_button"),
 			  "clicked",
@@ -439,20 +475,28 @@ gth_file_tool_crop_get_options (GthFileTool *base)
                           "changed",
                           G_CALLBACK (grid_type_changed_cb),
                           self);
+	g_signal_connect (GET_WIDGET ("bind_dimensions_checkbutton"),
+			  "toggled",
+			  G_CALLBACK (bind_dimensions_checkbutton_toggled_cb),
+			  self);
+	g_signal_connect (GET_WIDGET ("bind_factor_spinbutton"),
+			  "value-changed",
+			  G_CALLBACK (bind_factor_spinbutton_value_changed_cb),
+			  self);
 
 	self->priv->selector = (GthImageSelector *) gth_image_selector_new (GTH_IMAGE_VIEWER (viewer), GTH_SELECTOR_TYPE_REGION);
 	gth_image_selector_set_grid_type (self->priv->selector, gtk_combo_box_get_active (GTK_COMBO_BOX (self->priv->grid_type_combobox)));
+	gth_image_selector_bind_dimensions (self->priv->selector,
+					    gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET("bind_dimensions_checkbutton"))),
+					    gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("bind_factor_spinbutton"))));
 	g_signal_connect (self->priv->selector,
 			  "selection-changed",
 			  G_CALLBACK (selector_selection_changed_cb),
 			  self);
-	/*g_signal_connect (self->priv->selector,
-			  "mask_visibility_changed",
-			  G_CALLBACK (selector_mask_visibility_changed_cb),
-			  self);*/
 
 	gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), (GthImageViewerTool *) self->priv->selector);
 	ratio_combobox_changed_cb (NULL, self);
+	update_sensitivity (self);
 
 	return options;
 }
@@ -476,6 +520,8 @@ gth_file_tool_crop_destroy_options (GthFileTool *base)
 		eel_gconf_set_integer (PREF_CROP_ASPECT_RATIO_HEIGHT, gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("ratio_h_spinbutton"))));
 		eel_gconf_set_enum (PREF_CROP_ASPECT_RATIO, GTH_TYPE_ASPECT_RATIO, gtk_combo_box_get_active (GTK_COMBO_BOX (self->priv->ratio_combobox)));
 		eel_gconf_set_boolean (PREF_CROP_ASPECT_RATIO_INVERT, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("invert_ratio_checkbutton"))));
+		eel_gconf_set_boolean (PREF_CROP_BIND_DIMENSIONS, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("bind_dimensions_checkbutton"))));
+		eel_gconf_set_integer (PREF_CROP_BIND_FACTOR, gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("bind_factor_spinbutton"))));
 
 		/* destroy the option data */
 
diff --git a/extensions/file_tools/preferences.h b/extensions/file_tools/preferences.h
index a7f391f..5c727ea 100644
--- a/extensions/file_tools/preferences.h
+++ b/extensions/file_tools/preferences.h
@@ -32,6 +32,8 @@ G_BEGIN_DECLS
 #define PREF_CROP_ASPECT_RATIO_INVERT   "/apps/gthumb/ext/crop/aspect_ratio_invert"
 #define PREF_CROP_ASPECT_RATIO_WIDTH    "/apps/gthumb/ext/crop/aspect_ratio_width"
 #define PREF_CROP_ASPECT_RATIO_HEIGHT   "/apps/gthumb/ext/crop/aspect_ratio_height"
+#define PREF_CROP_BIND_DIMENSIONS       "/apps/gthumb/ext/crop/bind_dimensions"
+#define PREF_CROP_BIND_FACTOR           "/apps/gthumb/ext/crop/bind_factor"
 
 #define PREF_RESIZE_UNIT                "/apps/gthumb/ext/resize/unit"
 #define PREF_RESIZE_WIDTH               "/apps/gthumb/ext/resize/width"
diff --git a/gthumb/gth-image-selector.c b/gthumb/gth-image-selector.c
index 0ec1174..5175e02 100644
--- a/gthumb/gth-image-selector.c
+++ b/gthumb/gth-image-selector.c
@@ -205,6 +205,8 @@ struct _GthImageSelectorPrivate {
 	gboolean         mask_visible;
 	GthGridType      grid_type;
 	gboolean         active;
+	gboolean         bind_dimensions;
+	int              bind_factor;
 
 	GdkRectangle     drag_start_selection_area;
 	GdkRectangle     selection_area;
@@ -841,6 +843,24 @@ get_semiplane_no (int x1,
 }
 
 
+static int
+bind_dimension (int dimension,
+		int factor)
+{
+	int d;
+	int d_next;
+
+	d = (dimension / factor) * factor;
+	d_next = d + factor;
+	if (dimension - d <= d_next - dimension)
+		dimension = d;
+	else
+		dimension = d_next;
+
+	return dimension;
+}
+
+
 static void
 check_and_set_new_selection (GthImageSelector *self,
 			     GdkRectangle      new_selection)
@@ -848,7 +868,13 @@ check_and_set_new_selection (GthImageSelector *self,
 	new_selection.width = MAX (0, new_selection.width);
 	new_selection.height = MAX (0, new_selection.height);
 
-	if (((self->priv->current_area == NULL) || (self->priv->current_area->id != C_SELECTION_AREA))
+	if (self->priv->bind_dimensions && (self->priv->bind_factor > 1)) {
+		new_selection.width = bind_dimension (new_selection.width, self->priv->bind_factor);
+		new_selection.height = bind_dimension (new_selection.height, self->priv->bind_factor);
+	}
+
+	if (((self->priv->current_area == NULL)
+	     || (self->priv->current_area->id != C_SELECTION_AREA))
 	    && self->priv->use_ratio)
 	{
 		if (rectangle_in_rectangle (new_selection, self->priv->pixbuf_area))
@@ -1298,6 +1324,8 @@ gth_image_selector_instance_init (GthImageSelector *self)
 	self->priv->ratio = 1.0;
 	self->priv->mask_visible = TRUE;
 	self->priv->grid_type = GTH_GRID_NONE;
+	self->priv->bind_dimensions = FALSE;
+	self->priv->bind_factor = 1;
 }
 
 
@@ -1605,3 +1633,13 @@ gth_image_selector_get_grid_type (GthImageSelector *self)
 {
         return self->priv->grid_type;
 }
+
+
+void
+gth_image_selector_bind_dimensions (GthImageSelector *self,
+				    gboolean          bind,
+				    int               factor)
+{
+	self->priv->bind_dimensions = bind;
+	self->priv->bind_factor = factor;
+}
diff --git a/gthumb/gth-image-selector.h b/gthumb/gth-image-selector.h
index 968c23d..253df9e 100644
--- a/gthumb/gth-image-selector.h
+++ b/gthumb/gth-image-selector.h
@@ -102,6 +102,9 @@ gboolean              gth_image_selector_get_mask_visible     (GthImageSelector
 void                  gth_image_selector_set_grid_type        (GthImageSelector *selector,
                                                                GthGridType       grid_type);
 GthGridType           gth_image_selector_get_grid_type        (GthImageSelector *selector);
+void                  gth_image_selector_bind_dimensions      (GthImageSelector *selector,
+							       gboolean          bind,
+							       int               factor);
 
 G_END_DECLS
 



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