src/gui/image/qpixmap.cpp
branchRCL_3
changeset 4 3b1da2848fc7
parent 3 41300fa6a67c
child 8 3f74d0d4af4c
equal deleted inserted replaced
3:41300fa6a67c 4:3b1da2848fc7
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
   355 QPixmap QPixmap::copy(const QRect &rect) const
   355 QPixmap QPixmap::copy(const QRect &rect) const
   356 {
   356 {
   357     if (isNull())
   357     if (isNull())
   358         return QPixmap();
   358         return QPixmap();
   359 
   359 
   360     const QRect r = rect.isEmpty() ? QRect(0, 0, width(), height()) : rect;
   360     QRect r(0, 0, width(), height());
       
   361     if (!rect.isEmpty())
       
   362         r = r.intersected(rect);
   361 
   363 
   362     QPixmapData *d = data->createCompatiblePixmapData();
   364     QPixmapData *d = data->createCompatiblePixmapData();
   363     d->copy(data.data(), r);
   365     d->copy(data.data(), r);
   364     return QPixmap(d);
   366     return QPixmap(d);
   365 }
   367 }
   829         QString::number(info.size()) + QLatin1Char('_') + QString::number(data ? data->pixelType() : QPixmapData::PixmapType);
   831         QString::number(info.size()) + QLatin1Char('_') + QString::number(data ? data->pixelType() : QPixmapData::PixmapType);
   830 
   832 
   831     if (QPixmapCache::find(key, *this))
   833     if (QPixmapCache::find(key, *this))
   832         return true;
   834         return true;
   833 
   835 
   834     QPixmapData *tmp = QPixmapData::create(0, 0, QPixmapData::PixmapType);
   836     bool ok;
   835     if (tmp->fromFile(fileName, format, flags)) {
   837 
   836         data = tmp;
   838     if (data) {
       
   839         ok = data->fromFile(fileName, format, flags);
       
   840     } else {
       
   841         QScopedPointer<QPixmapData> tmp(QPixmapData::create(0, 0, QPixmapData::PixmapType));
       
   842         ok = tmp->fromFile(fileName, format, flags);
       
   843         if (ok)
       
   844             data = tmp.take();
       
   845     }
       
   846 
       
   847     if (ok)
   837         QPixmapCache::insert(key, *this);
   848         QPixmapCache::insert(key, *this);
   838         return true;
   849 
   839     }
   850     return ok;
   840     delete tmp;
       
   841     return false;
       
   842 }
   851 }
   843 
   852 
   844 /*!
   853 /*!
   845     \fn bool QPixmap::loadFromData(const uchar *data, uint len, const char *format, Qt::ImageConversionFlags flags)
   854     \fn bool QPixmap::loadFromData(const uchar *data, uint len, const char *format, Qt::ImageConversionFlags flags)
   846 
   855