Launcher: preview image loading feedback
Expose the loading state as a property so the UI can show some feedback when the image is still loading.
This commit is contained in:
parent
033d5f65d5
commit
e6e055dbb0
3 changed files with 32 additions and 2 deletions
|
@ -25,6 +25,20 @@ Rectangle {
|
|||
width: parent.width
|
||||
height: parent.height
|
||||
imageUrl: __havePreviews ? root.previews[root.activePreview] : ""
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
visible: parent.isLoading
|
||||
opacity: 0.5
|
||||
color: "black"
|
||||
}
|
||||
|
||||
AnimatedImage {
|
||||
id: spinner
|
||||
source: "qrc:///spinner"
|
||||
anchors.centerIn: parent
|
||||
visible: parent.isLoading
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
|
|
|
@ -68,6 +68,11 @@ void PreviewImageItem::setGlobalNetworkAccess(QNetworkAccessManager *netAccess)
|
|||
global_previewNetAccess = netAccess;
|
||||
}
|
||||
|
||||
bool PreviewImageItem::isLoading() const
|
||||
{
|
||||
return m_requestActive;
|
||||
}
|
||||
|
||||
void PreviewImageItem::setImageUrl( QUrl url)
|
||||
{
|
||||
if (m_imageUrl == url)
|
||||
|
@ -90,6 +95,9 @@ void PreviewImageItem::startDownload()
|
|||
|
||||
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
|
||||
this, SLOT(onDownloadError(QNetworkReply::NetworkError)));
|
||||
|
||||
m_requestActive = true;
|
||||
emit isLoadingChanged();
|
||||
}
|
||||
|
||||
void PreviewImageItem::setImage(QImage image)
|
||||
|
@ -110,6 +118,8 @@ void PreviewImageItem::onFinished()
|
|||
return;
|
||||
}
|
||||
setImage(img);
|
||||
m_requestActive = false;
|
||||
emit isLoadingChanged();
|
||||
}
|
||||
|
||||
void PreviewImageItem::onDownloadError(QNetworkReply::NetworkError errorCode)
|
||||
|
@ -124,4 +134,6 @@ void PreviewImageItem::onDownloadError(QNetworkReply::NetworkError errorCode)
|
|||
|
||||
qWarning() << "failed to download:" << reply->url();
|
||||
qWarning() << reply->errorString();
|
||||
m_requestActive = false;
|
||||
emit isLoadingChanged();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,8 @@ class PreviewImageItem : public QQuickItem
|
|||
|
||||
Q_PROPERTY(QSize sourceSize READ sourceSize NOTIFY sourceSizeChanged)
|
||||
|
||||
// Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize NOTIFY maximumSizeChanged)
|
||||
Q_PROPERTY(bool isLoading READ isLoading NOTIFY isLoadingChanged)
|
||||
|
||||
public:
|
||||
PreviewImageItem(QQuickItem* parent = nullptr);
|
||||
~PreviewImageItem();
|
||||
|
@ -31,10 +32,12 @@ public:
|
|||
|
||||
static void setGlobalNetworkAccess(QNetworkAccessManager* netAccess);
|
||||
|
||||
bool isLoading() const;
|
||||
|
||||
signals:
|
||||
void imageUrlChanged();
|
||||
void sourceSizeChanged();
|
||||
|
||||
void isLoadingChanged();
|
||||
|
||||
public slots:
|
||||
|
||||
|
@ -53,6 +56,7 @@ private:
|
|||
bool m_imageDirty = false;
|
||||
QImage m_image;
|
||||
unsigned int m_downloadRetryCount = 0;
|
||||
bool m_requestActive = false;
|
||||
};
|
||||
|
||||
#endif // PREVIEW_IMAGEITEM_HXX
|
||||
|
|
Loading…
Add table
Reference in a new issue