simplify color cache code

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24920 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2008-05-23 20:29:48 +00:00
parent fae43b38d0
commit bbb9cb65e7
3 changed files with 21 additions and 48 deletions

View 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" },

View File

@ -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
void ColorCache::init()
{
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()
{
colormap.clear();
for (int col = 0; col <= Color_ignore; ++col)
lcolors_[col] = QColor(lcolor.getX11Name(ColorCode(col)).c_str());
}

View File

@ -16,32 +16,29 @@
#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];
};
///