From 768822f63c5e8086543438765450d8d20ce0a0fe Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 24 Jan 2018 12:24:09 -0500 Subject: Fix up the rendering quality of the lumina-pdf pages. Also get the new backend working properly with the next/previous page system and presentation mode. --- src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp | 38 +++++++++++++----------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp') diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp index be00e675..30f94e32 100644 --- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp @@ -1,6 +1,6 @@ #include "PrintWidget.h" -PrintWidget::PrintWidget(QWidget *parent) : QGraphicsView(parent), scene(0), curPage(1), +PrintWidget::PrintWidget(QWidget *parent) : QGraphicsView(parent), scene(0), curPage(1), viewMode(SinglePageView), zoomMode(FitInView), zoomFactor(1), initialized(false), fitting(true) { this->setMouseTracking(true); @@ -101,9 +101,10 @@ void PrintWidget::setVisible(bool visible) { } void PrintWidget::setCurrentPage(int pageNumber) { + if(pageNumber < 0 || pageNumber > (pages.count()+1) ){ return; } + publicPageNum = pageNumber; //publicly requested page number (+/- 1 from actual page range) if(pageNumber < 1 || pageNumber > pages.count()) return; - int lastPage = curPage; curPage = pageNumber; @@ -132,8 +133,8 @@ void PrintWidget::generatePreview() { populateScene(); // i.e. setPreviewPrintedPictures() e.l. layoutPages(); curPage = qBound(1, curPage, pages.count()); - if (fitting) - fit(); + publicPageNum = curPage; + if (fitting){ fit(); } } void PrintWidget::layoutPages() { @@ -145,22 +146,22 @@ void PrintWidget::layoutPages() { int cols = 1; // singleMode and default if (viewMode == AllPagesView) { cols = ((pictures->value(0)).width() > (pictures->value(0)).height()) ? qFloor(qSqrt(numPages)) : qCeil(qSqrt(numPages)); - cols += cols % 2; // Nicer with an even number of cols - } else if (viewMode == FacingPagesView) { + cols += cols % 2; // Nicer with an even number of cols + } else if (viewMode == FacingPagesView) { cols = 2; - numPagePlaces += 1; - } + numPagePlaces += 1; + } int rows = qCeil(double(numPagePlaces) / cols); - double itemWidth = pages.at(0)->boundingRect().width(); - double itemHeight = pages.at(0)->boundingRect().height(); - int pageNum = 1; for (int i = 0; i < rows && pageNum <= numPages; i++) { - for (int j = 0; j < cols && pageNum <= numPages; j++) { + double itemWidth = pages.at(0)->boundingRect().width(); + double itemHeight = pages.at(0)->boundingRect().height(); + int pageNum = 1; for (int i = 0; i < rows && pageNum <= numPages; i++) { + for (int j = 0; j < cols && pageNum <= numPages; j++) { if (!i && !j && viewMode == FacingPagesView) { - continue; - } else { - pages.at(pageNum-1)->setPos(QPointF(j*itemWidth, i*itemHeight)); - pageNum++; + continue; + } else { + pages.at(pageNum-1)->setPos(QPointF(j*itemWidth, i*itemHeight)); + pageNum++; } } } @@ -180,7 +181,7 @@ void PrintWidget::populateScene() qDebug() << "Image paperSize" << paperSize; for (int i = 0; i < numPages; i++) { - PageItem* item = new PageItem(i+1, (*pictures)[i], paperSize); + PageItem* item = new PageItem(i+1, (*pictures)[i].scaled( paperSize, Qt::KeepAspectRatio, Qt::SmoothTransformation), paperSize); scene->addItem(item); pages.append(item); } @@ -194,6 +195,7 @@ void PrintWidget::updateCurrentPage() { int newPage = calcCurrentPage(); if (newPage != curPage) { curPage = newPage; + publicPageNum = curPage; } } @@ -272,7 +274,7 @@ void PrintWidget::fit(bool doFitting) { void PrintWidget::setPictures(QHash *hash) { pictures = hash; -} +} void PrintWidget::setOrientation(QPageLayout::Orientation ori) { this->orientation = ori; -- cgit From 1adfea70bef728d359818db15ee3f6339303e360 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 24 Jan 2018 14:26:20 -0500 Subject: Some more final changes to lumina-pdf. This is now completely useable as full-fledged PDF **viewer** (not editor yet). --- src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp') diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp index 30f94e32..d2f2cd46 100644 --- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp @@ -36,10 +36,12 @@ PrintWidget::~PrintWidget() { void PrintWidget::fitView() { setZoomMode(FitInView); + setCurrentPage(publicPageNum); //Make sure we stay on the same page } void PrintWidget::fitToWidth() { setZoomMode(FitToWidth); + setCurrentPage(publicPageNum); //Make sure we stay on the same page } void PrintWidget::setZoomMode(ZoomMode mode) { @@ -103,6 +105,7 @@ void PrintWidget::setVisible(bool visible) { void PrintWidget::setCurrentPage(int pageNumber) { if(pageNumber < 0 || pageNumber > (pages.count()+1) ){ return; } publicPageNum = pageNumber; //publicly requested page number (+/- 1 from actual page range) + emit currentPageChanged(); if(pageNumber < 1 || pageNumber > pages.count()) return; int lastPage = curPage; @@ -134,6 +137,7 @@ void PrintWidget::generatePreview() { layoutPages(); curPage = qBound(1, curPage, pages.count()); publicPageNum = curPage; + emit currentPageChanged(); if (fitting){ fit(); } } @@ -196,6 +200,7 @@ void PrintWidget::updateCurrentPage() { if (newPage != curPage) { curPage = newPage; publicPageNum = curPage; + emit currentPageChanged(); } } -- cgit