[chronojump] Rest times (configurable) done!



commit e4fac4f119d8e6ca714859560f26a4d91831030d
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Nov 14 01:21:25 2016 +0100

    Rest times (configurable) done!

 glade/app1.glade      |   92 ++++++++++++++++++++++++++++++++++--------------
 src/gui/chronojump.cs |   23 ++++++++++--
 src/restTime.cs       |   22 +++++++++++-
 src/treeViewPerson.cs |   47 ++++++++++++++++++-------
 4 files changed, 138 insertions(+), 46 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index a9162f2..b795613 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -1564,12 +1564,12 @@
                                   </packing>
                                 </child>
                                 <child>
-                                  <widget class="GtkButton" id="button_crash">
-                                    <property name="label">CRASH_ME
-(debug purposes)</property>
+                                  <widget class="GtkButton" id="button_carles">
+                                    <property name="label">Button
+Carles</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <signal name="clicked" handler="on_debug_crash_activate" swapped="no"/>
+                                    <signal name="clicked" handler="on_button_carles_clicked" swapped="no"/>
                                   </widget>
                                   <packing>
                                     <property name="expand">False</property>
@@ -1578,12 +1578,12 @@
                                   </packing>
                                 </child>
                                 <child>
-                                  <widget class="GtkButton" id="button_carles">
-                                    <property name="label">Button
-Carles</property>
+                                  <widget class="GtkButton" id="button_crash">
+                                    <property name="label">CRASH_ME
+(debug purposes)</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <signal name="clicked" handler="on_button_carles_clicked" swapped="no"/>
+                                    <signal name="clicked" handler="on_debug_crash_activate" swapped="no"/>
                                   </widget>
                                   <packing>
                                     <property name="expand">False</property>
@@ -2183,7 +2183,7 @@ Carles</property>
                                                   <widget class="GtkHBox" id="hbox126">
                                                     <property name="visible">True</property>
                                                     <property name="can_focus">False</property>
-                                                    <property name="spacing">6</property>
+                                                    <property name="spacing">8</property>
                                                     <child>
                                                       <widget class="GtkHBox" id="hbox77">
                                                         <property name="visible">True</property>
@@ -2342,23 +2342,7 @@ Carles</property>
                                                           <widget class="GtkHBox" id="hbox35">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
-                                                            <property name="spacing">4</property>
-                                                            <child>
-                                                            <widget class="GtkLabel" 
id="label_current_person_title">
-                                                            <property name="visible">True</property>
-                                                            <property name="can_focus">False</property>
-                                                            <property name="xalign">0</property>
-                                                            <property name="label" 
translatable="yes">Current person</property>
-                                                            <property name="use_markup">True</property>
-                                                            <property name="ellipsize">end</property>
-                                                            <property name="max_width_chars">25</property>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">True</property>
-                                                            <property name="position">0</property>
-                                                            </packing>
-                                                            </child>
+                                                            <property name="spacing">7</property>
                                                             <child>
                                                             <widget class="GtkAlignment" id="alignment9">
                                                             <property name="visible">True</property>
@@ -2429,7 +2413,58 @@ Carles</property>
                                                             <packing>
                                                             <property name="expand">False</property>
                                                             <property name="fill">False</property>
-                                                            <property name="pack_type">end</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkHBox" id="hbox118">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="tooltip">Highlight higher 
resting times</property>
+                                                            <property name="spacing">2</property>
+                                                            <child>
+                                                            <widget class="GtkCheckButton" 
id="checkbutton_rest">
+                                                            <property name="label" 
translatable="yes">Rest</property>
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property 
name="receives_default">False</property>
+                                                            <property name="active">True</property>
+                                                            <property name="draw_indicator">True</property>
+                                                            <signal name="clicked" 
handler="on_checkbutton_rest_clicked" swapped="no"/>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkSpinButton" 
id="spinbutton_rest">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="max_length">2</property>
+                                                            <property name="invisible_char">●</property>
+                                                            <property name="width_chars">2</property>
+                                                            <property 
name="invisible_char_set">True</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">5 1 60 1 10 
0</property>
+                                                            <property name="climb_rate">1</property>
+                                                            <property name="numeric">True</property>
+                                                            <signal name="value_changed" 
handler="on_spinbutton_rest_value_changed" swapped="no"/>
+                                                            </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="position">1</property>
                                                             </packing>
                                                             </child>
