[glom] Field Formatting: Negative values color: Make this just a bool check box.



commit 9d9059d238776f5629033b2edac8f7867619e909
Author: Murray Cumming <murrayc murrayc com>
Date:   Sat Jan 16 14:36:22 2010 +0100

    Field Formatting: Negative values color: Make this just a bool check box.
    
      * glom/libglom/data_structure/numeric_format.[h|cc]: Use just a bool
      to say if negative values should be shown in an alternative color.
      Add static get_alternative_color_for_negatives() to get that color.
     * glom/libglom/data_structure/layout/fieldformatting.cc:
     get_text_format_color_foreground_to_use(): Updated the implementation.
     * glom/libglom/document/document.cc:
      load_after_layout_item_formatting(), save_before_layout_item_formatting():
    Updated.
    
    * glom/glom_developer.glade: window_formatting: Show only a checkbox, not
    a color too, for the alternative color for negatives.
    * glom/mode_design/layout/layout_item_dialogs/box_formatting.[h|cc]:
    Updated.

 ChangeLog                                          |   18 ++++++++++
 glom/glom_developer.glade                          |   36 ++++----------------
 .../data_structure/layout/fieldformatting.cc       |    5 ++-
 glom/libglom/data_structure/numeric_format.cc      |   13 +++++--
 glom/libglom/data_structure/numeric_format.h       |   11 ++++--
 glom/libglom/document/document.cc                  |   10 +++---
 .../layout/layout_item_dialogs/box_formatting.cc   |   13 ++-----
 .../layout/layout_item_dialogs/box_formatting.h    |    1 -
 8 files changed, 55 insertions(+), 52 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 488f02f..9ab85f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2010-01-16  Murray Cumming  <murrayc murrayc com>
+
+  Field Formatting: Negative values color: Make this just a bool check box.
+  
+  * glom/libglom/data_structure/numeric_format.[h|cc]: Use just a bool 
+  to say if negative values should be shown in an alternative color.
+  Add static get_alternative_color_for_negatives() to get that color.
+ 	* glom/libglom/data_structure/layout/fieldformatting.cc:
+ 	get_text_format_color_foreground_to_use(): Updated the implementation.
+ 	* glom/libglom/document/document.cc:
+  load_after_layout_item_formatting(), save_before_layout_item_formatting():
+	Updated.
+	
+	* glom/glom_developer.glade: window_formatting: Show only a checkbox, not 
+	a color too, for the alternative color for negatives.
+	* glom/mode_design/layout/layout_item_dialogs/box_formatting.[h|cc]:
+	Updated.
+
 2010-01-15  Michael Hasselmann  <michaelh openismus com>
 
 	Add forgotten header to libglom's Makefile
diff --git a/glom/glom_developer.glade b/glom/glom_developer.glade
index 31bd473..6551852 100644
--- a/glom/glom_developer.glade
+++ b/glom/glom_developer.glade
@@ -6394,36 +6394,14 @@ Which user should be added to this group?</property>
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkHBox" id="hbox_color_negatives">
+                  <object class="GtkCheckButton" id="checkbutton_foreground_negatives">
+                    <property name="label" translatable="yes">Alternative Color for Negative Values</property>
                     <property name="visible">True</property>
-                    <property name="spacing">6</property>
-                    <child>
-                      <object class="GtkCheckButton" id="checkbutton_foreground_negatives">
-                        <property name="label" translatable="yes">Color for Negative Values:</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="tooltip_text" translatable="yes">Click this check box to use a different foreground color to display negative values.</property>
-                        <property name="use_underline">True</property>
-                        <property name="draw_indicator">True</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">False</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkColorButton" id="colorbutton_foreground_negatives">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                      </object>
-                      <packing>
-                        <property name="pack_type">end</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="tooltip_text" translatable="yes">Click this check box to use a different foreground color to display negative values.</property>
+                    <property name="use_underline">True</property>
+                    <property name="draw_indicator">True</property>
                   </object>
                   <packing>
                     <property name="expand">False</property>
diff --git a/glom/libglom/data_structure/layout/fieldformatting.cc b/glom/libglom/data_structure/layout/fieldformatting.cc
index ae4ef11..2c12a7f 100644
--- a/glom/libglom/data_structure/layout/fieldformatting.cc
+++ b/glom/libglom/data_structure/layout/fieldformatting.cc
@@ -144,10 +144,11 @@ Glib::ustring FieldFormatting::get_text_format_color_foreground() const
 
 Glib::ustring FieldFormatting::get_text_format_color_foreground_to_use(const Gnome::Gda::Value& value) const
 {
-  if(!m_numeric_format.m_foreground_color_for_negatives.empty())
+  if(m_numeric_format.m_alt_foreground_color_for_negatives)
   {
+    //TODO: Use some other color if the alternative color is too similar to the foreground color.
     if(Conversions::get_double_for_gda_value_numeric(value) < 0)
-      return m_numeric_format.m_foreground_color_for_negatives;
+      return NumericFormat::get_alternative_color_for_negatives();
   }
 
   return m_text_color_foreground;
diff --git a/glom/libglom/data_structure/numeric_format.cc b/glom/libglom/data_structure/numeric_format.cc
index 5f40f3f..5578ae8 100644
--- a/glom/libglom/data_structure/numeric_format.cc
+++ b/glom/libglom/data_structure/numeric_format.cc
@@ -26,7 +26,8 @@ namespace Glom
 NumericFormat::NumericFormat()
 : m_use_thousands_separator(true), //A sensible default.
   m_decimal_places_restricted(false),
-  m_decimal_places(2) //A sensible default.
+  m_decimal_places(2), //A sensible default.
+  m_alt_foreground_color_for_negatives(false)
 {
 }
 
@@ -45,7 +46,7 @@ NumericFormat& NumericFormat::operator=(const NumericFormat& src)
   m_use_thousands_separator = src.m_use_thousands_separator;
   m_decimal_places_restricted = src.m_decimal_places_restricted;
   m_decimal_places = src.m_decimal_places;
-  m_foreground_color_for_negatives = src.m_foreground_color_for_negatives;
+  m_alt_foreground_color_for_negatives = src.m_alt_foreground_color_for_negatives;
 
   return *this;
 }
