[gthumb] image_print: allow to specify the number of rows and columns



commit bbab15bb0649dca82ec2eb08f34db859f76257ef
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Jan 2 14:33:39 2011 +0100

    image_print: allow to specify the number of rows and columns

 .../image_print/data/gthumb_image_print.schemas.in |   17 ++-
 extensions/image_print/data/ui/print-layout.ui     |  152 ++++++++++++++++---
 extensions/image_print/gth-image-print-job.c       |  109 +++++++--------
 extensions/image_print/preferences.h               |    9 +-
 4 files changed, 197 insertions(+), 90 deletions(-)
---
diff --git a/extensions/image_print/data/gthumb_image_print.schemas.in b/extensions/image_print/data/gthumb_image_print.schemas.in
index 9e31623..80891e2 100644
--- a/extensions/image_print/data/gthumb_image_print.schemas.in
+++ b/extensions/image_print/data/gthumb_image_print.schemas.in
@@ -28,8 +28,21 @@
       </schema>
 
       <schema>
-	<key>/schemas/apps/gthumb/ext/image_print/images_per_page</key>
-	<applyto>/apps/gthumb/ext/image_print/images_per_page</applyto>
+	<key>/schemas/apps/gthumb/ext/image_print/n_rows</key>
+	<applyto>/apps/gthumb/ext/image_print/n_rows</applyto>
+	<owner>gthumb</owner>
+	<type>int</type>
+	<default>1</default>
+	<locale name="C">
+	  <short></short>
+	  <long>
+	  </long>
+	</locale>
+      </schema>
+
+      <schema>
+	<key>/schemas/apps/gthumb/ext/image_print/n_columns</key>
+	<applyto>/apps/gthumb/ext/image_print/n_columns</applyto>
 	<owner>gthumb</owner>
 	<type>int</type>
 	<default>1</default>
diff --git a/extensions/image_print/data/ui/print-layout.ui b/extensions/image_print/data/ui/print-layout.ui
index eed43b3..39edf46 100644
--- a/extensions/image_print/data/ui/print-layout.ui
+++ b/extensions/image_print/data/ui/print-layout.ui
@@ -78,51 +78,147 @@
     <child>
       <object class="GtkVBox" id="vbox11">
         <property name="visible">True</property>
-        <property name="orientation">vertical</property>
         <property name="spacing">12</property>
         <child>
-          <object class="GtkHBox" id="hbox1">
+          <object class="GtkVBox" id="vbox2">
             <property name="visible">True</property>
-            <property name="spacing">7</property>
+            <property name="spacing">6</property>
             <child>
-              <object class="GtkLabel" id="label8">
+              <object class="GtkHBox" id="hbox9">
                 <property name="visible">True</property>
-                <property name="xalign">0</property>
-                <property name="label" translatable="yes">Images per page:</property>
+                <property name="spacing">6</property>
+                <child>
+                  <object class="GtkLabel" id="label2">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="label" translatable="yes">Layout</property>
+                    <property name="use_underline">True</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
               </object>
               <packing>
-                <property name="expand">False</property>
                 <property name="position">0</property>
               </packing>
             </child>
             <child>
-              <object class="GtkComboBox" id="ipp_combobox">
+              <object class="GtkAlignment" id="alignment6">
                 <property name="visible">True</property>
-                <property name="model">size_liststore</property>
-                <property name="active">0</property>
+                <property name="left_padding">12</property>
                 <child>
-                  <object class="GtkCellRendererText" id="cellrenderertext4"/>
-                  <attributes>
-                    <attribute name="text">0</attribute>
-                  </attributes>
+                  <object class="GtkVBox" id="vbox5">
+                    <property name="visible">True</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkTable" id="table2">
+                        <property name="visible">True</property>
+                        <property name="n_rows">2</property>
+                        <property name="n_columns">2</property>
+                        <property name="column_spacing">6</property>
+                        <property name="row_spacing">6</property>
+                        <child>
+                          <object class="GtkLabel" id="label9">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">_Rows:</property>
+                            <property name="use_underline">True</property>
+                            <property name="mnemonic_widget">rows_spinbutton</property>
+                          </object>
+                          <packing>
+                            <property name="x_options">GTK_FILL</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkHBox" id="hbox10">
+                            <property name="visible">True</property>
+                            <property name="spacing">6</property>
+                            <child>
+                              <object class="GtkSpinButton" id="rows_spinbutton">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="invisible_char">&#x25CF;</property>
+                                <property name="width_chars">6</property>
+                                <property name="adjustment">rows_adjustment</property>
+                                <property name="climb_rate">1</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="label11">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">Columns:</property>
+                            <property name="use_underline">True</property>
+                            <property name="mnemonic_widget">columns_spinbutton</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="GtkHBox" id="hbox12">
+                            <property name="visible">True</property>
+                            <property name="spacing">6</property>
+                            <child>
+                              <object class="GtkSpinButton" id="columns_spinbutton">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="invisible_char">&#x25CF;</property>
+                                <property name="width_chars">6</property>
+                                <property name="adjustment">columns_adjustment</property>
+                                <property name="climb_rate">1</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <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">1</property>
+                            <property name="bottom_attach">2</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                  </object>
                 </child>
               </object>
               <packing>
