Jean-Marc Lasgouttes schreef:
   I created a new class ColorCode (and renamed the old enum to
something else).

Why not Color?
I moved this class to Color.cpp and renamed it to Color.
You could remove this type and set mergecolor to Color_ignore when no
merging is required (would be the default)
Done. The nice thing is that we can now also make a new color: Color_deletedtextmodifier. This can be set by the user to specify the degree of lightening or darkening of the color. It would be nice if the user can also put this to Color_ignore to indicate that there shouldn't be any merging.
A drawback of this is that everywhere a ColorCode is passed, we end up
with objects in stead of an enum-value, and we have a lot of implicit
constructors.

I am not sure how bad it is in practice.
Me neither.

+       bool operator!=(ColorCode const & color) const
+       {
+               return (baseColor_ != color.baseColor_);
+       }

Not needed when == exists.
I really can't compile when this isn't defined.. am I doing something wrong ? The same for all other operators.

The following patches are attached:

*merging_colors_2.patch
 The basic code of the change.

*merging_color_2_compilable.patch
A compilable patch that uses some tricks in order not to have a patch with 186 changes in 48 files.

*merging_colors_2_track_changes.patch
Example of the implementation of change tracking with merged colors in this framework.

*merging_colors_2_selections_in_note.patch
Example of the implementation of the coloring of a completely selected note.

If I can go through with this, I would like to have a few OKs, because changing all ColorCode's in the sources to Color is a quite intrusive operation.

Vincent



Index: src/Color.cpp
===================================================================
--- src/Color.cpp       (revision 28166)
+++ src/Color.cpp       (working copy)
@@ -84,6 +84,54 @@
 }
 
 