@@ -18382,6 +18417,9 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index d3b0452..b9588a2 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -187,6 +187,8 @@ public partial class ChronoJumpWindow
        //menu person
        [Widget] Gtk.Button button_persons_up;
        [Widget] Gtk.Button button_persons_down;
+       [Widget] Gtk.CheckButton checkbutton_rest;
+       [Widget] Gtk.SpinButton spinbutton_rest;
        [Widget] Gtk.Button button_edit_current_person;
        [Widget] Gtk.Button button_show_all_person_events;
        [Widget] Gtk.Button button_delete_current_person;
@@ -670,10 +672,8 @@ public partial class ChronoJumpWindow
                if(normalGUI) {
                        //if change these values, change also in glade
                        //frame_test_options.BoxChild.Expand(true);
-                       label_current_person_title.Text=Catalog.GetString("Current person");
                } else {
                        //frame_test_options.BoxChild.Expand(false);
-                       label_current_person_title.Text=Catalog.GetString("Current");
                }
        }
 */
@@ -1101,7 +1101,7 @@ public partial class ChronoJumpWindow
         */
 
        private void createTreeView_persons (Gtk.TreeView tv) {
-               myTreeViewPersons = new TreeViewPersons( tv );
+               myTreeViewPersons = new TreeViewPersons(tv, Convert.ToInt32(spinbutton_rest.Value));
                tv.Selection.Changed += onTreeviewPersonsSelectionEntry;
        }
 
@@ -1155,7 +1155,7 @@ public partial class ChronoJumpWindow
        
        private void treeview_persons_storeReset() {
                myTreeViewPersons.RemoveColumns();
-               myTreeViewPersons = new TreeViewPersons(treeview_persons);
+               myTreeViewPersons = new TreeViewPersons(treeview_persons, 
Convert.ToInt32(spinbutton_rest.Value));
        }
        
        //private void on_treeview_persons_cursor_changed (object o, EventArgs args) {
@@ -4092,6 +4092,21 @@ public partial class ChronoJumpWindow
                return true;
        }
 
