[gthumb: 117/129] rotate tool: improved UI with the new grid



commit 2484b9bbd4ab398090c809378549f26539c82302
Author: Stefano Pettini <spettini users sourceforge net>
Date:   Mon Apr 25 15:43:12 2011 +0100

    rotate tool: improved UI with the new grid

 extensions/file_tools/data/ui/rotate-options.ui |  132 ++++++++++---
 extensions/file_tools/gth-file-tool-rotate.c    |  242 +++++++++++++----------
 2 files changed, 247 insertions(+), 127 deletions(-)
---
diff --git a/extensions/file_tools/data/ui/rotate-options.ui b/extensions/file_tools/data/ui/rotate-options.ui
index 98500fa..52f9b82 100644
--- a/extensions/file_tools/data/ui/rotate-options.ui
+++ b/extensions/file_tools/data/ui/rotate-options.ui
@@ -27,10 +27,31 @@
                         <property name="visible">True</property>
                         <property name="spacing">6</property>
                         <child>
-                          <object class="GtkHBox" id="rotation_angle_hbox">
+                          <object class="GtkTable" id="table2">
                             <property name="visible">True</property>
+                            <property name="n_columns">2</property>
+                            <property name="column_spacing">6</property>
+                            <property name="row_spacing">6</property>
                             <child>
-                              <placeholder/>
+                              <object class="GtkHBox" id="rotation_angle_hbox">
+                                <property name="visible">True</property>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="right_attach">2</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="rotation_angle_label">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">Angle</property>
+                              </object>
+                              <packing>
+                                <property name="x_options">GTK_FILL</property>
+                              </packing>
                             </child>
                           </object>
                           <packing>
@@ -39,11 +60,10 @@
                         </child>
                         <child>
                           <object class="GtkCheckButton" id="high_quality">
-                            <property name="label" translatable="yes">High _quality</property>
+                            <property name="label" translatable="yes">High quality</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="active">True</property>
                             <property name="draw_indicator">True</property>
                           </object>
@@ -56,10 +76,9 @@
                   </object>
                 </child>
                 <child type="label">
-                  <object class="GtkLabel" id="manual_rotation_label">
+                  <object class="GtkLabel" id="label11">
                     <property name="visible">True</property>
-                    <property name="yalign">0.47999998927116394</property>
-                    <property name="label" translatable="yes">Manual rotation</property>
+                    <property name="label" translatable="yes">Rotation</property>
                     <attributes>
                       <attribute name="weight" value="bold"/>
                     </attributes>
@@ -222,6 +241,8 @@
                                 </child>
                               </object>
                               <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
                                 <property name="position">0</property>
                               </packing>
                             </child>
@@ -242,6 +263,8 @@
                                 </child>
                               </object>
                               <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
                                 <property name="position">1</property>
                               </packing>
                             </child>
@@ -286,11 +309,10 @@
                         <property name="spacing">6</property>
                         <child>
                           <object class="GtkCheckButton" id="enable_guided_crop">
-                            <property name="label" translatable="yes">Enable _guided crop</property>
+                            <property name="label" translatable="yes">Enable guided crop</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="active">True</property>
                             <property name="draw_indicator">True</property>
                           </object>
@@ -300,11 +322,10 @@
                         </child>
                         <child>
                           <object class="GtkCheckButton" id="keep_aspect_ratio">
-                            <property name="label" translatable="yes">_Keep aspect ratio</property>
+                            <property name="label" translatable="yes">Keep aspect ratio</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="active">True</property>
                             <property name="draw_indicator">True</property>
                           </object>
@@ -313,25 +334,86 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkHBox" id="crop_p1_hbox">
+                          <object class="GtkTable" id="table1">
                             <property name="visible">True</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>
                             <child>