+Color::Color() : baseColor(Color_none), mergeColor(Color_ignore)
+{}
+
+
+Color::Color(ColorCode base_color) : mergeColor(Color_ignore)
+{
+       baseColor = base_color;
+}
+
+
+Color::Color(int base_color) : mergeColor(Color_ignore)
+{
+       baseColor = static_cast<ColorCode>(base_color);
+}
+
+
+bool Color::operator==(Color const & color) const
+{
+       return (baseColor == color.baseColor);
+}
+
+
+bool Color::operator!=(Color const & color) const      
+{
+       return (baseColor != color.baseColor);
+}
+
+
+bool Color::operator<(Color const & color) const
+{
+       return (baseColor < color.baseColor);
+}
+
+
+bool Color::operator<=(Color const & color) const
+{
+       return (baseColor < color.baseColor)
+               || (baseColor == color.baseColor);
+}
+
+
+std::ostream & operator<<(std::ostream & os, Color color)
+{
+       os << color.baseColor;
+       return os;
+}
+
+
 ColorSet::ColorSet()
 {
        char const * grey40 = "#666666";
Index: src/Color.h
===================================================================
--- src/Color.h (revision 28166)
+++ src/Color.h (working copy)
@@ -29,6 +29,45 @@
 namespace lyx {
 
 /**
+ * \class Color
+ *
+ * A class holding a definition of a certain color.
+ *
+ * A color can be one of the following kinds:
+ *
+ * - a single color, then mergeColor = Color_ignore
+ * - a merged color, i.e. the average of the base and merge colors.
+ */
+
+class Color
+{
+public:
+       ///
+       Color();
+       ///
+       Color(ColorCode base_color);
+       ///
+       Color(int base_color);
+
+       /// comparison operators.
+       //@{
+       bool operator==(Color const & color) const;
+       bool operator!=(Color const & color) const;
+       bool operator<(Color const & color) const;
+       bool operator<=(Color const & color) const;
+       //@}
+
+       /// the base color
+       ColorCode baseColor;
+       /// The color that is merged with the base color. Set
+       /// mergeColor to Color_ignore if no merging is wanted.
+       ColorCode mergeColor;
+};
+
+std::ostream & operator<<(std::ostream & os, Color color);
+
+
+/**
  * \class ColorSet
  *
  * A class holding color definitions and associated names for
Index: src/frontends/qt4/ColorCache.cpp
===================================================================
--- src/frontends/qt4/ColorCache.cpp    (revision 28166)
+++ src/frontends/qt4/ColorCache.cpp    (working copy)
@@ -32,9 +32,17 @@
 {
        if (!initialized_)
                const_cast<ColorCache *>(this)->init();
-       if (color <= Color_ignore)
-               return lcolors_[color];
-       // used by branches
+       if (color <= Color_ignore && color.mergeColor == Color_ignore)
+               return lcolors_[color.baseColor];
+       // used by branches & merged and blended colors
+       if (color.mergeColor != Color_ignore) {
+               QColor base_color = get(color.baseColor).toRgb();
+               QColor merge_color = get(color.mergeColor).toRgb();
+               return QColor(
+                       (base_color.red() + merge_color.red())/2,
+                       (base_color.green() + merge_color.green())/2,
+                       (base_color.blue() + merge_color.blue())/2);
+       }
        return QColor(lcolor.getX11Name(color).c_str()); 
 }
 
Index: src/Color.cpp
===================================================================
--- src/Color.cpp       (revision 28166)
+++ src/Color.cpp       (working copy)
@@ -84,6 +84,54 @@
 }
 
 
+ColorCode::ColorCode() : baseColor(Color_none), mergeColor(Color_ignore)
+{}
+
+
+ColorCode::ColorCode(ColorCodes base_color) : mergeColor(Color_ignore)
+{
+       baseColor = base_color;
+}
+
+
+ColorCode::ColorCode(int base_color) : mergeColor(Color_ignore)
+{
+       baseColor = static_cast<ColorCodes>(base_color);
+}
+
+
+bool ColorCode::operator==(ColorCode const & color) const
+{
+       return (baseColor == color.baseColor);
+}
+
+
+bool ColorCode::operator!=(ColorCode const & color) const      
+{
+       return (baseColor != color.baseColor);
+}
+
+
+bool ColorCode::operator<(ColorCode const & color) const
+{
+       return (baseColor < color.baseColor);
+}
+
+
+bool ColorCode::operator<=(ColorCode const & color) const
+{
+       return (baseColor < color.baseColor)
+               || (baseColor == color.baseColor);
+}
+
+
+std::ostream & operator<<(std::ostream & os, ColorCode color)
+{
+       os << color.baseColor;
+       return os;
+}
+
+
 ColorSet::ColorSet()
 {
        char const * grey40 = "#666666";
Index: src/Color.h
===================================================================
--- src/Color.h (revision 28166)
+++ src/Color.h (working copy)
@@ -29,6 +29,45 @@
 namespace lyx {
 
 /**
+ * \class ColorCode
+ *
+ * A class holding a definition of a certain color.
+ *
+ * A color can be one of the following kinds:
+ *
+ * - a single color, then mergeColor = Color_ignore
+ * - a merged color, i.e. the average of the base and merge colors.
+ */
+
+class ColorCode
+{
+public:
+       ///
+       ColorCode();
+       ///
+       ColorCode(ColorCodes base_color);
+       ///
+       ColorCode(int base_color);
+
+       /// comparison operators.
+       //@{
+       bool operator==(ColorCode const & color) const;
+       bool operator!=(ColorCode const & color) const;
+       bool operator<(ColorCode const & color) const;
+       bool operator<=(ColorCode const & color) const;
+       //@}
+
+       /// the base color
+       ColorCodes baseColor;
+       /// The color that is merged with the base color. Set
+       /// mergeColor to Color_ignore if no merging is wanted.
+       ColorCodes mergeColor;
+};
+
+std::ostream & operator<<(std::ostream & os, ColorCode color);
+
+
+/**
  * \class ColorSet
  *
  * A class holding color definitions and associated names for
Index: src/ColorCode.h
===================================================================
--- src/ColorCode.h     (revision 28166)
+++ src/ColorCode.h     (working copy)
@@ -13,7 +13,7 @@
 namespace lyx {
 
 /// Names of colors, including all logical colors
-enum ColorCode
+enum ColorCodes
 {
        /// No particular color---clear or default
        Color_none,
@@ -217,4 +217,6 @@
 
 } // namespace lyx
 
+#include "Color.h"
+
 #endif
Index: src/Font.cpp
===================================================================
--- src/Font.cpp        (revision 28166)
+++ src/Font.cpp        (working copy)
@@ -747,7 +747,7 @@
                features.require("noun");
                LYXERR(Debug::LATEX, "Noun enabled. Font: " << 
to_utf8(stateText(0)));
        }
-       switch (bits_.color()) {
+       switch (bits_.color().baseColor) {
                case Color_none:
                case Color_inherit:
                case Color_ignore:
Index: src/frontends/qt4/ColorCache.cpp
===================================================================
--- src/frontends/qt4/ColorCache.cpp    (revision 28166)
+++ src/frontends/qt4/ColorCache.cpp    (working copy)
@@ -32,9 +32,17 @@
 {
        if (!initialized_)
                const_cast<ColorCache *>(this)->init();
-       if (color <= Color_ignore)
-               return lcolors_[color];
-       // used by branches
+       if (color <= Color_ignore && color.mergeColor == Color_ignore)
+               return lcolors_[color.baseColor];
+       // used by branches & merged and blended colors
+       if (color.mergeColor != Color_ignore) {
+               QColor base_color = get(color.baseColor).toRgb();
+               QColor merge_color = get(color.mergeColor).toRgb();
+               return QColor(
+                       (base_color.red() + merge_color.red())/2,
+                       (base_color.green() + merge_color.green())/2,
+                       (base_color.blue() + merge_color.blue())/2);
+       }
        return QColor(lcolor.getX11Name(color).c_str()); 
 }
 
Index: src/frontends/qt4/GuiPainter.cpp
===================================================================
--- src/frontends/qt4/GuiPainter.cpp    (revision 28166)
+++ src/frontends/qt4/GuiPainter.cpp    (working copy)
@@ -97,7 +97,7 @@
        sig.append(QChar(static_cast<short>(f.series())));
        sig.append(QChar(static_cast<short>(f.realShape())));
        sig.append(QChar(static_cast<short>(f.size())));
-       sig.append(QChar(static_cast<short>(f.color())));
+       sig.append(QChar(static_cast<short>(f.color().baseColor)));
        if (!monochrome_min_.empty()) {
                QColor const & min = monochrome_min_.top();
                QColor const & max = monochrome_max_.top();
Index: src/MetricsInfo.cpp
===================================================================
--- src/MetricsInfo.cpp (revision 28166)
+++ src/MetricsInfo.cpp (working copy)
@@ -226,7 +226,7 @@
 ColorChanger::ColorChanger(FontInfo & font, string const & color)
        : Changer<FontInfo, string>(font)
 {
-       save_ = lcolor.getFromLyXName(color);
+       save_ = lcolor.getFromLyXName(color).baseColor;
        font.setColor(lcolor.getFromLyXName(color));
 }
 
Index: src/MetricsInfo.cpp
===================================================================
--- src/MetricsInfo.cpp (revision 28166)
+++ src/MetricsInfo.cpp (working copy)
@@ -69,24 +69,24 @@
 
 ColorCode PainterInfo::backgroundColor(Inset const * inset, bool sel) const
 {
-       ColorCode const color_bg = inset->backgroundColor();
+       ColorCode color_bg = inset->backgroundColor();
+       
+       if (selected && sel)
+               color_bg.mergeColor = Color_selection;
 
-       if (selected && sel)
-               // This inset is in a selection
-               return Color_selection;
-       else {
-               if (color_bg != Color_none)
-                       // This inset has its own color
-                       return color_bg;
-               else {
-                       if (background_color == Color_none)
-                               // This inset has no own color and does not 
inherit a color
-                               return Color_background;
-                       else
-                               // This inset has no own color, but inherits a 
color
-                               return background_color;
-               }
+       if (color_bg == Color_none) {
+               // This inset has not an own color
+               if (background_color == Color_background)
+                       // This inset has no own color and does not inherit a 
color
+                       // (color_bg.mergeColor is reset to Color_ignore)
+                       color_bg = selected && sel ? Color_selection : 
Color_background;
+               else
+                       // This inset has no own color, but inherits a color
+                       color_bg.baseColor = background_color.baseColor;
        }
+       
+
+       return color_bg;
 }
ÿþIndex: src/Changes.cpp

===================================================================

--- src/Changes.cpp (revision 28166)

+++ src/Changes.cpp (working copy)

...@@ -74,6 +74,10 ...@@

                    color = 
Color_changedtextauthor5;

                    break;

      }

+

+     if (deleted())

+            color.mergeColor = Color_white;

+

      return color;

 }

Reply via email to