[chronojump] Background color can be selected on preferences win



commit 21087d0c5b3f3fa5e1a459f424de5c2ba01f8fa4
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Mar 19 19:56:53 2020 +0100

    Background color can be selected on preferences win

 glade/preferences_win.glade | 53 ++++++++++++++++++++++++++++++++++++++++++++-
 src/gui/preferences.cs      | 28 +++++++++++++++++++++++-
 src/preferences.cs          |  1 +
 src/utilGtk.cs              | 14 ++++++++++++
 4 files changed, 94 insertions(+), 2 deletions(-)
---
diff --git a/glade/preferences_win.glade b/glade/preferences_win.glade
index a29d6081..22b15095 100644
--- a/glade/preferences_win.glade
+++ b/glade/preferences_win.glade
@@ -155,6 +155,57 @@
                     <property name="position">0</property>
                   </packing>
                 </child>
+                <child>
+                  <widget class="GtkHBox" id="hbox19">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="spacing">8</property>
+                    <child>
+                      <widget class="GtkLabel" id="label127">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">Background color</property>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkDrawingArea" id="drawingarea_background_color">
+                        <property name="width_request">40</property>
+                        <property name="height_request">40</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkButton" id="button_color_choose">
+                        <property name="label" translatable="yes">Choose</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <signal name="clicked" handler="on_button_color_choose_clicked" swapped="no"/>
+                      </widget>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
                 <child>
                   <widget class="GtkHButtonBox" id="hbuttonbox1">
                     <property name="can_focus">False</property>
@@ -177,7 +228,7 @@
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">False</property>
-                    <property name="position">1</property>
+                    <property name="position">2</property>
                   </packing>
                 </child>
               </widget>
diff --git a/src/gui/preferences.cs b/src/gui/preferences.cs
index 72a669ff..b9a38575 100644
--- a/src/gui/preferences.cs
+++ b/src/gui/preferences.cs
@@ -53,6 +53,7 @@ public class PreferencesWindow
        [Widget] Gtk.CheckButton check_appearance_person_win_hide;
        [Widget] Gtk.CheckButton check_appearance_person_photo;
        [Widget] Gtk.Alignment alignment_undecorated;
+       [Widget] Gtk.DrawingArea drawingarea_background_color;
 
        //database tab
        [Widget] Gtk.Button button_data_folder_open;
@@ -226,7 +227,6 @@ public class PreferencesWindow
        [Widget] Gtk.Frame frame_networks;
        [Widget] Gtk.CheckButton check_networks_devices;
 
-
        [Widget] Gtk.Button button_accept;
        [Widget] Gtk.Button button_cancel;
        public Gtk.Button FakeButtonImported;
@@ -234,6 +234,8 @@ public class PreferencesWindow
        
        static PreferencesWindow PreferencesWindowBox;
 
+       private Gdk.Color colorBackground;
+
        private UtilAll.OperatingSystems operatingSystem;
        private Preferences preferences; //stored to update SQL if anything changed
        private Thread thread;
@@ -335,6 +337,9 @@ public class PreferencesWindow
                else
                        PreferencesWindowBox.check_appearance_person_photo.Active = false;
 
+               PreferencesWindowBox.colorBackground = UtilGtk.ColorParse(preferences.colorBackgroundString);
+               PreferencesWindowBox.paintColorDrawingArea(PreferencesWindowBox.colorBackground);
+
                //multimedia tab
                if(preferences.volumeOn)  
                        PreferencesWindowBox.checkbutton_volume.Active = true; 
@@ -630,6 +635,27 @@ public class PreferencesWindow
                return PreferencesWindowBox;
        }
 
+       private void paintColorDrawingArea(Gdk.Color color)
+       {
+               UtilGtk.PaintColorDrawingArea(drawingarea_background_color, color);
+       }
+       private void on_button_color_choose_clicked(object o, EventArgs args)
+       {
+               using (ColorSelectionDialog colorSelectionDialog = new ColorSelectionDialog 
(Catalog.GetString("Select color")))
+               {
+                       colorSelectionDialog.TransientFor = preferences_win;
+                       colorSelectionDialog.ColorSelection.CurrentColor = colorBackground;
+                       colorSelectionDialog.ColorSelection.HasPalette = true;
+
+                       if (colorSelectionDialog.Run () == (int) ResponseType.Ok) {
+                               colorBackground = colorSelectionDialog.ColorSelection.CurrentColor;
+                               paintColorDrawingArea(colorBackground);
+                       }
+
+                       colorSelectionDialog.Hide ();
+               }
+       }
+
        private void on_radio_encoder_capture_show_all_bars_toggled (object o, EventArgs args)
        {
                spin_encoder_capture_show_only_some_bars.Sensitive = false;
diff --git a/src/preferences.cs b/src/preferences.cs
index 651a5999..31a83b57 100644
--- a/src/preferences.cs
+++ b/src/preferences.cs
@@ -32,6 +32,7 @@ public class Preferences
        public MaximizedTypes maximized;
        public bool personWinHide;
        public bool personPhoto;
+       public string colorBackgroundString = "#0e1e46";
 
        public enum UnitsEnum { METRIC, IMPERIAL };
        public UnitsEnum units;
diff --git a/src/utilGtk.cs b/src/utilGtk.cs
index da696a9f..f71ace50 100644
--- a/src/utilGtk.cs
+++ b/src/utilGtk.cs
@@ -739,6 +739,20 @@ public class UtilGtk
                
                UtilGtk.ErasePaint(da, px);
        }
+
+       //color string like "#0e1e46" for Chronojump blue
+       public static Gdk.Color ColorParse(string colorString)
+       {
+               Gdk.Color color = new Gdk.Color();
+               Gdk.Color.Parse(colorString, ref color);
+               return color;
+       }
+
+       public static void PaintColorDrawingArea(Gtk.DrawingArea da, Gdk.Color color)
+       {
+               da.ModifyBg(StateType.Normal, color);
+       }
+
        
        /*
         *


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