-                              <placeholder/>
+                              <object class="GtkHBox" id="crop_p1_hbox">
+                                <property name="visible">True</property>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="right_attach">2</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkHBox" id="crop_p2_hbox">
+                                <property name="visible">True</property>
+                                <child>
+                                  <placeholder/>
+                                </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>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="crop_p1_label">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">P1</property>
+                              </object>
+                              <packing>
+                                <property name="x_options">GTK_FILL</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="crop_p2_label">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">P2</property>
+                              </object>
+                              <packing>
+                                <property name="top_attach">1</property>
+                                <property name="bottom_attach">2</property>
+                                <property name="x_options">GTK_FILL</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="crop_grid_label">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">Grid</property>
+                              </object>
+                              <packing>
+                                <property name="top_attach">2</property>
+                                <property name="bottom_attach">3</property>
+                                <property name="x_options">GTK_FILL</property>
+                              </packing>
                             </child>
-                          </object>
-                          <packing>
-                            <property name="position">2</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkHBox" id="crop_p2_hbox">
-                            <property name="visible">True</property>
                             <child>
-                              <placeholder/>
+                              <object class="GtkVBox" id="crop_grid_hbox">
+                                <property name="visible">True</property>
+                                <child>
+                                  <placeholder/>
+                                </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>
+                              </packing>
                             </child>
                           </object>
                           <packing>
-                            <property name="position">3</property>
+                            <property name="position">2</property>
                           </packing>
                         </child>
                         <child>
@@ -361,7 +443,7 @@
                             </child>
                           </object>
                           <packing>
-                            <property name="position">4</property>
+                            <property name="position">3</property>
                           </packing>
                         </child>
                       </object>
@@ -369,7 +451,7 @@
                   </object>
                 </child>
                 <child type="label">
-                  <object class="GtkLabel" id="guided_crop_label">
+                  <object class="GtkLabel" id="label10">
                     <property name="visible">True</property>
                     <property name="label" translatable="yes">Guided crop</property>
                     <attributes>
