Commit 3a0dbaf9 authored by Ronan Abhamon's avatar Ronan Abhamon

fix(ImageProvider): set size on request

parent 56890720
...@@ -247,7 +247,7 @@ ImageProvider::ImageProvider () : QQuickImageProvider( ...@@ -247,7 +247,7 @@ ImageProvider::ImageProvider () : QQuickImageProvider(
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
QImage ImageProvider::requestImage (const QString &id, QSize *, const QSize &) { QImage ImageProvider::requestImage (const QString &id, QSize *size, const QSize &requestedSize) {
const QString path = QStringLiteral(":/assets/images/%1").arg(id); const QString path = QStringLiteral(":/assets/images/%1").arg(id);
qInfo() << QStringLiteral("Image `%1` requested.").arg(path); qInfo() << QStringLiteral("Image `%1` requested.").arg(path);
...@@ -281,7 +281,13 @@ QImage ImageProvider::requestImage (const QString &id, QSize *, const QSize &) { ...@@ -281,7 +281,13 @@ QImage ImageProvider::requestImage (const QString &id, QSize *, const QSize &) {
// 3. Create en empty image. // 3. Create en empty image.
const QRectF viewBox = renderer.viewBoxF(); const QRectF viewBox = renderer.viewBoxF();
QImage image(static_cast<int>(viewBox.width()), static_cast<int>(viewBox.height()), QImage::Format_ARGB32); const int width = requestedSize.width();
const int height = requestedSize.height();
QImage image(
width > 0 ? width : static_cast<int>(viewBox.width()),
height > 0 ? height : static_cast<int>(viewBox.height()),
QImage::Format_ARGB32
);
if (Q_UNLIKELY(image.isNull())) { if (Q_UNLIKELY(image.isNull())) {
qWarning() << QStringLiteral("Unable to create image of size `(%1, %2)` from path: `%3`.") qWarning() << QStringLiteral("Unable to create image of size `(%1, %2)` from path: `%3`.")
.arg(viewBox.width()).arg(viewBox.height()).arg(path); .arg(viewBox.width()).arg(viewBox.height()).arg(path);
...@@ -289,6 +295,8 @@ QImage ImageProvider::requestImage (const QString &id, QSize *, const QSize &) { ...@@ -289,6 +295,8 @@ QImage ImageProvider::requestImage (const QString &id, QSize *, const QSize &) {
} }
image.fill(0x00000000); image.fill(0x00000000);
*size = image.size();
// 4. Paint! // 4. Paint!
QPainter painter(&image); QPainter painter(&image);
renderer.render(&painter); renderer.render(&painter);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment