Source Code (Use browser search to find items of interest.)

Class Index

kpresenter'KPPixmapCollection (./koffice/kpresenter/kppixmapcollection.h:114)

class KPPixmapCollection
{
public:
    struct Key
    {
	Key()
	    : dataKey(), size( orig_size )
	{}

	Key( const KPPixmapDataCollection::Key &dk, const QSize &sz )
	    : dataKey( dk ), size( sz )
	{}

	Key( const Key &key )
	    : dataKey( key.dataKey ), size( key.size )
	{}

	Key &operator=( const Key &key ) {
	    dataKey = key.dataKey;
	    size = key.size;
	    return *this;
	}

	bool operator==( const Key &key ) const {
	    return ( dataKey == key.dataKey &&
		     size == key.size );
	}

	bool operator<( const Key &key ) const {
	    QString s1( key.toString() );
	    QString s2( toString() );
	    return s1 < s2;
	}

	QString toString() const {
	    QString s = QString( "%1_%2_%3" ).arg( dataKey.toString() ).arg( size.width() ).arg( size.height() );
	    return QString( s );
	}

	KPPixmapDataCollection::Key dataKey;
	QSize size;
    };

    KPPixmapCollection()
	: allowChangeRef( TRUE )
    { date = QDate::currentDate(); time = QTime::currentTime(); }
    ~KPPixmapCollection();

    QPixmap* findPixmap( Key &key );

    void addRef( const Key &key );
    void removeRef( const Key &key );

    KPPixmapDataCollection &getPixmapDataCollection() { return dataCollection; }

    QDate tmpDate() { return date; }
    QTime tmpTime() { return time; }

    void setAllowChangeRef( bool b )
    { allowChangeRef = b ; }

protected:
    QPixmap *loadPixmap( const QImage &image, const Key &key, bool insert );

    QMap< Key, QPixmap > pixmaps;
    QMap< Key, int > refs;
    KPPixmapDataCollection dataCollection;

    QDate date;
    QTime time;

    bool allowChangeRef;

};


kpresenter'KPPixmapCollection::~KPPixmapCollection() (./koffice/kpresenter/kppixmapcollection.cc:145)

KPPixmapCollection::~KPPixmapCollection()
{
    pixmaps.clear();
}

/*================================================================*/

kpresenter'KPPixmapCollection::findPixmap() (./koffice/kpresenter/kppixmapcollection.cc:151)

QPixmap* KPPixmapCollection::findPixmap( Key &key )
{
    //printf( "	 KPPixmapCollection::findPixmap( key = %s )\n", key.toString().latin1() );

    if ( key.size == orig_size ) {
	QImage *i = dataCollection.findPixmapData( key.dataKey );
	if ( i )
	    key.size = i->size();
	else {
	    QImage img( key.dataKey.filename );
	    key.size = img.size();
	}
    }

    //printf( "	   key = %s )\n", key.toString().latin1() );

    QMap< Key, QPixmap >::Iterator it = pixmaps.begin();
    it = pixmaps.find( key );

    if ( it != pixmaps.end() && it.key() == key ) {
	//printf( "    pixmap found in pixmaps: %s\n", it.key().toString().latin1() );
	addRef( key );
	return &it.data();
    } else {
	QImage *img = dataCollection.findPixmapData( key.dataKey );
	if ( img ) {
	    //printf( "	   pixmap found in data collection: %s\n", key.dataKey.toString().latin1() );
	    dataCollection.addRef( key.dataKey );
	    return loadPixmap( *img, key, true );
	} else {
	    QImage image( key.dataKey.filename );

	    //printf( "	   pixmap not found anywhere\n" );
	    dataCollection.insertPixmapData( key.dataKey, image );
	    return loadPixmap( image, key, true );
	}
    }
}

/*================================================================*/

kpresenter'KPPixmapCollection::addRef() (./koffice/kpresenter/kppixmapcollection.cc:191)

void KPPixmapCollection::addRef( const Key &key )
{
    if ( !allowChangeRef )
	return;

//     printf( "	 KPPixmapCollection::addRef( key = %s )\n", key.toString().latin1() );

    if ( refs.contains( key ) ) {
	int ref = refs[ key ];
	refs[ key ] = ++ref;
// 	printf( "    ref: %d\n", refs[ key ] );
    }

    dataCollection.addRef( key.dataKey );
}

/*================================================================*/

kpresenter'KPPixmapCollection::removeRef() (./koffice/kpresenter/kppixmapcollection.cc:208)

void KPPixmapCollection::removeRef( const Key &key )
{
    if ( !allowChangeRef )
	return;

//     printf( "	 KPPixmapCollection::removeRef( key = %s )\n", key.toString().latin1() );

    if ( refs.contains( key ) ) {
	int ref = refs[ key ];
	refs[ key ] = --ref;
// 	printf( "    ref: %d\n", refs[ key ] );

	if ( ref == 0 ) {
	    refs.remove( key );
	    pixmaps.remove( key );
// 	    printf( "	   remove: %s\n", key.toString().latin1() );
	}
    }

    dataCollection.removeRef( key.dataKey );
}

/*================================================================*/

kpresenter'KPPixmapCollection::loadPixmap() (./koffice/kpresenter/kppixmapcollection.cc:231)

QPixmap *KPPixmapCollection::loadPixmap( const QImage &image, const Key &key, bool insert )
{
    //printf( "	 KPPixmapCollection::loadPixmap( image = %d, key = %s, insert = %d )\n",
    //	      !image.isNull(), key.toString().latin1(), insert );

    QPixmap *pixmap = new QPixmap;
    pixmap->convertFromImage( image );

    if ( !pixmap->isNull() ) {
	QSize size = key.size;
	if ( size != pixmap->size() && size != orig_size && pixmap->width() != 0 && pixmap->height() != 0 ) {
	    QWMatrix m;
	    m.scale( static_cast<float>( size.width() ) / static_cast<float>( pixmap->width() ),
		     static_cast<float>( size.height() ) / static_cast<float>( pixmap->height() ) );
	    *pixmap = pixmap->xForm( m );
	}
    }

    if ( insert ) {
	pixmaps.insert( Key( key ), *pixmap );
	int ref = 1;
	refs.insert( Key( key ), ref );
	return pixmap;
	return &pixmaps[ key ];
    }

    return pixmap;
}

/*================================================================*/