void GPSImageModel::slotThumbnailLoaded(const LoadingDescription& loadingDescription, const QPixmap& thumb) { if (thumb.isNull()) { return; } const QModelIndex currentIndex = indexFromUrl(QUrl::fromLocalFile(loadingDescription.filePath)); if (currentIndex.isValid()) { QPersistentModelIndex goodIndex(currentIndex); emit(signalThumbnailForIndexAvailable(goodIndex, thumb.copy(1, 1, thumb.size().width()-2, thumb.size().height()-2))); } }
void KipiImageModel::slotThumbnailFromInterface(const KUrl& url, const QPixmap& pixmap) { kDebug()<<url<<pixmap.size(); if (pixmap.isNull()) return; const int effectiveSize = qMax(pixmap.size().width(), pixmap.size().height()); // find the item corresponding to the URL: const QModelIndex imageIndex = indexFromUrl(url); kDebug()<<url<<imageIndex.isValid(); if (imageIndex.isValid()) { // this is tricky: some kipi interfaces return pixmaps at the requested size, others do not. // therefore we check whether a pixmap of this size has been requested. If so, we send it on. // If a pixmap of this size has not been requested, we rescale it to fulfill all other requests. // index, size QList<QPair<int, int> > openRequests; for (int i=0; i<d->requestedPixmaps.count(); ++i) { if (d->requestedPixmaps.at(i).first==imageIndex) { const int requestedSize = d->requestedPixmaps.at(i).second; if (requestedSize==effectiveSize) { // match, send it out. d->requestedPixmaps.removeAt(i); kDebug()<<i; // save the pixmap: const QString itemKeyString = CacheKeyFromSizeAndUrl(effectiveSize, url); d->pixmapCache->insert(itemKeyString, pixmap); emit(signalThumbnailForIndexAvailable(imageIndex, pixmap)); return; } else { openRequests << QPair<int, int>(i, requestedSize); } } } // the pixmap was not requested at this size, fulfill all requests: for (int i=openRequests.count()-1; i>=0; --i) { const int targetSize = openRequests.at(i).second; d->requestedPixmaps.removeAt(openRequests.at(i).first); kDebug()<<i<<targetSize; QPixmap scaledPixmap = pixmap.scaled(targetSize, targetSize, Qt::KeepAspectRatio); // save the pixmap: const QString itemKeyString = CacheKeyFromSizeAndUrl(targetSize, url); d->pixmapCache->insert(itemKeyString, scaledPixmap); emit(signalThumbnailForIndexAvailable(imageIndex, scaledPixmap)); } } }