59 lines
1.2 KiB
C++
59 lines
1.2 KiB
C++
|
#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)
|
||
|
|
||
|
// Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize NOTIFY maximumSizeChanged)
|
||
|
public:
|
||
|
PreviewImageItem(QQuickItem* parent = nullptr);
|
||
|
~PreviewImageItem();
|
||
|
|
||
|
QSGNode* updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
|
||
|
|
||
|
QUrl imageUrl() const;
|
||
|
|
||
|
QSize sourceSize() const;
|
||
|
|
||
|
static void setGlobalNetworkAccess(QNetworkAccessManager* netAccess);
|
||
|
|
||
|
signals:
|
||
|
void imageUrlChanged();
|
||
|
void sourceSizeChanged();
|
||
|
|
||
|
|
||
|
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;
|
||
|
};
|
||
|
|
||
|
#endif // PREVIEW_IMAGEITEM_HXX
|