[chronojump] PersonWin height witn new code for metric/imperial



commit c018c7d34f5a9fba83c2a865aebdcd619c172002
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Mar 9 21:29:49 2020 +0100

    PersonWin height witn new code for metric/imperial

 glade/person_win.glade      | 107 +++++++++++++++++++++++++++++++++++++++-----
 src/gui/person/addModify.cs |  68 ++++++++++++++++++----------
 src/util.cs                 |   9 +++-
 3 files changed, 148 insertions(+), 36 deletions(-)
---
diff --git a/glade/person_win.glade b/glade/person_win.glade
index 33e8e3ff..2e43334a 100644
--- a/glade/person_win.glade
+++ b/glade/person_win.glade
@@ -611,12 +611,12 @@
                           </packing>
                         </child>
                         <child>
-                          <widget class="GtkHBox" id="hbox12">
+                          <widget class="GtkHBox" id="hbox_height_metric">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
                             <property name="spacing">10</property>
                             <child>
-                              <widget class="GtkSpinButton" id="spinbutton_height">
+                              <widget class="GtkSpinButton" id="spinbutton_height_metric">
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="invisible_char">●</property>
@@ -656,17 +656,102 @@
                           </packing>
                         </child>
                         <child>
-                          <widget class="GtkButton" id="button_height_metric">
-                            <property name="label" translatable="yes">Use metric units</property>
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">True</property>
-                            <signal name="clicked" handler="on_button_height_metric_clicked" swapped="no"/>
+                          <widget class="GtkHBox" id="hbox_height_imperial">
+                            <property name="can_focus">False</property>
+                            <property name="spacing">10</property>
+                            <child>
+                              <widget class="GtkHBox" id="hbox8">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="spacing">8</property>
+                                <child>
+                                  <widget class="GtkSpinButton" id="spinbutton_height_imperial_feet">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="invisible_char">●</property>
+                                    <property name="primary_icon_activatable">False</property>
+                                    <property name="secondary_icon_activatable">False</property>
+                                    <property name="primary_icon_sensitive">True</property>
+                                    <property name="secondary_icon_sensitive">True</property>
+                                    <property name="adjustment">0 0 8 1 1 0</property>
+                                    <property name="snap_to_ticks">True</property>
+                                    <property name="numeric">True</property>
+                                    <property name="update_policy">if-valid</property>
+                                  </widget>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">False</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <widget class="GtkLabel" id="label14">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label" translatable="yes">Feet</property>
+                                  </widget>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </widget>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <widget class="GtkHBox" id="hbox10">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="spacing">8</property>
+                                <child>
+                                  <widget class="GtkSpinButton" id="spinbutton_height_imperial_inches">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="invisible_char">●</property>
+                                    <property name="primary_icon_activatable">False</property>
+                                    <property name="secondary_icon_activatable">False</property>
+                                    <property name="primary_icon_sensitive">True</property>
+                                    <property name="secondary_icon_sensitive">True</property>
+                                    <property name="adjustment">0 0 11 0.01 1 0</property>
+                                    <property name="digits">2</property>
+                                    <property name="snap_to_ticks">True</property>
+                                    <property name="numeric">True</property>
+                                    <property name="update_policy">if-valid</property>
+                                  </widget>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">False</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <widget class="GtkLabel" id="label30">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label" translatable="yes">Inches</property>
+                                  </widget>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </widget>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
                           </widget>
                           <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="pack_type">end</property>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
                             <property name="position">2</property>
                           </packing>
                         </child>
diff --git a/src/gui/person/addModify.cs b/src/gui/person/addModify.cs
index b77aa3b7..e48c833a 100644
--- a/src/gui/person/addModify.cs
+++ b/src/gui/person/addModify.cs
@@ -61,7 +61,13 @@ public class PersonAddModifyWindow
        [Widget] Gtk.HBox hbox_weight_imperial;
        [Widget] Gtk.SpinButton spinbutton_weight_metric;
        [Widget] Gtk.SpinButton spinbutton_weight_imperial;
