mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 11:35:24 +01:00
Don't download images until they're displayed, show a message if an image couldn't be downloaded, show bigger fullsize images.
This commit is contained in:
parent
565ec47e42
commit
fbb62a2f43
@ -1403,6 +1403,9 @@ msgstr ""
|
||||
msgid "Previous track"
|
||||
msgstr ""
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1404,6 +1404,9 @@ msgstr ""
|
||||
msgid "Previous track"
|
||||
msgstr ""
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1433,6 +1433,9 @@ msgstr "Previsualitza"
|
||||
msgid "Previous track"
|
||||
msgstr "Pista anterior"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Progrés"
|
||||
|
||||
|
@ -1408,6 +1408,9 @@ msgstr "Náhled"
|
||||
msgid "Previous track"
|
||||
msgstr "Předchozí skladba"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Průběh"
|
||||
|
||||
|
@ -1409,6 +1409,9 @@ msgstr ""
|
||||
msgid "Previous track"
|
||||
msgstr "Forrige spor"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1434,6 +1434,9 @@ msgstr "Vorschau"
|
||||
msgid "Previous track"
|
||||
msgstr "Vorheriges Stück"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Fortschritt"
|
||||
|
||||
|
@ -1437,6 +1437,9 @@ msgstr "Προεπισκόπηση"
|
||||
msgid "Previous track"
|
||||
msgstr "Προηγούμενο κομμάτι"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Πρόοδος"
|
||||
|
||||
|
@ -1408,6 +1408,9 @@ msgstr ""
|
||||
msgid "Previous track"
|
||||
msgstr "Previous track"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Progress"
|
||||
|
||||
|
@ -1405,6 +1405,9 @@ msgstr ""
|
||||
msgid "Previous track"
|
||||
msgstr "Previous track"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1438,6 +1438,9 @@ msgstr "Vista previa"
|
||||
msgid "Previous track"
|
||||
msgstr "Pista anterior"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Progreso"
|
||||
|
||||
|
@ -1406,6 +1406,9 @@ msgstr "Esikatselu"
|
||||
msgid "Previous track"
|
||||
msgstr "Edellinen kappale"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1442,6 +1442,9 @@ msgstr "Aperçu"
|
||||
msgid "Previous track"
|
||||
msgstr "Piste précédente"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Progression"
|
||||
|
||||
|
@ -1410,6 +1410,9 @@ msgstr ""
|
||||
msgid "Previous track"
|
||||
msgstr ""
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1431,6 +1431,9 @@ msgstr "Előnézet"
|
||||
msgid "Previous track"
|
||||
msgstr "Előző szám"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Folyamat"
|
||||
|
||||
|
@ -1442,6 +1442,9 @@ msgstr "Anteprima"
|
||||
msgid "Previous track"
|
||||
msgstr "Traccia precedente"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Avanzamento"
|
||||
|
||||
|
@ -1405,6 +1405,9 @@ msgstr ""
|
||||
msgid "Previous track"
|
||||
msgstr ""
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1404,6 +1404,9 @@ msgstr ""
|
||||
msgid "Previous track"
|
||||
msgstr ""
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1407,6 +1407,9 @@ msgstr ""
|
||||
msgid "Previous track"
|
||||
msgstr "Forrige spor"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1437,6 +1437,9 @@ msgstr "Voorbeeld"
|
||||
msgid "Previous track"
|
||||
msgstr "Vorige track"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Voortgang"
|
||||
|
||||
|
@ -1403,6 +1403,9 @@ msgstr ""
|
||||
msgid "Previous track"
|
||||
msgstr "Pista precedenta"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Progression"
|
||||
|
||||
|
@ -1433,6 +1433,9 @@ msgstr "Podgląd"
|
||||
msgid "Previous track"
|
||||
msgstr "Poprzedni utwór"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Postęp"
|
||||
|
||||
|
@ -1434,6 +1434,9 @@ msgstr "Antevisão"
|
||||
msgid "Previous track"
|
||||
msgstr "Faixa anterior"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Evolução"
|
||||
|
||||
|
@ -1422,6 +1422,9 @@ msgstr "Pré-visualização"
|
||||
msgid "Previous track"
|
||||
msgstr "Faixa anterior"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Andamento"
|
||||
|
||||
|
@ -1404,6 +1404,9 @@ msgstr ""
|
||||
msgid "Previous track"
|
||||
msgstr "Piesa precedentă"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1426,6 +1426,9 @@ msgstr "Предпросмотр"
|
||||
msgid "Previous track"
|
||||
msgstr "Предыдущая композиция"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Ход выполнения"
|
||||
|
||||
|
@ -1427,6 +1427,9 @@ msgstr "Náhľad"
|
||||
msgid "Previous track"
|
||||
msgstr "Predchádzajúca skladba"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Priebeh"
|
||||
|
||||
|
@ -1427,6 +1427,9 @@ msgstr "Predogled"
|
||||
msgid "Previous track"
|
||||
msgstr "Predhodna skladba"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Potek"
|
||||
|
||||
|
@ -1409,6 +1409,9 @@ msgstr "Преглед"
|
||||
msgid "Previous track"
|
||||
msgstr "Претходна нумера"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Напредак"
|
||||
|
||||
|
@ -1413,6 +1413,9 @@ msgstr "Förhandsvisning"
|
||||
msgid "Previous track"
|
||||
msgstr "Föregående spår"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Förlopp"
|
||||
|
||||
|
@ -1430,6 +1430,9 @@ msgstr "Önizleme"
|
||||
msgid "Previous track"
|
||||
msgstr "Önceki parça"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "İlerleme"
|
||||
|
||||
|
@ -1394,6 +1394,9 @@ msgstr ""
|
||||
msgid "Previous track"
|
||||
msgstr ""
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1427,6 +1427,9 @@ msgstr "Перегляд"
|
||||
msgid "Previous track"
|
||||
msgstr "Попередня доріжка"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "Поступ"
|
||||
|
||||
|
@ -1403,6 +1403,9 @@ msgstr ""
|
||||
msgid "Previous track"
|
||||
msgstr "上一音轨"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1409,6 +1409,9 @@ msgstr "試聽"
|
||||
msgid "Previous track"
|
||||
msgstr "上一首歌曲"
|
||||
|
||||
msgid "Problem loading image"
|
||||
msgstr ""
|
||||
|
||||
msgid "Progress"
|
||||
msgstr "進展"
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "ui/iconloader.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QFileDialog>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
@ -74,7 +75,8 @@ QRect PrettyImageView::right() const {
|
||||
|
||||
QRect PrettyImageView::middle() const {
|
||||
return QRect(kEdgeWidth + kEdgePadding, kBorderHeight,
|
||||
width() - (kEdgeWidth + kEdgePadding) * 2, kImageHeight - kBorderHeight);
|
||||
width() - (kEdgeWidth + kEdgePadding) * 2,
|
||||
kImageHeight - kBorderHeight);
|
||||
}
|
||||
|
||||
void PrettyImageView::Clear() {
|
||||
@ -85,15 +87,22 @@ void PrettyImageView::Clear() {
|
||||
}
|
||||
|
||||
void PrettyImageView::AddImage(const QUrl& url) {
|
||||
const int index = images_.count();
|
||||
images_ << Image(url);
|
||||
}
|
||||
|
||||
void PrettyImageView::LazyLoadImage(int index) {
|
||||
if (index < 0 || index >= images_.count())
|
||||
return;
|
||||
Image* image = &images_[index];
|
||||
if (image->state_ != Image::WaitingForLazyLoad)
|
||||
return;
|
||||
|
||||
const int id = next_image_request_id_ ++;
|
||||
|
||||
// Add the image to the list
|
||||
images_ << Image(url);
|
||||
|
||||
// Start fetching the image
|
||||
network_->Get(url, this, "ImageFetched", id);
|
||||
network_->Get(image->url_, this, "ImageFetched", id);
|
||||
image_requests_[id] = index;
|
||||
image->state_ = Image::Loading;
|
||||
}
|
||||
|
||||
void PrettyImageView::ImageFetched(quint64 id, QNetworkReply* reply) {
|
||||
@ -105,10 +114,12 @@ void PrettyImageView::ImageFetched(quint64 id, QNetworkReply* reply) {
|
||||
Image& data = images_[image_requests_.take(id)];
|
||||
|
||||
QImage image = QImage::fromData(reply->readAll());
|
||||
if (image.isNull())
|
||||
return;
|
||||
|
||||
data.SetImage(image);
|
||||
if (image.isNull()) {
|
||||
data.state_ = Image::Failed;
|
||||
} else {
|
||||
data.SetImage(image);
|
||||
data.state_ = Image::Loaded;
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
@ -116,9 +127,6 @@ void PrettyImageView::paintEvent(QPaintEvent*) {
|
||||
QPainter p(this);
|
||||
p.setRenderHint(QPainter::Antialiasing, true);
|
||||
|
||||
p.setBrush(palette().color(QPalette::Highlight));
|
||||
p.setPen(QPen(palette().color(QPalette::Text), 0.5));
|
||||
|
||||
const int next_index = current_index_ + 1;
|
||||
const int prev_index = current_index_ - 1;
|
||||
const int image_width = width() - kEdgeWidth * 2;
|
||||
@ -133,6 +141,11 @@ void PrettyImageView::paintEvent(QPaintEvent*) {
|
||||
const QRect prev_rect(-image_width + kEdgeWidth, kBorderHeight,
|
||||
image_width, kImageHeight - kBorderHeight);
|
||||
|
||||
// Start the images loading if they're not already
|
||||
LazyLoadImage(current_index_);
|
||||
LazyLoadImage(next_index);
|
||||
LazyLoadImage(prev_index);
|
||||
|
||||
// Draw the images
|
||||
DrawImage(&p, current_rect, Qt::AlignHCenter, 1.0, current_index_);
|
||||
DrawImage(&p, next_rect, Qt::AlignLeft, next_opacity, next_index);
|
||||
@ -145,7 +158,7 @@ void PrettyImageView::DrawImage(QPainter* p, const QRect& rect, Qt::Alignment al
|
||||
return;
|
||||
const Image& image = images_[image_index];
|
||||
|
||||
QSize image_size = image.image_.isNull() ? QSize(100, 160) : image.image_.size();
|
||||
QSize image_size = image.image_.isNull() ? QSize(160, 100) : image.image_.size();
|
||||
|
||||
// Scale the image rect to fit in the rectangle
|
||||
image_size.scale(rect.size(), Qt::KeepAspectRatio);
|
||||
@ -161,7 +174,7 @@ void PrettyImageView::DrawImage(QPainter* p, const QRect& rect, Qt::Alignment al
|
||||
|
||||
// Draw the main image
|
||||
p->setOpacity(opacity);
|
||||
DrawThumbnail(p, draw_rect, image);
|
||||
DrawThumbnail(p, draw_rect, align, image);
|
||||
|
||||
// Draw the reflection
|
||||
// Figure out where to draw it
|
||||
@ -183,7 +196,7 @@ void PrettyImageView::DrawImage(QPainter* p, const QRect& rect, Qt::Alignment al
|
||||
reflection.rect().bottomRight());
|
||||
|
||||
// Draw the reflection into the buffer
|
||||
DrawThumbnail(&reflection_painter, reflection.rect(), image);
|
||||
DrawThumbnail(&reflection_painter, reflection.rect(), align, image);
|
||||
|
||||
// Make it fade out towards the bottom
|
||||
QLinearGradient fade_gradient(fade_rect.topLeft(), fade_rect.bottomLeft());
|
||||
@ -199,14 +212,23 @@ void PrettyImageView::DrawImage(QPainter* p, const QRect& rect, Qt::Alignment al
|
||||
p->drawImage(reflection_rect, reflection);
|
||||
}
|
||||
|
||||
void PrettyImageView::DrawThumbnail(QPainter* p, const QRect& rect, const Image& image) {
|
||||
if (image.image_.isNull()) {
|
||||
// Draw an empty box if there's no image to show
|
||||
void PrettyImageView::DrawThumbnail(QPainter* p, const QRect& rect,
|
||||
Qt::Alignment align, const Image& image) {
|
||||
switch (image.state_) {
|
||||
case Image::WaitingForLazyLoad:
|
||||
case Image::Loading:
|
||||
p->setPen(palette().color(QPalette::Disabled, QPalette::Text));
|
||||
p->drawText(rect, Qt::AlignHCenter | Qt::AlignBottom, tr("Loading..."));
|
||||
} else {
|
||||
// Draw the image
|
||||
p->drawText(rect, align | Qt::AlignBottom, tr("Loading..."));
|
||||
break;
|
||||
|
||||
case Image::Failed:
|
||||
p->setPen(palette().color(QPalette::Disabled, QPalette::Text));
|
||||
p->drawText(rect, align | Qt::AlignBottom, tr("Problem loading image"));
|
||||
break;
|
||||
|
||||
case Image::Loaded:
|
||||
p->drawPixmap(rect, image.thumbnail_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,15 +302,23 @@ void PrettyImageView::ShowFullsize() {
|
||||
|
||||
const QImage& image = images_[current_index_].image_;
|
||||
|
||||
// Work out how large to make the window, based on the size of the screen
|
||||
QRect desktop_rect(QApplication::desktop()->availableGeometry(this));
|
||||
QSize window_size(qMin(desktop_rect.width() - 20, image.width() + 2),
|
||||
qMin(desktop_rect.height() - 20, image.height() + 2));
|
||||
|
||||
// Create the window
|
||||
QScrollArea* window = new QScrollArea;
|
||||
|
||||
QLabel* label = new QLabel(window);
|
||||
label->setPixmap(QPixmap::fromImage(image));
|
||||
window->setWidget(label);
|
||||
|
||||
window->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
window->setWindowTitle(tr("Clementine image viewer"));
|
||||
window->resize(qMin(800, image.width() + 2), qMin(500, image.height() + 2));
|
||||
window->resize(window_size);
|
||||
|
||||
// Create the label that displays the image
|
||||
QLabel* label = new QLabel(window);
|
||||
label->setPixmap(QPixmap::fromImage(image));
|
||||
|
||||
// Show the label in the window
|
||||
window->setWidget(label);
|
||||
window->show();
|
||||
}
|
||||
|
||||
|
@ -61,11 +61,18 @@ private slots:
|
||||
|
||||
private:
|
||||
struct Image {
|
||||
Image(const QUrl& url) : loading_(false), url_(url) {}
|
||||
Image(const QUrl& url) : state_(WaitingForLazyLoad), url_(url) {}
|
||||
|
||||
void SetImage(const QImage& image);
|
||||
|
||||
bool loading_;
|
||||
enum State {
|
||||
WaitingForLazyLoad,
|
||||
Loading,
|
||||
Failed,
|
||||
Loaded,
|
||||
};
|
||||
|
||||
State state_;
|
||||
QUrl url_;
|
||||
QImage image_;
|
||||
QPixmap thumbnail_;
|
||||
@ -77,8 +84,12 @@ private:
|
||||
|
||||
void SetTimeLineActive(QTimeLine* timeline, bool active);
|
||||
|
||||
void DrawImage(QPainter* p, const QRect& rect, Qt::Alignment align, qreal opacity, int image_index);
|
||||
void DrawThumbnail(QPainter* p, const QRect& rect, const Image& image);
|
||||
void DrawImage(QPainter* p, const QRect& rect, Qt::Alignment align,
|
||||
qreal opacity, int image_index);
|
||||
void DrawThumbnail(QPainter* p, const QRect& rect, Qt::Alignment align,
|
||||
const Image& image);
|
||||
|
||||
void LazyLoadImage(int index);
|
||||
|
||||
private slots:
|
||||
void ImageFetched(quint64 id, QNetworkReply* reply);
|
||||
|
Loading…
x
Reference in New Issue
Block a user