From 94278f7be0553533f4a11f73998c3b58a0101fb3 Mon Sep 17 00:00:00 2001 From: John Levon Date: Sat, 24 May 2003 15:19:05 +0000 Subject: [PATCH] lcolor cache git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7039 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 11 ++++++++ src/frontends/qt2/Makefile.am | 1 + src/frontends/qt2/QLPainter.C | 7 ++--- src/frontends/qt2/QPrefs.C | 3 ++- src/frontends/qt2/QWorkArea.C | 3 ++- src/frontends/qt2/lcolorcache.C | 36 ++++++++++++++++++++++++++ src/frontends/qt2/lcolorcache.h | 45 +++++++++++++++++++++++++++++++++ src/frontends/qt2/lyx_gui.C | 7 ++--- 8 files changed, 105 insertions(+), 8 deletions(-) create mode 100644 src/frontends/qt2/lcolorcache.C create mode 100644 src/frontends/qt2/lcolorcache.h diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 0ce7139e2f..3dbb4bac2c 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,14 @@ +2003-05-24 John Levon + + * Makefile.am: + * lcolorcache.h: + * lcolorcache.C: add LColor::color -> QColor cache + + * QLPainter.C: + * QPrefs.C: + * QWorkArea.C: + * lyx_gui.C: use it + 2003-05-22 Angus Leeming compile fixes. diff --git a/src/frontends/qt2/Makefile.am b/src/frontends/qt2/Makefile.am index ad56368790..c8014104c7 100644 --- a/src/frontends/qt2/Makefile.am +++ b/src/frontends/qt2/Makefile.am @@ -69,6 +69,7 @@ libqt2_la_SOURCES = \ QtLyXView.h \ WorkAreaFactory.C \ lyx_gui.C \ + lcolorcache.h lcolorcache.C \ panelstack.h panelstack.C \ qcoloritem.h qcoloritem.C \ qfontexample.h qfontexample.C \ diff --git a/src/frontends/qt2/QLPainter.C b/src/frontends/qt2/QLPainter.C index 14b1ec9720..54fa7fb6bc 100644 --- a/src/frontends/qt2/QLPainter.C +++ b/src/frontends/qt2/QLPainter.C @@ -24,6 +24,7 @@ #include "QLPainter.h" #include "QLImage.h" #include "qt_helpers.h" +#include "lcolorcache.h" #include @@ -77,7 +78,7 @@ QPainter & QLPainter::setPen(LColor::color c, { QPen pen = qp_->pen(); - pen.setColor(toqstr(lcolor.getX11Name(c))); + pen.setColor(lcolorcache.get(c)); switch (ls) { case line_solid: pen.setStyle(QPen::SolidLine); break; @@ -149,7 +150,7 @@ Painter & QLPainter::fillRectangle(int x, int y, int w, int h, LColor::color col) { - qp_->fillRect(x, y, w, h, QColor(toqstr(lcolor.getX11Name(col)))); + qp_->fillRect(x, y, w, h, lcolorcache.get(col)); return *this; } @@ -168,7 +169,7 @@ Painter & QLPainter::fillPolygon(int const * xp, int const * yp, } setPen(col); - qp_->setBrush(toqstr(lcolor.getX11Name(col))); + qp_->setBrush(lcolorcache.get(col)); qp_->drawPolygon(QPointArray(np, points.get())); qp_->setBrush(Qt::NoBrush); diff --git a/src/frontends/qt2/QPrefs.C b/src/frontends/qt2/QPrefs.C index a4faff8e5e..6832c844fc 100644 --- a/src/frontends/qt2/QPrefs.C +++ b/src/frontends/qt2/QPrefs.C @@ -39,6 +39,7 @@ #include "frnt_lang.h" #include "helper_funcs.h" #include "qt_helpers.h" +#include "lcolorcache.h" #include "debug.h" #include @@ -296,7 +297,7 @@ void QPrefs::apply() QColorItem * ci(static_cast(ib)); LColor::color const col(dialog_->colors_[i]); - QColor const qcol(toqstr(lcolor.getX11Name(col))); + QColor const & qcol(lcolorcache.get(col)); // FIXME: dubious, but it's what xforms does if (qcol != ci->color()) { diff --git a/src/frontends/qt2/QWorkArea.C b/src/frontends/qt2/QWorkArea.C index cf6d6b311f..b5971a214a 100644 --- a/src/frontends/qt2/QWorkArea.C +++ b/src/frontends/qt2/QWorkArea.C @@ -21,6 +21,7 @@ #include "QWorkArea.h" #include "qt_helpers.h" +#include "lcolorcache.h" #include #include @@ -53,7 +54,7 @@ QWorkArea::QWorkArea(int, int, int, int) content_->show(); - content_->setBackgroundColor(toqstr(lcolor.getX11Name(LColor::background))); + content_->setBackgroundColor(lcolorcache.get(LColor::background)); QHBoxLayout * vl = new QHBoxLayout(this); vl->addWidget(content_, 5); diff --git a/src/frontends/qt2/lcolorcache.C b/src/frontends/qt2/lcolorcache.C new file mode 100644 index 0000000000..a7e4349e06 --- /dev/null +++ b/src/frontends/qt2/lcolorcache.C @@ -0,0 +1,36 @@ +/** + * \file lcolorcache.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * + * Full author contact details are available in file CREDITS + */ + +#include "lcolorcache.h" + +LColorCache lcolorcache; + + +LColorCache::LColorCache() +{ +} + + +QColor const & LColorCache::get(LColor::color col) const +{ + lcolor_map::const_iterator cit = colormap.find(col); + if (cit != colormap.end()) + return cit->second; + + QColor const qcol(lcolor.getX11Name(col).c_str()); + colormap[col] = qcol; + return colormap[col]; +} + + +void LColorCache::clear() +{ + colormap.clear(); +} diff --git a/src/frontends/qt2/lcolorcache.h b/src/frontends/qt2/lcolorcache.h new file mode 100644 index 0000000000..a4d8730267 --- /dev/null +++ b/src/frontends/qt2/lcolorcache.h @@ -0,0 +1,45 @@ +// -*- C++ -*- +/** + * \file lcolorcache.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * + * Full author contact details are available in file CREDITS + */ + +#ifndef LCOLORCACHE_H +#define LCOLORCACHE_H + +#include + +#include "LColor.h" + +#include + +// FIXME: use a fixed-size array not a map ? + +/** + * Cache from LColor to QColor. + */ +class LColorCache { +public: + LColorCache(); + + /// get the given color + QColor const & get(LColor::color color) const; + + /// clear all colors + void clear(); + +private: + typedef std::map lcolor_map; + + mutable lcolor_map colormap; +}; + +/// singleton instance +extern LColorCache lcolorcache; + +#endif // LCOLORCACHE_H diff --git a/src/frontends/qt2/lyx_gui.C b/src/frontends/qt2/lyx_gui.C index 4a754dea7b..870ae4c66c 100644 --- a/src/frontends/qt2/lyx_gui.C +++ b/src/frontends/qt2/lyx_gui.C @@ -43,6 +43,7 @@ #include "QLImage.h" #include "qfont_loader.h" #include "io_callback.h" +#include "lcolorcache.h" #include #include @@ -208,14 +209,14 @@ FuncStatus getStatus(FuncRequest const & ev) string const hexname(LColor::color col) { - QColor color(toqstr(lcolor.getX11Name(col))); - return ltrim(fromqstr(color.name()), "#"); + return ltrim(fromqstr(lcolorcache.get(col).name()), "#"); } void update_color(LColor::color) { - // no need + // FIXME: Bleh, can't we just clear them all at once ? + lcolorcache.clear(); } -- 2.39.2