diff options
author | Ken Moore <ken@ixsystems.com> | 2018-01-24 12:24:09 -0500 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2018-01-24 12:24:09 -0500 |
commit | 768822f63c5e8086543438765450d8d20ce0a0fe (patch) | |
tree | 869aba8006dba9f454afafc618ad05cbdae9184b /src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | |
parent | a Couple more minor tweaks. (diff) | |
download | lumina-768822f63c5e8086543438765450d8d20ce0a0fe.tar.gz lumina-768822f63c5e8086543438765450d8d20ce0a0fe.tar.bz2 lumina-768822f63c5e8086543438765450d8d20ce0a0fe.zip |
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.
Diffstat (limited to 'src-qt5/desktop-utils/lumina-pdf/mainUI.cpp')
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp index 57afbfe1..04cba34b 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -106,7 +106,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ connect(ui->actionNext_Page, SIGNAL(triggered()), this, SLOT(nextPage()) ); connect(ui->actionLast_Page, SIGNAL(triggered()), this, SLOT(lastPage()) ); connect(ui->actionProperties, SIGNAL(triggered()), this, SLOT(showInformation())); - connect(ui->actionFind, SIGNAL(triggered()), this, SLOT(enableFind())); + connect(ui->actionFind, SIGNAL(triggered()), this, SLOT(enableFind())); connect(ui->actionFind_Next, &QAction::triggered, this, [&] { find(ui->textEdit->text(), true); }); connect(ui->actionFind_Previous, &QAction::triggered, this, @@ -244,20 +244,12 @@ void MainUI::loadFile(QString path){ } void MainUI::loadPage(int num, Poppler::Document *doc, MainUI *obj, QSize dpi, QSizeF page){ - //PERFORMANCE NOTES: - // Using Poppler to scale the image (adjust dpi value) helps a bit but you take a large CPU loading hit (and still quite a lot of pixelization) - // Using Qt to scale the image (adjust page value) smooths out the image quite a bit without a lot of performance loss (but cannot scale up without pixelization) - // The best approach seams to be to increase the DPI a bit, but match that with the same scaling on the page size (smoothing) - //qDebug() << " - Render Page:" << num; Poppler::Page *PAGE = doc->page(num); if(PAGE!=0){ - //qDebug() << "DPI:" << dpi << "Size:" << page << "Page Size (pt):" << PAGE->pageSize(); - float scalefactor = (dpi.width()/72.0); //How different the screen DPI compares to standard page DPI - //qDebug() << "Scale Factor:" << scalefactor; - QImage raw = PAGE->renderToImage((scalefactor+0.2)*dpi.width(), (scalefactor+0.2)*dpi.height()); //make the raw image a tiny bit larger than the end result + QImage raw = PAGE->renderToImage(dpi.width(),dpi.height()); //make the raw image a bit larger than the end result //qDebug() << " - Raw Image Size:" << raw.size(); - loadingHash.insert(num, raw.scaled(scalefactor*page.width(), scalefactor*page.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation) ); + loadingHash.insert(num, raw.scaled(page.width(), page.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation) ); raw = QImage(); //clear it /* QList<Annotation*> anno = PAGE->annotations(Annotations::AText ); @@ -312,7 +304,7 @@ void MainUI::startPresentation(bool atStart){ QScreen *screen = getScreen(false, cancelled); //let the user select which screen to use (if multiples) if(cancelled){ return;} int page = 0; - if(!atStart){ page = WIDGET->currentPage()-1; } //currentPage() starts at 1 rather than 0 + if(!atStart){ page = WIDGET->currentPage(); } //PDPI = QSize(SCALEFACTOR*screen->physicalDotsPerInchX(), SCALEFACTOR*screen->physicalDotsPerInchY()); //Now create the full-screen window on the selected screen if(presentationLabel == 0){ @@ -343,16 +335,18 @@ void MainUI::startPresentation(bool atStart){ void MainUI::ShowPage(int page){ //Check for valid document/page //qDebug() << "Load Page:" << page << "/" << numPages << "Index:" << page; - if(page<0 || page > numPages || (page==numPages && CurrentPage==page) ){ + if(page<0 || page > numPages+1 || (page==numPages && CurrentPage==page) ){ endPresentation(); return; //invalid - no document loaded or invalid page specified } WIDGET->setCurrentPage(page); //page numbers start at 1 for this widget //Stop here if no presentation currently running + if(presentationLabel == 0 || !presentationLabel->isVisible()){ return; } + //qDebug() << "Show Page:" << page << "/" << numPages; CurrentPage = page; QImage PAGEIMAGE; - if(page<numPages){ PAGEIMAGE = loadingHash[page]; } + if(page<numPages+1){ PAGEIMAGE = loadingHash[page-1]; } //Now scale the image according to the user-designations and show it if(!PAGEIMAGE.isNull()){ @@ -379,21 +373,31 @@ void MainUI::endPresentation(){ void MainUI::startLoadingPages(){ if(numPages>0){ return; } //currently loaded[ing] - qDebug() << " - Start Loading Pages"; + //qDebug() << " - Start Loading Pages"; + loadingHash.clear(); numPages = DOC->numPages(); //qDebug() << "numPages:" << numPages; progress->setRange(0,numPages); progress->setValue(0); progAct->setVisible(true); - QSizeF pageSize = DOC->page(0)->pageSizeF()*2; + + //PERFORMANCE NOTES: + // Using Poppler to scale the image (adjust dpi value) helps a bit but you take a larger CPU loading hit (and still quite a lot of pixelization) + // Using Qt to scale the image (adjust page value) smooths out the image quite a bit without a lot of performance loss (but cannot scale up without pixelization) + // The best approach seams to be to increase the DPI a bit, but match that with the same scaling on the page size (smoothing) + + double scalefactor = 2.0; + QSizeF pageSize = DOC->page(0)->pageSizeF()*scalefactor; //QSize DPI(loadingHash[0]->resolution(),loadingHash[0]->resolution()); QSize DPI(76,76); + DPI = DPI*(scalefactor+1); //need this a bit higher than the page scaling + /*qDebug() << "Screen Resolutions:"; QList<QScreen*> screens = QApplication::screens(); for(int i=0; i<screens.length(); i++){ qDebug() << screens[i]->name() << screens[i]->logicalDotsPerInchX() << screens[i]->logicalDotsPerInchY(); }*/ - qDebug() << "Poppler pageSize: " << pageSize; + //qDebug() << "Poppler pageSize: " << pageSize; for(int i=0; i<numPages; i++){ //qDebug() << " - Kickoff page load:" << i; QtConcurrent::run(this, &MainUI::loadPage, i, DOC, this, DPI, pageSize); @@ -404,12 +408,13 @@ void MainUI::slotPageLoaded(int page){ Q_UNUSED(page); //qDebug() << "Page Loaded:" << page; int finished = loadingHash.keys().length(); + //qDebug() << " - finished:" << finished; if(finished == numPages){ progAct->setVisible(false); - qDebug() << "Setting Pictures"; + //qDebug() << "Setting Pictures"; WIDGET->setPictures(&loadingHash); WIDGET->setVisible(true); - //QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); + QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); //qDebug() << "Updating"; ui->actionStop_Presentation->setEnabled(false); ui->actionStart_Here->setEnabled(true); @@ -419,10 +424,6 @@ void MainUI::slotPageLoaded(int page){ } } -/*void MainUI::slotStartPresentation(QAction *act){ - startPresentation(act == ui->actionAt_Beginning); -}*/ - void MainUI::paintToPrinter(QPrinter *PRINTER){ if(loadingHash.keys().length() != numPages){ return; } @@ -512,7 +513,7 @@ void MainUI::rotate(bool ccw) { loadingHash.insert(i, image); } //Rotates the page as well as the image - //WIDGET->setOrientation((WIDGET->orientation() == QPageLayout::Landscape) ? + //WIDGET->setOrientation((WIDGET->orientation() == QPageLayout::Landscape) ? //QPageLayout::Portrait : QPageLayout::Landscape); QTimer::singleShot(0, WIDGET, SLOT(updatePreview())); } @@ -553,7 +554,7 @@ void MainUI::keyPressEvent(QKeyEvent *event){ if(inPresentation){ endPresentation(); } else{ startPresentationHere(); } }else if(event->key() == Qt::Key_Up) { - //Scroll the widget up + //Scroll the widget up }else if(event->key() == Qt::Key_Down) { //Scroll the widget down /*qDebug() << "Send Wheel Event"; @@ -589,7 +590,7 @@ void MainUI::find(QString text, bool forward) { for(int i = 0; i < numPages; i++) { QList<Poppler::TextBox*> textList = DOC->page(i)->textList(); for(int j = 0; j < textList.size(); j++) { - if(textList[j]->text().contains(text, (matchCase) + if(textList[j]->text().contains(text, (matchCase) ? Qt::CaseSensitive : Qt::CaseInsensitive)) { results.insert(textList[j], i); } @@ -606,7 +607,7 @@ void MainUI::find(QString text, bool forward) { }else{ currentHighlight--; //Ensure currentHighlight will be between 0 and results.size() - 1 - if(currentHighlight < 0) + if(currentHighlight < 0) currentHighlight = results.size() - 1; } @@ -618,7 +619,7 @@ void MainUI::find(QString text, bool forward) { QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); }else{ - //Print "No results found" + //Print "No results found" } } } @@ -626,17 +627,17 @@ void MainUI::find(QString text, bool forward) { void MainUI::enableFind() { if(ui->findGroup->isVisible()) { qDebug() << "Disabling Find"; - ui->findGroup->setVisible(false); - WIDGET->setGeometry(QRect(WIDGET->pos(), + ui->findGroup->setVisible(false); + WIDGET->setGeometry(QRect(WIDGET->pos(), QSize(WIDGET->width(), WIDGET->height()+ui->findGroup->height()))); QTimer::singleShot(0, WIDGET, SLOT(updatePreview())); this->setFocus(); }else{ qDebug() << "Enabling Find"; - ui->findGroup->setGeometry(QRect(QPoint(0, WIDGET->height()-ui->findGroup->height()), + ui->findGroup->setGeometry(QRect(QPoint(0, WIDGET->height()-ui->findGroup->height()), QSize(WIDGET->width()-12, ui->findGroup->height()))); - ui->findGroup->setVisible(true); - WIDGET->setGeometry(QRect(WIDGET->pos(), + ui->findGroup->setVisible(true); + WIDGET->setGeometry(QRect(WIDGET->pos(), QSize(WIDGET->width(), WIDGET->height()-ui->findGroup->height()))); QTimer::singleShot(0, WIDGET, SLOT(updatePreview())); @@ -650,7 +651,7 @@ void MainUI::showBookmarks() { void MainUI::resizeEvent(QResizeEvent *event) { if(ui->findGroup->isVisible()) { - ui->findGroup->setGeometry(QRect(QPoint(0, WIDGET->height()-ui->findGroup->height()), + ui->findGroup->setGeometry(QRect(QPoint(0, WIDGET->height()-ui->findGroup->height()), QSize(WIDGET->width()-10, ui->findGroup->height()))); } QMainWindow::resizeEvent(event); |