[PATCH] Add user definible options to the print menu
Dirk Hohndel
dirk at hohndel.org
Sun Mar 17 14:54:36 PDT 2013
Salvador Cuñat <salvador.cunat at gmail.com> writes:
> Define a new frame wich will englobe the layout options.
> 1.- Move to this frame the color profile printing by Amit
> 2.- Add an option which switches the position of the profile and a predefined block
> comprensive of header, tanks data and notes.
> - Divide print() in two macros PROFILE_BLOCK and NOTES_BLOCK
> - Add a gboolean to print_options. If unselected (default) we get the actual
> disposition. If selected, switches blocks.
> 3.- Add three spin buttons with labels to set the height of the profile, notes and tanks.
> We select the percentage of layout occupied by each option, reserving 7% for the
> header (non adjustable).
> - Values in % have got hardcoded min/max (e.g. being the profile a major feature
> of subsurface, would be senseless make it < 37%)
> - The values are initialised to the actual ones, so leaving them untouched defaults
> to the old printout.
> - The maths involved in SCALECALLBACK function seem infantile and are,
> probably, very improvable.
>
> Signed-off-by: Salvador Cuñat <salvador.cunat at gmail.com>
Thanks for the update - this is getting much closer to what I think we
want. Still, a couple of comments...
> +#define NOTES_BLOCK() \
> + show_dive_header(dive, cr, w*2, dive_header_height, font, w_scale_factor);\
> + cairo_translate(cr, 0, dive_header_height); \
> + show_dive_tanks (dive, cr, w*1, dive_tanks_height, font, w_scale_factor);\
> + cairo_translate(cr, 0, dive_tanks_height);\
> + show_dive_notes(dive, cr, w*2, dive_notes_height, font, w_scale_factor);\
> + cairo_translate(cr, 0, dive_notes_height);
> +
> +#define PROFILE_BLOCK() \
> + show_dive_profile(dive, cr, w*2, dive_profile_height);\
> + cairo_translate(cr, 0, dive_profile_height);
> +
> static void print(int divenr, cairo_t *cr, double x, double y, double w,
> double h, PangoFontDescription *font, double w_scale_factor)
> {
Wouldn't this lend itself to something like this:
+ if (print_options.notes_up)
+ NOTES_BLOCK()
+ PROFILE_BLOCK()
+ if (!print_options.notes_up)
+ NOTES_BLOCK()
less duplicated code...
Or even better, turn this into functions :-)
> @@ -873,11 +888,55 @@ static void name(GtkWidget *w, gpointer data) \
>
> OPTIONSELECTEDCALLBACK(print_selection_toggle, print_options.print_selected)
> OPTIONSELECTEDCALLBACK(color_selection_toggle, print_options.color_selected)
> +OPTIONSELECTEDCALLBACK(notes_up, print_options.notes_up)
> +
> +/*
> + * Hardcoded minimum and maximum values for the scaling spin_buttons
> + */
> +#define profile_height_min (37)
> +#define notes_height_min (7)
> +#define tanks_height_min (7)
> +#define profile_height_max (77)
> +#define notes_height_max (49)
> +#define tanks_height_max (17)
So these are now percentages - which means that sum(...) = 100?
> +/*
> + * Callback function that sets the values of the heigths.
> + * It takes care of avoiding sub minimal values as they can result
> + * in plots bigger than avaliable height, e.g. Big numbers for profile
> + * and notes can make tanks < 7, this would be corrected by the spin_button
> + * funcs that will make it 7 again, but then the sum of all three heights
> + * would be bigger than maximum size avaliable for printing 93%.
> + * There's a 7% reserved for the header which isn't scaled
> + */
> +#define SCALECALLBACK(name, scales1, scales2, scales3)\
> +static void name(GtkWidget *button, Spin_buttons_block *data)\
> +{ \
> + print_options.scales1 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(button)); \
> + print_options.scales2 = 93 - print_options.scales1 - print_options.scales3; \
> + if (print_options.scales2 < scales2##_min) { \
> + print_options.scales2 = scales2##_min; \
> + print_options.scales3 = 93 - print_options.scales1 - print_options.scales3; \
> + } \
> + gtk_spin_button_set_value (GTK_SPIN_BUTTON(data->spin1), print_options.profile_height);\
> + gtk_spin_button_set_value (GTK_SPIN_BUTTON(data->spin2), print_options.notes_height);\
> + gtk_spin_button_set_value (GTK_SPIN_BUTTON(data->spin3), print_options.tanks_height);\
> + gtk_box_pack_start (GTK_BOX(data->box), data->spin1, TRUE, TRUE, 5);\
> + gtk_box_pack_start (GTK_BOX(data->box), data->spin2, TRUE, TRUE, 5);\
> + gtk_box_pack_start (GTK_BOX(data->box), data->spin3, TRUE, TRUE, 5);\
> +}
Ok, this confuses me. These callbacks are supposed to ensure that we
don't violate the maximum and minimum values - but they do allow me to
have values that don't sum up to 100?
> +SCALECALLBACK (prof_spin_button, profile_height, notes_height, tanks_height)
> +SCALECALLBACK (notes_spin_button, notes_height, profile_height, tanks_height)
> +SCALECALLBACK (tanks_spin_button, tanks_height, notes_height, profile_height)
Wouldn't it make much more sense to have spin buttons for notes and
tanks and simply give the rest to the profile?
/D
More information about the subsurface
mailing list