diff --git a/extensions/file_tools/gth-file-tool-rotate.c b/extensions/file_tools/gth-file-tool-rotate.c
index 3818789..3282524 100644
--- a/extensions/file_tools/gth-file-tool-rotate.c
+++ b/extensions/file_tools/gth-file-tool-rotate.c
@@ -44,10 +44,12 @@ struct _GthFileToolRotatePrivate {
 	int               screen_height;
 	GtkAdjustment    *rotation_angle_adj;
 	GtkWidget        *high_quality;
+	GtkWidget        *show_grid;
 	GtkWidget        *enable_guided_crop;
 	GtkWidget        *keep_aspect_ratio;
 	GtkAdjustment    *crop_p1_adj;
 	GtkAdjustment    *crop_p2_adj;
+	GtkWidget        *crop_grid;
 	GthImageSelector *selector_crop;
 	GthImageSelector *selector_align;
 	guint             selector_align_point;
@@ -57,6 +59,119 @@ struct _GthFileToolRotatePrivate {
 
 
 static void
+update_crop_region (gpointer user_data)
+{
+	GthFileToolRotate *self = user_data;
+	GtkWidget         *window;
+	GtkWidget         *viewer_page;
+	GtkWidget         *viewer;
+	double             rotation_angle;
+	gboolean           enable_guided_crop;
+	gboolean           keep_aspect_ratio;
+	double             crop_alpha, crop_beta, crop_alpha_plus_beta;
+	double             crop_gamma, crop_delta, crop_gamma_plus_delta;
+
+	window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
+	viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
+	viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
+
+	gtk_widget_set_sensitive (GTK_WIDGET (self->priv->enable_guided_crop), TRUE);
+
+	enable_guided_crop = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->enable_guided_crop));
+
+	if (enable_guided_crop) {
+		
+		gtk_widget_set_sensitive (GTK_WIDGET (self->priv->keep_aspect_ratio), TRUE);
+		gtk_widget_set_sensitive (GTK_WIDGET (self->priv->crop_grid), TRUE);
+		gtk_widget_set_sensitive (GET_WIDGET ("crop_button"), TRUE);
+		
+		rotation_angle = gtk_adjustment_get_value (self->priv->rotation_angle_adj);
+		keep_aspect_ratio = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->keep_aspect_ratio));
+
+		if (keep_aspect_ratio) {
+
+			gtk_widget_set_sensitive (GET_WIDGET ("crop_p1_hbox"), FALSE);
+			gtk_widget_set_sensitive (GET_WIDGET ("crop_p2_hbox"), FALSE);
+
+			_gdk_pixbuf_rotate_get_cropping_parameters (self->priv->src_pixbuf, rotation_angle,
+								    &crop_alpha_plus_beta, &crop_gamma_plus_delta);
+
+			crop_alpha = crop_alpha_plus_beta  / 2.0;
+			crop_beta  = crop_alpha_plus_beta  / 2.0;
+			crop_gamma = crop_gamma_plus_delta / 2.0;
+			crop_delta = crop_gamma_plus_delta / 2.0;
+		}
+		else {
+			gtk_widget_set_sensitive (GET_WIDGET ("crop_p1_hbox"), TRUE);
+			gtk_widget_set_sensitive (GET_WIDGET ("crop_p2_hbox"), TRUE);
+
+			crop_alpha = gtk_adjustment_get_value (self->priv->crop_p1_adj);
+			crop_beta  = gtk_adjustment_get_value (self->priv->crop_p2_adj);
+			crop_gamma = crop_alpha;
+			crop_delta = crop_beta;
+		}
+		
+		_gdk_pixbuf_rotate_get_cropping_region (self->priv->src_pixbuf, rotation_angle,
+							crop_alpha, crop_beta, crop_gamma, crop_delta,
+							&self->priv->crop_region);
+
+		gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), (GthImageViewerTool *) self->priv->selector_crop);
+
+		gth_image_selector_set_selection (self->priv->selector_crop, self->priv->crop_region);
+	}
+	else {
+		gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), NULL);
+		
+		gtk_widget_set_sensitive (GTK_WIDGET (self->priv->keep_aspect_ratio), FALSE);
+		gtk_widget_set_sensitive (GET_WIDGET ("crop_p1_hbox"), FALSE);
+		gtk_widget_set_sensitive (GET_WIDGET ("crop_p2_hbox"), FALSE);
+		gtk_widget_set_sensitive (GTK_WIDGET (self->priv->crop_grid), FALSE);
+		gtk_widget_set_sensitive (GET_WIDGET ("crop_button"),  FALSE);
+	}
+}
+
+
+static void
+update_crop_grid (gpointer user_data)
+{
+	GthFileToolRotate *self = user_data;
+
+	gth_image_selector_set_grid_type (self->priv->selector_crop, gtk_combo_box_get_active (GTK_COMBO_BOX (self->priv->crop_grid)));
+}
+
+
+static gboolean
+apply_cb (gpointer user_data)
+{
+	GthFileToolRotate *self = user_data;
+	GtkWidget         *window;
+	GtkWidget         *viewer_page;
+	double             rotation_angle;
+	gboolean           high_quality;
+	
+	if (self->priv->apply_event != 0) {
+		g_source_remove (self->priv->apply_event);
+		self->priv->apply_event = 0;
+	}
+
+	window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
+	viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
+
+	rotation_angle = gtk_adjustment_get_value (self->priv->rotation_angle_adj);
+	high_quality = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->high_quality));
+	
+	_g_object_unref (self->priv->dest_pixbuf);
+	self->priv->dest_pixbuf = _gdk_pixbuf_rotate (self->priv->src_pixbuf, rotation_angle, high_quality);
+
+	gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), self->priv->dest_pixbuf, FALSE);
+
+	update_crop_region (user_data);
+	
+	return FALSE;
+}
+
+
+static void
 gth_file_tool_rotate_update_sensitivity (GthFileTool *base)
 {
 	GtkWidget *window;
@@ -154,6 +269,7 @@ crop_button_clicked_cb (GtkButton         *button,
 	gtk_widget_set_sensitive (GET_WIDGET ("crop_p1_hbox"), FALSE);
 	gtk_widget_set_sensitive (GET_WIDGET ("crop_p2_hbox"), FALSE);
 	gtk_widget_set_sensitive (GET_WIDGET ("crop_button"), FALSE);
+	gtk_widget_set_sensitive (GTK_WIDGET (self->priv->crop_grid), FALSE);
 }
 
 
@@ -195,104 +311,10 @@ cancel_button_clicked_cb (GtkButton         *button,
 
 
 static void
-update_crop_region (gpointer user_data)
-{
-	GthFileToolRotate *self = user_data;
-	GtkWidget         *window;
-	GtkWidget         *viewer_page;
-	GtkWidget         *viewer;
-	double             rotation_angle;
-	gboolean           enable_guided_crop;
-	gboolean           keep_aspect_ratio;
-	double             crop_alpha, crop_beta, crop_alpha_plus_beta;
-	double             crop_gamma, crop_delta, crop_gamma_plus_delta;
-
-	window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
-	viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
-	viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
-
-	gtk_widget_set_sensitive (GTK_WIDGET (self->priv->enable_guided_crop), TRUE);
-
-	enable_guided_crop = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->enable_guided_crop));
-
-	if (enable_guided_crop) {
-		
-		gtk_widget_set_sensitive (GTK_WIDGET (self->priv->keep_aspect_ratio), TRUE);
-		gtk_widget_set_sensitive (GET_WIDGET ("crop_button"), TRUE);
-		
-		rotation_angle = gtk_adjustment_get_value (self->priv->rotation_angle_adj);
-		keep_aspect_ratio = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->keep_aspect_ratio));
-
-		if (keep_aspect_ratio) {
-
-			gtk_widget_set_sensitive (GET_WIDGET ("crop_p1_hbox"), FALSE);
-			gtk_widget_set_sensitive (GET_WIDGET ("crop_p2_hbox"), FALSE);
-
-			_gdk_pixbuf_rotate_get_cropping_parameters (self->priv->src_pixbuf, rotation_angle,
-								    &crop_alpha_plus_beta, &crop_gamma_plus_delta);
-
-			crop_alpha = crop_alpha_plus_beta  / 2.0;
-			crop_beta  = crop_alpha_plus_beta  / 2.0;
-			crop_gamma = crop_gamma_plus_delta / 2.0;
-			crop_delta = crop_gamma_plus_delta / 2.0;
-		}
-		else {
-			gtk_widget_set_sensitive (GET_WIDGET ("crop_p1_hbox"), TRUE);
-			gtk_widget_set_sensitive (GET_WIDGET ("crop_p2_hbox"), TRUE);
-
-			crop_alpha = gtk_adjustment_get_value (self->priv->crop_p1_adj);
-			crop_beta  = gtk_adjustment_get_value (self->priv->crop_p2_adj);
-			crop_gamma = crop_alpha;
-			crop_delta = crop_beta;
-		}
-		
-		_gdk_pixbuf_rotate_get_cropping_region (self->priv->src_pixbuf, rotation_angle,
-							crop_alpha, crop_beta, crop_gamma, crop_delta,
-							&self->priv->crop_region);
-
-		gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), (GthImageViewerTool *) self->priv->selector_crop);
-
-		gth_image_selector_set_selection (self->priv->selector_crop, self->priv->crop_region);
-	}
-	else {
-		gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), NULL);
-		
-		gtk_widget_set_sensitive (GTK_WIDGET (self->priv->keep_aspect_ratio), FALSE);
-		gtk_widget_set_sensitive (GET_WIDGET ("crop_p1_hbox"), FALSE);
-		gtk_widget_set_sensitive (GET_WIDGET ("crop_p2_hbox"), FALSE);
-		gtk_widget_set_sensitive (GET_WIDGET ("crop_button"),  FALSE);
-	}
-}
-
-
-static gboolean
-apply_cb (gpointer user_data)
+crop_grid_changed_cb (GtkAdjustment     *adj,
+		      GthFileToolRotate *self)
 {
-	GthFileToolRotate *self = user_data;
-	GtkWidget         *window;
-	GtkWidget         *viewer_page;
-	double             rotation_angle;
-	gboolean           high_quality;
-	
-	if (self->priv->apply_event != 0) {
-		g_source_remove (self->priv->apply_event);
-		self->priv->apply_event = 0;
-	}
-
-	window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
-	viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
-
-	rotation_angle = gtk_adjustment_get_value (self->priv->rotation_angle_adj);
-	high_quality = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->high_quality));
-	
-	_g_object_unref (self->priv->dest_pixbuf);
-	self->priv->dest_pixbuf = _gdk_pixbuf_rotate (self->priv->src_pixbuf, rotation_angle, high_quality);
-
-	gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), self->priv->dest_pixbuf, FALSE);
-
-	update_crop_region (user_data);
-	
-	return FALSE;
+	update_crop_grid (self);
 }
 
 