-       [Widget] Gtk.SpinButton spinbutton_height;
+
+       [Widget] Gtk.HBox hbox_height_metric;
+       [Widget] Gtk.HBox hbox_height_imperial;
+       [Widget] Gtk.SpinButton spinbutton_height_metric;
+       [Widget] Gtk.SpinButton spinbutton_height_imperial_feet;
+       [Widget] Gtk.SpinButton spinbutton_height_imperial_inches;
+
        [Widget] Gtk.SpinButton spinbutton_leg_length;
        [Widget] Gtk.SpinButton spinbutton_trochanter_floor_on_flexion;
        
@@ -219,16 +225,28 @@ public class PersonAddModifyWindow
                if(radio_metric.Active)
                {
                        spinbutton_weight_metric.Value = Util.ConvertPoundsToKg 
(spinbutton_weight_imperial.Value);
+                       spinbutton_height_metric.Value = Util.ConvertFeetInchesToCm (
+                                       Convert.ToInt32(spinbutton_height_imperial_feet.Value),
+                                       spinbutton_height_imperial_inches.Value);
 
                        hbox_weight_metric.Visible = true;
                        hbox_weight_imperial.Visible = false;
+                       hbox_height_metric.Visible = true;
+                       hbox_height_imperial.Visible = false;
                }
                else if(radio_imperial.Active)
                {
                        spinbutton_weight_imperial.Value = Util.ConvertKgToPounds 
(spinbutton_weight_metric.Value);
+                       int feet = 0;
+                       double inches = 0;
+                       Util.ConvertCmToFeetInches (spinbutton_height_metric.Value, out feet, out inches);
+                       spinbutton_height_imperial_feet.Value = feet;
+                       spinbutton_height_imperial_inches.Value = inches;
 
                        hbox_weight_metric.Visible = false;
                        hbox_weight_imperial.Visible = true;
+                       hbox_height_metric.Visible = false;
+                       hbox_height_imperial.Visible = true;
                }
        }
 
@@ -643,11 +661,17 @@ public class PersonAddModifyWindow
                        if(metric) {
                                hbox_weight_metric.Visible = true;
                                hbox_weight_imperial.Visible = false;
+                               hbox_height_metric.Visible = true;
+                               hbox_height_imperial.Visible = false;
+
                                radio_metric.Active = true;
                        }
                        else {
                                hbox_weight_metric.Visible = false;
                                hbox_weight_imperial.Visible = true;
+                               hbox_height_metric.Visible = false;
+                               hbox_height_imperial.Visible = true;
+
                                radio_imperial.Active = true;
                        }
 
@@ -687,12 +711,18 @@ public class PersonAddModifyWindow
                        //PERSONSESSION STUFF
                        PersonSession myPS = SqlitePersonSession.Select(currentPerson.UniqueID, 
currentSession.UniqueID);
 
-                       if(metric)
+                       if(metric) {
                                spinbutton_weight_metric.Value = myPS.Weight;
-                       else
+                               spinbutton_height_metric.Value = myPS.Height;
+                       } else {
                                spinbutton_weight_imperial.Value = Util.ConvertKgToPounds(myPS.Weight);
+                               int feet = 0;
+                               double inches = 0;
+                               Util.ConvertCmToFeetInches (myPS.Height, out feet, out inches);
+                               spinbutton_height_imperial_feet.Value = feet;
+                               spinbutton_height_imperial_inches.Value = inches;
+                       }
 
-                       spinbutton_height.Value = myPS.Height;
                        spinbutton_leg_length.Value = myPS.TrochanterToe; //future1: altura trochanter - 
punta del pie en extension
                        spinbutton_trochanter_floor_on_flexion.Value = myPS.TrochanterFloorOnFlexion; 
//future2: altura trochanter - suelo en flexión
 
@@ -767,22 +797,6 @@ public class PersonAddModifyWindow
                on_entries_required_changed(new object(), new EventArgs());
        }
 
