diff options
-rw-r--r-- | src/quick/items/qquickborderimage.cpp | 92 | ||||
-rw-r--r-- | src/quick/items/qquickimagebase.cpp | 138 | ||||
-rw-r--r-- | src/quick/items/qquickimagebase_p.h | 11 |
3 files changed, 94 insertions, 147 deletions
diff --git a/src/quick/items/qquickborderimage.cpp b/src/quick/items/qquickborderimage.cpp index edd3805d7c..32407a474f 100644 --- a/src/quick/items/qquickborderimage.cpp +++ b/src/quick/items/qquickborderimage.cpp @@ -168,6 +168,7 @@ QT_BEGIN_NAMESPACE QQuickBorderImage::QQuickBorderImage(QQuickItem *parent) : QQuickImageBase(*(new QQuickBorderImagePrivate), parent) { + connect(this, &QQuickImageBase::sourceSizeChanged, this, &QQuickBorderImage::sourceSizeChanged); } QQuickBorderImage::~QQuickBorderImage() @@ -295,20 +296,7 @@ void QQuickBorderImage::load() Q_D(QQuickBorderImage); if (d->url.isEmpty()) { - d->pix.clear(this); - d->status = Null; - setImplicitSize(0, 0); - emit statusChanged(d->status); - if (d->progress != 0.0) { - d->progress = 0.0; - emit progressChanged(d->progress); - } - if (sourceSize() != d->oldSourceSize) { - d->oldSourceSize = sourceSize(); - emit sourceSizeChanged(); - } - pixmapChange(); - return; + loadEmptyUrl(); } else { if (d->url.path().endsWith(QLatin1String("sci"))) { QString lf = QQmlFile::urlToLocalFileOrQrc(d->url); @@ -316,7 +304,6 @@ void QQuickBorderImage::load() QFile file(lf); file.open(QIODevice::ReadOnly); setGridScaledImage(QQuickGridScaledImage(&file)); - return; } else { #if QT_CONFIG(qml_network) if (d->progress != 0.0) { @@ -328,50 +315,13 @@ void QQuickBorderImage::load() d->sciReply = qmlEngine(this)->networkAccessManager()->get(req); qmlobject_connect(d->sciReply, QNetworkReply, SIGNAL(finished()), this, QQuickBorderImage, SLOT(sciRequestFinished())); + emit statusChanged(d->status); #endif } } else { - QQuickPixmap::Options options; - if (d->async) - options |= QQuickPixmap::Asynchronous; - if (d->cache) - options |= QQuickPixmap::Cache; - d->pix.clear(this); - - const qreal targetDevicePixelRatio = (window() ? window()->effectiveDevicePixelRatio() : qGuiApp->devicePixelRatio()); - d->devicePixelRatio = 1.0; - - QUrl loadUrl = d->url; - resolve2xLocalFile(d->url, targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio); - d->pix.load(qmlEngine(this), loadUrl, d->sourcesize * d->devicePixelRatio, options, QQuickImageProviderOptions(), d->currentFrame, d->frameCount); - - if (d->pix.isLoading()) { - if (d->progress != 0.0) { - d->progress = 0.0; - emit progressChanged(d->progress); - } - d->status = Loading; - - static int thisRequestProgress = -1; - static int thisRequestFinished = -1; - if (thisRequestProgress == -1) { - thisRequestProgress = - QQuickImageBase::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)"); - thisRequestFinished = - QQuickImageBase::staticMetaObject.indexOfSlot("requestFinished()"); - } - d->pix.connectFinished(this, thisRequestFinished); - d->pix.connectDownloadProgress(this, thisRequestProgress); - - update(); //pixmap may have invalidated texture, updatePaintNode needs to be called before the next repaint - } else { - requestFinished(); - return; - } + loadPixmap(d->url, LoadPixmapOptions(HandleDPR | UseProviderOptions)); } } - - emit statusChanged(d->status); } /*! @@ -472,39 +422,7 @@ void QQuickBorderImage::setGridScaledImage(const QQuickGridScaledImage& sci) d->verticalTileMode = sci.verticalTileRule(); d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl())); - - QQuickPixmap::Options options; - if (d->async) - options |= QQuickPixmap::Asynchronous; - if (d->cache) - options |= QQuickPixmap::Cache; - d->pix.clear(this); - d->pix.load(qmlEngine(this), d->sciurl, options); - - if (d->pix.isLoading()) { - if (d->progress != 0.0) { - d->progress = 0.0; - emit progressChanged(d->progress); - } - if (d->status != Loading) { - d->status = Loading; - emit statusChanged(d->status); - } - static int thisRequestProgress = -1; - static int thisRequestFinished = -1; - if (thisRequestProgress == -1) { - thisRequestProgress = - QQuickBorderImage::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)"); - thisRequestFinished = - QQuickBorderImage::staticMetaObject.indexOfSlot("requestFinished()"); - } - - d->pix.connectFinished(this, thisRequestFinished); - d->pix.connectDownloadProgress(this, thisRequestProgress); - - } else { - requestFinished(); - } + loadPixmap(d->sciurl); } } diff --git a/src/quick/items/qquickimagebase.cpp b/src/quick/items/qquickimagebase.cpp index 8bab14bfd1..55b29d7a70 100644 --- a/src/quick/items/qquickimagebase.cpp +++ b/src/quick/items/qquickimagebase.cpp @@ -241,46 +241,47 @@ int QQuickImageBase::frameCount() const return d->frameCount; } -void QQuickImageBase::load() +void QQuickImageBase::loadEmptyUrl() { Q_D(QQuickImageBase); + d->pix.clear(this); + if (d->progress != 0.0) { + d->progress = 0.0; + emit progressChanged(d->progress); + } + d->status = Null; + setImplicitSize(0, 0); // also called in QQuickImageBase::pixmapChange, but not QQuickImage/QQuickBorderImage overrides + pixmapChange(); // This calls update() in QQuickBorderImage and QQuickImage, not in QQuickImageBase... - if (d->url.isEmpty()) { - d->pix.clear(this); - if (d->progress != 0.0) { - d->progress = 0.0; - emit progressChanged(d->progress); - } - pixmapChange(); - d->status = Null; - emit statusChanged(d->status); - - if (sourceSize() != d->oldSourceSize) { - d->oldSourceSize = sourceSize(); - emit sourceSizeChanged(); - } - if (autoTransform() != d->oldAutoTransform) { - d->oldAutoTransform = autoTransform(); - emitAutoTransformBaseChanged(); - } - update(); - - } else { - QQuickPixmap::Options options; - if (d->async) - options |= QQuickPixmap::Asynchronous; - if (d->cache) - options |= QQuickPixmap::Cache; - d->pix.clear(this); + emit statusChanged(d->status); + if (sourceSize() != d->oldSourceSize) { + d->oldSourceSize = sourceSize(); + emit sourceSizeChanged(); + } + if (autoTransform() != d->oldAutoTransform) { + d->oldAutoTransform = autoTransform(); + emitAutoTransformBaseChanged(); + } + update(); // .. but double updating should be harmless +} +void QQuickImageBase::loadPixmap(const QUrl &url, LoadPixmapOptions loadOptions) +{ + Q_D(QQuickImageBase); + QQuickPixmap::Options options; + if (d->async) + options |= QQuickPixmap::Asynchronous; + if (d->cache) + options |= QQuickPixmap::Cache; + d->pix.clear(this); + QUrl loadUrl = url; + QQmlEngine* engine = qmlEngine(this); + if (engine && engine->urlInterceptor()) + loadUrl = engine->urlInterceptor()->intercept(loadUrl, QQmlAbstractUrlInterceptor::UrlString); + + if (loadOptions & HandleDPR) { const qreal targetDevicePixelRatio = (window() ? window()->effectiveDevicePixelRatio() : qApp->devicePixelRatio()); d->devicePixelRatio = 1.0; - - QUrl loadUrl = d->url; - QQmlEngine* engine = qmlEngine(this); - if (engine && engine->urlInterceptor()) - loadUrl = engine->urlInterceptor()->intercept(loadUrl, QQmlAbstractUrlInterceptor::UrlString); - bool updatedDevicePixelRatio = false; if (d->sourcesize.isValid()) updatedDevicePixelRatio = d->updateDevicePixelRatio(targetDevicePixelRatio); @@ -290,34 +291,51 @@ void QQuickImageBase::load() // an "@2x" file is found. resolve2xLocalFile(d->url, targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio); } + } + + d->pix.load(qmlEngine(this), + loadUrl, + (loadOptions & HandleDPR) ? d->sourcesize * d->devicePixelRatio : QSize(), + options, + (loadOptions & UseProviderOptions) ? d->providerOptions : QQuickImageProviderOptions(), + d->currentFrame, d->frameCount); + + if (d->pix.isLoading()) { + if (d->progress != 0.0) { + d->progress = 0.0; + emit progressChanged(d->progress); + } + if (d->status != Loading) { + d->status = Loading; + emit statusChanged(d->status); + } - d->pix.load(qmlEngine(this), loadUrl, d->sourcesize * d->devicePixelRatio, options, d->providerOptions, d->currentFrame, d->frameCount); - - if (d->pix.isLoading()) { - if (d->progress != 0.0) { - d->progress = 0.0; - emit progressChanged(d->progress); - } - if (d->status != Loading) { - d->status = Loading; - emit statusChanged(d->status); - } - - static int thisRequestProgress = -1; - static int thisRequestFinished = -1; - if (thisRequestProgress == -1) { - thisRequestProgress = - QQuickImageBase::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)"); - thisRequestFinished = - QQuickImageBase::staticMetaObject.indexOfSlot("requestFinished()"); - } - - d->pix.connectFinished(this, thisRequestFinished); - d->pix.connectDownloadProgress(this, thisRequestProgress); - update(); //pixmap may have invalidated texture, updatePaintNode needs to be called before the next repaint - } else { - requestFinished(); + static int thisRequestProgress = -1; + static int thisRequestFinished = -1; + if (thisRequestProgress == -1) { + thisRequestProgress = + QQuickImageBase::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)"); + thisRequestFinished = + QQuickImageBase::staticMetaObject.indexOfSlot("requestFinished()"); } + + d->pix.connectFinished(this, thisRequestFinished); + d->pix.connectDownloadProgress(this, thisRequestProgress); + update(); //pixmap may have invalidated texture, updatePaintNode needs to be called before the next repaint + } else { + requestFinished(); + } +} + +void QQuickImageBase::load() +{ + Q_D(QQuickImageBase); + + if (d->url.isEmpty()) { + loadEmptyUrl(); + update(); + } else { + loadPixmap(d->url, LoadPixmapOptions(HandleDPR | UseProviderOptions)); } } diff --git a/src/quick/items/qquickimagebase_p.h b/src/quick/items/qquickimagebase_p.h index d1d01ad27d..9308230bfa 100644 --- a/src/quick/items/qquickimagebase_p.h +++ b/src/quick/items/qquickimagebase_p.h @@ -76,6 +76,15 @@ class Q_QUICK_PRIVATE_EXPORT QQuickImageBase : public QQuickImplicitSizeItem QML_UNCREATABLE("ImageBase is an abstract base class.") public: + enum LoadPixmapOption { + NoOption = 0x0000, + HandleDPR = 0x0001, + UseProviderOptions = 0x0002 + }; + + Q_DECLARE_FLAGS(LoadPixmapOptions, LoadPixmapOption) + Q_FLAG(LoadPixmapOptions) + QQuickImageBase(QQuickItem *parent=nullptr); ~QQuickImageBase(); enum Status { Null, Ready, Loading, Error }; @@ -127,6 +136,8 @@ Q_SIGNALS: Q_REVISION(14) void frameCountChanged(); protected: + void loadEmptyUrl(); + void loadPixmap(const QUrl &url, LoadPixmapOptions loadOptions = NoOption); virtual void load(); void componentComplete() override; virtual void pixmapChange(); |