aboutsummaryrefslogtreecommitdiff
path: root/src-qt5
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5')
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp19
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/PrintWidget.h2
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp5
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp86
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/Renderer.h2
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/lrucache.h5
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/mainUI.cpp26
7 files changed, 92 insertions, 53 deletions
diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp
index 7a2251cd..53f3fa62 100644
--- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp
+++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp
@@ -1,6 +1,7 @@
#include "PrintWidget.h"
#include <QGraphicsProxyWidget>
#include <QPushButton>
+#include <QtConcurrent>
PrintWidget::PrintWidget(Renderer *backend, QWidget *parent)
: QGraphicsView(parent), scene(0), curPage(1), viewMode(SinglePageView),
@@ -129,11 +130,23 @@ void PrintWidget::setCurrentPage(int pageNumber) {
this->centerOn(pages.at(curPage - 1));
}
}*/
-
- if (lastPage != curPage){
+ QSize DPI(300, 300);
+ if (lastPage != curPage || !BACKEND->imageSize(curPage).isNull()){
updatePreview();
+ 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); }
+ else{
+ if (BACKEND->loadMultiThread()) {
+ QtConcurrent::run(BACKEND, &Renderer::renderPage, i, DPI, degrees);
+ } else {
+ BACKEND->renderPage(i, DPI, degrees);
+ }
+ }
+ }
}
- //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/PrintWidget.h b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h
index 1240d140..0eebeb88 100644
--- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h
+++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h
@@ -60,7 +60,7 @@ public:
ZoomMode getZoomMode() const { return this->zoomMode; }
int currentPage() const {
return curPage;
- return publicPageNum;
+ //return publicPageNum;
}
signals:
diff --git a/src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp b/src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp
index 002650f2..5acf71c7 100644
--- a/src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp
+++ b/src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp
@@ -657,9 +657,10 @@ QSize Renderer::imageSize(int pagenum){
int Renderer::hashSize() { return dataHash.size(); }
-void Renderer::clearHash() {
+void Renderer::clearHash(int pagenum) {
//qDeleteAll(dataHash);
- dataHash.clear();
+ if(pagenum<0){ dataHash.clear(); }
+ else if(dataHash.contains(pagenum)){ dataHash.remove(pagenum); }
}
TextData *Renderer::linkList(int pagenum, int entry) {
diff --git a/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp b/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp
index 8f0755d4..a1620e92 100644
--- a/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp
+++ b/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp
@@ -1,7 +1,7 @@
#include "Renderer.h"
#include "drawablepage.h"
#include "link.h"
-#include "lrucache.h"
+//#include "lrucache.h"
#include <QThread>
#include <atomic>
#include <poppler/qt5/poppler-qt5.h>
@@ -9,21 +9,24 @@
static std::unique_ptr<Poppler::Document> DOC;
QHash<int, QImage> loadingHash;
-static std::vector<LuminaPDF::drawablePage> pages;
+//static std::vector<LuminaPDF::drawablePage> pages;
static std::vector<QList<LuminaPDF::Link *>> links;
static std::atomic<int> pagesStillLoading;
// static QHash<int, QList<LuminaPDF::Link *>> linkHash;
-static LuminaPDF::LRUCache<QImage> imageCache;
+//static LuminaPDF::LRUCache<QImage> imageCache;
+
+QSize DPI;
+int ROTATE = 0;
Renderer::Renderer() : pnum(0), needpass(false), degrees(0) {
DOC.reset(nullptr);
pagesStillLoading = 1;
- imageCache.setCacheSize(5);
+ //imageCache.setCacheSize(5);
}
Renderer::~Renderer() {
// qDeleteAll(loadingHash);
- pages.clear();
+ //pages.clear();
for (auto &linkList : links) {
qDeleteAll(linkList);
}
@@ -41,7 +44,7 @@ bool Renderer::loadDocument(QString path, QString password) {
if (DOC != nullptr && path != docpath) {
// Clear out the old document first
DOC.reset(nullptr);
- pages.clear();
+ //pages.clear();
links.clear();
needpass = false;
pnum = 0;
@@ -83,9 +86,9 @@ bool Renderer::loadDocument(QString path, QString password) {
WIDGET->setOrientation(QPageLayout::Portrait);
}*/
delete PAGE;
- pages.reserve(pnum + 1);
+ //pages.reserve(pnum + 1);
- for (int i = 0; i < pnum + 1; ++i) {
+ /*for (int i = 0; i < pnum + 1; ++i) {
LuminaPDF::drawablePage temp;
pages.emplace_back(std::move(temp));
}
@@ -94,8 +97,8 @@ bool Renderer::loadDocument(QString path, QString password) {
QList<LuminaPDF::Link *> temp;
links.push_back(temp);
}
-
- pagesStillLoading = pnum;
+ */
+ //pagesStillLoading = pnum;
return true; // could load the first page
}
@@ -103,9 +106,9 @@ bool Renderer::loadDocument(QString path, QString password) {
}
void Renderer::renderPage(int pagenum, QSize DPI, int degrees) {
- // qDebug() << "Render Page:" << pagenum << DPI << degrees;
-
- emit SetProgress(pages.size() - pagesStillLoading);
+ if(loadingHash.contains(pagenum)){ return; } //nothing to do
+ qDebug() << "Render Page:" << pagenum << DPI << degrees;
+ //emit SetProgress(pnum - pagesStillLoading);
if (DOC != nullptr) {
Poppler::Page *PAGE = DOC->page(pagenum - 1);
@@ -127,11 +130,11 @@ void Renderer::renderPage(int pagenum, QSize DPI, int degrees) {
}
LuminaPDF::drawablePage temp(PAGE, DPI, rotation);
- pages[pagenum] = std::move(temp);
- // img = PAGE->renderToImage(DPI.width(), DPI.height(), -1, -1, -1, -1,
- // rotation);
- // loadingHash.insert(pagenum, img);
- QList<LuminaPDF::Link *> linkArray;
+ //pages[pagenum] = std::move(temp);
+ img = PAGE->renderToImage(DPI.width(), DPI.height(), -1, -1, -1, -1,
+ rotation);
+ loadingHash.insert(pagenum, img);
+ /*QList<LuminaPDF::Link *> linkArray;
foreach (Poppler::Link *link, PAGE->links()) {
QString location;
@@ -146,21 +149,22 @@ void Renderer::renderPage(int pagenum, QSize DPI, int degrees) {
links[pagenum] = linkArray;
// linkHash.insert(pagenum, linkArray);
+ */
}
- // qDebug() << "Done Render Page:" << pagenum << img.size();
+ //qDebug() << "Done Render Page:" << pagenum << img.size();
} else {
- pages[pagenum] = LuminaPDF::drawablePage();
- // loadingHash.insert(pagenum, QImage());
+ //pages[pagenum] = LuminaPDF::drawablePage();
+ loadingHash.insert(pagenum, QImage());
}
- if (pagesStillLoading == 1) {
+ //if (pagesStillLoading > 0) {
emit PageLoaded(pagenum);
- }
+ //}
- --pagesStillLoading;
+ //--pagesStillLoading;
}
-bool Renderer::isDoneLoading(int page) { return imageCache.contains(page); }
+bool Renderer::isDoneLoading(int page) { return loadingHash.contains(page); }
QList<TextData *> Renderer::searchDocument(QString text, bool matchCase) {
QList<TextData *> results;
@@ -178,31 +182,37 @@ QList<TextData *> Renderer::searchDocument(QString text, bool matchCase) {
}
QSize Renderer::imageSize(int pagenum) {
- if(!imageCache.contains(pagenum)){ return QSize(); }
- return pages[pagenum].size();
+ if(!loadingHash.contains(pagenum)){ return QSize(); }
+ return loadingHash[pagenum].size();
}
QImage Renderer::imageHash(int pagenum) {
- if(!imageCache.contains(pagenum)){ return QImage(); }
+ if(loadingHash.contains(pagenum)){
+ return loadingHash[pagenum];
+ }else{
+ return QImage();
+ }
+ //if(!imageCache.contains(pagenum)){ return QImage(); }
// while(pagesStillLoading > 0) { qDebug() << "pagesStillLoading!\n";}
- std::optional<QImage> cachedImage = imageCache.get(pagenum);
+ //std::optional<QImage> cachedImage = imageCache.get(pagenum);
- if (cachedImage.has_value())
- return *cachedImage;
+ /*if (cachedImage.has_value())
+ return *cachedImage;*/
- imageCache.push(pagenum, pages[pagenum].render());
- return *imageCache.get(pagenum);
+ //imageCache.push(pagenum, pages[pagenum].render());
+ //return *imageCache.get(pagenum);
}
int Renderer::hashSize() {
- qDebug() << "pages contains " << pages.size() << " elements.\n";
- return pages.size();
+ //qDebug() << "pages contains " << pages.size() << " elements.\n";
+ return loadingHash.size();
}
-void Renderer::clearHash() {
- loadingHash.clear();
- pages.clear();
+void Renderer::clearHash( int pagenum) {
+ if(pagenum<0){ loadingHash.clear(); }
+ else if(loadingHash.contains(pagenum)){ loadingHash.remove(pagenum); }
+ //pages.clear();
}
// Highlighting found text, bookmarks, and page properties disabled for Poppler
diff --git a/src-qt5/desktop-utils/lumina-pdf/Renderer.h b/src-qt5/desktop-utils/lumina-pdf/Renderer.h
index 6d4e4736..3b3fa3c7 100644
--- a/src-qt5/desktop-utils/lumina-pdf/Renderer.h
+++ b/src-qt5/desktop-utils/lumina-pdf/Renderer.h
@@ -59,7 +59,7 @@ public:
virtual Widget *widgetList(int, int);
virtual int widgetSize(int);
- virtual void clearHash();
+ virtual void clearHash(int pagenum = -1);
// Makes sure degrees is between 0 and 360 then rotates the matrix and
void setDegrees(int degrees) {
// Mods by 360, but adds and remods because of how C++ treats negative mods
diff --git a/src-qt5/desktop-utils/lumina-pdf/lrucache.h b/src-qt5/desktop-utils/lumina-pdf/lrucache.h
index 8c68c1bb..0ed241c2 100644
--- a/src-qt5/desktop-utils/lumina-pdf/lrucache.h
+++ b/src-qt5/desktop-utils/lumina-pdf/lrucache.h
@@ -44,6 +44,11 @@ public:
hashmap[k] = values.begin();
}
+ bool contains(const Key k){
+ auto itr = hashmap.find(k);
+ return ( itr!=hashmap.end() );
+ }
+
private:
size_t max;
std::list<std::tuple<Key, Value>> values;
diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp
index 1b93f3c3..8278f77a 100644
--- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp
+++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp
@@ -481,7 +481,13 @@ void MainUI::startLoadingPages(int degrees) {
// 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)
- QSize DPI(250, 250); // print-quality (some printers even go to 600 DPI nowdays)
+ //QSize DPI(250, 250); // print-quality (some printers even go to 600 DPI nowdays)
+
+
+ int curpage = WIDGET->currentPage();
+ if(curpage<0){ curpage = 1; }
+ else if(curpage>=BACKEND->numPages()){ curpage=BACKEND->numPages(); }
+ WIDGET->setCurrentPage(curpage);
/*qDebug() << "Screen Resolutions:";
QList<QScreen*> screens = QApplication::screens();
@@ -489,7 +495,7 @@ void MainUI::startLoadingPages(int degrees) {
qDebug() << screens[i]->name() << screens[i]->logicalDotsPerInchX() <<
screens[i]->logicalDotsPerInchY();
}*/
- int n = BACKEND->numPages() + 1;
+ /*int n = BACKEND->numPages() + 1;
for (int i = 1; i < n; i++) {
// qDebug() << " - Kickoff page load:" << i;
if (BACKEND->loadMultiThread()) {
@@ -500,23 +506,27 @@ void MainUI::startLoadingPages(int degrees) {
QCoreApplication::processEvents();
}
}
- }
+ }*/
//qDebug() << "Finish page loading kickoff";
}
void MainUI::slotSetProgress(int finished) { progress->setValue(finished); }
void MainUI::slotPageLoaded(int page) {
+ int curpage = WIDGET->currentPage();
+ if(curpage == page || (curpage <0 && page==1) ){
+ //current page loaded
+
//qDebug() << "slotPageLoaded";
- loadingQueue.push_back(page);
- int finished = loadingQueue.size();
+ /*loadingQueue.push_back(page);
+ int finished = loadingQueue.size();*/
//qDebug() << "Page Loaded:" << page << finished;
- if (finished == BACKEND->numPages()) {
+ //if (finished == BACKEND->numPages()) {
progAct->setVisible(false);
WIDGET->setVisible(true);
BOOKMARKS->setVisible(true);
- ui->splitter->setSizes(QList<int>() << 0 << this->width());
- WIDGET->setCurrentPage(1);
+ //ui->splitter->setSizes(QList<int>() << 0 << this->width());
+ //WIDGET->setCurrentPage(1);
ui->actionStop_Presentation->setEnabled(false);
ui->actionStart_Here->setEnabled(true);
ui->actionStart_Begin->setEnabled(true);
bgstack15