From 2332239082db6a33ee66bb08491c1e9cf099f9b6 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Tue, 18 Dec 2018 09:53:00 +0100 Subject: preview works --- src/gui/previewwindow.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/gui/previewwindow.cpp') diff --git a/src/gui/previewwindow.cpp b/src/gui/previewwindow.cpp index 0a37e1b..8625045 100644 --- a/src/gui/previewwindow.cpp +++ b/src/gui/previewwindow.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include PreviewWindow::PreviewWindow(QWidget *parent) : @@ -45,7 +46,15 @@ PreviewWindow::~PreviewWindow() void PreviewWindow::setPdf(QString file) { Poppler::Document *oldDoc = _doc; - _doc = Poppler::Document::load(file); + Poppler::Document *newDoc = Poppler::Document::load(file); + if (!newDoc) { + QMessageBox::warning(nullptr, + "Could not read PDF", + "Could not read: '" + file + "'."); + return; + } + + _doc = newDoc; _doc->setRenderHint(Poppler::Document::Antialiasing); _doc->setRenderHint(Poppler::Document::TextAntialiasing); _doc->setRenderHint(Poppler::Document::TextHinting ); @@ -82,8 +91,8 @@ void PreviewWindow::render() { QSizeF size = _page->pageSizeF(); QRect rect = ui->scrollArea->visibleRegion().boundingRect(); - int w = rect.width(); - int h = rect.height(); + int w = rect.width() - 20; + int h = rect.height() - 20; qreal scale = fmin(static_cast(w) / size.width(), static_cast(h) / size.height()); int dpi = static_cast(scale * 72.0); -- cgit v1.2.3