diff options
author | Ken Moore <ken@ixsystems.com> | 2017-03-17 12:11:37 -0400 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2017-03-17 12:11:37 -0400 |
commit | 982246b8aafe790776092276174b5b294e9eab8b (patch) | |
tree | 33c8b2759a219d98f7311a4dc57354f82809c3a2 /src-qt5/desktop-utils | |
parent | Add the beginnings of a new "lumina-mediaplayer" application. This is a hobby... (diff) | |
parent | Remove the alpha channel from the alternate base color for lumina-glass - bas... (diff) | |
download | lumina-982246b8aafe790776092276174b5b294e9eab8b.tar.gz lumina-982246b8aafe790776092276174b5b294e9eab8b.tar.bz2 lumina-982246b8aafe790776092276174b5b294e9eab8b.zip |
Merge branch 'master' of github.com:trueos/lumina
Diffstat (limited to 'src-qt5/desktop-utils')
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 71 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/mainUI.h | 9 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/mainUI.ui | 24 |
3 files changed, 58 insertions, 46 deletions
diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp index 8149aac6..fefa6158 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -11,8 +11,10 @@ #include <QImage> #include <QSize> #include <QFileDialog> +#include <QInputDialog> #include <QDebug> #include <QApplication> +#include <QScreen> #include <LuminaXDG.h> @@ -23,22 +25,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(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 +80,43 @@ 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) ); + Printer->setPageMargins(QMarginsF(0,0,0,0), QPageLayout::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 +126,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(); @@ -122,26 +139,34 @@ 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); - 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); + qDebug() << "Printer DPI:" << DPI; + //qDebug() << "Screen DPI:" << SDPI; 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) ); + 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()); } + 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..7198b3c3 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h @@ -32,19 +32,26 @@ 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 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 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> |