Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into catpacks
This commit is contained in:
commit
ba159ba971
@ -97,37 +97,30 @@ public:
|
|||||||
return;
|
return;
|
||||||
if ((info.suffix().compare("png", Qt::CaseInsensitive) != 0))
|
if ((info.suffix().compare("png", Qt::CaseInsensitive) != 0))
|
||||||
return;
|
return;
|
||||||
int tries = 5;
|
if (!m_cache->stale(m_path))
|
||||||
while (tries)
|
return;
|
||||||
{
|
QImage image(m_path);
|
||||||
if (!m_cache->stale(m_path))
|
if (image.isNull()) {
|
||||||
return;
|
m_resultEmitter.emitResultsFailed(m_path);
|
||||||
QImage image(m_path);
|
qDebug() << "Error loading screenshot: " + m_path + ". Perhaps too large?";
|
||||||
if (image.isNull())
|
|
||||||
{
|
|
||||||
QThread::msleep(500);
|
|
||||||
tries--;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
QImage small;
|
|
||||||
if (image.width() > image.height())
|
|
||||||
small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation);
|
|
||||||
else
|
|
||||||
small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation);
|
|
||||||
QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2);
|
|
||||||
QImage square(QSize(256, 256), QImage::Format_ARGB32);
|
|
||||||
square.fill(Qt::transparent);
|
|
||||||
|
|
||||||
QPainter painter(&square);
|
|
||||||
painter.drawImage(offset, small);
|
|
||||||
painter.end();
|
|
||||||
|
|
||||||
QIcon icon(QPixmap::fromImage(square));
|
|
||||||
m_cache->add(m_path, icon);
|
|
||||||
m_resultEmitter.emitResultsReady(m_path);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_resultEmitter.emitResultsFailed(m_path);
|
QImage small;
|
||||||
|
if (image.width() > image.height())
|
||||||
|
small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation);
|
||||||
|
else
|
||||||
|
small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation);
|
||||||
|
QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2);
|
||||||
|
QImage square(QSize(256, 256), QImage::Format_ARGB32);
|
||||||
|
square.fill(Qt::transparent);
|
||||||
|
|
||||||
|
QPainter painter(&square);
|
||||||
|
painter.drawImage(offset, small);
|
||||||
|
painter.end();
|
||||||
|
|
||||||
|
QIcon icon(QPixmap::fromImage(square));
|
||||||
|
m_cache->add(m_path, icon);
|
||||||
|
m_resultEmitter.emitResultsReady(m_path);
|
||||||
}
|
}
|
||||||
QString m_path;
|
QString m_path;
|
||||||
SharedIconCachePtr m_cache;
|
SharedIconCachePtr m_cache;
|
||||||
@ -146,9 +139,12 @@ public:
|
|||||||
m_thumbnailCache = std::make_shared<SharedIconCache>();
|
m_thumbnailCache = std::make_shared<SharedIconCache>();
|
||||||
m_thumbnailCache->add("placeholder", APPLICATION->getThemedIcon("screenshot-placeholder"));
|
m_thumbnailCache->add("placeholder", APPLICATION->getThemedIcon("screenshot-placeholder"));
|
||||||
connect(&watcher, SIGNAL(fileChanged(QString)), SLOT(fileChanged(QString)));
|
connect(&watcher, SIGNAL(fileChanged(QString)), SLOT(fileChanged(QString)));
|
||||||
// FIXME: the watched file set is not updated when files are removed
|
|
||||||
}
|
}
|
||||||
virtual ~FilterModel() { m_thumbnailingPool.waitForDone(500); }
|
virtual ~FilterModel() {
|
||||||
|
m_thumbnailingPool.clear();
|
||||||
|
if (!m_thumbnailingPool.waitForDone(500))
|
||||||
|
qDebug() << "Thumbnail pool took longer than 500ms to finish";
|
||||||
|
}
|
||||||
virtual QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const
|
virtual QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const
|
||||||
{
|
{
|
||||||
auto model = sourceModel();
|
auto model = sourceModel();
|
||||||
@ -215,10 +211,12 @@ private slots:
|
|||||||
void fileChanged(QString filepath)
|
void fileChanged(QString filepath)
|
||||||
{
|
{
|
||||||
m_thumbnailCache->setStale(filepath);
|
m_thumbnailCache->setStale(filepath);
|
||||||
thumbnailImage(filepath);
|
|
||||||
// reinsert the path...
|
// reinsert the path...
|
||||||
watcher.removePath(filepath);
|
watcher.removePath(filepath);
|
||||||
watcher.addPath(filepath);
|
if (QFile::exists(filepath)) {
|
||||||
|
watcher.addPath(filepath);
|
||||||
|
thumbnailImage(filepath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user