2 * Copyright (C) 2008-2012 Robert Ancell
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License as published by the Free Software
6 * Foundation, either version 2 of the License, or (at your option) any later
7 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
11 public class MathPreferencesDialog
: Gtk
.Dialog
13 private MathEquation equation
;
14 private Gtk
.ComboBox angle_unit_combo
;
15 private Gtk
.ComboBox number_format_combo
;
16 private Gtk
.ComboBox word_size_combo
;
17 private Gtk
.SpinButton decimal_places_spin
;
18 private Gtk
.CheckButton thousands_separator_check
;
19 private Gtk
.CheckButton trailing_zeroes_check
;
21 public MathPreferencesDialog (MathEquation equation
)
23 this
.equation
= equation
;
25 set_title (/* Title of preferences dialog */
28 add_button (/* Label on close button in preferences dialog */
31 var grid
= new Gtk
.Grid ();
33 grid
.border_width
= 5;
34 grid
.column_spacing
= 6;
35 grid
.row_spacing
= 12;
36 get_content_area ().pack_start (grid
, true, true, 0);
38 var label
= new Gtk
.Label
.with_mnemonic (/* Preferences dialog: Label for number format combo box */
39 _("Number _Format:"));
42 grid
.attach (label
, 0, 0, 1, 1);
44 number_format_combo
= new Gtk
.ComboBox ();
45 label
.mnemonic_widget
= number_format_combo
;
46 number_format_combo
.show ();
47 number_format_combo
.changed
.connect (number_format_combo_changed_cb
);
48 grid
.attach (number_format_combo
, 1, 0, 1, 1);
50 var model
= new Gtk
.ListStore (2, typeof (string), typeof (int));
51 number_format_combo
.model
= model
;
53 model
.append (out iter
);
55 /* Number display mode combo: Automatic, e.g. 1234 (or scientific for large number 1.234×10^99) */
56 _("Automatic"), 1, DisplayFormat
.AUTOMATIC
, -1);
57 model
.append (out iter
);
59 /* Number display mode combo: Fixed, e.g. 1234 */
60 _("Fixed"), 1, DisplayFormat
.FIXED
, -1);
61 model
.append (out iter
);
63 /* Number display mode combo: Scientific, e.g. 1.234×10^3 */
64 _("Scientific"), 1, DisplayFormat
.SCIENTIFIC
, -1);
65 model
.append (out iter
);
67 /* Number display mode combo: Engineering, e.g. 1.234k */
68 _("Engineering"), 1, DisplayFormat
.ENGINEERING
, -1);
69 var renderer
= new Gtk
.CellRendererText ();
70 number_format_combo
.pack_start (renderer
, true);
71 number_format_combo
.add_attribute (renderer
, "text", 0);
73 var alignment
= new Gtk
.Alignment (0.5f
, 0.5f
, 1.0f
, 1.0f
);
74 alignment
.bottom_padding
= 6;
75 alignment
.left_padding
= 12;
77 grid
.attach (alignment
, 0, 1, 2, 1);
79 var format_options_box
= new Gtk
.Box (Gtk
.Orientation
.VERTICAL
, 6);
80 format_options_box
.show ();
81 alignment
.add (format_options_box
);
83 var places_box
= new Gtk
.Box (Gtk
.Orientation
.HORIZONTAL
, 6);
85 format_options_box
.pack_start (places_box
, false, false, 0);
87 /* Label used in preferences dialog. The %d is replaced by a spinbutton */
88 var string = _("Show %d decimal _places");
89 var tokens
= string.split ("%d", 2);
91 var decimal_places_adjustment
= new Gtk
.Adjustment (0.0, 0.0, 9.0, 1.0, 1.0, 0.0);
92 decimal_places_spin
= new Gtk
.SpinButton (decimal_places_adjustment
, 0.0, 0);
94 if (tokens
.length
> 0)
96 label
= new Gtk
.Label
.with_mnemonic (tokens
[0].strip ());
97 label
.mnemonic_widget
= decimal_places_spin
;
99 places_box
.pack_start (label
, false, false, 0);
102 decimal_places_spin
.show ();
103 decimal_places_spin
.value_changed
.connect (() => { equation
.accuracy
= decimal_places_spin
.get_value_as_int (); });
104 places_box
.pack_start (decimal_places_spin
, false, false, 0);
106 if (tokens
.length
== 2)
108 label
= new Gtk
.Label
.with_mnemonic (tokens
[1].strip ());
109 label
.mnemonic_widget
= decimal_places_spin
;
111 places_box
.pack_start (label
, false, false, 0);
114 trailing_zeroes_check
= new Gtk
.CheckButton
.with_mnemonic (/* Preferences dialog: label for show trailing zeroes check button */
115 _("Show trailing _zeroes"));
116 trailing_zeroes_check
.show ();
117 trailing_zeroes_check
.toggled
.connect (() => { equation
.show_trailing_zeroes
= trailing_zeroes_check
.get_active (); });
118 format_options_box
.pack_start (trailing_zeroes_check
, false, false, 0);
120 thousands_separator_check
= new Gtk
.CheckButton
.with_mnemonic (/* Preferences dialog: label for show show thousands separator check button */
121 _("Show _thousands separators"));
122 thousands_separator_check
.show ();
123 thousands_separator_check
.toggled
.connect (() => { equation
.show_thousands_separators
= thousands_separator_check
.get_active (); });
124 format_options_box
.pack_start (thousands_separator_check
, false, false, 0);
126 label
= new Gtk
.Label
.with_mnemonic (/* Preferences dialog: Label for angle unit combo box */
130 grid
.attach (label
, 0, 2, 1, 1);
132 angle_unit_combo
= new Gtk
.ComboBox ();
133 label
.mnemonic_widget
= angle_unit_combo
;
134 angle_unit_combo
.show ();
135 angle_unit_combo
.changed
.connect (angle_unit_combo_changed_cb
);
136 grid
.attach (angle_unit_combo
, 1, 2, 1, 1);
138 model
= new Gtk
.ListStore (2, typeof (string), typeof (int));
139 angle_unit_combo
.model
= model
;
140 model
.append (out iter
);
142 /* Preferences dialog: Angle unit combo box: Use degrees for trigonometric calculations */
143 _("Degrees"), 1, AngleUnit
.DEGREES
, -1);
144 model
.append (out iter
);
146 /* Preferences dialog: Angle unit combo box: Use radians for trigonometric calculations */
147 _("Radians"), 1, AngleUnit
.RADIANS
, -1);
148 model
.append (out iter
);
150 /* Preferences dialog: Angle unit combo box: Use gradians for trigonometric calculations */
151 _("Gradians"), 1, AngleUnit
.GRADIANS
, -1);
152 renderer
= new Gtk
.CellRendererText ();
153 angle_unit_combo
.pack_start (renderer
, true);
154 angle_unit_combo
.add_attribute (renderer
, "text", 0);
156 label
= new Gtk
.Label
.with_mnemonic (/* Preferences dialog: Label for word size combo box */
160 grid
.attach (label
, 0, 3, 1, 1);
162 word_size_combo
= new Gtk
.ComboBox ();
163 label
.mnemonic_widget
= word_size_combo
;
164 word_size_combo
.show ();
165 word_size_combo
.changed
.connect (word_size_combo_changed_cb
);
166 grid
.attach (word_size_combo
, 1, 3, 1, 1);
168 model
= new Gtk
.ListStore (2, typeof (string), typeof (int));
169 word_size_combo
.model
= model
;
170 model
.append (out iter
);
171 model
.set (iter
, 0, /* Word size combo: 8 bits */ _("8 bits"), 1, 8);
172 model
.append (out iter
);
173 model
.set (iter
, 0, /* Word size combo: 16 bits */ _("16 bits"), 1, 16);
174 model
.append (out iter
);
175 model
.set (iter
, 0, /* Word size combo: 32 bits */ _("32 bits"), 1, 32);
176 model
.append (out iter
);
177 model
.set (iter
, 0, /* Word size combo: 64 bits */ _("64 bits"), 1, 64);
178 renderer
= new Gtk
.CellRendererText ();
179 word_size_combo
.pack_start (renderer
, true);
180 word_size_combo
.add_attribute (renderer
, "text", 0);
182 decimal_places_spin
.set_value (equation
.accuracy
);
183 equation
.notify
["accuracy"].connect ((pspec
) => { decimal_places_spin
.set_value (equation
.accuracy
); });
185 thousands_separator_check
.set_active (equation
.show_thousands_separators
);
186 equation
.notify
["show-thousands-separators"].connect (() => { thousands_separator_check
.set_active (equation
.show_thousands_separators
); });
188 trailing_zeroes_check
.set_active (equation
.show_trailing_zeroes
);
189 equation
.notify
["show-trailing_zeroes"].connect (() => { trailing_zeroes_check
.set_active (equation
.show_trailing_zeroes
); });
191 set_combo_box_from_int (number_format_combo
, equation
.number_format
);
192 equation
.notify
["number-format"].connect ((pspec
) => { set_combo_box_from_int (number_format_combo
, equation
.number_format
); });
194 set_combo_box_from_int (word_size_combo
, equation
.word_size
);
195 equation
.notify
["word-size"].connect ((pspec
) => { set_combo_box_from_int (word_size_combo
, equation
.word_size
); });
197 set_combo_box_from_int (angle_unit_combo
, equation
.angle_units
);
198 equation
.notify
["angle-units"].connect ((pspec
) => { set_combo_box_from_int (angle_unit_combo
, equation
.angle_units
); });
201 protected override void response (int id
)
206 protected override bool delete_event (Gdk
.EventAny event
)
212 private void number_format_combo_changed_cb (Gtk
.ComboBox combo
)
215 combo
.get_active_iter (out iter
);
217 combo
.model
.get (iter
, 1, out value
, -1);
218 equation
.number_format
= value
;
221 private void angle_unit_combo_changed_cb (Gtk
.ComboBox combo
)
224 combo
.get_active_iter (out iter
);
226 combo
.model
.get (iter
, 1, out value
, -1);
227 equation
.angle_units
= value
;
230 private void word_size_combo_changed_cb (Gtk
.ComboBox combo
)
233 combo
.get_active_iter (out iter
);
235 combo
.model
.get (iter
, 1, out value
, -1);
236 equation
.word_size
= value
;
239 private void set_combo_box_from_int (Gtk
.ComboBox combo
, int value
)
242 var valid
= combo
.model
.get_iter_first (out iter
);
247 combo
.model
.get (iter
, 1, out v
, -1);
250 valid
= combo
.model
.iter_next (ref iter
);
253 valid
= combo
.model
.get_iter_first (out iter
);
255 combo
.set_active_iter (iter
);