From bbb9cb65e779ac3d1c563df1d44dab2236a7c1fd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 23 May 2008 20:29:48 +0000 Subject: [PATCH 1/1] simplify color cache code git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24920 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Color.cpp | 14 ++++++++----- src/frontends/qt4/ColorCache.cpp | 34 +++----------------------------- src/frontends/qt4/ColorCache.h | 21 +++++++++----------- 3 files changed, 21 insertions(+), 48 deletions(-) diff --git a/src/Color.cpp b/src/Color.cpp index 349bf067b0..47e251d14b 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -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" }, diff --git a/src/frontends/qt4/ColorCache.cpp b/src/frontends/qt4/ColorCache.cpp index bfccf7a6f6..16c4497eab 100644 --- a/src/frontends/qt4/ColorCache.cpp +++ b/src/frontends/qt4/ColorCache.cpp @@ -18,38 +18,10 @@ 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()); } diff --git a/src/frontends/qt4/ColorCache.h b/src/frontends/qt4/ColorCache.h index 4ac4905011..54768f6124 100644 --- a/src/frontends/qt4/ColorCache.h +++ b/src/frontends/qt4/ColorCache.h @@ -16,32 +16,29 @@ #include -#include - 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 lcolor_map; - - mutable lcolor_map colormap; + /// + void init(); + /// + QColor lcolors_[Color_ignore + 1]; }; /// -- 2.39.2