diff options
author | Ken Moore <ken@ixsystems.com> | 2017-03-14 07:05:13 -0400 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2017-03-14 07:05:13 -0400 |
commit | 89ba7785e706fb6a43e96d7c2b34203767d27097 (patch) | |
tree | 73eb52dc01811adf00edf375283c44e325d6debf /src-qt5 | |
parent | Add a new desktop application: lumina-pdf (diff) | |
download | lumina-89ba7785e706fb6a43e96d7c2b34203767d27097.tar.gz lumina-89ba7785e706fb6a43e96d7c2b34203767d27097.tar.bz2 lumina-89ba7785e706fb6a43e96d7c2b34203767d27097.zip |
Update the new lumina-pdf to work as a QMainWindow with a QPrintPreviewWidget embedded within it (instead of a QPrintPrevewDialog for everything).
Diffstat (limited to 'src-qt5')
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro | 2 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/main.cpp | 4 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 101 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/mainUI.h | 23 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/mainUI.ui | 149 |
5 files changed, 249 insertions, 30 deletions
diff --git a/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro b/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro index 31815629..7d5562ed 100644 --- a/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro +++ b/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro @@ -20,6 +20,8 @@ SOURCES += main.cpp\ HEADERS += mainUI.h +FORMS += mainUI.ui + LIBS += -lpoppler-qt5 INCLUDEPATH+= $${L_INCLUDEDIR}/poppler/qt5 diff --git a/src-qt5/desktop-utils/lumina-pdf/main.cpp b/src-qt5/desktop-utils/lumina-pdf/main.cpp index ad0797d7..f6bb9839 100644 --- a/src-qt5/desktop-utils/lumina-pdf/main.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/main.cpp @@ -21,10 +21,10 @@ int main(int argc, char ** argv) 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); + if(!path.isEmpty()){ 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 index 22e41dbb..8149aac6 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -5,21 +5,73 @@ // See the LICENSE file for full details //=========================================== #include "mainUI.h" +#include "ui_mainUI.h" + #include <QPainter> #include <QImage> #include <QSize> -#include <QMessageBox> +#include <QFileDialog> #include <QDebug> #include <QApplication> #include <LuminaXDG.h> -MainUI::MainUI() : QPrintPreviewDialog(0, Qt::Window){ +MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ + ui->setupUi(this); - //this->addStatusBar(); - - connect(this, SIGNAL(paintRequested(QPrinter*)), this, SLOT(paintOnWidget(QPrinter*)) ); + this->setWindowTitle(tr("Lumina PDF Viewer")); + this->setWindowIcon( LXDG::findIcon("application-pdf","unknown")); + + 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; + + 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); + + //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("zoom-fit-width","")); + 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("view-split-left-right","")); + ui->actionAll_Pages->setIcon(LXDG::findIcon("view-grid","")); } MainUI::~MainUI(){ @@ -30,35 +82,35 @@ void MainUI::loadFile(QString path){ if(DOC!=0){ //Clear out the old document first delete DOC; + DOC=0; } - if(!QFile::exists(path) || path.isEmpty() ){QApplication::exit(1); } + qDebug() << "Opening File:" << path; + if(!QFile::exists(path) || path.isEmpty() ){ return; } 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) ); + lastdir = path.section("/",0,-2); //save this for later + PRINTER->setPageSize( QPageSize(PAGE->pageSize(), QPageSize::Point) ); switch(PAGE->orientation()){ case Poppler::Page::Landscape: - this->printer()->setOrientation(QPrinter::Landscape); break; + PRINTER->setOrientation(QPrinter::Landscape); break; default: - this->printer()->setOrientation(QPrinter::Portrait); + PRINTER->setOrientation(QPrinter::Portrait); } delete PAGE; + WIDGET->updatePreview(); //start loading the file preview } } -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; } + this->show(); + QApplication::processEvents(); int pages = DOC->numPages(); int firstpage = 0; //qDebug() << "Start Rendering PDF:" << PRINTER->fromPage() << PRINTER->toPage(); @@ -72,12 +124,10 @@ void MainUI::paintOnWidget(QPrinter *PRINTER){ 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) ); + progress->setRange(firstpage, pages-1); + ui->toolBar2->setVisible(true); + for(int i=firstpage; i<pages; i++){ + progress->setValue(i); //qDebug() << "Loading Page:" << i; QApplication::processEvents(); //Now paint this page on the printer @@ -88,15 +138,16 @@ void MainUI::paintOnWidget(QPrinter *PRINTER){ }else{ painter.drawImage(0,0,QImage()); } - QApplication::processEvents(); + //QApplication::processEvents(); } if(PAGE!=0){ delete PAGE; } - wait.close(); + ui->toolBar2->setVisible(false); } 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/desktop-utils/lumina-pdf/mainUI.h b/src-qt5/desktop-utils/lumina-pdf/mainUI.h index 34bbc801..e25eab2b 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h @@ -7,12 +7,19 @@ #ifndef _LUMINA_PDF_VIEWER_MAIN_WINDOW_H #define _LUMINA_PDF_VIEWER_MAIN_WINDOW_H -#include <QPrintPreviewDialog> +#include <QPrintPreviewWidget> +#include <QPrintDialog> #include <QPrinter> +#include <QMainWindow> +#include <QProgressBar> #include <poppler-qt5.h> -class MainUI : public QPrintPreviewDialog{ +namespace Ui{ + class MainUI; +}; + +class MainUI : public QMainWindow{ Q_OBJECT public: MainUI(); @@ -20,13 +27,23 @@ public: void loadFile(QString path); - virtual void done(int); private: Poppler::Document *DOC; + QPrintPreviewWidget *WIDGET; + Ui::MainUI *ui; + QPrinter* PRINTER; + QPrintDialog *PrintDLG; + + QString lastdir; + + //Other Interface elements + QProgressBar *progress; private slots: void paintOnWidget(QPrinter *PRINTER); + + //Button Slots void OpenNewFile(); }; diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.ui b/src-qt5/desktop-utils/lumina-pdf/mainUI.ui new file mode 100644 index 00000000..5547d219 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.ui @@ -0,0 +1,149 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainUI</class> + <widget class="QMainWindow" name="MainUI"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>659</width> + <height>588</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget"/> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>659</width> + <height>22</height> + </rect> + </property> + <widget class="QMenu" name="menuFile"> + <property name="title"> + <string>File</string> + </property> + <addaction name="actionPrint"/> + <addaction name="separator"/> + <addaction name="actionOpen_PDF"/> + <addaction name="separator"/> + <addaction name="actionClose"/> + </widget> + <addaction name="menuFile"/> + </widget> + <widget class="QStatusBar" name="statusbar"/> + <widget class="QToolBar" name="toolBar"> + <property name="windowTitle"> + <string>toolBar</string> + </property> + <property name="movable"> + <bool>false</bool> + </property> + <property name="floatable"> + <bool>false</bool> + </property> + <attribute name="toolBarArea"> + <enum>TopToolBarArea</enum> + </attribute> + <attribute name="toolBarBreak"> + <bool>true</bool> + </attribute> + <addaction name="actionFit_Page"/> + <addaction name="actionFit_Width"/> + <addaction name="separator"/> + <addaction name="actionSingle_Page"/> + <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> + </property> + <property name="shortcut"> + <string>Ctrl+O</string> + </property> + </action> + <action name="actionClose"> + <property name="text"> + <string>Close</string> + </property> + <property name="shortcut"> + <string>Ctrl+Q</string> + </property> + </action> + <action name="actionFit_Page"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="text"> + <string>Fit Page</string> + </property> + </action> + <action name="actionFit_Width"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="text"> + <string>Fit Width</string> + </property> + </action> + <action name="actionPrint"> + <property name="text"> + <string>Print</string> + </property> + <property name="shortcut"> + <string>Ctrl+P</string> + </property> + </action> + <action name="actionSingle_Page"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="text"> + <string>Single Page</string> + </property> + </action> + <action name="actionDual_Pages"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="text"> + <string>Dual Pages</string> + </property> + </action> + <action name="actionAll_Pages"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="text"> + <string>All Pages</string> + </property> + </action> + </widget> + <resources/> + <connections/> +</ui> |