From a560b3b1f5ac5931bf1c45f6c3f72d9974ab125a Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 10 Aug 2017 22:50:35 -0400 Subject: Get lumina-pdf almost finished. 1) Add Presentation mode 2) Multi-thread the document loading routines --- src-qt5/experimental/lumina-pdf/lumina-pdf.pro | 2 +- src-qt5/experimental/lumina-pdf/main.cpp | 6 +- src-qt5/experimental/lumina-pdf/mainUI.cpp | 182 ++++++++++++++++++++----- src-qt5/experimental/lumina-pdf/mainUI.h | 57 +++++++- src-qt5/experimental/lumina-pdf/mainUI.ui | 26 +++- 5 files changed, 232 insertions(+), 41 deletions(-) (limited to 'src-qt5/experimental/lumina-pdf') diff --git a/src-qt5/experimental/lumina-pdf/lumina-pdf.pro b/src-qt5/experimental/lumina-pdf/lumina-pdf.pro index 7d5562ed..c1c1c681 100644 --- a/src-qt5/experimental/lumina-pdf/lumina-pdf.pro +++ b/src-qt5/experimental/lumina-pdf/lumina-pdf.pro @@ -15,7 +15,7 @@ target.path = $${L_BINDIR} include(../../core/libLumina/LUtils.pri) #includes LUtils include(../../core/libLumina/LuminaXDG.pri) -SOURCES += main.cpp\ +SOURCES += main.cpp \ mainUI.cpp HEADERS += mainUI.h diff --git a/src-qt5/experimental/lumina-pdf/main.cpp b/src-qt5/experimental/lumina-pdf/main.cpp index f6bb9839..f0430fc8 100644 --- a/src-qt5/experimental/lumina-pdf/main.cpp +++ b/src-qt5/experimental/lumina-pdf/main.cpp @@ -10,20 +10,18 @@ int main(int argc, char ** argv) { //LTHEME::LoadCustomEnvSettings(); + unsetenv("QT_AUTO_SCREEN_SCALE_FACTOR"); //need pixel-perfect geometries QApplication a(argc, argv); LUtils::LoadTranslation(&a, "l-pdf"); - //LuminaThemeEngine theme(&a); - //Read the input variables QString path = ""; for(int i=1; i #include #include +#include + +#include #include MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ ui->setupUi(this); - + presentationLabel = 0; this->setWindowTitle(tr("Lumina PDF Viewer")); this->setWindowIcon( LXDG::findIcon("application-pdf","unknown")); - + CurrentPage = 0; lastdir = QDir::homePath(); Printer = new QPrinter(); WIDGET = new QPrintPreviewWidget(Printer,this); this->setCentralWidget(WIDGET); connect(WIDGET, SIGNAL(paintRequested(QPrinter*)), this, SLOT(paintOnWidget(QPrinter*)) ); DOC = 0; + connect(this, SIGNAL(PageLoaded(int)), this, SLOT(slotPageLoaded(int)) ); PrintDLG = new QPrintDialog(this); connect(PrintDLG, SIGNAL(accepted(QPrinter*)), this, SLOT(paintOnWidget(QPrinter*)) ); //Can change to PaintToPrinter() later + connect(ui->menuStart_Presentation, SIGNAL(triggered(QAction*)), this, SLOT(slotStartPresentation(QAction*)) ); //Create the other interface widgets progress = new QProgressBar(this); @@ -101,6 +106,8 @@ void MainUI::loadFile(QString path){ delete DOC; DOC=0; } + loadingHash.clear(); //clear out this hash + numPages = -1; DOC = TDOC; //Save this for later qDebug() << "Opening File:" << path; this->setWindowTitle(DOC->title()); @@ -110,7 +117,7 @@ void MainUI::loadFile(QString path){ 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: @@ -119,15 +126,149 @@ void MainUI::loadFile(QString path){ Printer->setOrientation(QPrinter::Portrait); } delete PAGE; - WIDGET->updatePreview(); //start loading the file preview + qDebug() << " - Document Setup"; + QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); //start loading the file preview } } +void MainUI::loadPage(int num, Poppler::Document *doc, MainUI *obj, QSize dpi, QSizeF page){ + //qDebug() << " - Render Page:" << num; + Poppler::Page *PAGE = doc->page(num); + if(PAGE!=0){ + loadingHash.insert(num, PAGE->renderToImage(3*dpi.width(), 3*dpi.height()).scaled(page.width(), page.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation) ); + }else{ + loadingHash.insert(num, QImage()); + } + if(PAGE!=0){ delete PAGE; } + obj->emit PageLoaded(num); +} + +QScreen* MainUI::getScreen(bool current, bool &cancelled){ + //Note: the "cancelled" boolian is actually an output - not an input + QList screens = QApplication::screens(); + cancelled = false; + if(screens.length() ==1){ return screens[0]; } //only one option + //Multiple screens available - figure it out + if(current){ + //Just return the screen the window is currently on + for(int i=0; igeometry().contains( this->mapToGlobal(this->pos()) )){ + return screens[i]; + } + } + //If it gets this far, there was an error and it should just return the primary screen + return QApplication::primaryScreen(); + }else{ + //Ask the user to select a screen (for presentations, etc..) + QStringList names; + for(int i=0; isize().width())+"x"+QString::number(screens[i]->size().height()); + names << QString(tr("%1 (%2)")).arg(screens[i]->name(), screensize); + } + bool ok = false; + QString sel = QInputDialog::getItem(this, tr("Select Screen"), tr("Screen:"), names, 0, false, &ok); + cancelled = !ok; + if(!ok){ return screens[0]; } //cancelled - just return the first one + int index = names.indexOf(sel); + if(index < 0){ return screens[0]; } //error - should never happen though + return screens[index]; //return the selected screen + } +} + +void MainUI::startPresentation(bool atStart){ + if(DOC==0){ return; } //just in case + bool cancelled = false; + QScreen *screen = getScreen(false, cancelled); //let the user select which screen to use (if multiples) + if(cancelled){ return;} + int page = 0; + if(!atStart){ page = CurrentPage; } + //PDPI = QSize(SCALEFACTOR*screen->physicalDotsPerInchX(), SCALEFACTOR*screen->physicalDotsPerInchY()); + //Now create the full-screen window on the selected screen + if(presentationLabel == 0){ + //Create the label and any special flags for it + presentationLabel = new QLabel(0, Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + presentationLabel->setStyleSheet("background-color: black;"); + presentationLabel->setAlignment(Qt::AlignCenter); + } + //Now put the label in the proper location + presentationLabel->setGeometry(screen->geometry()); + presentationLabel->showFullScreen(); + + ui->actionStop_Presentation->setEnabled(true); + ui->menuStart_Presentation->setEnabled(false); + QApplication::processEvents(); + //Now start at the proper page + ShowPage(page); + this->grabKeyboard(); //Grab any keyboard events - even from the presentation window +} + +void MainUI::ShowPage(int page){ + if(presentationLabel == 0 || !presentationLabel->isVisible()){ return; } + //Check for valid document/page + if(page<0 || page >=numPages ){ + endPresentation(); + return; //invalid - no document loaded or invalid page specified + } + CurrentPage = page; + QImage PAGEIMAGE = loadingHash[page]; + + //Now scale the image according to the user-designations and show it + if(!PAGEIMAGE.isNull()){ + QPixmap pix; + pix.convertFromImage( PAGEIMAGE.scaled( presentationLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation) ); + presentationLabel->setPixmap(pix); + presentationLabel->show(); //always make sure it was not hidden + }else{ + presentationLabel->setPixmap(QPixmap()); + endPresentation(); + } +} + +void MainUI::endPresentation(){ + if(presentationLabel==0 || !presentationLabel->isVisible()){ return; } //not in presentation mode + presentationLabel->hide(); //just hide this (no need to re-create the label for future presentations) + ui->actionStop_Presentation->setEnabled(false); + ui->menuStart_Presentation->setEnabled(true); + this->releaseKeyboard(); +} + +void MainUI::startLoadingPages(QPrinter *printer){ + if(numPages>0){ return; } //currently loaded[ing] + //qDebug() << " - Start Loading Pages"; + numPages = DOC->numPages(); + progress->setRange(0,numPages); + progress->setValue(0); + progAct->setVisible(true); + QRectF pageSize = printer->pageRect(QPrinter::DevicePixel); + QSize DPI(printer->resolution(),printer->resolution()); + for(int i=0; isetVisible(false); + progAct->setVisible(false); + QTimer::singleShot(0, WIDGET, SLOT(updatePreview())); + }else{ + progress->setValue(finished); + } +} + +void MainUI::slotStartPresentation(QAction *act){ + startPresentation(act == ui->actionAt_Beginning); +} + void MainUI::paintOnWidget(QPrinter *PRINTER){ if(DOC==0){ return; } //this->show(); - //QApplication::processEvents(); + if(loadingHash.keys().length() != numPages){ startLoadingPages(PRINTER); return; } + int pages = DOC->numPages(); int firstpage = 0; //qDebug() << "Start Rendering PDF:" << PRINTER->fromPage() << PRINTER->toPage(); @@ -135,38 +276,12 @@ void MainUI::paintOnWidget(QPrinter *PRINTER){ firstpage = PRINTER->fromPage() - 1; pages = PRINTER->toPage(); } - qDebug() << " - Generating Pages:" << firstpage << pages; - //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); - //qDebug() << " - ProcessEvents"; - QApplication::processEvents(); - //Now paint this page on the printer - //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(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(loadingHash.contains(i)){ painter.drawImage(0,0, loadingHash[i]); } + else{ painter.drawImage(0,0, QImage()); } } - //qDebug() << "Done Loading Pages"; - progAct->setVisible(false); } void MainUI::OpenNewFile(){ @@ -174,5 +289,4 @@ void MainUI::OpenNewFile(){ QString path = QFileDialog::getOpenFileName(this, tr("Open PDF"), lastdir, tr("PDF Documents (*.pdf)")); //Now Open it if(!path.isEmpty()){ loadFile(path); } - } diff --git a/src-qt5/experimental/lumina-pdf/mainUI.h b/src-qt5/experimental/lumina-pdf/mainUI.h index 1bd1699b..fa1d5a55 100644 --- a/src-qt5/experimental/lumina-pdf/mainUI.h +++ b/src-qt5/experimental/lumina-pdf/mainUI.h @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include #include @@ -41,12 +44,64 @@ private: QProgressBar *progress; QAction *progAct; //action associated with the progressbar - + //PDF Page Loading cache variables + QHash loadingHash; + int numPages; + + void loadPage(int num, Poppler::Document *doc, MainUI *obj, QSize dpi, QSizeF page); + + //Functions/variables for the presentation mode + QLabel *presentationLabel; + QScreen *getScreen(bool current, bool &cancelled); + int CurrentPage; + void startPresentation(bool atStart); + void ShowPage(int page); + void endPresentation(); + private slots: + void startLoadingPages(QPrinter *printer); + void slotPageLoaded(int); + void slotStartPresentation(QAction *act); + void paintOnWidget(QPrinter *PRINTER); //Button Slots void OpenNewFile(); +signals: + void PageLoaded(int); + +protected: + void keyPressEvent(QKeyEvent *event){ + //See if this is one of the special hotkeys and act appropriately + // NOTE: Some of this is duplicated with the QShortcut definitions (for non-presentation mode) + // This routine does not always work for the main window viewer due to differing widget focus policies + if(presentationLabel!=0 && presentationLabel->isVisible()){ + //qDebug() << "Got Key Press:"; + if( event->key()==Qt::Key_Escape || event->key()==Qt::Key_Backspace){ + //qDebug() << " - Escape/Backspace"; + endPresentation(); + }else if(event->key()==Qt::Key_Right || event->key()==Qt::Key_Down || event->key()==Qt::Key_Space){ + //qDebug() << " - Right/Down/Spacebar"; + ShowPage( CurrentPage+1 ); + }else if(event->key()==Qt::Key_Left || event->key()==Qt::Key_Up){ + //qDebug() << " - Left/Up"; + ShowPage( CurrentPage-1 ); + }else if(event->key()==Qt::Key_Home){ + //qDebug() << " - Home"; + ShowPage(0); //go to the first page + }else if(event->key()==Qt::Key_End){ + //qDebug() << " - End"; + ShowPage( numPages-1 ); //go to the last page + }else if(event->key()==Qt::Key_F11){ + //qDebug() << " - F11"; + endPresentation(); + }else{ + QMainWindow::keyPressEvent(event); + } + }else{ + QMainWindow::keyPressEvent(event); + } + } }; #endif diff --git a/src-qt5/experimental/lumina-pdf/mainUI.ui b/src-qt5/experimental/lumina-pdf/mainUI.ui index e12cd6fd..bbc76bab 100644 --- a/src-qt5/experimental/lumina-pdf/mainUI.ui +++ b/src-qt5/experimental/lumina-pdf/mainUI.ui @@ -20,7 +20,7 @@ 0 0 659 - 20 + 24 @@ -33,7 +33,21 @@ + + + Presentation + + + + Start Presentation + + + + + + + @@ -123,6 +137,16 @@ All Pages + + + At Beginning + + + + + Stop Presentation + + -- cgit From e9d9cc6a2aeaf1cc87bc258d75c56c860a456aca Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Fri, 11 Aug 2017 13:57:18 -0400 Subject: Remove the "experimental" lumina-pdf directory. Is included in the desktop-utils builds now. --- src-qt5/experimental/lumina-pdf/lumina-pdf.desktop | 10 - src-qt5/experimental/lumina-pdf/lumina-pdf.pro | 101 ------- src-qt5/experimental/lumina-pdf/main.cpp | 29 -- src-qt5/experimental/lumina-pdf/mainUI.cpp | 292 --------------------- src-qt5/experimental/lumina-pdf/mainUI.h | 107 -------- src-qt5/experimental/lumina-pdf/mainUI.ui | 153 ----------- 6 files changed, 692 deletions(-) delete mode 100644 src-qt5/experimental/lumina-pdf/lumina-pdf.desktop delete mode 100644 src-qt5/experimental/lumina-pdf/lumina-pdf.pro delete mode 100644 src-qt5/experimental/lumina-pdf/main.cpp delete mode 100644 src-qt5/experimental/lumina-pdf/mainUI.cpp delete mode 100644 src-qt5/experimental/lumina-pdf/mainUI.h delete mode 100644 src-qt5/experimental/lumina-pdf/mainUI.ui (limited to 'src-qt5/experimental/lumina-pdf') diff --git a/src-qt5/experimental/lumina-pdf/lumina-pdf.desktop b/src-qt5/experimental/lumina-pdf/lumina-pdf.desktop deleted file mode 100644 index c9632c9f..00000000 --- a/src-qt5/experimental/lumina-pdf/lumina-pdf.desktop +++ /dev/null @@ -1,10 +0,0 @@ -[Desktop Entry] -Exec=lumina-pdf %f -Icon=application-pdf -Terminal=false -Type=Application -StartupNotify=true -Categories=Utility; -MimeType=application/pdf; -Name=Lumina PDF Viewer -Comment=View PDF Files diff --git a/src-qt5/experimental/lumina-pdf/lumina-pdf.pro b/src-qt5/experimental/lumina-pdf/lumina-pdf.pro deleted file mode 100644 index c1c1c681..00000000 --- a/src-qt5/experimental/lumina-pdf/lumina-pdf.pro +++ /dev/null @@ -1,101 +0,0 @@ -include("$${PWD}/../../OS-detect.pri") - -QT += core gui -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets concurrent - - -TARGET = lumina-pdf -TEMPLATE = app - -QT += printsupport - -target.path = $${L_BINDIR} - -#include all the special classes from the Lumina tree -include(../../core/libLumina/LUtils.pri) #includes LUtils -include(../../core/libLumina/LuminaXDG.pri) - -SOURCES += main.cpp \ - mainUI.cpp - -HEADERS += mainUI.h - -FORMS += mainUI.ui - -LIBS += -lpoppler-qt5 -INCLUDEPATH+= $${L_INCLUDEDIR}/poppler/qt5 - -TRANSLATIONS = i18n/l-pdf_af.ts \ - i18n/l-pdf_ar.ts \ - i18n/l-pdf_az.ts \ - i18n/l-pdf_bg.ts \ - i18n/l-pdf_bn.ts \ - i18n/l-pdf_bs.ts \ - i18n/l-pdf_ca.ts \ - i18n/l-pdf_cs.ts \ - i18n/l-pdf_cy.ts \ - i18n/l-pdf_da.ts \ - i18n/l-pdf_de.ts \ - i18n/l-pdf_el.ts \ - i18n/l-pdf_en_GB.ts \ - i18n/l-pdf_en_ZA.ts \ - i18n/l-pdf_es.ts \ - i18n/l-pdf_et.ts \ - i18n/l-pdf_eu.ts \ - i18n/l-pdf_fa.ts \ - i18n/l-pdf_fi.ts \ - i18n/l-pdf_fr.ts \ - i18n/l-pdf_fr_CA.ts \ - i18n/l-pdf_gl.ts \ - i18n/l-pdf_he.ts \ - i18n/l-pdf_hi.ts \ - i18n/l-pdf_hr.ts \ - i18n/l-pdf_hu.ts \ - i18n/l-pdf_id.ts \ - i18n/l-pdf_is.ts \ - i18n/l-pdf_it.ts \ - i18n/l-pdf_ja.ts \ - i18n/l-pdf_ka.ts \ - i18n/l-pdf_ko.ts \ - i18n/l-pdf_lt.ts \ - i18n/l-pdf_lv.ts \ - i18n/l-pdf_mk.ts \ - i18n/l-pdf_mn.ts \ - i18n/l-pdf_ms.ts \ - i18n/l-pdf_mt.ts \ - i18n/l-pdf_nb.ts \ - i18n/l-pdf_nl.ts \ - i18n/l-pdf_pa.ts \ - i18n/l-pdf_pl.ts \ - i18n/l-pdf_pt.ts \ - i18n/l-pdf_pt_BR.ts \ - i18n/l-pdf_ro.ts \ - i18n/l-pdf_ru.ts \ - i18n/l-pdf_sk.ts \ - i18n/l-pdf_sl.ts \ - i18n/l-pdf_sr.ts \ - i18n/l-pdf_sv.ts \ - i18n/l-pdf_sw.ts \ - i18n/l-pdf_ta.ts \ - i18n/l-pdf_tg.ts \ - i18n/l-pdf_th.ts \ - i18n/l-pdf_tr.ts \ - i18n/l-pdf_uk.ts \ - i18n/l-pdf_uz.ts \ - i18n/l-pdf_vi.ts \ - i18n/l-pdf_zh_CN.ts \ - i18n/l-pdf_zh_HK.ts \ - i18n/l-pdf_zh_TW.ts \ - i18n/l-pdf_zu.ts - -dotrans.path=$${L_SHAREDIR}/lumina-desktop/i18n/ -dotrans.extra=cd i18n && $${LRELEASE} -nounfinished *.ts && cp *.qm $(INSTALL_ROOT)$${L_SHAREDIR}/lumina-desktop/i18n/ - -desktop.files=lumina-pdf.desktop -desktop.path=$${L_SHAREDIR}/applications/ - -INSTALLS += target desktop - -WITH_I18N{ - INSTALLS += dotrans -} diff --git a/src-qt5/experimental/lumina-pdf/main.cpp b/src-qt5/experimental/lumina-pdf/main.cpp deleted file mode 100644 index f0430fc8..00000000 --- a/src-qt5/experimental/lumina-pdf/main.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include -#include - -#include "mainUI.h" -#include -//#include - -int main(int argc, char ** argv) -{ - //LTHEME::LoadCustomEnvSettings(); - unsetenv("QT_AUTO_SCREEN_SCALE_FACTOR"); //need pixel-perfect geometries - QApplication a(argc, argv); - LUtils::LoadTranslation(&a, "l-pdf"); - - //Read the input variables - QString path = ""; - for(int i=1; i -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ - ui->setupUi(this); - presentationLabel = 0; - this->setWindowTitle(tr("Lumina PDF Viewer")); - this->setWindowIcon( LXDG::findIcon("application-pdf","unknown")); - CurrentPage = 0; - lastdir = QDir::homePath(); - Printer = new QPrinter(); - WIDGET = new QPrintPreviewWidget(Printer,this); - this->setCentralWidget(WIDGET); - connect(WIDGET, SIGNAL(paintRequested(QPrinter*)), this, SLOT(paintOnWidget(QPrinter*)) ); - DOC = 0; - connect(this, SIGNAL(PageLoaded(int)), this, SLOT(slotPageLoaded(int)) ); - - PrintDLG = new QPrintDialog(this); - connect(PrintDLG, SIGNAL(accepted(QPrinter*)), this, SLOT(paintOnWidget(QPrinter*)) ); //Can change to PaintToPrinter() later - connect(ui->menuStart_Presentation, SIGNAL(triggered(QAction*)), this, SLOT(slotStartPresentation(QAction*)) ); - - //Create the other interface widgets - progress = new QProgressBar(this); - progress->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); - progress->setFormat("%v/%m (%p%)"); // [current]/[total] - progAct = ui->toolBar->addWidget(progress); - progAct->setVisible(false); - //Put the various actions into logical groups - QActionGroup *tmp = new QActionGroup(this); - tmp->setExclusive(true); - tmp->addAction(ui->actionFit_Width); - tmp->addAction(ui->actionFit_Page); - ui->actionFit_Page->setChecked(true); - - tmp = new QActionGroup(this); - tmp->setExclusive(true); - tmp->addAction(ui->actionSingle_Page); - tmp->addAction(ui->actionDual_Pages); - tmp->addAction(ui->actionAll_Pages); - ui->actionSingle_Page->setChecked(true); - - //Connect up the buttons - connect(ui->actionClose, SIGNAL(triggered()), this, SLOT(close()) ); - connect(ui->actionPrint, SIGNAL(triggered()), PrintDLG, SLOT(open()) ); - connect(ui->actionFit_Width, SIGNAL(triggered()), WIDGET, SLOT(fitToWidth()) ); - connect(ui->actionFit_Page, SIGNAL(triggered()), WIDGET, SLOT(fitInView()) ); - connect(ui->actionOpen_PDF, SIGNAL(triggered()), this, SLOT(OpenNewFile()) ); - connect(ui->actionSingle_Page, SIGNAL(triggered()), WIDGET, SLOT(setSinglePageViewMode()) ); - connect(ui->actionDual_Pages, SIGNAL(triggered()), WIDGET, SLOT(setFacingPagesViewMode()) ); - connect(ui->actionAll_Pages, SIGNAL(triggered()), WIDGET, SLOT(setAllPagesViewMode()) ); - - //Setup all the icons - ui->actionPrint->setIcon( LXDG::findIcon("document-print","")); - ui->actionClose->setIcon( LXDG::findIcon("window-close","")); - ui->actionFit_Width->setIcon(LXDG::findIcon("arrow-expand-all","")); - ui->actionFit_Page->setIcon(LXDG::findIcon("zoom-fit-best","")); - ui->actionOpen_PDF->setIcon(LXDG::findIcon("document-open","")); - ui->actionSingle_Page->setIcon(LXDG::findIcon("view-preview","")); - ui->actionDual_Pages->setIcon(LXDG::findIcon("format-view-agenda","")); - ui->actionAll_Pages->setIcon(LXDG::findIcon("format-view-grid-small","")); -} - -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; - } - loadingHash.clear(); //clear out this hash - numPages = -1; - DOC = TDOC; //Save this for later - qDebug() << "Opening File:" << path; - 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->setPageMargins(QMarginsF(0,0,0,0), QPageLayout::Point); - switch(PAGE->orientation()){ - case Poppler::Page::Landscape: - Printer->setOrientation(QPrinter::Landscape); break; - default: - Printer->setOrientation(QPrinter::Portrait); - } - delete PAGE; - qDebug() << " - Document Setup"; - QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); //start loading the file preview - } - -} - -void MainUI::loadPage(int num, Poppler::Document *doc, MainUI *obj, QSize dpi, QSizeF page){ - //qDebug() << " - Render Page:" << num; - Poppler::Page *PAGE = doc->page(num); - if(PAGE!=0){ - loadingHash.insert(num, PAGE->renderToImage(3*dpi.width(), 3*dpi.height()).scaled(page.width(), page.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation) ); - }else{ - loadingHash.insert(num, QImage()); - } - if(PAGE!=0){ delete PAGE; } - obj->emit PageLoaded(num); -} - -QScreen* MainUI::getScreen(bool current, bool &cancelled){ - //Note: the "cancelled" boolian is actually an output - not an input - QList screens = QApplication::screens(); - cancelled = false; - if(screens.length() ==1){ return screens[0]; } //only one option - //Multiple screens available - figure it out - if(current){ - //Just return the screen the window is currently on - for(int i=0; igeometry().contains( this->mapToGlobal(this->pos()) )){ - return screens[i]; - } - } - //If it gets this far, there was an error and it should just return the primary screen - return QApplication::primaryScreen(); - }else{ - //Ask the user to select a screen (for presentations, etc..) - QStringList names; - for(int i=0; isize().width())+"x"+QString::number(screens[i]->size().height()); - names << QString(tr("%1 (%2)")).arg(screens[i]->name(), screensize); - } - bool ok = false; - QString sel = QInputDialog::getItem(this, tr("Select Screen"), tr("Screen:"), names, 0, false, &ok); - cancelled = !ok; - if(!ok){ return screens[0]; } //cancelled - just return the first one - int index = names.indexOf(sel); - if(index < 0){ return screens[0]; } //error - should never happen though - return screens[index]; //return the selected screen - } -} - -void MainUI::startPresentation(bool atStart){ - if(DOC==0){ return; } //just in case - bool cancelled = false; - QScreen *screen = getScreen(false, cancelled); //let the user select which screen to use (if multiples) - if(cancelled){ return;} - int page = 0; - if(!atStart){ page = CurrentPage; } - //PDPI = QSize(SCALEFACTOR*screen->physicalDotsPerInchX(), SCALEFACTOR*screen->physicalDotsPerInchY()); - //Now create the full-screen window on the selected screen - if(presentationLabel == 0){ - //Create the label and any special flags for it - presentationLabel = new QLabel(0, Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); - presentationLabel->setStyleSheet("background-color: black;"); - presentationLabel->setAlignment(Qt::AlignCenter); - } - //Now put the label in the proper location - presentationLabel->setGeometry(screen->geometry()); - presentationLabel->showFullScreen(); - - ui->actionStop_Presentation->setEnabled(true); - ui->menuStart_Presentation->setEnabled(false); - QApplication::processEvents(); - //Now start at the proper page - ShowPage(page); - this->grabKeyboard(); //Grab any keyboard events - even from the presentation window -} - -void MainUI::ShowPage(int page){ - if(presentationLabel == 0 || !presentationLabel->isVisible()){ return; } - //Check for valid document/page - if(page<0 || page >=numPages ){ - endPresentation(); - return; //invalid - no document loaded or invalid page specified - } - CurrentPage = page; - QImage PAGEIMAGE = loadingHash[page]; - - //Now scale the image according to the user-designations and show it - if(!PAGEIMAGE.isNull()){ - QPixmap pix; - pix.convertFromImage( PAGEIMAGE.scaled( presentationLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation) ); - presentationLabel->setPixmap(pix); - presentationLabel->show(); //always make sure it was not hidden - }else{ - presentationLabel->setPixmap(QPixmap()); - endPresentation(); - } -} - -void MainUI::endPresentation(){ - if(presentationLabel==0 || !presentationLabel->isVisible()){ return; } //not in presentation mode - presentationLabel->hide(); //just hide this (no need to re-create the label for future presentations) - ui->actionStop_Presentation->setEnabled(false); - ui->menuStart_Presentation->setEnabled(true); - this->releaseKeyboard(); -} - -void MainUI::startLoadingPages(QPrinter *printer){ - if(numPages>0){ return; } //currently loaded[ing] - //qDebug() << " - Start Loading Pages"; - numPages = DOC->numPages(); - progress->setRange(0,numPages); - progress->setValue(0); - progAct->setVisible(true); - QRectF pageSize = printer->pageRect(QPrinter::DevicePixel); - QSize DPI(printer->resolution(),printer->resolution()); - for(int i=0; isetVisible(false); - progAct->setVisible(false); - QTimer::singleShot(0, WIDGET, SLOT(updatePreview())); - }else{ - progress->setValue(finished); - } -} - -void MainUI::slotStartPresentation(QAction *act){ - startPresentation(act == ui->actionAt_Beginning); -} - -void MainUI::paintOnWidget(QPrinter *PRINTER){ - if(DOC==0){ return; } - //this->show(); - if(loadingHash.keys().length() != numPages){ startLoadingPages(PRINTER); return; } - - int pages = DOC->numPages(); - int firstpage = 0; - //qDebug() << "Start Rendering PDF:" << PRINTER->fromPage() << PRINTER->toPage(); - if(PRINTER->fromPage() != PRINTER->toPage() || PRINTER->fromPage()!=0){ - firstpage = PRINTER->fromPage() - 1; - pages = PRINTER->toPage(); - } - QPainter painter(PRINTER); - for(int i=firstpage; inewPage(); } //this is the start of the next page (not needed for first) - if(loadingHash.contains(i)){ painter.drawImage(0,0, loadingHash[i]); } - else{ painter.drawImage(0,0, QImage()); } - } -} - -void MainUI::OpenNewFile(){ - //Prompt for a file - QString path = QFileDialog::getOpenFileName(this, tr("Open PDF"), lastdir, tr("PDF Documents (*.pdf)")); - //Now Open it - if(!path.isEmpty()){ loadFile(path); } -} diff --git a/src-qt5/experimental/lumina-pdf/mainUI.h b/src-qt5/experimental/lumina-pdf/mainUI.h deleted file mode 100644 index fa1d5a55..00000000 --- a/src-qt5/experimental/lumina-pdf/mainUI.h +++ /dev/null @@ -1,107 +0,0 @@ -//=========================================== -// Lumina Desktop source code -// Copyright (c) 2017, Ken Moore -// Available under the 3-clause BSD license -// See the LICENSE file for full details -//=========================================== -#ifndef _LUMINA_PDF_VIEWER_MAIN_WINDOW_H -#define _LUMINA_PDF_VIEWER_MAIN_WINDOW_H - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace Ui{ - class MainUI; -}; - -class MainUI : public QMainWindow{ - Q_OBJECT -public: - MainUI(); - ~MainUI(); - - void loadFile(QString path); - - -private: - Poppler::Document *DOC; - QPrintPreviewWidget *WIDGET; - Ui::MainUI *ui; - QPrinter* Printer; - QPrintDialog *PrintDLG; - - QString lastdir; - - //Other Interface elements - QProgressBar *progress; - QAction *progAct; //action associated with the progressbar - - //PDF Page Loading cache variables - QHash loadingHash; - int numPages; - - void loadPage(int num, Poppler::Document *doc, MainUI *obj, QSize dpi, QSizeF page); - - //Functions/variables for the presentation mode - QLabel *presentationLabel; - QScreen *getScreen(bool current, bool &cancelled); - int CurrentPage; - void startPresentation(bool atStart); - void ShowPage(int page); - void endPresentation(); - -private slots: - void startLoadingPages(QPrinter *printer); - void slotPageLoaded(int); - void slotStartPresentation(QAction *act); - - void paintOnWidget(QPrinter *PRINTER); - - //Button Slots - void OpenNewFile(); - -signals: - void PageLoaded(int); - -protected: - void keyPressEvent(QKeyEvent *event){ - //See if this is one of the special hotkeys and act appropriately - // NOTE: Some of this is duplicated with the QShortcut definitions (for non-presentation mode) - // This routine does not always work for the main window viewer due to differing widget focus policies - if(presentationLabel!=0 && presentationLabel->isVisible()){ - //qDebug() << "Got Key Press:"; - if( event->key()==Qt::Key_Escape || event->key()==Qt::Key_Backspace){ - //qDebug() << " - Escape/Backspace"; - endPresentation(); - }else if(event->key()==Qt::Key_Right || event->key()==Qt::Key_Down || event->key()==Qt::Key_Space){ - //qDebug() << " - Right/Down/Spacebar"; - ShowPage( CurrentPage+1 ); - }else if(event->key()==Qt::Key_Left || event->key()==Qt::Key_Up){ - //qDebug() << " - Left/Up"; - ShowPage( CurrentPage-1 ); - }else if(event->key()==Qt::Key_Home){ - //qDebug() << " - Home"; - ShowPage(0); //go to the first page - }else if(event->key()==Qt::Key_End){ - //qDebug() << " - End"; - ShowPage( numPages-1 ); //go to the last page - }else if(event->key()==Qt::Key_F11){ - //qDebug() << " - F11"; - endPresentation(); - }else{ - QMainWindow::keyPressEvent(event); - } - }else{ - QMainWindow::keyPressEvent(event); - } - } -}; -#endif diff --git a/src-qt5/experimental/lumina-pdf/mainUI.ui b/src-qt5/experimental/lumina-pdf/mainUI.ui deleted file mode 100644 index bbc76bab..00000000 --- a/src-qt5/experimental/lumina-pdf/mainUI.ui +++ /dev/null @@ -1,153 +0,0 @@ - - - MainUI - - - - 0 - 0 - 659 - 588 - - - - MainWindow - - - - - - 0 - 0 - 659 - 24 - - - - - File - - - - - - - - - - Presentation - - - - Start Presentation - - - - - - - - - - - - - toolBar - - - false - - - false - - - TopToolBarArea - - - false - - - - - - - - - - - Open PDF - - - Ctrl+O - - - - - Close - - - Ctrl+Q - - - - - true - - - Fit Page - - - - - true - - - Fit Width - - - - - Print - - - Ctrl+P - - - - - true - - - Single Page - - - - - true - - - Dual Pages - - - - - true - - - All Pages - - - - - At Beginning - - - - - Stop Presentation - - - - - - -- cgit