mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
lcolor cache
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7039 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
9dc8c48bf6
commit
94278f7be0
@ -1,3 +1,14 @@
|
||||
2003-05-24 John Levon <levon@movementarian.org>
|
||||
|
||||
* 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 <leeming@lyx.org>
|
||||
|
||||
compile fixes.
|
||||
|
@ -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 \
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "QLPainter.h"
|
||||
#include "QLImage.h"
|
||||
#include "qt_helpers.h"
|
||||
#include "lcolorcache.h"
|
||||
|
||||
#include <boost/scoped_array.hpp>
|
||||
|
||||
@ -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);
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "frnt_lang.h"
|
||||
#include "helper_funcs.h"
|
||||
#include "qt_helpers.h"
|
||||
#include "lcolorcache.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
@ -296,7 +297,7 @@ void QPrefs::apply()
|
||||
QColorItem * ci(static_cast<QColorItem*>(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()) {
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "QWorkArea.h"
|
||||
#include "qt_helpers.h"
|
||||
#include "lcolorcache.h"
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qevent.h>
|
||||
@ -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);
|
||||
|
36
src/frontends/qt2/lcolorcache.C
Normal file
36
src/frontends/qt2/lcolorcache.C
Normal file
@ -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();
|
||||
}
|
45
src/frontends/qt2/lcolorcache.h
Normal file
45
src/frontends/qt2/lcolorcache.h
Normal file
@ -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 <map>
|
||||
|
||||
#include "LColor.h"
|
||||
|
||||
#include <qcolor.h>
|
||||
|
||||
// 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::color, QColor> lcolor_map;
|
||||
|
||||
mutable lcolor_map colormap;
|
||||
};
|
||||
|
||||
/// singleton instance
|
||||
extern LColorCache lcolorcache;
|
||||
|
||||
#endif // LCOLORCACHE_H
|
@ -43,6 +43,7 @@
|
||||
#include "QLImage.h"
|
||||
#include "qfont_loader.h"
|
||||
#include "io_callback.h"
|
||||
#include "lcolorcache.h"
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qwidget.h>
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user