Skip to content

Commit

Permalink
fixes for a46a9a8 "use default icons in Files"
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed Dec 27, 2024
1 parent e9cd066 commit 94f06b5
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/docks/filesdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static const QSet<QString> kVideoExtensions {

static void cacheMediaType(FilesModel *model, const QString &filePath, int mediaType,
const QModelIndex &index);
static void cacheThumbnail(FilesModel *model, const QString &filePath, const QImage &image,
static void cacheThumbnail(FilesModel *model, const QString &filePath, QImage &image,
const QModelIndex &index);

class FilesMediaTypeTask : public QRunnable
Expand Down Expand Up @@ -222,7 +222,9 @@ class FilesThumbnailTask : public QRunnable
auto height = PlaylistModel::THUMBNAIL_HEIGHT * 2;
image = MLT.image(producer, 0, width, height);
}
cacheThumbnail(m_model, m_filePath, image, m_index);
if (!image.isNull()) {
cacheThumbnail(m_model, m_filePath, image, m_index);
}
}
};

Expand Down Expand Up @@ -266,9 +268,9 @@ class FilesModel : public QFileSystemModel
case ThumbnailRole: {
const auto path = filePath(index);
const auto thumbnailKey = FilesThumbnailTask::cacheKey(path);
const auto image = DB.getThumbnail(thumbnailKey);
auto image = DB.getThumbnail(thumbnailKey);
if (image.isNull()) {
::cacheThumbnail(const_cast<FilesModel *>(this), path, image, QModelIndex());
::cacheThumbnail(const_cast<FilesModel *>(this), path, image, index);
if (!path.endsWith(QStringLiteral(".mlt"), Qt::CaseInsensitive))
QThreadPool::globalInstance()->start(
new FilesThumbnailTask(const_cast<FilesModel *>(this), path, index));
Expand Down Expand Up @@ -333,15 +335,18 @@ class FilesModel : public QFileSystemModel
emit dataChanged(index, index);
}

void cacheThumbnail(const QString &filePath, QImage image, const QModelIndex &index)
void cacheThumbnail(const QString &filePath, QImage &image, const QModelIndex &index)
{
if (image.isNull()) {
image = QImage(64, 64, QImage::Format_ARGB32);
image.fill(Qt::transparent);
const auto pixmap = QFileSystemModel::data(index, Qt::DecorationRole).value<QIcon>().pixmap({16, 16},
m_dock->devicePixelRatioF());
QPainter painter(&image);
QIcon(pixmap).paint(&painter, image.rect());
if (index.isValid()) {
const auto pixmap = QFileSystemModel::data(index,
Qt::DecorationRole).value<QIcon>().pixmap({16, 16},
m_dock->devicePixelRatioF());
QPainter painter(&image);
QIcon(pixmap).paint(&painter, image.rect());
}
}
auto key = FilesThumbnailTask::cacheKey(filePath);
DB.putThumbnail(key, image);
Expand All @@ -356,7 +361,7 @@ static void cacheMediaType(FilesModel *model, const QString &filePath, int media
model->cacheMediaType(filePath, mediaType, index);
}

static void cacheThumbnail(FilesModel *model, const QString &filePath, const QImage &image,
static void cacheThumbnail(FilesModel *model, const QString &filePath, QImage &image,
const QModelIndex &index)
{
model->cacheThumbnail(filePath, image, index);
Expand Down

0 comments on commit 94f06b5

Please sign in to comment.