From 672e26a24a9f86364afe9bc3c7ed440c73b670d5 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 14 Mar 2017 11:27:53 -0400 Subject: Fix up the loading of multuple files within the same session. Move the progress bar to the top toolbar instead of a bottom one. --- src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 64 +++++++++++++++++++---------- src-qt5/desktop-utils/lumina-pdf/mainUI.h | 3 +- src-qt5/desktop-utils/lumina-pdf/mainUI.ui | 24 +---------- 3 files changed, 46 insertions(+), 45 deletions(-) (limited to 'src-qt5') diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp index 8149aac6..9e396a40 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -23,22 +24,21 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ this->setWindowIcon( LXDG::findIcon("application-pdf","unknown")); lastdir = QDir::homePath(); - PRINTER = new QPrinter(); - WIDGET = new QPrintPreviewWidget(PRINTER, this); + Printer = new QPrinter(); + WIDGET = new QPrintPreviewWidget(Printer, this); this->setCentralWidget(WIDGET); connect(WIDGET, SIGNAL(paintRequested(QPrinter*)), this, SLOT(paintOnWidget(QPrinter*)) ); DOC = 0; - PrintDLG = new QPrintDialog(PRINTER,this); + PrintDLG = new QPrintDialog(Printer,this); connect(PrintDLG, SIGNAL(accepted(QPrinter*)), this, SLOT(paintOnWidget(QPrinter*)) ); //Can change to PaintToPrinter() later //Create the other interface widgets progress = new QProgressBar(this); progress->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); progress->setFormat("%v/%m (%p%)"); // [current]/[total] - ui->toolBar2->addWidget(progress); - ui->toolBar2->setVisible(false); - + progAct = ui->toolBar->addWidget(progress); + progAct->setVisible(false); //Put the various actions into logical groups QActionGroup *tmp = new QActionGroup(this); tmp->setExclusive(true); @@ -79,27 +79,42 @@ MainUI::~MainUI(){ } void MainUI::loadFile(QString path){ + + if(!QFile::exists(path) || path.isEmpty() ){ return; } + Poppler::Document *TDOC = Poppler::Document::load(path); + if(TDOC==0){ + qDebug() << "Could not open file:" << path; + return; + }else if(TDOC->isLocked()){ + //Prompt for password to unlock the document + QString pass = ""; + bool ok = true; //flag this to go into the loop the first time (if password prompt is cancelled - this becomes false) + while( (ok ? true : !TDOC->unlock(QByteArray(), pass.toLocal8Bit())) ){ //make sure the unlock function is only called when ok is true + pass = QInputDialog::getText(this, tr("Unlock PDF"), tr("Password:"), QLineEdit::Password, "", &ok); + } + if(TDOC->isLocked()){ return; } //Cancelled - still locked + } + if(DOC!=0){ //Clear out the old document first delete DOC; DOC=0; } + DOC = TDOC; //Save this for later qDebug() << "Opening File:" << path; - if(!QFile::exists(path) || path.isEmpty() ){ return; } - DOC = Poppler::Document::load(path); - if(DOC!=0){ this->setWindowTitle(DOC->title()); } + this->setWindowTitle(DOC->title()); if(this->windowTitle().isEmpty()){ this->setWindowTitle(path.section("/",-1)); } //Setup the Document Poppler::Page *PAGE = DOC->page(0); if(PAGE!=0){ lastdir = path.section("/",0,-2); //save this for later - PRINTER->setPageSize( QPageSize(PAGE->pageSize(), QPageSize::Point) ); + Printer->setPageSize( QPageSize(PAGE->pageSize(), QPageSize::Point) ); switch(PAGE->orientation()){ case Poppler::Page::Landscape: - PRINTER->setOrientation(QPrinter::Landscape); break; + Printer->setOrientation(QPrinter::Landscape); break; default: - PRINTER->setOrientation(QPrinter::Portrait); + Printer->setOrientation(QPrinter::Portrait); } delete PAGE; WIDGET->updatePreview(); //start loading the file preview @@ -109,8 +124,8 @@ void MainUI::loadFile(QString path){ void MainUI::paintOnWidget(QPrinter *PRINTER){ if(DOC==0){ return; } - this->show(); - QApplication::processEvents(); + //this->show(); + //QApplication::processEvents(); int pages = DOC->numPages(); int firstpage = 0; //qDebug() << "Start Rendering PDF:" << PRINTER->fromPage() << PRINTER->toPage(); @@ -123,25 +138,30 @@ void MainUI::paintOnWidget(QPrinter *PRINTER){ QRectF size = PRINTER->pageRect(QPrinter::DevicePixel); QSize DPI(PRINTER->resolution(),PRINTER->resolution()); QPainter painter(PRINTER); - Poppler::Page *PAGE = 0; - progress->setRange(firstpage, pages-1); - ui->toolBar2->setVisible(true); + //qDebug() << "Set progress bar range:" << firstpage+1 << pages; + progress->setRange(firstpage+1,pages+1); + //progress->setValue(firstpage); + progAct->setVisible(true); + for(int i=firstpage; isetValue(i); //qDebug() << "Loading Page:" << i; + progress->setValue(i+1); + //qDebug() << " - ProcessEvents"; QApplication::processEvents(); //Now paint this page on the printer - if(PAGE!=0){ delete PAGE; PRINTER->newPage(); } //this is the start of the next page (not needed for first) - PAGE = DOC->page(i); + //qDebug() << " - Load Poppler Page"; + if(i != firstpage){ PRINTER->newPage(); } //this is the start of the next page (not needed for first) + Poppler::Page *PAGE = DOC->page(i); if(PAGE!=0){ painter.drawImage(0,0,PAGE->renderToImage(DPI.width(), DPI.height()).scaled(size.width(), size.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation) ); }else{ painter.drawImage(0,0,QImage()); } + if(PAGE!=0){ delete PAGE; } //QApplication::processEvents(); } - if(PAGE!=0){ delete PAGE; } - ui->toolBar2->setVisible(false); + //qDebug() << "Done Loading Pages"; + progAct->setVisible(false); } void MainUI::OpenNewFile(){ diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.h b/src-qt5/desktop-utils/lumina-pdf/mainUI.h index e25eab2b..d7de8485 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h @@ -32,13 +32,14 @@ private: Poppler::Document *DOC; QPrintPreviewWidget *WIDGET; Ui::MainUI *ui; - QPrinter* PRINTER; + QPrinter* Printer; QPrintDialog *PrintDLG; QString lastdir; //Other Interface elements QProgressBar *progress; + QAction *progAct; //action associated with the progressbar private slots: void paintOnWidget(QPrinter *PRINTER); diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.ui b/src-qt5/desktop-utils/lumina-pdf/mainUI.ui index 5547d219..e12cd6fd 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.ui +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.ui @@ -20,7 +20,7 @@ 0 0 659 - 22 + 20 @@ -50,7 +50,7 @@ TopToolBarArea - true + false @@ -59,26 +59,6 @@ - - - toolBar_2 - - - false - - - Qt::BottomToolBarArea - - - false - - - BottomToolBarArea - - - false - - Open PDF -- cgit From 93dca5272ec13a70f2421534e0c2937affa79c0d Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 15 Mar 2017 10:34:32 -0400 Subject: A couple more updates for lumina-pdf, slower loading with 2x DPI right now, still working on finding the right balance of DPI/speed. --- src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 13 +++++++++---- src-qt5/desktop-utils/lumina-pdf/mainUI.h | 6 ++++++ 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src-qt5') diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp index 9e396a40..fefa6158 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -25,12 +26,12 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ lastdir = QDir::homePath(); Printer = new QPrinter(); - WIDGET = new QPrintPreviewWidget(Printer, this); + WIDGET = new QPrintPreviewWidget(Printer,this); this->setCentralWidget(WIDGET); connect(WIDGET, SIGNAL(paintRequested(QPrinter*)), this, SLOT(paintOnWidget(QPrinter*)) ); DOC = 0; - PrintDLG = new QPrintDialog(Printer,this); + PrintDLG = new QPrintDialog(this); connect(PrintDLG, SIGNAL(accepted(QPrinter*)), this, SLOT(paintOnWidget(QPrinter*)) ); //Can change to PaintToPrinter() later //Create the other interface widgets @@ -110,6 +111,7 @@ void MainUI::loadFile(QString path){ if(PAGE!=0){ lastdir = path.section("/",0,-2); //save this for later Printer->setPageSize( QPageSize(PAGE->pageSize(), QPageSize::Point) ); + Printer->setPageMargins(QMarginsF(0,0,0,0), QPageLayout::Point); switch(PAGE->orientation()){ case Poppler::Page::Landscape: Printer->setOrientation(QPrinter::Landscape); break; @@ -137,12 +139,15 @@ void MainUI::paintOnWidget(QPrinter *PRINTER){ //Now start painting all the pages onto the widget QRectF size = PRINTER->pageRect(QPrinter::DevicePixel); QSize DPI(PRINTER->resolution(),PRINTER->resolution()); + //QScreen *scrn = QApplication::screens().first(); + //QSize SDPI(scrn->logicalDotsPerInchX(), scrn->logicalDotsPerInchY()); QPainter painter(PRINTER); //qDebug() << "Set progress bar range:" << firstpage+1 << pages; progress->setRange(firstpage+1,pages+1); //progress->setValue(firstpage); progAct->setVisible(true); - + qDebug() << "Printer DPI:" << DPI; + //qDebug() << "Screen DPI:" << SDPI; for(int i=firstpage; isetValue(i+1); @@ -153,7 +158,7 @@ void MainUI::paintOnWidget(QPrinter *PRINTER){ if(i != firstpage){ PRINTER->newPage(); } //this is the start of the next page (not needed for first) Poppler::Page *PAGE = DOC->page(i); if(PAGE!=0){ - painter.drawImage(0,0,PAGE->renderToImage(DPI.width(), DPI.height()).scaled(size.width(), size.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation) ); + painter.drawImage(0,0,PAGE->renderToImage(2*DPI.width(), 2*DPI.height()).scaled(size.width(), size.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation) ); }else{ painter.drawImage(0,0,QImage()); } diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.h b/src-qt5/desktop-utils/lumina-pdf/mainUI.h index d7de8485..7198b3c3 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h @@ -41,11 +41,17 @@ private: QProgressBar *progress; QAction *progAct; //action associated with the progressbar + private slots: + //void startPainting(QPrinter *PRINTER); void paintOnWidget(QPrinter *PRINTER); + //void paintPage(QPrinter *PRINTER, QImage img, bool newpage); //Button Slots void OpenNewFile(); +signals: + //void pageLoaded(QPrinter*, QImage, bool); + }; #endif -- cgit From dbd3d9febcbfd27be5d4c92aaa02e33a1a0b6765 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 15 Mar 2017 12:05:01 -0400 Subject: Remove the alpha channel from the alternate base color for lumina-glass - base colors should not be transparent since many base widgets do not permit transparency. --- src-qt5/core/colors/Lumina-Glass.qss.colors | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src-qt5') diff --git a/src-qt5/core/colors/Lumina-Glass.qss.colors b/src-qt5/core/colors/Lumina-Glass.qss.colors index 89534aaa..4c75b1dd 100644 --- a/src-qt5/core/colors/Lumina-Glass.qss.colors +++ b/src-qt5/core/colors/Lumina-Glass.qss.colors @@ -1,6 +1,6 @@ ACCENTCOLOR=rgba(255,252,234,100) ACCENTDISABLECOLOR=rgba(0,0,0,100) -ALTBASECOLOR=rgba(255,255,255,125) +ALTBASECOLOR=rgb(255,255,255) BASECOLOR=rgb(247,246,244) HIGHLIGHTCOLOR=rgba(212,212,212,170) HIGHLIGHTDISABLECOLOR=rgba(184,184,184,100) -- cgit