Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'CachedImage (./kdelibs/khtml/misc/loader.h:183)
class CachedImage : public QObject, public CachedObject
{
Q_OBJECT
public:
CachedImage(const DOM::DOMString &url, const DOM::DOMString &baseURL);
virtual ~CachedImage();
const QPixmap &pixmap() const;
virtual void ref(CachedObjectClient *consumer);
virtual void deref(CachedObjectClient *consumer);
virtual void data( QBuffer &buffer, bool eof );
virtual void error( int err, const char *text );
/**
* tell the CachedObjectClient's, that the image is ready.
* if o = 0 notify all clients
*/
void notify(CachedObjectClient *c = 0);
virtual bool isImage() const { return true; }
void load();
public slots:
/**
* gets called, whenever a QMovie changes frame
*/
void movieUpdated( const QRect &rect );
public:
QPixmap *p;
QMovie *m;
protected:
void clear();
int width;
int height;
// Is the name of the movie format type
const char* formatType;
// Is set if movie format type ( incremental/animation) was checked
bool typeChecked;
bool gotFrame;
ImageSource* imgSource;
DOM::DOMString m_baseURL;
};
/**
* @internal
*/
kdelibs'CachedImage::CachedImage() (./kdelibs/khtml/misc/loader.cpp:250)
CachedImage::CachedImage(const DOMString &url, const DOMString &baseURL)
: QObject(), CachedObject(url, Image)
{
p = 0;
m = 0;
typeChecked = false;
formatType = 0;
m_status = Unknown;
m_size = 0;
imgSource = 0;
gotFrame = false;
m_baseURL = baseURL;
if ( Cache::autoloadImages() )
load();
}
kdelibs'CachedImage::~CachedImage() (./kdelibs/khtml/misc/loader.cpp:267)
CachedImage::~CachedImage()
{
if( m ) delete m;
if( p ) delete p;
//kdDebug( 6060 ) << "CachedImage::~CachedImage() " << url().string() << endl;
}
kdelibs'CachedImage::ref() (./kdelibs/khtml/misc/loader.cpp:274)
void CachedImage::ref( CachedObjectClient *c )
{
// make sure we don't get it twice...
m_clients.remove(c);
m_clients.append(c);
if( m_status != Pending || m )
notify( c );
}
kdelibs'CachedImage::deref() (./kdelibs/khtml/misc/loader.cpp:284)
void CachedImage::deref( CachedObjectClient *c )
{
m_clients.remove( c );
if(m && m_clients.isEmpty() && m->running())
m->pause();
if ( m_clients.count() == 0 && m_free )
delete this;
}
kdelibs'CachedImage::pixmap() (./kdelibs/khtml/misc/loader.cpp:294)
const QPixmap &CachedImage::pixmap() const
{
return m ? m->framePixmap() : ( p ? *p : *Cache::nullPixmap );
}
kdelibs'CachedImage::notify() (./kdelibs/khtml/misc/loader.cpp:299)
void CachedImage::notify( CachedObjectClient *c )
{
//kdDebug( 6060 ) << "Cache::notify()" << endl;
if ( m )
{
if(m->finished())
m->restart();
if(m->paused())
m->unpause();
}
if( c )
{
// sanity check...
if( m_clients.find( c ) == -1 )
m_clients.append( c );
if ( m )
c->setPixmap( m->framePixmap() );
else if ( p != 0 && !p->isNull() )
c->setPixmap( *p );
return;
}
// notify all objects in our list...
QPixmap pixmap;
if ( m )
pixmap = m->framePixmap();
else if ( p != 0 && !p->isNull() )
pixmap = *p;
if ( !pixmap.isNull() )
{
CachedObjectClient *c;
for ( c = m_clients.first(); c != 0; c = m_clients.next() )
c->setPixmap( pixmap );
}
}
kdelibs'CachedImage::movieUpdated() (./kdelibs/khtml/misc/loader.cpp:341)
void CachedImage::movieUpdated( const QRect & )
{
//kdDebug( 6060 ) << "Cache::movieUpdated()" << endl;
QPixmap pixmap = m->framePixmap();
CachedObjectClient *c;
for ( c = m_clients.first(); c != 0; c = m_clients.next() )
c->setPixmap( pixmap );
}
kdelibs'CachedImage::clear() (./kdelibs/khtml/misc/loader.cpp:350)
void CachedImage::clear()
{
if( m ) {
delete m;
m = 0;
}
if( p ) {
delete p;
p = 0;
}
formatType = 0;
typeChecked = false;
m_size = 0;
// No need to delete imageSource - QMovie does it for us
imgSource = 0;
gotFrame = false;
}
kdelibs'CachedImage::data() (./kdelibs/khtml/misc/loader.cpp:371)
void CachedImage::data ( QBuffer &_buffer, bool eof )
{
//kdDebug( 6060 ) << "in CachedImage::data()" << endl;
if ( !typeChecked )
{
clear();
formatType = QImageDecoder::formatName( (const uchar*)_buffer.buffer().data(), _buffer.size());
typeChecked = true;
if ( formatType ) // movie format exists
{
imgSource = new ImageSource( _buffer.buffer() );
m = new QMovie( imgSource );
m->connectUpdate( this, SLOT( movieUpdated( const QRect &) ));
gotFrame = false;
if(eof) computeStatus();
return;
}
}
if ( !eof )
{
if ( imgSource )
imgSource->maybeReady();
return;
}
if( !formatType )
{
p = new QPixmap();
p->loadFromData( _buffer.buffer() );
// set size of image.
if( p && !p->isNull() )
m_size = p->width() * p->height() * p->depth() / 8;
notify(); // Notify only if we have a pixmap. Movies notifies itself via movieUpdated.
}
else
{
m_size = _buffer.size();
if ( imgSource )
{
imgSource->setEOF( true );
imgSource->maybeReady();
}
}
computeStatus();
return;
}
kdelibs'CachedImage::error() (./kdelibs/khtml/misc/loader.cpp:423)
void CachedImage::error( int /*err*/, const char */*text*/ )
{
p = 0;
notify();
}
kdelibs'CachedImage::load() (./kdelibs/khtml/misc/loader.cpp:430)
void CachedImage::load()
{
Cache::loader()->load(this, m_baseURL, true);
}
// ------------------------------------------------------------------------------------------