diff options
Diffstat (limited to 'src-qt5/desktop-utils/lumina-pdf')
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp | 5 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp | 32 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 20 |
3 files changed, 38 insertions, 19 deletions
diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp index 53f3fa62..abb4ac17 100644 --- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp @@ -130,10 +130,11 @@ void PrintWidget::setCurrentPage(int pageNumber) { this->centerOn(pages.at(curPage - 1)); } }*/ + QSize DPI(300, 300); if (lastPage != curPage || !BACKEND->imageSize(curPage).isNull()){ updatePreview(); - for(int i=(curPage-3); i<BACKEND->numPages(); i++){ + for(int i=(curPage-3); i<=BACKEND->numPages(); i++){ if(i<0){ continue; } else if( i < (curPage-2) ){ BACKEND->clearHash(i); } else if( i > (curPage+2) ){ BACKEND->clearHash(i); } @@ -146,7 +147,7 @@ void PrintWidget::setCurrentPage(int pageNumber) { } } } - qDebug() << "Current page set to " << pageNumber << "\n"; + //qDebug() << "Current page set to " << pageNumber << "\n"; } void PrintWidget::highlightText(TextData *text) { diff --git a/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp b/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp index a1620e92..3e3bf678 100644 --- a/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp @@ -3,24 +3,23 @@ #include "link.h" //#include "lrucache.h" #include <QThread> +#include <QMutex> #include <atomic> #include <poppler/qt5/poppler-qt5.h> static std::unique_ptr<Poppler::Document> DOC; QHash<int, QImage> loadingHash; +QMutex hashMutex; //static std::vector<LuminaPDF::drawablePage> pages; static std::vector<QList<LuminaPDF::Link *>> links; -static std::atomic<int> pagesStillLoading; +//static std::atomic<int> pagesStillLoading; // static QHash<int, QList<LuminaPDF::Link *>> linkHash; //static LuminaPDF::LRUCache<QImage> imageCache; -QSize DPI; -int ROTATE = 0; - Renderer::Renderer() : pnum(0), needpass(false), degrees(0) { DOC.reset(nullptr); - pagesStillLoading = 1; + //pagesStillLoading = 1; //imageCache.setCacheSize(5); } @@ -107,11 +106,15 @@ bool Renderer::loadDocument(QString path, QString password) { void Renderer::renderPage(int pagenum, QSize DPI, int degrees) { if(loadingHash.contains(pagenum)){ return; } //nothing to do - qDebug() << "Render Page:" << pagenum << DPI << degrees; + //qDebug() << "Render Page:" << pagenum;// << DPI << degrees; + hashMutex.lock(); + loadingHash.insert(pagenum, QImage()); //temporary placeholder while we load the image + hashMutex.unlock(); + //emit SetProgress(pnum - pagesStillLoading); if (DOC != nullptr) { - Poppler::Page *PAGE = DOC->page(pagenum - 1); + Poppler::Page *PAGE = DOC->page(pagenum-1); //needs to be 0+ QImage img; if (PAGE != nullptr) { Poppler::Page::Rotation rotation; @@ -133,7 +136,9 @@ void Renderer::renderPage(int pagenum, QSize DPI, int degrees) { //pages[pagenum] = std::move(temp); img = PAGE->renderToImage(DPI.width(), DPI.height(), -1, -1, -1, -1, rotation); + hashMutex.lock(); loadingHash.insert(pagenum, img); + hashMutex.unlock(); /*QList<LuminaPDF::Link *> linkArray; foreach (Poppler::Link *link, PAGE->links()) { @@ -147,14 +152,15 @@ void Renderer::renderPage(int pagenum, QSize DPI, int degrees) { linkArray.append(newLink); } - links[pagenum] = linkArray; + links[pagenum] = linkArray;*/ // linkHash.insert(pagenum, linkArray); - */ } //qDebug() << "Done Render Page:" << pagenum << img.size(); - } else { - //pages[pagenum] = LuminaPDF::drawablePage(); - loadingHash.insert(pagenum, QImage()); + }else{ + //Could not load the image - go ahead and remove it from the loading hash + hashMutex.lock(); + loadingHash.remove(pagenum); + hashMutex.unlock(); } //if (pagesStillLoading > 0) { @@ -210,8 +216,10 @@ int Renderer::hashSize() { } void Renderer::clearHash( int pagenum) { + hashMutex.lock(); if(pagenum<0){ loadingHash.clear(); } else if(loadingHash.contains(pagenum)){ loadingHash.remove(pagenum); } + hashMutex.unlock(); //pages.clear(); } diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp index 8278f77a..d2dc5231 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -106,9 +106,13 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()) { tmp->setExclusive(true); tmp->addAction(ui->actionSingle_Page); tmp->addAction(ui->actionDual_Pages); - tmp->addAction(ui->actionAll_Pages); + //tmp->addAction(ui->actionAll_Pages); ui->actionSingle_Page->setChecked(true); + //Disable the all pages view - does not work with partial cache of pages + ui->actionAll_Pages->setVisible(false); + ui->actionAll_Pages->setEnabled(false); + // Connect up the buttons QObject::connect(ui->actionClose, SIGNAL(triggered()), this, SLOT(close())); QObject::connect(ui->actionPrint, SIGNAL(triggered()), PrintDLG, @@ -439,7 +443,11 @@ void MainUI::ShowPage(int page) { // Blank page (useful so there is one blank page after the last slide before // stopping the presentation) presentationLabel->setPixmap(QPixmap()); - presentationLabel->setText(tr("Presentation Finished: Hit \"ESC\" key to close presentation view")); + if(CurrentPage>BACKEND->numPages() || CurrentPage <1){ + presentationLabel->setText(tr("Presentation Finished: Hit \"ESC\" key to close presentation view")); + }else{ + presentationLabel->setText(tr("Loading Page....")); + } presentationLabel->setAlignment(Qt::AlignBottom | Qt::AlignHCenter); } } @@ -520,19 +528,21 @@ void MainUI::slotPageLoaded(int page) { //qDebug() << "slotPageLoaded"; /*loadingQueue.push_back(page); int finished = loadingQueue.size();*/ - //qDebug() << "Page Loaded:" << page << finished; + //qDebug() << "Page Loaded:" << page; //if (finished == BACKEND->numPages()) { progAct->setVisible(false); WIDGET->setVisible(true); BOOKMARKS->setVisible(true); - //ui->splitter->setSizes(QList<int>() << 0 << this->width()); - //WIDGET->setCurrentPage(1); + if(BACKEND->getBookmarks().isEmpty()){ + ui->splitter->setSizes(QList<int>() << 0 << this->width()); + } ui->actionStop_Presentation->setEnabled(false); ui->actionStart_Here->setEnabled(true); ui->actionStart_Begin->setEnabled(true); pageAct->setVisible(true); PROPDIALOG->setSize(pageSize); //qDebug() << " - Document Setup: All pages loaded"; + ShowPage(page); } // QTimer::singleShot(10, WIDGET, // SLOT(updatePreview())); // start loading the file preview |