From 43eb84bc466f9a3afba8d393d9c62d02b6c18621 Mon Sep 17 00:00:00 2001 From: Maurizio Monge Date: Sat, 14 Jul 2007 20:31:20 +0200 Subject: [PATCH] Added support for loading static values (non size-depent) from lua, cached only once. --- src/chesstable.cpp | 6 ++---- src/pixmaploader.cpp | 44 ++++++++++++++++++++++++++++++++++++-------- src/pixmaploader.h | 4 ++++ 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/chesstable.cpp b/src/chesstable.cpp index f3d95b4..23e8fa9 100644 --- a/src/chesstable.cpp +++ b/src/chesstable.cpp @@ -81,10 +81,8 @@ void ChessTable::settingsChanged() { if(m_wallpaper) delete m_wallpaper; - bool was0 = m_board->squareSize() == 0; - if(was0) m_board->tagsLoader()->setSize(1); - QPixmap bg = m_board->tagsLoader()->operator()("wallpaper"); - if(was0) m_board->tagsLoader()->setSize(0); + + QPixmap bg = m_board->tagsLoader()->getStaticValue("wallpaper"); if(!bg.isNull()) { std::cout << "Size is " << bg.size().width() << " "<< bg.size().height() << std::endl; m_wallpaper = new KGameCanvasTiledPixmap(bg, QSize(), QPoint(), false, this); diff --git a/src/pixmaploader.cpp b/src/pixmaploader.cpp index b2bfcc7..68d11c8 100644 --- a/src/pixmaploader.cpp +++ b/src/pixmaploader.cpp @@ -41,6 +41,7 @@ void PixmapLoader::flush() { /* unref the size */ if(m_size) m_loader->unrefSize(m_size); + m_loader->unrefSize(0); /* unref the loader, and possibly destroy it */ if(!--m_loader->m_ref_count) { @@ -62,6 +63,9 @@ void PixmapLoader::setBasePath(const QString& base) { } void PixmapLoader::setSize(int s) { + if(s == m_size) + return; + if(m_loader) { if(s) m_loader->refSize(s); @@ -76,15 +80,18 @@ void PixmapLoader::initialize() { return; /* try to get a loader */ - if(s_loaders.count(m_base)) - m_loader = s_loaders[m_base]; + ThemeLoadersCache::iterator it = s_loaders.find(m_base); + if(it != s_loaders.end()) + m_loader = it->second; else { m_loader = new ThemeLoader(m_base); s_loaders[m_base] = m_loader; } m_loader->m_ref_count++; - m_loader->refSize(m_size); + if(m_size) + m_loader->refSize(m_size); + m_loader->refSize(0); } template @@ -100,9 +107,30 @@ T PixmapLoader::getValue(const QString& id) { template QPixmap PixmapLoader::getValue(const QString& /*id*/); template Loader::PixmapOrMap PixmapLoader::getValue(const QString& /*id*/); -template Loader::Glyph PixmapLoader::getValue(const QString& /*id*/); -template double PixmapLoader::getValue(const QString& /*id*/); +template Loader::Glyph PixmapLoader::getValue(const QString& /*id*/); +template double PixmapLoader::getValue(const QString& /*id*/); template QPointF PixmapLoader::getValue(const QString& /*id*/); -template QRectF PixmapLoader::getValue(const QString& /*id*/); -template QBrush PixmapLoader::getValue(const QString& /*id*/); -template QColor PixmapLoader::getValue(const QString& /*id*/); +template QRectF PixmapLoader::getValue(const QString& /*id*/); +template QBrush PixmapLoader::getValue(const QString& /*id*/); +template QColor PixmapLoader::getValue(const QString& /*id*/); + + +template +T PixmapLoader::getStaticValue(const QString& id) { + if(m_base.isEmpty()) + return T(); + + if(!m_loader) + initialize(); + + return m_loader->getValue(id, 0); +} + +template QPixmap PixmapLoader::getStaticValue(const QString& /*id*/); +template Loader::PixmapOrMap PixmapLoader::getStaticValue(const QString& /*id*/); +template Loader::Glyph PixmapLoader::getStaticValue(const QString& /*id*/); +template double PixmapLoader::getStaticValue(const QString& /*id*/); +template QPointF PixmapLoader::getStaticValue(const QString& /*id*/); +template QRectF PixmapLoader::getStaticValue(const QString& /*id*/); +template QBrush PixmapLoader::getStaticValue(const QString& /*id*/); +template QColor PixmapLoader::getStaticValue(const QString& /*id*/); diff --git a/src/pixmaploader.h b/src/pixmaploader.h index db4cb31..83fd503 100644 --- a/src/pixmaploader.h +++ b/src/pixmaploader.h @@ -76,6 +76,10 @@ public: /** returns a value */ template T getValue(const QString& id); + + /** returns a static value (not depending on the size) */ + template + T getStaticValue(const QString& id); }; #endif // PIXMAPLOADER_H -- 2.11.4.GIT