Revert accidental animated image change
This commit is contained in:
parent
1ea5449c18
commit
78784babd1
2 changed files with 31 additions and 47 deletions
|
|
@ -8,7 +8,6 @@
|
|||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QMimeDatabase>
|
||||
#include <QMovie>
|
||||
#include <QQuickWindow>
|
||||
#include <QSGImageNode>
|
||||
#include <QStandardPaths>
|
||||
|
|
@ -35,12 +34,8 @@ MxcAnimatedImage::startDownload()
|
|||
|
||||
QByteArray mimeType = QString::fromStdString(mtx::accessors::mimetype(*event)).toUtf8();
|
||||
|
||||
static const auto movieFormats = QMovie::supportedFormats();
|
||||
QByteArray imageFormat;
|
||||
const auto imageFormats = QImageReader::imageFormatsForMimeType(mimeType);
|
||||
if (!imageFormats.isEmpty())
|
||||
imageFormat = imageFormats.front();
|
||||
animatable_ = movieFormats.contains(imageFormat);
|
||||
static const auto formats = QMovie::supportedFormats();
|
||||
animatable_ = formats.contains(mimeType.split('/').back());
|
||||
animatableChanged();
|
||||
|
||||
if (!animatable_)
|
||||
|
|
@ -71,14 +66,14 @@ MxcAnimatedImage::startDownload()
|
|||
|
||||
QPointer<MxcAnimatedImage> self = this;
|
||||
|
||||
auto processBuffer = [this, imageFormat, encryptionInfo, self](QIODevice &device) {
|
||||
auto processBuffer = [this, mimeType, encryptionInfo, self](QIODevice &device) {
|
||||
if (!self)
|
||||
return;
|
||||
|
||||
try {
|
||||
if (buffer.isOpen()) {
|
||||
frameTimer.stop();
|
||||
movie->setDevice(nullptr);
|
||||
movie.stop();
|
||||
movie.setDevice(nullptr);
|
||||
buffer.close();
|
||||
}
|
||||
|
||||
|
|
@ -97,22 +92,21 @@ MxcAnimatedImage::startDownload()
|
|||
nhlog::net()->error("Failed to setup animated image buffer: {}", e.what());
|
||||
}
|
||||
|
||||
QTimer::singleShot(0, this, [this, imageFormat] {
|
||||
QTimer::singleShot(0, this, [this, mimeType] {
|
||||
nhlog::ui()->info(
|
||||
"Playing movie with size: {}, {}", buffer.bytesAvailable(), buffer.isOpen());
|
||||
movie->setFormat(imageFormat);
|
||||
movie->setDevice(&buffer);
|
||||
movie.setFormat(mimeType);
|
||||
movie.setDevice(&buffer);
|
||||
|
||||
if (height() != 0 && width() != 0)
|
||||
movie->setScaledSize(this->size().toSize());
|
||||
|
||||
if (movie->supportsAnimation())
|
||||
frameTimer.setInterval(movie->nextImageDelay());
|
||||
|
||||
movie.setScaledSize(this->size().toSize());
|
||||
if (buffer.bytesAvailable() <
|
||||
4LL * 1024 * 1024 * 1024) // cache images smaller than 4MB in RAM
|
||||
movie.setCacheMode(QMovie::CacheAll);
|
||||
if (play_)
|
||||
frameTimer.start();
|
||||
movie.start();
|
||||
else
|
||||
movie->jumpToImage(0);
|
||||
movie.jumpToFrame(0);
|
||||
emit loadedChanged();
|
||||
update();
|
||||
});
|
||||
|
|
@ -165,9 +159,9 @@ MxcAnimatedImage::geometryChanged(const QRectF &newGeometry, const QRectF &oldGe
|
|||
|
||||
if (newGeometry.size() != oldGeometry.size()) {
|
||||
if (height() != 0 && width() != 0) {
|
||||
QSizeF r = movie->scaledSize();
|
||||
QSizeF r = movie.scaledSize();
|
||||
r.scale(newGeometry.size(), Qt::KeepAspectRatio);
|
||||
movie->setScaledSize(r.toSize());
|
||||
movie.setScaledSize(r.toSize());
|
||||
imageDirty = true;
|
||||
update();
|
||||
}
|
||||
|
|
@ -190,15 +184,16 @@ MxcAnimatedImage::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeD
|
|||
n->setFlags(QSGNode::OwnedByParent);
|
||||
}
|
||||
|
||||
n->setSourceRect(currentFrame.rect());
|
||||
if (!currentFrame.isNull())
|
||||
n->setTexture(window()->createTextureFromImage(currentFrame));
|
||||
auto img = movie.currentImage();
|
||||
n->setSourceRect(img.rect());
|
||||
if (!img.isNull())
|
||||
n->setTexture(window()->createTextureFromImage(std::move(img)));
|
||||
else {
|
||||
delete n;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QSizeF r = currentFrame.size();
|
||||
QSizeF r = img.size();
|
||||
r.scale(size(), Qt::KeepAspectRatio);
|
||||
|
||||
n->setRect((width() - r.width()) / 2, (height() - r.height()) / 2, r.width(), r.height());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue