Beispiel #1
0
void ThumbnailLoader::run()
{
    ThumbnailRequestHandler requestHandler( this );

    {
        QMutexLocker locker( &m_initMutex );

        m_requestHandler = &requestHandler;

        connect( &requestHandler, SIGNAL(thumbnailLoaded(QImage)),
                 this           , SLOT  (thumbnailLoaded(QImage)) );

        m_initCondition.wakeAll();
    }

    exec();

    QMutexLocker locker( &m_initMutex );

    disconnect( &requestHandler );

    m_requestHandler = 0;

    m_initCondition.wakeAll();
}
QVariant ThumbnailModel::data(const QModelIndex &index, int role) const
{
    if (role == Qt::DecorationRole && index.isValid()) {
        QString id = itemId(index).toString();

        QFutureWatcher<QImage> *future = cache.object(id);

        if (!future) {
            future = new QFutureWatcher<QImage>;

            QString path = imagePath(index);

            if (!path.isEmpty()) {
                future->setFuture(QtConcurrent::run(ThumbnailModel::load, path));

                connect(future, SIGNAL(finished()), this, SLOT(thumbnailLoaded()));
            }

            cache.insert(id, future);
        }

        return !future->isCanceled()
                ? future->result()
                : QVariant();
    } else {
        return QGalleryQueryModel::data(index, role);
    }
}
void TestImageDelegate::fields()
{
    QFETCH(QString, imagePath);

    Image image(imagePath);
    image.extraInfo().insert("SPECIAL", 1);
    sapi::ImageDelegate delegate(&image);

    QSignalSpy loadSpy(&image, SIGNAL(loaded()));
    QSignalSpy makeThumbnailSpy(&image, SIGNAL(thumbnailLoaded()));
    image.load();
    QVERIFY(loadSpy.wait());

    QCOMPARE(delegate.name(), image.name());
    QCOMPARE(delegate.size(), image.size());
    QCOMPARE(delegate.hash(), image.source()->hashStr());
    QCOMPARE(delegate.extraInfo(), image.extraInfo());
    QCOMPARE(delegate.isAnimation(), image.isAnimation());
    QCOMPARE(delegate.frameCount(), image.frameCount());
    QCOMPARE(delegate.durations(), image.durations());
    for (int i = 0; i < delegate.frameCount(); ++i) {
        QCOMPARE(*(delegate.frames()[i]), *(image.frames()[i]));
    }

    if (makeThumbnailSpy.count() == 0) {
        QVERIFY(makeThumbnailSpy.wait());
    }
    QCOMPARE(delegate.thumbnail(), image.thumbnail());
    QVERIFY(!delegate.readRaw().isNull());
}
Beispiel #4
0
void FileSystemItem::loadCover(QString path)
{
    ImageSource *src = ImageSourceManager::instance()->createSingle(path);
    m_coverImage = new Image(src);
    connect(m_coverImage, SIGNAL(thumbnailLoaded()),
            this, SLOT(coverThumbnailLoaded()));
    connect(m_coverImage, SIGNAL(thumbnailLoadFailed()),
            this, SLOT(coverThumbnailLoadFailed()));
    m_coverImage->loadThumbnail(true);
}
Beispiel #5
0
bool ThumbnailRequestHandler::event( QEvent *event )
{
    if( event->type() == QEvent::User )
    {
        ThumbnailRequestEvent *e = static_cast< ThumbnailRequestEvent * >( event );

        emit thumbnailLoaded( m_loader->loadThumbnail( e->fileName(), e->size() ) );

        return true;
    }
    else
        return QObject::event( event );
}
Beispiel #6
0
void YTChannel::storeThumbnail(const QByteArray &bytes) {
    thumbnail.loadFromData(bytes);
    qreal maxRatio = IconUtils::maxSupportedPixelRatio();
    thumbnail.setDevicePixelRatio(maxRatio);
    const int maxWidth = 88 * maxRatio;

    QDir dir;
    dir.mkpath(getThumbnailDir());

    if (thumbnail.width() > maxWidth) {
        thumbnail = thumbnail.scaledToWidth(maxWidth, Qt::SmoothTransformation);
        thumbnail.setDevicePixelRatio(maxRatio);
        thumbnail.save(getThumbnailLocation(), "JPG");
    } else {
        QFile file(getThumbnailLocation());
        if (!file.open(QIODevice::WriteOnly))
            qWarning() << "Error opening file for writing" << file.fileName();
        QDataStream stream(&file);
        stream.writeRawData(bytes.constData(), bytes.size());
    }

    emit thumbnailLoaded();
    loadingThumbnail = false;
}
Beispiel #7
0
void ThumbnailLoader::thumbnailLoaded( const QImage &image )
{
    thumbnailLoaded( QPixmap::fromImage( image ) );
}
ThumbnailModel::ThumbnailModel(QAbstractGallery *gallery, QObject *parent)
    : QGalleryQueryModel(gallery, parent)
{
    connect(&cache, SIGNAL(thumbnailReady()), this, SLOT(thumbnailLoaded()));
}