@@ -390,27 +412,38 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
 	gtk_widget_show (options);
 	
 	self->priv->rotation_angle_adj = gimp_scale_entry_new (GET_WIDGET ("rotation_angle_hbox"),
-							       GTK_LABEL (GET_WIDGET ("manual_rotation_label")),
+							       GTK_LABEL (GET_WIDGET ("rotation_angle_label")),
 							       0.0, -90.0, 90.0, 0.1, 1.0, 1);
 	
 	self->priv->high_quality = _gtk_builder_get_widget (self->priv->builder, "high_quality");
+	self->priv->show_grid = _gtk_builder_get_widget (self->priv->builder, "show_grid");
 	self->priv->enable_guided_crop = _gtk_builder_get_widget (self->priv->builder, "enable_guided_crop");
 	self->priv->keep_aspect_ratio = _gtk_builder_get_widget (self->priv->builder, "keep_aspect_ratio");
 
 	self->priv->crop_p1_adj = gimp_scale_entry_new (GET_WIDGET ("crop_p1_hbox"),
-							GTK_LABEL (GET_WIDGET ("guided_crop_label")),
+							GTK_LABEL (GET_WIDGET ("crop_p1_label")),
 							1.0, 0.0, 1.0, 0.01, 0.1, 2);
 
 	self->priv->crop_p2_adj = gimp_scale_entry_new (GET_WIDGET ("crop_p2_hbox"),
-							GTK_LABEL (GET_WIDGET ("guided_crop_label")),
+							GTK_LABEL (GET_WIDGET ("crop_p2_label")),
 							1.0, 0.0, 1.0, 0.01, 0.1, 2);
 