-       void on_button_height_metric_clicked(object obj, EventArgs args) 
-       {
-               genericWin = GenericWindow.Show(Catalog.GetString("Height"), Catalog.GetString("Select your 
height"), Constants.GenericWindowShow.HEIGHTMETRIC, true);
-               genericWin.Button_accept.Clicked += new EventHandler(on_button_height_metric_accepted);
-       }
-       void on_button_height_metric_accepted (object obj, EventArgs args)
-       {
-               genericWin.Button_accept.Clicked -= new EventHandler(on_button_height_metric_accepted);
-
-               string [] myStr = genericWin.TwoSpinSelected.Split(new char[] {':'});
-               spinbutton_height.Value = Util.ConvertFeetInchesToCm(
-                       Convert.ToInt32(myStr[0]), 
-                       Convert.ToDouble(myStr[1])
-               );
-       }
-       
        void on_button_leg_length_metric_clicked(object obj, EventArgs args)
        {
                genericWin = GenericWindow.Show(Catalog.GetString("Height"), Catalog.GetString("Select your 
leg length"), Constants.GenericWindowShow.HEIGHTMETRIC, true);
@@ -1133,10 +1147,16 @@ public class PersonAddModifyWindow
                //      dateTime.Year.ToString();
                
                double weight = 0;
-               if(radio_metric.Active)
+               double height = 0;
+               if(radio_metric.Active) {
                        weight = (double) spinbutton_weight_metric.Value;
-               else
+                       height = (double) spinbutton_height_metric.Value;
+               } else {
                        weight = Util.ConvertPoundsToKg(spinbutton_weight_imperial.Value);
+                       height = Util.ConvertFeetInchesToCm(
+                                       Convert.ToInt32(spinbutton_height_imperial_feet.Value),
+                                       spinbutton_height_imperial_inches.Value);
+               }
 
                //convert margarias (it's power is calculated using weight and it's written on description)
                string [] myMargarias = SqliteRun.SelectRuns(false, currentSession.UniqueID, 
currentPerson.UniqueID, "Margaria",
@@ -1166,7 +1186,7 @@ public class PersonAddModifyWindow
                        LogB.Information("Going to insert personSession");
                        currentPersonSession = new PersonSession (
                                        currentPerson.UniqueID, currentSession.UniqueID, 
-                                       (double) spinbutton_height.Value, (double) weight, 
+                                       height, (double) weight,
                                        sport.UniqueID, 
                                        Convert.ToInt32(Util.FindOnArray(':', 2, 0, 
UtilGtk.ComboGetActive(combo_speciallities), speciallities)),
                                        Util.FetchID(UtilGtk.ComboGetActive(combo_levels)),
@@ -1212,7 +1232,7 @@ public class PersonAddModifyWindow
                        currentPersonSession = new PersonSession (
                                        ps.UniqueID,
                                        currentPerson.UniqueID, currentSession.UniqueID, 
-                                       (double) spinbutton_height.Value, (double) weight, 
+                                       height, (double) weight,
                                        sport.UniqueID, 
                                        Convert.ToInt32(Util.FindOnArray(':', 2, 0, 
UtilGtk.ComboGetActive(combo_speciallities), speciallities)),
                                        Util.FetchID(UtilGtk.ComboGetActive(combo_levels)),
diff --git a/src/util.cs b/src/util.cs
index fa7e54f2..2286bfd6 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -2218,7 +2218,14 @@ public class Util
        public static double ConvertFeetInchesToCm(int feet, double inches) {
                return feet * 30.48 + inches * 2.54;
        }
-       
+
+       public static void ConvertCmToFeetInches(double cm, out int feet, out double inches)
+       {
+               double numInches = UtilAll.DivideSafe(cm, 2.54);
+               feet = Convert.ToInt32(Math.Floor(UtilAll.DivideSafe(numInches, 12)));
+               inches = numInches % 12;
+       }
+
        public static double ConvertPoundsToKg(double pounds) {
                return pounds * 0.45359237;
        }


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