2017-10-13 15:48:24 +00:00
|
|
|
#ifndef PREVIEW_IMAGEITEM_HXX
|
|
|
|
#define PREVIEW_IMAGEITEM_HXX
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <QQuickItem>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
|
|
|
|
class QNetworkAccessManager;
|
|
|
|
|
|
|
|
class PreviewImageItem : public QQuickItem
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY(QUrl imageUrl READ imageUrl WRITE setImageUrl NOTIFY imageUrlChanged)
|
|
|
|
|
|
|
|
Q_PROPERTY(QSize sourceSize READ sourceSize NOTIFY sourceSizeChanged)
|
|
|
|
|
2017-12-08 16:14:39 +00:00
|
|
|
Q_PROPERTY(bool isLoading READ isLoading NOTIFY isLoadingChanged)
|
|
|
|
|
2017-10-13 15:48:24 +00:00
|
|
|
public:
|
|
|
|
PreviewImageItem(QQuickItem* parent = nullptr);
|
|
|
|
~PreviewImageItem();
|
|
|
|
|
|
|
|
QSGNode* updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
|
|
|
|
|
|
|
|
QUrl imageUrl() const;
|
|
|
|
|
|
|
|
QSize sourceSize() const;
|
|
|
|
|
|
|
|
static void setGlobalNetworkAccess(QNetworkAccessManager* netAccess);
|
|
|
|
|
2017-12-08 16:14:39 +00:00
|
|
|
bool isLoading() const;
|
|
|
|
|
2017-10-13 15:48:24 +00:00
|
|
|
signals:
|
|
|
|
void imageUrlChanged();
|
|
|
|
void sourceSizeChanged();
|
2017-12-08 16:14:39 +00:00
|
|
|
void isLoadingChanged();
|
2017-10-13 15:48:24 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
|
|
|
void setImageUrl(QUrl url);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void onDownloadError(QNetworkReply::NetworkError errorCode);
|
|
|
|
|
|
|
|
void onFinished();
|
|
|
|
private:
|
|
|
|
void setImage(QImage image);
|
|
|
|
void startDownload();
|
|
|
|
|
|
|
|
QUrl m_imageUrl;
|
|
|
|
|
|
|
|
bool m_imageDirty = false;
|
|
|
|
QImage m_image;
|
|
|
|
unsigned int m_downloadRetryCount = 0;
|
2017-12-08 16:14:39 +00:00
|
|
|
bool m_requestActive = false;
|
2017-10-13 15:48:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PREVIEW_IMAGEITEM_HXX
|