+	self->priv->crop_grid = _gtk_combo_box_new_with_texts (_("None"),
+							       _("Rule of Thirds"),
+							       _("Golden Sections"),
+							       _("Center Lines"),
+							       _("Uniform"),
+							       NULL);
+							       
+	gtk_combo_box_set_active (GTK_COMBO_BOX (self->priv->crop_grid), GTH_GRID_UNIFORM);
+	gtk_widget_show (self->priv->crop_grid);
+	gtk_box_pack_start (GTK_BOX (GET_WIDGET ("crop_grid_hbox")), self->priv->crop_grid, FALSE, FALSE, 0);
+	gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("crop_grid_label")), self->priv->crop_grid);
+
 	self->priv->selector_crop = (GthImageSelector *) gth_image_selector_new (GTH_IMAGE_VIEWER (viewer), GTH_SELECTOR_TYPE_REGION);
 	self->priv->selector_align = (GthImageSelector *) gth_image_selector_new (GTH_IMAGE_VIEWER (viewer), GTH_SELECTOR_TYPE_POINT);
 
 	gth_image_selector_set_mask_visible (self->priv->selector_crop, TRUE);
-	gth_image_selector_set_grid_type (self->priv->selector_crop, GTH_GRID_UNIFORM);
-	
 	gth_image_selector_set_mask_visible (self->priv->selector_align, TRUE);
 
 	self->priv->selector_align_point = 0;
@@ -467,6 +500,10 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
 			  "toggled",
 			  G_CALLBACK (crop_parameters_changed_cb),
 			  self);
+	g_signal_connect (G_OBJECT (self->priv->crop_grid),
+			  "changed",
+			  G_CALLBACK (crop_grid_changed_cb),
+			  self);
 	g_signal_connect (self->priv->selector_align,
 			  "selected",
 			  G_CALLBACK (selector_selected_cb),
@@ -477,6 +514,7 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
 			  self);
 
 	update_crop_region (self);
+	update_crop_grid (self);
 	
 	return options;
 }



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