diff options
author | Ken Moore <ken@ixsystems.com> | 2017-03-13 15:41:39 -0400 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2017-03-13 15:41:39 -0400 |
commit | cbef967cead76a6e465d534284acdd1927ad632e (patch) | |
tree | 74e336cb732edb37495f1312ce15135830c7ec51 /src-qt5/desktop-utils/lumina-pdf | |
parent | Merge branch 'master' of github.com:trueos/lumina (diff) | |
download | lumina-cbef967cead76a6e465d534284acdd1927ad632e.tar.gz lumina-cbef967cead76a6e465d534284acdd1927ad632e.tar.bz2 lumina-cbef967cead76a6e465d534284acdd1927ad632e.zip |
Add a new desktop application: lumina-pdf
This is a basic PDF file viewer application, with printing capabilities.
NOTE: This is not quite done yet - the basic PDF viewer works if an input file is supplied, but I have not finished adding all the normal window operations around it yet (menu bar with close, open file options, progress bar for loading status rather than using a message box, etc...)
Diffstat (limited to 'src-qt5/desktop-utils/lumina-pdf')
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/lumina-pdf.desktop | 10 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro | 99 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/main.cpp | 31 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 102 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/mainUI.h | 33 |
5 files changed, 275 insertions, 0 deletions
diff --git a/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.desktop b/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.desktop new file mode 100644 index 00000000..c9632c9f --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.desktop @@ -0,0 +1,10 @@ +[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/desktop-utils/lumina-pdf/lumina-pdf.pro b/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro new file mode 100644 index 00000000..31815629 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro @@ -0,0 +1,99 @@ +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 + +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/desktop-utils/lumina-pdf/main.cpp b/src-qt5/desktop-utils/lumina-pdf/main.cpp new file mode 100644 index 00000000..ad0797d7 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/main.cpp @@ -0,0 +1,31 @@ +#include <QTranslator> +#include <QApplication> +#include <QDebug> +#include <QFile> + +#include "mainUI.h" +#include <LUtils.h> +//#include <LuminaThemes.h> + +int main(int argc, char ** argv) +{ + //LTHEME::LoadCustomEnvSettings(); + QApplication a(argc, argv); + LUtils::LoadTranslation(&a, "l-pdf"); + //LuminaThemeEngine theme(&a); + + + //Read the input variables + QString path = ""; + for(int i=1; i<argc; i++){ + path = LUtils::PathToAbsolute( argv[i] ); + if(QFile::exists(path)){ break; } //already found a valid file + } +if(path.isEmpty()){ return 1; } + MainUI w; + //QObject::connect(&theme, SIGNAL(updateIcons()), &w, SLOT(UpdateIcons()) ); + w.loadFile(path); + w.show(); + int retCode = a.exec(); + return retCode; +} diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp new file mode 100644 index 00000000..22e41dbb --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -0,0 +1,102 @@ +//=========================================== +// Lumina Desktop source code +// Copyright (c) 2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "mainUI.h" +#include <QPainter> +#include <QImage> +#include <QSize> +#include <QMessageBox> +#include <QDebug> +#include <QApplication> + +#include <LuminaXDG.h> + +MainUI::MainUI() : QPrintPreviewDialog(0, Qt::Window){ + + //this->addStatusBar(); + + connect(this, SIGNAL(paintRequested(QPrinter*)), this, SLOT(paintOnWidget(QPrinter*)) ); + DOC = 0; +} + +MainUI::~MainUI(){ + +} + +void MainUI::loadFile(QString path){ + if(DOC!=0){ + //Clear out the old document first + delete DOC; + } + if(!QFile::exists(path) || path.isEmpty() ){QApplication::exit(1); } + DOC = Poppler::Document::load(path); + if(DOC!=0){ this->setWindowTitle(DOC->title()); } + if(this->windowTitle().isEmpty()){ this->setWindowTitle(path.section("/",-1)); } + this->setWindowIcon( LXDG::findIcon("application-pdf","unknown")); + //Setup the Document + Poppler::Page *PAGE = DOC->page(0); + if(PAGE!=0){ + this->printer()->setPageSize( QPageSize(PAGE->pageSize(), QPageSize::Point) ); + switch(PAGE->orientation()){ + case Poppler::Page::Landscape: + this->printer()->setOrientation(QPrinter::Landscape); break; + default: + this->printer()->setOrientation(QPrinter::Portrait); + } + delete PAGE; + } + +} + +void MainUI::done(int val){ + //This is automatically called with value=1 when the "print()" function finishes + //Otherwise close down the application + if(val==0){ QApplication::exit(0); } +} + +void MainUI::paintOnWidget(QPrinter *PRINTER){ + if(DOC==0){ 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(); + } + 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()); + QPainter painter(PRINTER); + Poppler::Page *PAGE = 0; + QMessageBox wait(QMessageBox::NoIcon, tr("Opening PDF..."), QString(tr("Preparing Document (%1 pages)")).arg(QString::number(pages)), QMessageBox::Abort, this); + wait.setInformativeText(" "); //Make sure the window is the right size before showing it + wait.setStandardButtons(QMessageBox::Abort); //make sure that no buttons are used + wait.show(); + for(int i=firstpage; i<pages && wait.isVisible(); i++){ + wait.setInformativeText( QString(tr("Loading Page: %1")).arg(i+1) ); + //qDebug() << "Loading Page:" << i; + 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); + 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()); + } + QApplication::processEvents(); + } + if(PAGE!=0){ delete PAGE; } + wait.close(); +} + +void MainUI::OpenNewFile(){ + //Prompt for a file + + //Now Open it + +} diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.h b/src-qt5/desktop-utils/lumina-pdf/mainUI.h new file mode 100644 index 00000000..34bbc801 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h @@ -0,0 +1,33 @@ +//=========================================== +// 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 <QPrintPreviewDialog> +#include <QPrinter> + +#include <poppler-qt5.h> + +class MainUI : public QPrintPreviewDialog{ + Q_OBJECT +public: + MainUI(); + ~MainUI(); + + void loadFile(QString path); + + virtual void done(int); + +private: + Poppler::Document *DOC; + +private slots: + void paintOnWidget(QPrinter *PRINTER); + void OpenNewFile(); + +}; +#endif |