Skip to content

Commit d5578ec

Browse files
committed
Fix some Elements thumbnail bugs
1 parent 9844698 commit d5578ec

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

src/models/elementsmodel.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class ElementsThumbnailTask : public QRunnable
7777
producer.attach(converter);
7878
const auto width = PlaylistModel::THUMBNAIL_WIDTH * 2;
7979
const auto height = PlaylistModel::THUMBNAIL_HEIGHT * 2;
80-
image = MLT.image(producer, 0, width, height);
80+
image = MLT.image(producer, producer.get_length() / 2, width, height);
8181
}
8282
}
8383
if (!image.isNull()) {
@@ -162,6 +162,14 @@ int ElementsModel::rowCount(const QModelIndex &parent) const
162162
return m_files.count();
163163
}
164164

165+
static void cacheThumbnail(ElementsModel *model,
166+
const QString &filePath,
167+
QImage &image,
168+
const QModelIndex &index)
169+
{
170+
model->updateThumbnail(filePath, image, index);
171+
}
172+
165173
QVariant ElementsModel::data(const QModelIndex &index, int role) const
166174
{
167175
if (!index.isValid() || index.row() >= m_files.count())
@@ -188,6 +196,7 @@ QVariant ElementsModel::data(const QModelIndex &index, int role) const
188196
const auto key = ElementsThumbnailTask::cacheKey(info.filePath());
189197
auto image = DB.getThumbnail(key);
190198
if (image.isNull()) {
199+
::cacheThumbnail(const_cast<ElementsModel *>(this), info.filePath(), image, index);
191200
QThreadPool::globalInstance()->start(
192201
new ElementsThumbnailTask(const_cast<ElementsModel *>(this),
193202
info.filePath(),
@@ -236,12 +245,16 @@ void ElementsModel::setDir(const QDir &dir)
236245
endResetModel();
237246
}
238247

239-
void ElementsModel::updateThumbnail(const QString &filePath,
240-
QImage &image,
241-
const QModelIndex &persistentIndex)
248+
void ElementsModel::updateThumbnail(const QString &filePath, QImage &image, const QModelIndex &index)
242249
{
243-
const auto key = ElementsThumbnailTask::cacheKey(filePath);
250+
bool updateModel = !image.isNull();
251+
252+
if (image.isNull()) {
253+
image = QImage(64, 64, QImage::Format_ARGB32);
254+
image.fill(Qt::transparent);
255+
}
256+
auto key = ElementsThumbnailTask::cacheKey(filePath);
244257
DB.putThumbnail(key, image);
245-
if (persistentIndex.isValid())
246-
emit dataChanged(persistentIndex, persistentIndex, {ThumbnailRole});
258+
if (updateModel)
259+
emit dataChanged(index, index);
247260
}

0 commit comments

Comments
 (0)