void Settings::setThumbnailSize(int size)
{
    if (size != thumbnailSize()) {
        QSettings().setValue(QStringLiteral("thumbnailSize"), size);
        emit thumbnailSizeChanged();
    }
}
Example #2
0
Thumbnail::Thumbnail(const QPixmap &originalPixmap)
{
	QPixmap pixmap = originalPixmap.scaled(PixmapSize, PixmapSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
	QPixmap shadow;
	QRect pixmapRect(Margin + PixmapSize / 2 - pixmap.size().width() / 2, Margin + PixmapSize / 2 - pixmap.size().height() / 2, pixmap.size().width(), pixmap.size().height());
	
	if (_shadowCache.contains(pixmap.size()))
	{
		shadow = _shadowCache.value(pixmap.size());
	}
	else
	{
		shadow = QPixmap(thumbnailSize());
		shadow.fill(Qt::transparent);
		
		QGraphicsScene scene(shadow.rect());
		auto rectItem = scene.addRect(pixmapRect, Qt::NoPen, Qt::white);
		QGraphicsDropShadowEffect effect(0);
		effect.setBlurRadius(6);
		effect.setOffset(0);
		rectItem->setGraphicsEffect(&effect);
		
		QPainter painter(&shadow);
		scene.render(&painter);
		painter.end();
		
		_shadowCache.insert(pixmap.size(), shadow);
	}
	
	_thumbnail = shadow;
	QPainter painter(&_thumbnail);
	painter.drawPixmap(pixmapRect.topLeft(), pixmap);
}
Example #3
0
bool makeThumbnail(const QString & path,
                   ThumbnailType type)
{
    QFileInfo info(path);
    ContentThumbnail db(info.path());
    QImage thumbnail;
    if (!db.loadThumbnail(path, THUMBNAIL_LARGE, thumbnail))
    {
        // So far, only support image thumbnail in explorer.
        // The viewer can generate thumbnail themselves.
        if (!isImage(info.suffix()))
        {
            return false;
        }

        // Try to load it if it's a image.
        if (!thumbnail.load(path))
        {
            return false;
        }

        thumbnail = thumbnail.scaled(thumbnailSize(THUMBNAIL_LARGE), Qt::IgnoreAspectRatio);
        db.storeThumbnail(info.fileName(), THUMBNAIL_LARGE, thumbnail);

        // Return true even the thumbnail can not be stored.
        return true;
    }
    return true;

}