@@ -56,7 +57,7 @@ bool NumericFormat::operator==(const NumericFormat& src) const
          (m_use_thousands_separator == src.m_use_thousands_separator) &&
          (m_decimal_places_restricted == src.m_decimal_places_restricted) &&
          (m_decimal_places == src.m_decimal_places) && 
-         (m_foreground_color_for_negatives == src.m_foreground_color_for_negatives);
+         (m_alt_foreground_color_for_negatives == src.m_alt_foreground_color_for_negatives);
 }
 
 bool NumericFormat::operator!=(const NumericFormat& src) const
@@ -69,4 +70,10 @@ guint NumericFormat::get_default_precision()
   return 15;
 }
 
+Glib::ustring NumericFormat::get_alternative_color_for_negatives()
+{
+  return "#ffff00000000"; //red
+}
+
+
 } //namespace Glom
diff --git a/glom/libglom/data_structure/numeric_format.h b/glom/libglom/data_structure/numeric_format.h
index 5c2f728..d765b18 100644
--- a/glom/libglom/data_structure/numeric_format.h
+++ b/glom/libglom/data_structure/numeric_format.h
@@ -21,7 +21,7 @@
 #ifndef GLOM_DATA_STRUCTURE_NUMERIC_FORMAT_H
 #define GLOM_DATA_STRUCTURE_NUMERIC_FORMAT_H
 
-#include "privileges.h"
+#include <glom/libglom/data_structure/privileges.h>
 #include <glibmm/ustring.h>
 #include <map>
 
@@ -39,6 +39,11 @@ public:
 
   bool operator==(const NumericFormat& src) const;
   bool operator!=(const NumericFormat& src) const;
