~ubuntu-app-review-contributors/ubuntu-app-reviews/limoo

« back to all changes in this revision

Viewing changes to imageprovider.cpp

  • Committer: App Bot
  • Date: 2012-06-12 12:26:24 UTC
  • Revision ID: appbot@holba.ch-20120612122624-yq0ueol26sxtovpm
initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "imageprovider.h"
 
2
 
 
3
#include <QHash>
 
4
#include <QPainter>
 
5
 
 
6
QHash<QString,QPixmap> provider_pixmap_hash;
 
7
 
 
8
ImageProvider::ImageProvider() :
 
9
    QDeclarativeImageProvider( QDeclarativeImageProvider::Pixmap )
 
10
{
 
11
}
 
12
 
 
13
QString ImageProvider::getId()
 
14
{
 
15
    static int id_pointer = -1;
 
16
    id_pointer++;
 
17
    return QString::number( id_pointer );
 
18
}
 
19
 
 
20
void ImageProvider::addPixmap( const QString & id , const QPixmap & pixmap )
 
21
{
 
22
    provider_pixmap_hash.insert( id , pixmap );
 
23
    if( pixmap.isNull() )
 
24
        provider_pixmap_hash.remove( id );
 
25
}
 
26
 
 
27
QPixmap ImageProvider::pixmap( const QString & id )
 
28
{
 
29
    return provider_pixmap_hash.value(id);
 
30
}
 
31
 
 
32
QPixmap ImageProvider::requestPixmap( const QString & id, QSize *size, const QSize & requestedSize )
 
33
{
 
34
    int width  = 22;
 
35
    int height = 22;
 
36
 
 
37
    if (size)
 
38
        *size = QSize(width, height);
 
39
 
 
40
    QPixmap pixmap = provider_pixmap_hash.value(id).scaled( requestedSize.width() > 0 ? requestedSize.width() : width,
 
41
                                                            requestedSize.height() > 0 ? requestedSize.height() : height,
 
42
                                                            Qt::KeepAspectRatio , Qt::FastTransformation );
 
43
 
 
44
    return pixmap;
 
45
}
 
46
 
 
47
ImageProvider::~ImageProvider()
 
48
{
 
49
}