+       private void on_checkbutton_rest_clicked(object o, EventArgs args)
+       {
+               if(checkbutton_rest.Active) {
+                       spinbutton_rest.Sensitive = true;
+                       myTreeViewPersons.RestMinutesMark = Convert.ToInt32(spinbutton_rest.Value);
+               } else {
+                       spinbutton_rest.Sensitive = false;
+                       myTreeViewPersons.RestMinutesMark = 0;
+               }
+       }
+
+       private void on_spinbutton_rest_value_changed(object o, EventArgs args)
+       {
+               myTreeViewPersons.RestMinutesMark = Convert.ToInt32(spinbutton_rest.Value);
+       }
 
 
        /* ---------------------------------------------------------
diff --git a/src/restTime.cs b/src/restTime.cs
index c546e2b..919f373 100644
--- a/src/restTime.cs
+++ b/src/restTime.cs
@@ -42,13 +42,15 @@ public class LastTestTime
        {
                return personID.ToString() + ":" + time.ToString();
        }
-       
+
+       const string maxTimeString = "+60'";
+
        public string RestedTime
        {
                get {
                        TimeSpan ts = DateTime.Now.Subtract(time);
                        if(ts.TotalMinutes >= 60)
-                               return "+60'"; //TODO: check if this is correctly sorted on treeview persons
+                               return maxTimeString; //TODO: check if this is correctly sorted on treeview 
persons
 
                        //add a 0 if values are <10 to order them correctly on treeview persons
                        int m = ts.Minutes;
@@ -64,6 +66,22 @@ public class LastTestTime
                }
        }
 
+       public static int GetMinutes(string restedTime)
+       {
+               if(restedTime == null || restedTime == "")
+                       return 0;
+               if(restedTime == maxTimeString)
+                       return 60;
+
+               int minutes = 0;
+               try {
+                       minutes = Convert.ToInt32(restedTime.Substring(0,2));
+               } catch {
+                       return 0;
+               }
+               return minutes;
+       }
+
        public int PersonID
        {
                get { return personID; } 
diff --git a/src/treeViewPerson.cs b/src/treeViewPerson.cs
index 93591c5..c86e44f 100644
--- a/src/treeViewPerson.cs
+++ b/src/treeViewPerson.cs
@@ -29,17 +29,23 @@ public class TreeViewPersons
 {
        protected TreeStore store;
        protected Gtk.TreeView treeview;
+
+       //if 0 don't use it
+       //if > 0 then show in red when >= to this value
+       public int RestMinutesMark;
        
        public TreeViewPersons ()
        {
        }
        
-       public TreeViewPersons (Gtk.TreeView treeview)
+       public TreeViewPersons (Gtk.TreeView treeview, int restMinutes)
        {
                this.treeview = treeview;
 
+               RestMinutesMark = restMinutes;
+
                store = getStore(3);
-               string [] columnsString = { "ID", Catalog.GetString("person"), "Rest time"};
+               string [] columnsString = { "ID", Catalog.GetString("person"), Catalog.GetString("Rest")};
                treeview.Model = store;
                prepareHeaders(columnsString);
        }
@@ -61,25 +67,40 @@ public class TreeViewPersons
                int i=0;
                bool visible = false;
                foreach(string myCol in columnsString) {
-                       UtilGtk.CreateCols(treeview, store, Catalog.GetString(myCol), i++, visible);
+                       if(i < 2)
+                               UtilGtk.CreateCols(treeview, store, Catalog.GetString(myCol), i++, visible);
+                       else {
+                               //do it here to use a custom colored Renderer
+                               Gtk.TreeViewColumn aColumn = new Gtk.TreeViewColumn ();
+                               CellRendererText aCell = new CellRendererText();
+                               aColumn.Title = Catalog.GetString(myCol);
+                               aColumn.PackStart (aCell, true);
+                               aColumn.SetCellDataFunc (aCell, new Gtk.TreeCellDataFunc (RenderRestTime));
+
+                               aColumn.SortColumnId = i;
+                               aColumn.SortIndicator = true;
+                               aColumn.Visible = visible;
+                               treeview.AppendColumn ( aColumn );
+                       }
+
                        if(i == 1)
                                store.SetSortFunc (0, UtilGtk.IdColumnCompare);
 
-                       //TODO: store.SetSortFunc for column "Rest time"
                        visible = true;
                }
        }
 
-       /*
-       public int idColumnCompare (TreeModel model, TreeIter iter1, TreeIter iter2)     {
-               int val1 = 0;
-               int val2 = 0;
-               val1 = Convert.ToInt32(model.GetValue(iter1, 0));
-               val2 = Convert.ToInt32(model.GetValue(iter2, 0));
-               
-               return (val1-val2);
+       private void RenderRestTime (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, 
Gtk.TreeIter iter)
+       {
+               string restTime = (string) model.GetValue(iter, 2);
+               (cell as Gtk.CellRendererText).Text = restTime;
+
+               if(RestMinutesMark > 0 && LastTestTime.GetMinutes(restTime) >= RestMinutesMark)
+                       (cell as Gtk.CellRendererText).Foreground = UtilGtk.ColorBad;
+               else
+                       (cell as Gtk.CellRendererText).Foreground = null;       //will show default color
        }
-       */
+
 
        public void RemoveColumns() {
                Gtk.TreeViewColumn [] myColumns = treeview.Columns;


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