+  
+  /** The foreground color to use for negative values, 
+   * if m_alt_foreground_color_for_negatives is true.
+   */
+  static Glib::ustring get_alternative_color_for_negatives();
 
   /** Get the number of decimal places we should allow to be shown until we
     * show the awkward e syntax.  This should not be used if
@@ -51,8 +56,8 @@ public:
   bool m_decimal_places_restricted;
   guint m_decimal_places;
   
-  /// The foreground color to use for negative values.
-  Glib::ustring m_foreground_color_for_negatives;
+  /// Whether to use an alernative foreground color for negative values.
+  bool m_alt_foreground_color_for_negatives;
 };
 
 } //namespace Glom
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index a450e12..3d495c2 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -175,7 +175,7 @@ namespace Glom
 #define GLOM_ATTRIBUTE_FORMAT_DECIMAL_PLACES_RESTRICTED "format_decimal_places_restricted"
 #define GLOM_ATTRIBUTE_FORMAT_DECIMAL_PLACES "format_decimal_places"
 #define GLOM_ATTRIBUTE_FORMAT_CURRENCY_SYMBOL "format_currency_symbol"
-#define GLOM_ATTRIBUTE_FORMAT_NEGATIVE_COLOR "color_fg_negative"
+#define GLOM_ATTRIBUTE_FORMAT_USE_ALT_NEGATIVE_COLOR "format_use_alt_negative_color" //Just a  bool, not a color.
 
 #define GLOM_ATTRIBUTE_FORMAT_TEXT_MULTILINE "format_text_multiline"
 #define GLOM_ATTRIBUTE_FORMAT_TEXT_MULTILINE_HEIGHT_LINES "format_text_multiline_height_lines"
@@ -1885,8 +1885,8 @@ void Document::load_after_layout_item_formatting(const xmlpp::Element* element,
     format.m_numeric_format.m_decimal_places_restricted = get_node_attribute_value_as_bool(element, GLOM_ATTRIBUTE_FORMAT_DECIMAL_PLACES_RESTRICTED);
     format.m_numeric_format.m_decimal_places = get_node_attribute_value_as_decimal(element, GLOM_ATTRIBUTE_FORMAT_DECIMAL_PLACES);
     format.m_numeric_format.m_currency_symbol = get_node_attribute_value(element, GLOM_ATTRIBUTE_FORMAT_CURRENCY_SYMBOL);
-    format.m_numeric_format.m_foreground_color_for_negatives = 
-      get_node_attribute_value(element, GLOM_ATTRIBUTE_FORMAT_NEGATIVE_COLOR);
+    format.m_numeric_format.m_alt_foreground_color_for_negatives = 
+      get_node_attribute_value_as_bool(element, GLOM_ATTRIBUTE_FORMAT_USE_ALT_NEGATIVE_COLOR);
   }
 
   //Text formatting:
@@ -2877,8 +2877,8 @@ void Document::save_before_layout_item_formatting(xmlpp::Element* nodeItem, cons
     set_node_attribute_value_as_bool(nodeItem, GLOM_ATTRIBUTE_FORMAT_DECIMAL_PLACES_RESTRICTED, format.m_numeric_format.m_decimal_places_restricted);
     set_node_attribute_value_as_decimal(nodeItem, GLOM_ATTRIBUTE_FORMAT_DECIMAL_PLACES, format.m_numeric_format.m_decimal_places);
     set_node_attribute_value(nodeItem, GLOM_ATTRIBUTE_FORMAT_CURRENCY_SYMBOL, format.m_numeric_format.m_currency_symbol);
-    set_node_attribute_value(nodeItem, GLOM_ATTRIBUTE_FORMAT_NEGATIVE_COLOR,
-      format.m_numeric_format.m_foreground_color_for_negatives);
+    set_node_attribute_value_as_bool(nodeItem, GLOM_ATTRIBUTE_FORMAT_USE_ALT_NEGATIVE_COLOR,
+      format.m_numeric_format.m_alt_foreground_color_for_negatives);
 
     set_node_attribute_value_as_bool(nodeItem, GLOM_ATTRIBUTE_FORMAT_CHOICES_RESTRICTED, format.get_choices_restricted());
     set_node_attribute_value_as_bool(nodeItem, GLOM_ATTRIBUTE_FORMAT_CHOICES_CUSTOM, format.get_has_custom_choices());
diff --git a/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc b/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
index 93877b3..846be55 100644
--- a/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
+++ b/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
@@ -33,7 +33,6 @@ Box_Formatting::Box_Formatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::
   m_entry_format_decimal_places(0),
   m_entry_currency_symbol(0),
   m_checkbox_format_color_negatives(0),
-  m_colorbutton_negatives(0),
   m_vbox_text_format(0),
   m_checkbox_format_text_multiline(0),
   m_label_format_text_multiline_height(0),
@@ -61,7 +60,6 @@ Box_Formatting::Box_Formatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::
   builder->get_widget("checkbutton_format_use_decimal_places", m_checkbox_format_use_decimal_places);
   builder->get_widget("entry_format_decimal_places", m_entry_format_decimal_places);
   builder->get_widget_derived("entry_currency_symbol", m_entry_currency_symbol);
-  builder->get_widget("colorbutton_foreground_negatives", m_colorbutton_negatives);
   builder->get_widget("checkbutton_foreground_negatives", m_checkbox_format_color_negatives);
 
   //Text formatting:
@@ -152,9 +150,8 @@ void Box_Formatting::set_formatting(const FieldFormatting& format)
 
   m_entry_currency_symbol->get_entry()->set_text(format.m_numeric_format.m_currency_symbol);
 
-  const Glib::ustring color_negatives = format.m_numeric_format.m_foreground_color_for_negatives;
-  m_checkbox_format_color_negatives->set_active(!color_negatives.empty());
-  m_colorbutton_negatives->set_color( Gdk::Color(color_negatives) );
+  m_checkbox_format_color_negatives->set_active(
+    format.m_numeric_format.m_alt_foreground_color_for_negatives );
 
 
   m_checkbox_format_text_multiline->set_active(format.get_text_format_multiline());
@@ -223,10 +220,8 @@ bool Box_Formatting::get_formatting(FieldFormatting& format) const
 
   m_format.m_numeric_format.m_currency_symbol = m_entry_currency_symbol->get_entry()->get_text();
 
-  Glib::ustring color_negatives;
-  if(m_checkbox_format_color_negatives->get_active())
-    color_negatives = m_colorbutton_negatives->get_color().to_string();
-  m_format.m_numeric_format.m_foreground_color_for_negatives = color_negatives;
+  m_format.m_numeric_format.m_alt_foreground_color_for_negatives = 
+    m_checkbox_format_color_negatives->get_active();
 
   //Text formatting:
   m_format.set_text_format_multiline(m_checkbox_format_text_multiline->get_active());
diff --git a/glom/mode_design/layout/layout_item_dialogs/box_formatting.h b/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
index f2a392e..3f3955f 100644
--- a/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
+++ b/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
@@ -70,7 +70,6 @@ private:
   Gtk::Entry* m_entry_format_decimal_places;
   ComboEntry_Currency* m_entry_currency_symbol;
   Gtk::CheckButton* m_checkbox_format_color_negatives;
-  Gtk::ColorButton* m_colorbutton_negatives;
 
   Gtk::VBox* m_vbox_text_format;
   Gtk::CheckButton* m_checkbox_format_text_multiline;



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