diff options
Diffstat (limited to 'src-qt5')
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 64 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/mainUI.h | 3 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/mainUI.ui | 24 |
3 files changed, 46 insertions, 45 deletions
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 <QImage> #include <QSize> #include <QFileDialog> +#include <QInputDialog> #include <QDebug> #include <QApplication> @@ -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; i<pages; i++){ - progress->setValue(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 @@ <x>0</x> <y>0</y> <width>659</width> - <height>22</height> + <height>20</height> </rect> </property> <widget class="QMenu" name="menuFile"> @@ -50,7 +50,7 @@ <enum>TopToolBarArea</enum> </attribute> <attribute name="toolBarBreak"> - <bool>true</bool> + <bool>false</bool> </attribute> <addaction name="actionFit_Page"/> <addaction name="actionFit_Width"/> @@ -59,26 +59,6 @@ <addaction name="actionDual_Pages"/> <addaction name="actionAll_Pages"/> </widget> - <widget class="QToolBar" name="toolBar2"> - <property name="windowTitle"> - <string>toolBar_2</string> - </property> - <property name="movable"> - <bool>false</bool> - </property> - <property name="allowedAreas"> - <set>Qt::BottomToolBarArea</set> - </property> - <property name="floatable"> - <bool>false</bool> - </property> - <attribute name="toolBarArea"> - <enum>BottomToolBarArea</enum> - </attribute> - <attribute name="toolBarBreak"> - <bool>false</bool> - </attribute> - </widget> <action name="actionOpen_PDF"> <property name="text"> <string>Open PDF</string> |