]> git.lyx.org Git - features.git/commitdiff
simplify color cache code
authorAndré Pönitz <poenitz@gmx.net>
Fri, 23 May 2008 20:29:48 +0000 (20:29 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 23 May 2008 20:29:48 +0000 (20:29 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24920 a592a061-630c-0410-9148-cb99ea01b6c8

src/Color.cpp
src/frontends/qt4/ColorCache.cpp
src/frontends/qt4/ColorCache.h

index 349bf067b0d3523d6a2239b055cdcbcd38a333b0..47e251d14b7ee2fa2e9c04c07713e054f900950d 100644 (file)
@@ -87,6 +87,10 @@ RGBColor rgbFromHexName(string const & x11hexname)
 
 ColorSet::ColorSet()
 {
+       char const * grey40 = "#666666";
+       char const * grey60 = "#999999";
+       char const * grey80 = "#cccccc";
+       //char const * grey90 = "#e5e5e5";
        //  ColorCode, gui, latex, x11, lyx
        static ColorEntry const items[] = {
        { Color_none, N_("none"), "none", "black", "none" },
@@ -106,9 +110,9 @@ ColorSet::ColorSet()
                "selectiontext", "black", "selectiontext" },
        { Color_latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
        { Color_inlinecompletion, N_("inline completion"),
-               "inlinecompletion", "grey60", "inlinecompletion" },
+               "inlinecompletion", grey60, "inlinecompletion" },
        { Color_nonunique_inlinecompletion, N_("non-unique inline completion"),
-               "nonuniqueinlinecompletion", "grey80", "nonuniqueinlinecompletion" },
+               "nonuniqueinlinecompletion", grey80, "nonuniqueinlinecompletion" },
        { Color_preview, N_("previewed snippet"), "preview", "black", "preview" },
        { Color_notelabel, N_("note label"), "note", "yellow", "note" },
        { Color_notebg, N_("note background"), "notebg", "yellow", "notebg" },
@@ -141,12 +145,12 @@ ColorSet::ColorSet()
        { Color_mathmacrolabel, N_("Math macro label"), "mathmacrolabel", "#a19992", "mathmacrolabel" },
        { Color_mathmacroframe, N_("Math macro frame"), "mathmacroframe", "#ede2d8", "mathmacroframe" },
        { Color_mathmacroblend, N_("Math macro blended out"), "mathmacroblend", "black", "mathmacroblend" },
-       { Color_mathmacrooldarg, N_("Math macro old parameter"), "mathmacrooldarg", "grey80", "mathmacrooldarg" },
+       { Color_mathmacrooldarg, N_("Math macro old parameter"), "mathmacrooldarg", grey80, "mathmacrooldarg" },
        { Color_mathmacronewarg, N_("Math macro new parameter"), "mathmacronewarg", "black", "mathmacronewarg" },
        { Color_captionframe, N_("caption frame"), "captionframe", "DarkRed", "captionframe" },
        { Color_collapsable, N_("collapsable inset text"), "collapsable", "DarkRed", "collapsable" },
        { Color_collapsableframe, N_("collapsable inset frame"), "collapsableframe", "IndianRed", "collapsableframe" },
-       { Color_insetbg, N_("inset background"), "insetbg", "grey80", "insetbg" },
+       { Color_insetbg, N_("inset background"), "insetbg", grey80, "insetbg" },
        { Color_insetframe, N_("inset frame"), "insetframe", "IndianRed", "insetframe" },
        { Color_error, N_("LaTeX error"), "error", "Red", "error" },
        { Color_eolmarker, N_("end-of-line marker"), "eolmarker", "Brown", "eolmarker" },
@@ -159,7 +163,7 @@ ColorSet::ColorSet()
        { Color_tabularline, N_("table line"), "tabularline", "black", "tabularline" },
        { Color_tabularonoffline, N_("table on/off line"), "tabularonoffline",
             "LightSteelBlue", "tabularonoffline" },
-       { Color_bottomarea, N_("bottom area"), "bottomarea", "grey40", "bottomarea" },
+       { Color_bottomarea, N_("bottom area"), "bottomarea", grey40, "bottomarea" },
        { Color_newpage, N_("new page"), "newpage", "Blue", "newpage" },
        { Color_pagebreak, N_("page break / line break"), "pagebreak", "RoyalBlue", "pagebreak" },
        { Color_buttonframe, N_("frame of button"), "buttonframe", "#dcd2c8", "buttonframe" },
index bfccf7a6f60a9a8473055f042a1bb270ab5805aa..16c4497eab66ea07afa86bce84cb34be57b26724 100644 (file)
 
 namespace lyx {
 
-const QColor grey40(0x66, 0x66, 0x66);
-const QColor grey60(0x99, 0x99, 0x99);
-const QColor grey80(0xcc, 0xcc, 0xcc);
-const QColor grey90(0xe5, 0xe5, 0xe5);
-const QColor none = Qt::black;
-
-QColor const & ColorCache::get(ColorCode col) const
-{
-       lcolor_map::const_iterator cit = colormap.find(col);
-       if (cit != colormap.end())
-               return cit->second;
-
-       if (lcolor.getX11Name(col) == "grey40")
-               colormap[col] = grey40;
-       else if (lcolor.getX11Name(col) == "grey60")
-               colormap[col] = grey60;
-       else if (lcolor.getX11Name(col) == "grey80")
-               colormap[col] = grey80;
-       else if (lcolor.getX11Name(col) == "grey90")
-               colormap[col] = grey90;
-       else if (lcolor.getX11Name(col) == "none")
-               colormap[col] = none;
-       else
-               colormap[col] = QColor(lcolor.getX11Name(col).c_str());
-
-       return colormap[col];
-}
-
-
-void ColorCache::clear()
+void ColorCache::init()
 {
-       colormap.clear();
+       for (int col = 0; col <= Color_ignore; ++col)
+               lcolors_[col] = QColor(lcolor.getX11Name(ColorCode(col)).c_str());
 }
 
 
index 4ac490501160c2f244a2a67167ee2235245d2593..54768f612443b21e98ece648f5b113a139088e16 100644 (file)
 
 #include <QColor>
 
-#include <map>
-
 namespace lyx {
 
 struct RGBColor;
 
-
-// FIXME: use a fixed-size array not a map ?
-
 /**
  * Cache from Color to QColor.
  */
-class ColorCache {
+class ColorCache
+{
 public:
-       ColorCache() {}
+       ColorCache() { init(); }
 
        /// get the given color
-       QColor const & get(ColorCode color) const;
+       QColor const & get(ColorCode color) const { return lcolors_[color]; }
 
        /// clear all colors
-       void clear();
+       void clear() { init(); }
 
 private:
-       typedef std::map<ColorCode, QColor> lcolor_map;
-
-       mutable lcolor_map colormap;
+       ///
+       void init();
+       ///
+       QColor lcolors_[Color_ignore + 1];
 };
 
 ///