Launcher: fixes for lingering previews
Also better fix for some ‘assign Qurl from undefined’ warnings
This commit is contained in:
parent
8738e18921
commit
1555e1d6cb
4 changed files with 42 additions and 22 deletions
|
@ -78,6 +78,17 @@ float PreviewImageItem::aspectRatio() const
|
|||
return static_cast<float>(m_image.width()) / m_image.height();
|
||||
}
|
||||
|
||||
void PreviewImageItem::clear()
|
||||
{
|
||||
m_imageUrl.clear();
|
||||
m_image = QImage{};
|
||||
m_imageDirty = true;
|
||||
m_requestActive = false;
|
||||
update();
|
||||
emit imageUrlChanged();
|
||||
emit isLoadingChanged();
|
||||
}
|
||||
|
||||
void PreviewImageItem::setImageUrl( QUrl url)
|
||||
{
|
||||
if (m_imageUrl == url)
|
||||
|
@ -117,6 +128,11 @@ void PreviewImageItem::setImage(QImage image)
|
|||
void PreviewImageItem::onFinished()
|
||||
{
|
||||
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
|
||||
if (reply->url() != m_imageUrl) {
|
||||
// if replies arrive out of order, don't trample the correct one
|
||||
return;
|
||||
}
|
||||
|
||||
QImage img;
|
||||
if (!img.load(reply, nullptr)) {
|
||||
qWarning() << Q_FUNC_INFO << "failed to read image data from" << reply->url();
|
||||
|
@ -137,8 +153,8 @@ void PreviewImageItem::onDownloadError(QNetworkReply::NetworkError errorCode)
|
|||
}
|
||||
}
|
||||
|
||||
qWarning() << "failed to download:" << reply->url();
|
||||
qWarning() << reply->errorString();
|
||||
qWarning() << Q_FUNC_INFO << "failed to download:" << reply->url();
|
||||
qWarning() << "\t" << reply->errorString();
|
||||
m_requestActive = false;
|
||||
emit isLoadingChanged();
|
||||
}
|
||||
|
|
|
@ -37,6 +37,11 @@ public:
|
|||
|
||||
float aspectRatio() const;
|
||||
|
||||
/**
|
||||
@brief clear the image immediately, so we don't see a stale / expired
|
||||
one while attemtping to load the next one
|
||||
*/
|
||||
Q_INVOKABLE void clear();
|
||||
signals:
|
||||
void imageUrlChanged();
|
||||
void sourceSizeChanged();
|
||||
|
|
|
@ -9,6 +9,7 @@ Rectangle {
|
|||
readonly property bool __havePreviews: (previews.length > 0)
|
||||
onPreviewsChanged: {
|
||||
activePreview = 0
|
||||
preview.clear()
|
||||
}
|
||||
|
||||
height: width / preview.aspectRatio
|
||||
|
@ -25,7 +26,15 @@ Rectangle {
|
|||
id: preview
|
||||
width: parent.width
|
||||
height: parent.height
|
||||
imageUrl: __havePreviews ? root.previews[root.activePreview] : ""
|
||||
|
||||
function activePreviewUrl()
|
||||
{
|
||||
if (!__havePreviews) return "";
|
||||
if (root.previews.length <= root.activePreview) return "";
|
||||
return root.previews[root.activePreview];
|
||||
}
|
||||
|
||||
imageUrl: activePreviewUrl();
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
|
|
|
@ -29,9 +29,14 @@ Item {
|
|||
width: height * aspectRatio
|
||||
height: scale * sourceSize.height
|
||||
|
||||
property var urlsList: []
|
||||
property var urlsList: _launcher.defaultSplashUrls()
|
||||
property int __currentUrl: 0
|
||||
|
||||
Binding on urlsList {
|
||||
when: _launcher.selectedAircraftInfo.previews.length > 0
|
||||
value: _launcher.selectedAircraftInfo.previews
|
||||
}
|
||||
|
||||
onUrlsListChanged: {
|
||||
__currentUrl = 0;
|
||||
}
|
||||
|
@ -46,29 +51,14 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
function currentPreviewUrl()
|
||||
function currentUrl()
|
||||
{
|
||||
if (__currentUrl >= urlsList.length) return "";
|
||||
if (urlsList.length <= __currentUrl) return "";
|
||||
return urlsList[__currentUrl];
|
||||
}
|
||||
|
||||
visible: imageUrl != ""
|
||||
imageUrl: currentPreviewUrl()
|
||||
|
||||
// conditional binding when we have valid previews
|
||||
Binding {
|
||||
when: (_launcher.selectedAircraftInfo.previews.length > 0)
|
||||
target: preview
|
||||
property: "urlsList"
|
||||
value: _launcher.selectedAircraftInfo.previews
|
||||
}
|
||||
|
||||
Binding {
|
||||
when: _launcher.selectedAircraftInfo.previews.length === 0
|
||||
target: preview
|
||||
property: "urlsList"
|
||||
value: _launcher.defaultSplashUrls()
|
||||
}
|
||||
imageUrl: currentUrl()
|
||||
}
|
||||
|
||||
Text {
|
||||
|
|
Loading…
Reference in a new issue