author | zecke <zecke> | 2004-12-26 13:40:21 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-12-26 13:40:21 (UTC) |
commit | 99b055b572f64f180751b3a43440796d1bf9fc4f (patch) (side-by-side diff) | |
tree | 2caf1b3d3e9ecec68d616880d4a354033574b8c0 /library | |
parent | d8f38f36ad533f93d46c8ff883c6b42f15c96c28 (diff) | |
download | opie-99b055b572f64f180751b3a43440796d1bf9fc4f.zip opie-99b055b572f64f180751b3a43440796d1bf9fc4f.tar.gz opie-99b055b572f64f180751b3a43440796d1bf9fc4f.tar.bz2 |
Merge the way we insert Images into the PixmapCache
-rw-r--r-- | library/resource.cpp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/library/resource.cpp b/library/resource.cpp index cfa0d26..43fdc60 100644 --- a/library/resource.cpp +++ b/library/resource.cpp @@ -17,100 +17,125 @@ ** not clear to you. ** **********************************************************************/ #define QTOPIA_INTERNAL_MIMEEXT #include <qpe/qpeapplication.h> #include "resource.h" #include "mimetype.h" #include <qdir.h> #include <qpixmapcache.h> // this namespace is just a workaround for a gcc bug // gcc exports inline functions in the generated file // inlinepics_p.h namespace { #include "inlinepics_p.h" } static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET"); /*! \class Resource resource.h \brief The Resource class provides access to named resources. The resources may be provided from files or other sources. The allSounds() function returns a list of all the sounds available. A particular sound can be searched for using findSound(). Images can be loaded with loadImage(), loadPixmap(), loadBitmap() and loadIconSet(). \ingroup qtopiaemb */ /*! \fn Resource::Resource() \internal */ /*! Returns the QPixmap called \a pix. You should avoid including any filename type extension (e.g. .png, .xpm). */ QPixmap Resource::loadPixmap( const QString &pix ) { QPixmap pm; - QString key="QPE_"+pix; - if ( !QPixmapCache::find(key,pm) ) { - pm.convertFromImage(loadImage(pix)); - QPixmapCache::insert(key,pm); + + // Give the pixmaps some kind of namespace in the pixmapcache + int index = pix.find('/'); + QString appName1 = qApp->argv()[0]; + appName1 = appName1.replace(QRegExp(".*/"),""); + QString appName2 = pix.left(index); + + if ( appName2 == "" || appName2 == pix || appName2 == "icons" ) + appName2 = "Global"; + + QString appKey1 = "_QPE_" + appName1 + "_" + pix; + QString appKey2 = "_QPE_" + appName2 + "_" + pix.mid(index+1); + + if ( !QPixmapCache::find(appKey1, pm) ) { + if ( !QPixmapCache::find(appKey2, pm) ) { + QImage img; + QString f = findPixmap( pix ); + if ( !f.isEmpty() ) { + img.load(f); + if ( !img.isNull() ) { + pm.convertFromImage(img); + if ( f.contains(appName1) ) { + QPixmapCache::insert( appKey1, pm); + } else { + QPixmapCache::insert( appKey2, pm); + } + } + } + } } return pm; } /*! Returns the QBitmap called \a pix. You should avoid including any filename type extension (e.g. .png, .xpm). */ QBitmap Resource::loadBitmap( const QString &pix ) { QBitmap bm; bm = loadPixmap(pix); return bm; } /*! Returns the filename of a pixmap called \a pix. You should avoid including any filename type extension (e.g. .png, .xpm). Normally you will use loadPixmap() rather than this function. */ QString Resource::findPixmap( const QString &pix ) { QString picsPath = QPEApplication::qpeDir() + "pics/"; QString f; // Common case optimizations... f = picsPath + pix + ".png"; if ( QFile( f ).exists() ) return f; f = picsPath + pix + ".xpm"; if ( QFile( f ).exists() ) return f; // All formats... QStrList fileFormats = QImageIO::inputFormats(); QString ff = fileFormats.first(); while ( fileFormats.current() ) { QStringList exts = MimeType("image/"+ff.lower()).extensions(); for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { QString f = picsPath + pix + "." + *it; if ( QFile(f).exists() ) return f; } ff = fileFormats.next(); } |