aboutsummaryrefslogtreecommitdiff
path: root/src/browsertab.cpp
diff options
context:
space:
mode:
authorKarol Kosek <krkk@krkk.ct8.pl>2021-04-10 21:23:32 +0200
committerFelix Queißner <felix@ib-queissner.de>2021-04-10 22:58:25 +0200
commitf181d989d6fe2c5178bac08e8c47afe599633e85 (patch)
tree1b5136e6df8f0f8a1a81e351629dcc14f82d9493 /src/browsertab.cpp
parent726e965a3390b1a6eceb2f30c581a89a691b7dbe (diff)
BrowserTab: render image loading errors in a document
Diffstat (limited to 'src/browsertab.cpp')
-rw-r--r--src/browsertab.cpp37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/browsertab.cpp b/src/browsertab.cpp
index 5544a3b..e0bcb71 100644
--- a/src/browsertab.cpp
+++ b/src/browsertab.cpp
@@ -708,27 +708,38 @@ void BrowserTab::renderPage(const QByteArray &data, const MimeType &mime)
reader.setAutoDetectImageFormat(true);
auto pixmap = QPixmap::fromImageReader(&reader);
- if (!pixmap.isNull())
+ if (pixmap.isNull())
{
- this->graphics_scene.addPixmap(pixmap);
- this->graphics_scene.setSceneRect(pixmap.rect());
+ doc_type = Text;
+ QString error_data = tr("Failed to load picture: %1").arg(reader.errorString());
+
+ if (plaintext_only)
+ document = PlainTextRenderer::render(error_data.toUtf8(), doc_style);
+ else
+ document = GeminiRenderer::render(
+ error_data.toUtf8(),
+ this->current_location,
+ doc_style,
+ this->outline,
+ this->page_title);
}
else
{
- this->graphics_scene.addText(QString(tr("Failed to load picture:\r\n%1")).arg(reader.errorString()));
- }
+ this->graphics_scene.addPixmap(pixmap);
+ this->graphics_scene.setSceneRect(pixmap.rect());
- this->ui->graphics_browser->setScene(&graphics_scene);
+ this->ui->graphics_browser->setScene(&graphics_scene);
- connect(&graphics_scene, &QGraphicsScene::changed, this, [=]() {
- QSize imageSize = pixmap.size();
- QSize browserSize = this->ui->graphics_browser->sizeHint();
+ connect(&graphics_scene, &QGraphicsScene::changed, this, [=]() {
+ QSize imageSize = pixmap.size();
+ QSize browserSize = this->ui->graphics_browser->sizeHint();
- if (imageSize.width() > browserSize.width() || imageSize.height() > browserSize.height())
- this->ui->graphics_browser->fitInView(graphics_scene.sceneRect(), Qt::KeepAspectRatio);
+ if (imageSize.width() > browserSize.width() || imageSize.height() > browserSize.height())
+ this->ui->graphics_browser->fitInView(graphics_scene.sceneRect(), Qt::KeepAspectRatio);
- this->ui->graphics_browser->setSceneRect(graphics_scene.sceneRect());
- });
+ this->ui->graphics_browser->setSceneRect(graphics_scene.sceneRect());
+ });
+ }
will_cache = false;
}