-                <property name="expand">False</property>
                 <property name="position">1</property>
               </packing>
             </child>
           </object>
           <packing>
             <property name="expand">False</property>
-            <property name="fill">False</property>
             <property name="position">0</property>
           </packing>
         </child>
         <child>
           <object class="GtkVBox" id="vbox3">
             <property name="visible">True</property>
-            <property name="orientation">vertical</property>
             <property name="spacing">6</property>
             <child>
               <object class="GtkLabel" id="label5">
@@ -144,7 +240,6 @@
                 <child>
                   <object class="GtkVBox" id="vbox4">
                     <property name="visible">True</property>
-                    <property name="orientation">vertical</property>
                     <property name="spacing">6</property>
                     <child>
                       <object class="GtkScrolledWindow" id="caption_scrolledwindow">
@@ -223,7 +318,6 @@
         <child>
           <object class="GtkVBox" id="vbox6">
             <property name="visible">True</property>
-            <property name="orientation">vertical</property>
             <property name="spacing">6</property>
             <child>
               <object class="GtkHBox" id="hbox4">
@@ -256,7 +350,6 @@
                 <child>
                   <object class="GtkVBox" id="vbox1">
                     <property name="visible">True</property>
-                    <property name="orientation">vertical</property>
                     <property name="spacing">6</property>
                     <child>
                       <object class="GtkTable" id="table1">
@@ -511,12 +604,10 @@
     <child>
       <object class="GtkVBox" id="vbox24">
         <property name="visible">True</property>
-        <property name="orientation">vertical</property>
         <property name="spacing">6</property>
         <child>
           <object class="GtkVBox" id="vbox7">
             <property name="visible">True</property>
-            <property name="orientation">vertical</property>
             <child>
               <object class="GtkLabel" id="label7">
                 <property name="xalign">0</property>
@@ -536,7 +627,6 @@
                 <child>
                   <object class="GtkVBox" id="vbox25">
                     <property name="visible">True</property>
-                    <property name="orientation">vertical</property>
                     <child>
                       <object class="GtkHBox" id="hbox30">
                         <property name="visible">True</property>
@@ -637,9 +727,9 @@
     </child>
   </object>
   <object class="GtkAdjustment" id="scale_adjustment">
+    <property name="value">1</property>
     <property name="lower">0.01</property>
     <property name="upper">1</property>
-    <property name="value">1</property>
     <property name="step_increment">0.10000000000000001</property>
     <property name="page_increment">0.10000000000000001</property>
   </object>
@@ -689,4 +779,18 @@
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
+  <object class="GtkAdjustment" id="rows_adjustment">
+    <property name="value">1</property>
+    <property name="lower">1</property>
+    <property name="upper">100</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+  <object class="GtkAdjustment" id="columns_adjustment">
+    <property name="value">1</property>
+    <property name="lower">1</property>
+    <property name="upper">100</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
 </interface>
diff --git a/extensions/image_print/gth-image-print-job.c b/extensions/image_print/gth-image-print-job.c
index ba192a3..0fc0ad2 100644
--- a/extensions/image_print/gth-image-print-job.c
+++ b/extensions/image_print/gth-image-print-job.c
@@ -34,17 +34,6 @@
 #define GET_WIDGET(name) _gtk_builder_get_widget (self->priv->builder, (name))
 
 
-enum {
-	IMAGES_PER_PAGE_1,
-	IMAGES_PER_PAGE_2,
-	IMAGES_PER_PAGE_4,
-	IMAGES_PER_PAGE_8,
-	IMAGES_PER_PAGE_16,
-	IMAGES_PER_PAGE_32,
-	N_IMAGES_PER_PAGE
-};
-static int n_rows_for_ipp[N_IMAGES_PER_PAGE] = { 1, 2, 2, 4, 4, 8 };
-static int n_cols_for_ipp[N_IMAGES_PER_PAGE] = { 1, 1, 2, 2, 4, 4 };
 static gpointer parent_class = NULL;
 
 
