mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add plot size option for future compatibility
This is really just a copy of the number-range-option with some tests for the saved value being a pair which is used in later versions. If the pair is a pixel setting, then that value will be used, otherwise the default value is used. Should any report get saved, the saved values will be over written in the old format.
This commit is contained in:
parent
da0b3b5131
commit
12562bcc0c
@ -110,6 +110,7 @@
|
|||||||
(export gnc:options-make-date-interval!)
|
(export gnc:options-make-date-interval!)
|
||||||
|
|
||||||
(export gnc:make-number-range-option)
|
(export gnc:make-number-range-option)
|
||||||
|
(export gnc:make-number-plot-size-option)
|
||||||
(export gnc:make-internal-option)
|
(export gnc:make-internal-option)
|
||||||
(export gnc:make-query-option)
|
(export gnc:make-query-option)
|
||||||
(export gnc:make-color-option)
|
(export gnc:make-color-option)
|
||||||
|
@ -1143,6 +1143,48 @@
|
|||||||
(list lower-bound upper-bound num-decimals step-size)
|
(list lower-bound upper-bound num-decimals step-size)
|
||||||
#f #f #f)))
|
#f #f #f)))
|
||||||
|
|
||||||
|
|
||||||
|
;; plot size options use the option-data as a list whose
|
||||||
|
;; elements are: (lower-bound upper-bound num-decimals step-size)
|
||||||
|
(define (gnc:make-number-plot-size-option
|
||||||
|
section
|
||||||
|
name
|
||||||
|
sort-tag
|
||||||
|
documentation-string
|
||||||
|
default-value
|
||||||
|
lower-bound
|
||||||
|
upper-bound
|
||||||
|
num-decimals
|
||||||
|
step-size)
|
||||||
|
(let* ((value default-value)
|
||||||
|
(value->string (lambda () (number->string value))))
|
||||||
|
(gnc:make-option
|
||||||
|
section name sort-tag 'number-range documentation-string
|
||||||
|
(lambda () value)
|
||||||
|
(lambda (x)
|
||||||
|
(cond ((and (pair? x) ;; new pair value
|
||||||
|
(eq? 'pixels (car x)))
|
||||||
|
(set! value (cdr x)))
|
||||||
|
(else (set! value default-value)))
|
||||||
|
|
||||||
|
(if (number? x) ;; old single value
|
||||||
|
(set! value x)))
|
||||||
|
(lambda () default-value)
|
||||||
|
(gnc:restore-form-generator value->string)
|
||||||
|
(lambda (f p) (kvp-frame-set-slot-path-gslist f value p))
|
||||||
|
(lambda (f p)
|
||||||
|
(let ((v (kvp-frame-get-slot-path-gslist f p)))
|
||||||
|
(if (and v (number? v))
|
||||||
|
(set! value v))))
|
||||||
|
(lambda (x)
|
||||||
|
(cond ((not (number? x)) (list #f "number-plot-size-option: not a number"))
|
||||||
|
((and (>= value lower-bound)
|
||||||
|
(<= value upper-bound))
|
||||||
|
(list #t x))
|
||||||
|
(else (list #f "number-plot-size-option: out of range"))))
|
||||||
|
(list lower-bound upper-bound num-decimals step-size)
|
||||||
|
#f #f #f)))
|
||||||
|
|
||||||
(define (gnc:make-internal-option
|
(define (gnc:make-internal-option
|
||||||
section
|
section
|
||||||
name
|
name
|
||||||
|
@ -1980,6 +1980,71 @@ gnc_option_set_ui_widget_number_range (GNCOption *option, GtkBox *page_box,
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GtkWidget *
|
||||||
|
gnc_option_set_ui_widget_plot_size (GNCOption *option, GtkBox *page_box,
|
||||||
|
char *name, char *documentation,
|
||||||
|
/* Return values */
|
||||||
|
GtkWidget **enclosing, gboolean *packed)
|
||||||
|
{
|
||||||
|
GtkWidget *value;
|
||||||
|
GtkWidget *label;
|
||||||
|
gchar *colon_name;
|
||||||
|
GtkAdjustment *adj;
|
||||||
|
gdouble lower_bound = G_MINDOUBLE;
|
||||||
|
gdouble upper_bound = G_MAXDOUBLE;
|
||||||
|
gdouble step_size = 1.0;
|
||||||
|
int num_decimals = 0;
|
||||||
|
|
||||||
|
colon_name = g_strconcat(name, ":", NULL);
|
||||||
|
label = gtk_label_new(colon_name);
|
||||||
|
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
|
||||||
|
g_free(colon_name);
|
||||||
|
|
||||||
|
*enclosing = gtk_hbox_new(FALSE, 5);
|
||||||
|
|
||||||
|
gnc_option_get_range_info(option, &lower_bound, &upper_bound,
|
||||||
|
&num_decimals, &step_size);
|
||||||
|
adj = GTK_ADJUSTMENT(gtk_adjustment_new(lower_bound, lower_bound,
|
||||||
|
upper_bound, step_size,
|
||||||
|
step_size * 5.0,
|
||||||
|
0));
|
||||||
|
value = gtk_spin_button_new(adj, step_size, num_decimals);
|
||||||
|
gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(value), TRUE);
|
||||||
|
|
||||||
|
{
|
||||||
|
gdouble biggest;
|
||||||
|
gint num_digits;
|
||||||
|
|
||||||
|
biggest = ABS(lower_bound);
|
||||||
|
biggest = MAX(biggest, ABS(upper_bound));
|
||||||
|
|
||||||
|
num_digits = 0;
|
||||||
|
while (biggest >= 1)
|
||||||
|
{
|
||||||
|
num_digits++;
|
||||||
|
biggest = biggest / 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (num_digits == 0)
|
||||||
|
num_digits = 1;
|
||||||
|
|
||||||
|
num_digits += num_decimals;
|
||||||
|
|
||||||
|
gtk_entry_set_width_chars(GTK_ENTRY(value), num_digits);
|
||||||
|
}
|
||||||
|
|
||||||
|
gnc_option_set_widget (option, value);
|
||||||
|
gnc_option_set_ui_value(option, FALSE);
|
||||||
|
|
||||||
|
g_signal_connect(G_OBJECT(value), "changed",
|
||||||
|
G_CALLBACK(gnc_option_changed_widget_cb), option);
|
||||||
|
|
||||||
|
gtk_box_pack_start(GTK_BOX(*enclosing), label, FALSE, FALSE, 0);
|
||||||
|
gtk_box_pack_start(GTK_BOX(*enclosing), value, FALSE, FALSE, 0);
|
||||||
|
gtk_widget_show_all(*enclosing);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
static GtkWidget *
|
static GtkWidget *
|
||||||
gnc_option_set_ui_widget_color (GNCOption *option, GtkBox *page_box,
|
gnc_option_set_ui_widget_color (GNCOption *option, GtkBox *page_box,
|
||||||
char *name, char *documentation,
|
char *name, char *documentation,
|
||||||
@ -2468,6 +2533,25 @@ gnc_option_set_ui_value_number_range (GNCOption *option, gboolean use_default,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gnc_option_set_ui_value_plot_size (GNCOption *option, gboolean use_default,
|
||||||
|
GtkWidget *widget, SCM value)
|
||||||
|
{
|
||||||
|
GtkSpinButton *spinner;
|
||||||
|
gdouble d_value;;
|
||||||
|
|
||||||
|
spinner = GTK_SPIN_BUTTON(widget);
|
||||||
|
|
||||||
|
if (scm_is_number(value))
|
||||||
|
{
|
||||||
|
d_value = scm_to_double(value);
|
||||||
|
gtk_spin_button_set_value(spinner, d_value);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gnc_option_set_ui_value_color (GNCOption *option, gboolean use_default,
|
gnc_option_set_ui_value_color (GNCOption *option, gboolean use_default,
|
||||||
GtkWidget *widget, SCM value)
|
GtkWidget *widget, SCM value)
|
||||||
@ -2862,6 +2946,19 @@ gnc_option_get_ui_value_number_range (GNCOption *option, GtkWidget *widget)
|
|||||||
return (scm_from_double (value));
|
return (scm_from_double (value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SCM
|
||||||
|
gnc_option_get_ui_value_plot_size (GNCOption *option, GtkWidget *widget)
|
||||||
|
{
|
||||||
|
GtkSpinButton *spinner;
|
||||||
|
gdouble value;
|
||||||
|
|
||||||
|
spinner = GTK_SPIN_BUTTON(widget);
|
||||||
|
|
||||||
|
value = gtk_spin_button_get_value(spinner);
|
||||||
|
|
||||||
|
return (scm_from_double (value));
|
||||||
|
}
|
||||||
|
|
||||||
static SCM
|
static SCM
|
||||||
gnc_option_get_ui_value_color (GNCOption *option, GtkWidget *widget)
|
gnc_option_get_ui_value_color (GNCOption *option, GtkWidget *widget)
|
||||||
{
|
{
|
||||||
@ -2995,6 +3092,10 @@ static void gnc_options_initialize_options (void)
|
|||||||
"number-range", gnc_option_set_ui_widget_number_range,
|
"number-range", gnc_option_set_ui_widget_number_range,
|
||||||
gnc_option_set_ui_value_number_range, gnc_option_get_ui_value_number_range
|
gnc_option_set_ui_value_number_range, gnc_option_get_ui_value_number_range
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"plot-size", gnc_option_set_ui_widget_plot_size,
|
||||||
|
gnc_option_set_ui_value_plot_size, gnc_option_get_ui_value_plot_size
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"color", gnc_option_set_ui_widget_color,
|
"color", gnc_option_set_ui_widget_color,
|
||||||
gnc_option_set_ui_value_color, gnc_option_get_ui_value_color
|
gnc_option_set_ui_value_color, gnc_option_get_ui_value_color
|
||||||
|
@ -193,7 +193,7 @@
|
|||||||
default-width default-height)
|
default-width default-height)
|
||||||
(gnc:register-option
|
(gnc:register-option
|
||||||
options
|
options
|
||||||
(gnc:make-number-range-option
|
(gnc:make-number-plot-size-option
|
||||||
pagename name-width
|
pagename name-width
|
||||||
(string-append sort-tag "a")
|
(string-append sort-tag "a")
|
||||||
(N_ "Width of plot in pixels.") default-width
|
(N_ "Width of plot in pixels.") default-width
|
||||||
@ -201,7 +201,7 @@
|
|||||||
|
|
||||||
(gnc:register-option
|
(gnc:register-option
|
||||||
options
|
options
|
||||||
(gnc:make-number-range-option
|
(gnc:make-number-plot-size-option
|
||||||
pagename name-height
|
pagename name-height
|
||||||
(string-append sort-tag "b")
|
(string-append sort-tag "b")
|
||||||
(N_ "Height of plot in pixels.") default-height
|
(N_ "Height of plot in pixels.") default-height
|
||||||
|
Loading…
Reference in New Issue
Block a user