Exemple #1
0
QPixmap getIconPixmap( const char * pixmapName, int width, int height )
{
	if( width == -1 || height == -1 )
	{
		// Return cached pixmap
		QPixmap cached = s_pixmapCache.value( pixmapName );
		if( !cached.isNull() )
		{
			return cached;
		}

		// Or try to load it
		QList<QByteArray> formats = QImageReader::supportedImageFormats();
		QList<QString> candidates;
		QPixmap pixmap;
		QString name;
		int i;
		
		for ( i = 0; i < formats.size() && pixmap.isNull(); ++i )  
		{
			candidates << QString( pixmapName ) + "." + formats.at( i ).data();
		}

#ifdef PLUGIN_NAME
		for ( i = 0; i < candidates.size() && pixmap.isNull(); ++i )  {
			name = candidates.at( i );
			pixmap = QPixmap( "resources:plugins/" STRINGIFY( PLUGIN_NAME ) "_" + name );
		}
#endif
		for ( i = 0; i < candidates.size() && pixmap.isNull(); ++i )  {
			name = candidates.at( i );
			pixmap = QPixmap( "resources:" + name );
		}
		
		for ( i = 0; i < candidates.size() && pixmap.isNull(); ++i )  {
			name = candidates.at( i );
			const embed::descriptor & e = 
				findEmbeddedData( name.toUtf8().constData() );
			// found?
			if( name == e.name )
			{
				pixmap.loadFromData( e.data, e.size );
			}
		}
		
		// Fallback
		if( pixmap.isNull() )
		{
			pixmap = QPixmap( 1, 1 );
		}
		// Save to cache and return
		s_pixmapCache.insert( pixmapName, pixmap );
		return pixmap;
	}

	return getIconPixmap( pixmapName ).
		scaled( width, height, Qt::IgnoreAspectRatio,
			Qt::SmoothTransformation );
}
Exemple #2
0
QPixmap getIconPixmap( const char * _name, int _w, int _h )
{
    if( _w == -1 || _h == -1 )
    {
        // Return cached pixmap
        QPixmap cached = s_pixmapCache.value( _name );
        if( !cached.isNull() )
        {
            return cached;
        }

        // Or try to load it
        QList<QByteArray> formats =
            QImageReader::supportedImageFormats();
        QList<QString> candidates;
        QPixmap p;
        QString name;
        int i;

        for ( i = 0; i < formats.size() && p.isNull(); ++i )
        {
            candidates << QString( _name ) + "." + formats.at( i ).data();
        }

#ifdef PLUGIN_NAME
        for ( i = 0; i < candidates.size() && p.isNull(); ++i )  {
            name = candidates.at( i );
            p = QPixmap( configManager::inst()->artworkDir() + "plugins/" +
                         STRINGIFY( PLUGIN_NAME ) + "_" + name );
        }
#endif
        for ( i = 0; i < candidates.size() && p.isNull(); ++i )  {
            name = candidates.at( i );
            p = QPixmap( configManager::inst()->artworkDir() + name );
        }

        // nothing found, so look in default-artwork-dir
        for ( i = 0; i < candidates.size() && p.isNull(); ++i )  {
            name = candidates.at( i );
            p = QPixmap( configManager::inst()->defaultArtworkDir()
                         + name );
        }

        for ( i = 0; i < candidates.size() && p.isNull(); ++i )  {
            name = candidates.at( i );
            const embed::descriptor & e =
                findEmbeddedData( name.toUtf8().constData() );
            // found?
            if( QString( e.name ) == name )
            {
                p.loadFromData( e.data, e.size );
            }
        }

        // Fallback
        if(p.isNull())
        {
            p = QPixmap( 1, 1 );
        }
        // Save to cache and return
        s_pixmapCache.insert( _name, p );
        return p;

    }

    return getIconPixmap( _name ).
           scaled( _w, _h, Qt::IgnoreAspectRatio,
                   Qt::SmoothTransformation );
}