@@ -69,7 +58,8 @@ struct _GthImagePrintJobPrivate {
 
 	GthImageInfo      **images;
 	int                 n_images;
-	int                 requested_images_per_page;
+	int                 n_rows;
+	int                 n_columns;
 	int                 image_width;
 	int                 image_height;
 	GtkPageSetup       *page_setup;
@@ -81,7 +71,6 @@ struct _GthImagePrintJobPrivate {
 	/* layout info */
 
 	GthTask            *task;
-	int                 real_images_per_page;
 	double              max_image_width;
 	double		    max_image_height;
 	double              x_padding;
@@ -137,7 +126,8 @@ gth_image_print_job_init (GthImagePrintJob *self)
 	self->priv->caption_attributes = eel_gconf_get_string (PREF_IMAGE_PRINT_CAPTION, "");
 	self->priv->font_name = eel_gconf_get_string (PREF_IMAGE_PRINT_FONT_NAME, DEFAULT_FONT_NAME);
 	self->priv->selected = NULL;
-	self->priv->requested_images_per_page = eel_gconf_get_integer (PREF_IMAGE_PRINT_IMAGES_PER_PAGE, 1);
+	self->priv->n_rows = eel_gconf_get_integer (PREF_IMAGE_PRINT_N_ROWS, 1);
+	self->priv->n_columns = eel_gconf_get_integer (PREF_IMAGE_PRINT_N_COLUMNS, 1);
 	self->priv->unit = eel_gconf_get_enum (PREF_IMAGE_PRINT_UNIT, GTH_TYPE_METRIC, GTH_METRIC_PIXELS);
 }
 
@@ -170,82 +160,60 @@ gth_image_print_job_get_type (void)
 }
 
 
-static double
-_log2 (double x)
-{
-	return log (x) / log (2);
-}
-
-
-static int
-get_combo_box_index_from_ipp (int value)
-{
-	return (int) floor (_log2 (value) + 0.5);
-}
-
-
-static int
-get_ipp_from_combo_box_index (int idx)
-{
-	return (int) pow (2, idx);
-}
-
-
 static void
 gth_image_print_job_update_layout_info (GthImagePrintJob   *self,
 				        gdouble             page_width,
 				        gdouble             page_height,
 				        GtkPageOrientation  orientation)
 {
-	int idx;
 	int rows;
-	int cols;
+	int columns;
 	int current_page;
 	int current_row;
-	int current_col;
+	int current_column;
 	int i;
 
-	self->priv->real_images_per_page = self->priv->requested_images_per_page;
 	self->priv->x_padding = page_width / 40.0;
 	self->priv->y_padding = page_height / 40.0;
 
-	idx = get_combo_box_index_from_ipp (self->priv->real_images_per_page);
-	rows = n_rows_for_ipp[idx];
-	cols = n_cols_for_ipp[idx];
+	rows = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("rows_spinbutton")));
+	columns = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("columns_spinbutton")));
 	if ((orientation == GTK_PAGE_ORIENTATION_LANDSCAPE)
 	    || (orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE))
 	{
 		int tmp = rows;
-		rows = cols;
-		cols = tmp;
+		rows = columns;
+		columns = tmp;
 	}
 
-	self->priv->max_image_width = (page_width - ((cols - 1) * self->priv->x_padding)) / cols;
+	self->priv->n_rows = rows;
+	self->priv->n_columns = columns;
+	self->priv->max_image_width = (page_width - ((columns - 1) * self->priv->x_padding)) / columns;
 	self->priv->max_image_height = (page_height - ((rows - 1) * self->priv->y_padding)) / rows;
 
-	self->priv->n_pages = MAX ((int) ceil ((double) self->priv->n_images / self->priv->real_images_per_page), 1);
+	self->priv->n_pages = MAX ((int) ceil ((double) self->priv->n_images / (self->priv->n_rows * self->priv->n_columns)), 1);
 	if (self->priv->current_page >= self->priv->n_pages)
 		self->priv->current_page = self->priv->n_pages - 1;
 
 	current_page = 0;
 	current_row = 1;
