[poppler] 3 commits - qt4/demos

Pino Toscano pino at kemper.freedesktop.org
Sat Feb 16 16:21:34 PST 2008


 qt4/demos/viewer.cpp |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 qt4/demos/viewer.h   |    4 ++++
 2 files changed, 50 insertions(+)

New commits:
commit b287b611b1c7b7dd00e12518cee3a6c35044e161
Author: Pino Toscano <pino at kde.org>
Date:   Sun Feb 17 01:21:07 2008 +0100

    Really niptick: help menu with about dialog for us and Qt.

diff --git a/qt4/demos/viewer.cpp b/qt4/demos/viewer.cpp
index a0780de..ea673ae 100644
--- a/qt4/demos/viewer.cpp
+++ b/qt4/demos/viewer.cpp
@@ -63,6 +63,10 @@ PdfViewer::PdfViewer()
     m_settingsGfxAAAct->setCheckable(true);
     connect(m_settingsGfxAAAct, SIGNAL(toggled(bool)), this, SLOT(slotToggleGfxAA(bool)));
 
+    QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
+    act = helpMenu->addAction(tr("&About"), this, SLOT(slotAbout()));
+    act = helpMenu->addAction(tr("&About Qt"), this, SLOT(slotAboutQt()));
+
     NavigationToolBar *navbar = new NavigationToolBar(this);
     addToolBar(navbar);
     m_observers.append(navbar);
@@ -197,6 +201,17 @@ void PdfViewer::slotSaveCopy()
     }
 }
 
+void PdfViewer::slotAbout()
+{
+    const QString text("This is a demo of the Poppler-Qt4 library.");
+    QMessageBox::about(this, QString::fromLatin1("About Poppler-Qt4 Demo"), text);
+}
+
+void PdfViewer::slotAboutQt()
+{
+    QMessageBox::aboutQt(this);
+}
+
 void PdfViewer::slotToggleTextAA(bool value)
 {
     if (!m_doc) {
diff --git a/qt4/demos/viewer.h b/qt4/demos/viewer.h
index 5677b3b..06e0fb7 100644
--- a/qt4/demos/viewer.h
+++ b/qt4/demos/viewer.h
@@ -46,6 +46,8 @@ public:
 private Q_SLOTS:
     void slotOpenFile();
     void slotSaveCopy();
+    void slotAbout();
+    void slotAboutQt();
     void slotToggleTextAA(bool value);
     void slotToggleGfxAA(bool value);
 
commit 6400254fdabf3d0d32f27ebd00faa6958be62019
Author: Pino Toscano <pino at kde.org>
Date:   Sun Feb 17 01:12:27 2008 +0100

    Add a title to the viewer :)

diff --git a/qt4/demos/viewer.cpp b/qt4/demos/viewer.cpp
index a41945b..a0780de 100644
--- a/qt4/demos/viewer.cpp
+++ b/qt4/demos/viewer.cpp
@@ -39,6 +39,8 @@
 PdfViewer::PdfViewer()
     : QMainWindow(), m_currentPage(0), m_doc(0)
 {
+    setWindowTitle(tr("Poppler-Qt4 Demo"));
+
     // setup the menus
     QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
     m_fileOpenAct = fileMenu->addAction(tr("&Open"), this, SLOT(slotOpenFile()));
commit b363c0568c9c61e7ee8ed86d808f0eed0b93b525
Author: Pino Toscano <pino at kde.org>
Date:   Sun Feb 17 01:09:57 2008 +0100

    Add the possibility to save a copy of the file.

diff --git a/qt4/demos/viewer.cpp b/qt4/demos/viewer.cpp
index 402fb80..a41945b 100644
--- a/qt4/demos/viewer.cpp
+++ b/qt4/demos/viewer.cpp
@@ -43,6 +43,11 @@ PdfViewer::PdfViewer()
     QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
     m_fileOpenAct = fileMenu->addAction(tr("&Open"), this, SLOT(slotOpenFile()));
     m_fileOpenAct->setShortcut(Qt::CTRL + Qt::Key_O);
+    fileMenu->addSeparator();
+    m_fileSaveCopyAct = fileMenu->addAction(tr("&Save a Copy..."), this, SLOT(slotSaveCopy()));
+    m_fileSaveCopyAct->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_S);
+    m_fileSaveCopyAct->setEnabled(false);
+    fileMenu->addSeparator();
     QAction *act = fileMenu->addAction(tr("&Quit"), qApp, SLOT(closeAllWindows()));
     act->setShortcut(Qt::CTRL + Qt::Key_Q);
 
@@ -140,6 +145,8 @@ void PdfViewer::loadDocument(const QString &file)
         obs->documentLoaded();
         obs->pageChanged(0);
     }
+
+    m_fileSaveCopyAct->setEnabled(true);
 }
 
 void PdfViewer::closeDocument()
@@ -154,6 +161,8 @@ void PdfViewer::closeDocument()
 
     delete m_doc;
     m_doc = 0;
+
+    m_fileSaveCopyAct->setEnabled(false);
 }
 
 void PdfViewer::slotOpenFile()
@@ -166,6 +175,26 @@ void PdfViewer::slotOpenFile()
     loadDocument(fileName);
 }
 
+void PdfViewer::slotSaveCopy()
+{
+    if (!m_doc) {
+        return;
+    }
+
+    QString fileName = QFileDialog::getSaveFileName(this, tr("Save Copy"), QDir::homePath(), tr("PDF Documents (*.pdf)"));
+    if (fileName.isEmpty()) {
+        return;
+    }
+
+    Poppler::PDFConverter *converter = m_doc->pdfConverter();
+    converter->setOutputFileName(fileName);
+    converter->setPDFOptions(converter->pdfOptions() & ~Poppler::PDFConverter::WithChanges);
+    if (!converter->convert()) {
+        QMessageBox msgbox(QMessageBox::Critical, tr("Save Error"), tr("Cannot export to:\n%1").arg(fileName),
+                           QMessageBox::Ok, this);
+    }
+}
+
 void PdfViewer::slotToggleTextAA(bool value)
 {
     if (!m_doc) {
diff --git a/qt4/demos/viewer.h b/qt4/demos/viewer.h
index 6ee179c..5677b3b 100644
--- a/qt4/demos/viewer.h
+++ b/qt4/demos/viewer.h
@@ -45,6 +45,7 @@ public:
 
 private Q_SLOTS:
     void slotOpenFile();
+    void slotSaveCopy();
     void slotToggleTextAA(bool value);
     void slotToggleGfxAA(bool value);
 
@@ -55,6 +56,7 @@ private:
     int m_currentPage;
 
     QAction *m_fileOpenAct;
+    QAction *m_fileSaveCopyAct;
     QAction *m_settingsTextAAAct;
     QAction *m_settingsGfxAAAct;
 


More information about the poppler mailing list