-	current_col = 1;
+	current_column = 1;
 	for (i = 0; i < self->priv->n_images; i++) {
 		GthImageInfo *image_info = self->priv->images[i];
 
 		image_info->page = current_page;
-		image_info->col = current_col;
+		image_info->col = current_column;
 		image_info->row = current_row;
 
-		current_col++;
-		if (current_col > cols) {
+		current_column++;
+		if (current_column > columns) {
 			current_row++;
-			current_col = 1;
+			current_column = 1;
 		}
 
 		if (current_row > rows) {
 			current_page++;
-			current_col = 1;
+			current_column = 1;
 			current_row = 1;
 		}
 	}
@@ -988,13 +956,27 @@ preview_button_press_event_cb (GtkWidget      *widget,
 
 
 static void
-ipp_combobox_changed_cb (GtkComboBox *widget,
-			 gpointer     user_data)
+rows_spinbutton_changed_cb (GtkSpinButton *widget,
+			    gpointer       user_data)
 {
 	GthImagePrintJob *self = user_data;
 	int               i;
 
-	self->priv->requested_images_per_page = get_ipp_from_combo_box_index (gtk_combo_box_get_active (widget));
+	self->priv->n_rows = gtk_spin_button_get_value_as_int (widget);
+	for (i = 0; i < self->priv->n_images; i++)
+		gth_image_info_reset (self->priv->images[i]);
+	gth_image_print_job_update_preview (self);
+}
+
+
+static void
+columns_spinbutton_changed_cb (GtkSpinButton *widget,
+			       gpointer       user_data)
+{
+	GthImagePrintJob *self = user_data;
+	int               i;
+
+	self->priv->n_columns = gtk_spin_button_get_value_as_int (widget);
 	for (i = 0; i < self->priv->n_images; i++)
 		gth_image_info_reset (self->priv->images[i]);
 	gth_image_print_job_update_preview (self);
@@ -1277,7 +1259,9 @@ operation_create_custom_widget_cb (GtkPrintOperation *operation,
 	gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("unit_combobox")), self->priv->unit);
 	gtk_font_button_set_font_name (GTK_FONT_BUTTON (GET_WIDGET ("caption_fontbutton")), self->priv->font_name);
 
-	gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("ipp_combobox")), get_combo_box_index_from_ipp (self->priv->requested_images_per_page));
+	gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("rows_spinbutton")), self->priv->n_rows);
+	gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("columns_spinbutton")), self->priv->n_columns);
+
 	gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("unit_combobox")), eel_gconf_get_enum (PREF_IMAGE_PRINT_UNIT, GTH_TYPE_METRIC, GTH_METRIC_PIXELS));
 
 	g_signal_connect (GET_WIDGET ("preview_drawingarea"),
@@ -1296,9 +1280,13 @@ operation_create_custom_widget_cb (GtkPrintOperation *operation,
 			  "button-press-event",
 			  G_CALLBACK (preview_button_press_event_cb),
 			  self);
-	g_signal_connect (GET_WIDGET ("ipp_combobox"),
-			  "changed",
-	                  G_CALLBACK (ipp_combobox_changed_cb),
+	g_signal_connect (GET_WIDGET ("rows_spinbutton"),
+			  "value-changed",
+	                  G_CALLBACK (rows_spinbutton_changed_cb),
+	                  self);
+	g_signal_connect (GET_WIDGET ("columns_spinbutton"),
+			  "value-changed",
+	                  G_CALLBACK (columns_spinbutton_changed_cb),
 	                  self);
 	g_signal_connect (GET_WIDGET ("next_page_button"),
 			  "clicked",
@@ -1410,7 +1398,8 @@ operation_custom_widget_apply_cb (GtkPrintOperation *operation,
 {
 	GthImagePrintJob *self = user_data;
 
-	eel_gconf_set_integer (PREF_IMAGE_PRINT_IMAGES_PER_PAGE, self->priv->requested_images_per_page);
+	eel_gconf_set_integer (PREF_IMAGE_PRINT_N_ROWS, self->priv->n_rows);
+	eel_gconf_set_integer (PREF_IMAGE_PRINT_N_COLUMNS, self->priv->n_columns);
 	eel_gconf_set_enum (PREF_IMAGE_PRINT_UNIT, GTH_TYPE_METRIC, gtk_combo_box_get_active (GTK_COMBO_BOX (GET_WIDGET ("unit_combobox"))));
 }
 
diff --git a/extensions/image_print/preferences.h b/extensions/image_print/preferences.h
index e3c3960..dcd16df 100644
--- a/extensions/image_print/preferences.h
+++ b/extensions/image_print/preferences.h
@@ -26,10 +26,11 @@
 
 G_BEGIN_DECLS
 
-#define PREF_IMAGE_PRINT_CAPTION            "/apps/gthumb/ext/image_print/caption"
-#define PREF_IMAGE_PRINT_FONT_NAME          "/apps/gthumb/ext/image_print/font_name"
-#define PREF_IMAGE_PRINT_IMAGES_PER_PAGE    "/apps/gthumb/ext/image_print/images_per_page"
-#define PREF_IMAGE_PRINT_UNIT               "/apps/gthumb/ext/image_print/unit"
+#define PREF_IMAGE_PRINT_CAPTION      "/apps/gthumb/ext/image_print/caption"
+#define PREF_IMAGE_PRINT_FONT_NAME    "/apps/gthumb/ext/image_print/font_name"
+#define PREF_IMAGE_PRINT_N_ROWS       "/apps/gthumb/ext/image_print/n_rows"
+#define PREF_IMAGE_PRINT_N_COLUMNS    "/apps/gthumb/ext/image_print/n_columns"
+#define PREF_IMAGE_PRINT_UNIT         "/apps/gthumb/ext/image_print/unit"
 
 G_END_DECLS
 



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