[poppler] 3 commits - qt4/demos

Pino Toscano pino at kemper.freedesktop.org
Sat Feb 16 13:25:44 PST 2008


 qt4/demos/CMakeLists.txt       |    2 
 qt4/demos/Makefile.am          |    2 
 qt4/demos/abstractinfodock.cpp |   57 +++++++++++++++++++++++++
 qt4/demos/abstractinfodock.h   |   48 +++++++++++++++++++++
 qt4/demos/fonts.cpp            |   10 +---
 qt4/demos/fonts.h              |   11 ++---
 qt4/demos/info.cpp             |   10 +---
 qt4/demos/info.h               |   11 ++---
 qt4/demos/toc.cpp              |   90 +++++++++++++++++++++++++++++++++++++++++
 qt4/demos/toc.h                |   43 +++++++++++++++++++
 qt4/demos/viewer.cpp           |    7 +++
 11 files changed, 265 insertions(+), 26 deletions(-)

New commits:
commit 3abb8703d7d8b7a5fbcbb3c19d8e84d640abe88c
Author: Pino Toscano <pino at kde.org>
Date:   Sat Feb 16 22:25:11 2008 +0100

    Add a TOC info dock.

diff --git a/qt4/demos/CMakeLists.txt b/qt4/demos/CMakeLists.txt
index 0e206c2..bcf5cab 100644
--- a/qt4/demos/CMakeLists.txt
+++ b/qt4/demos/CMakeLists.txt
@@ -16,6 +16,7 @@ set(poppler_qt4viewer_SRCS
   main_viewer.cpp
   navigationtoolbar.cpp
   pageview.cpp
+  toc.cpp
   viewer.cpp
 )
 qt4_automoc(${poppler_qt4viewer_SRCS})
diff --git a/qt4/demos/Makefile.am b/qt4/demos/Makefile.am
index 0dc27ec..b53e2fa 100644
--- a/qt4/demos/Makefile.am
+++ b/qt4/demos/Makefile.am
@@ -28,6 +28,7 @@ poppler_qt4viewer_SOURCES =			\
 	main_viewer.cpp				\
 	navigationtoolbar.cpp			\
 	pageview.cpp				\
+	toc.cpp					\
 	viewer.cpp				\
 	viewer.moc
 
diff --git a/qt4/demos/toc.cpp b/qt4/demos/toc.cpp
new file mode 100644
index 0000000..7c0de9a
--- /dev/null
+++ b/qt4/demos/toc.cpp
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2008, Pino Toscano <pino at kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "toc.h"
+
+#include <poppler-qt4.h>
+
+#include <QtGui/QHeaderView>
+#include <QtGui/QTreeWidget>
+
+static void fillToc(const QDomNode &parent, QTreeWidget *tree, QTreeWidgetItem *parentItem)
+{
+    QTreeWidgetItem *newitem = 0;
+    for (QDomNode node = parent.firstChild(); !node.isNull(); node = node.nextSibling()) {
+        QDomElement e = node.toElement();
+
+        if (!parentItem) {
+            newitem = new QTreeWidgetItem(tree, newitem);
+        } else {
+            newitem = new QTreeWidgetItem(parentItem, newitem);
+        }
+        newitem->setText(0, e.tagName());
+
+        bool isOpen = false;
+        if (e.hasAttribute(QString::fromLatin1("Open"))) {
+            isOpen = QVariant(e.attribute(QString::fromLatin1("Open"))).toBool();
+        }
+        if (isOpen) {
+            tree->expandItem(newitem);
+        }
+
+        if (e.hasChildNodes()) {
+            fillToc(node, tree, newitem);
+        }
+    }
+}
+
+
+TocDock::TocDock(QWidget *parent)
+    : AbstractInfoDock(parent)
+{
+    m_tree = new QTreeWidget(this);
+    setWidget(m_tree);
+    m_tree->setAlternatingRowColors(true);
+    m_tree->header()->hide();
+    setWindowTitle(tr("TOC"));
+#if QT_VERSION >= 0x040200
+    m_tree->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
+#endif
+}
+
+TocDock::~TocDock()
+{
+}
+
+void TocDock::fillInfo()
+{
+    const QDomDocument *toc = document()->toc();
+    if (toc) {
+        fillToc(*toc, m_tree, 0);
+    } else {
+        QTreeWidgetItem *item = new QTreeWidgetItem();
+        item->setText(0, tr("No TOC"));
+        item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
+        m_tree->addTopLevelItem(item);
+    }
+}
+
+void TocDock::documentClosed()
+{
+    m_tree->clear();
+    AbstractInfoDock::documentClosed();
+}
+
+#include "toc.moc"
diff --git a/qt4/demos/toc.h b/qt4/demos/toc.h
new file mode 100644
index 0000000..bbc9082
--- /dev/null
+++ b/qt4/demos/toc.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2008, Pino Toscano <pino at kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef TOC_H
+#define TOC_H
+
+#include "abstractinfodock.h"
+
+class QTreeWidget;
+
+class TocDock : public AbstractInfoDock
+{
+    Q_OBJECT
+
+public:
+    TocDock(QWidget *parent = 0);
+    ~TocDock();
+
+    /*virtual*/ void documentClosed();
+
+protected:
+    /*virtual*/ void fillInfo();
+
+private:
+    QTreeWidget *m_tree;
+};
+
+#endif
diff --git a/qt4/demos/viewer.cpp b/qt4/demos/viewer.cpp
index 79cd0ff..f81fdea 100644
--- a/qt4/demos/viewer.cpp
+++ b/qt4/demos/viewer.cpp
@@ -22,6 +22,7 @@
 #include "info.h"
 #include "navigationtoolbar.h"
 #include "pageview.h"
+#include "toc.h"
 
 #include <poppler-qt4.h>
 
@@ -60,6 +61,12 @@ PdfViewer::PdfViewer()
     viewMenu->addAction(infoDock->toggleViewAction());
     m_observers.append(infoDock);
 
+    TocDock *tocDock = new TocDock(this);
+    addDockWidget(Qt::LeftDockWidgetArea, tocDock);
+    tocDock->hide();
+    viewMenu->addAction(tocDock->toggleViewAction());
+    m_observers.append(tocDock);
+
     FontsDock *fontsDock = new FontsDock(this);
     addDockWidget(Qt::LeftDockWidgetArea, fontsDock);
     fontsDock->hide();
commit 80925f06d125ebfc9909e36bdbe5d37fd0e48bdc
Author: Pino Toscano <pino at kde.org>
Date:   Sat Feb 16 21:51:10 2008 +0100

    Adapt the Fonts and Info docks to the new abstract info dock.

diff --git a/qt4/demos/fonts.cpp b/qt4/demos/fonts.cpp
index 017faae..e0ed82b 100644
--- a/qt4/demos/fonts.cpp
+++ b/qt4/demos/fonts.cpp
@@ -28,7 +28,7 @@ static QString yesNoStatement(bool value)
 }
 
 FontsDock::FontsDock(QWidget *parent)
-    : QDockWidget(parent)
+    : AbstractInfoDock(parent)
 {
     m_table = new QTableWidget(this);
     setWidget(m_table);
@@ -44,7 +44,7 @@ FontsDock::~FontsDock()
 {
 }
 
-void FontsDock::documentLoaded()
+void FontsDock::fillInfo()
 {
     const QList<Poppler::FontInfo> fonts = document()->fonts();
     m_table->setHorizontalHeaderLabels(QStringList() << tr("Name") << tr("Type") << tr("Embedded") << tr("Subset") << tr("File"));
@@ -68,11 +68,7 @@ void FontsDock::documentClosed()
 {
     m_table->clear();
     m_table->setRowCount(0);
-}
-
-void FontsDock::pageChanged(int page)
-{
-    Q_UNUSED(page)
+    AbstractInfoDock::documentClosed();
 }
 
 #include "fonts.moc"
diff --git a/qt4/demos/fonts.h b/qt4/demos/fonts.h
index 8612a33..81afa57 100644
--- a/qt4/demos/fonts.h
+++ b/qt4/demos/fonts.h
@@ -19,13 +19,11 @@
 #ifndef FONTS_H
 #define FONTS_H
 
-#include <QtGui/QDockWidget>
-
-#include "documentobserver.h"
+#include "abstractinfodock.h"
 
 class QTableWidget;
 
-class FontsDock : public QDockWidget, public DocumentObserver
+class FontsDock : public AbstractInfoDock
 {
     Q_OBJECT
 
@@ -33,9 +31,10 @@ public:
     FontsDock(QWidget *parent = 0);
     ~FontsDock();
 
-    /*virtual*/ void documentLoaded();
     /*virtual*/ void documentClosed();
-    /*virtual*/ void pageChanged(int page);
+
+protected:
+    /*virtual*/ void fillInfo();
 
 private:
     QTableWidget *m_table;
diff --git a/qt4/demos/info.cpp b/qt4/demos/info.cpp
index 6ba8dff..8fa8bef 100644
--- a/qt4/demos/info.cpp
+++ b/qt4/demos/info.cpp
@@ -23,7 +23,7 @@
 #include <QtGui/QTableWidget>
 
 InfoDock::InfoDock(QWidget *parent)
-    : QDockWidget(parent)
+    : AbstractInfoDock(parent)
 {
     m_table = new QTableWidget(this);
     setWidget(m_table);
@@ -39,7 +39,7 @@ InfoDock::~InfoDock()
 {
 }
 
-void InfoDock::documentLoaded()
+void InfoDock::fillInfo()
 {
     QStringList keys = document()->infoKeys();
     m_table->setHorizontalHeaderLabels(QStringList() << tr("Key") << tr("Value"));
@@ -68,11 +68,7 @@ void InfoDock::documentClosed()
 {
     m_table->clear();
     m_table->setRowCount(0);
-}
-
-void InfoDock::pageChanged(int page)
-{
-    Q_UNUSED(page)
+    AbstractInfoDock::documentClosed();
 }
 
 #include "info.moc"
diff --git a/qt4/demos/info.h b/qt4/demos/info.h
index 6c46e1d..d294b43 100644
--- a/qt4/demos/info.h
+++ b/qt4/demos/info.h
@@ -19,13 +19,11 @@
 #ifndef INFO_H
 #define INFO_H
 
-#include <QtGui/QDockWidget>
-
-#include "documentobserver.h"
+#include "abstractinfodock.h"
 
 class QTableWidget;
 
-class InfoDock : public QDockWidget, public DocumentObserver
+class InfoDock : public AbstractInfoDock
 {
     Q_OBJECT
 
@@ -33,9 +31,10 @@ public:
     InfoDock(QWidget *parent = 0);
     ~InfoDock();
 
-    /*virtual*/ void documentLoaded();
     /*virtual*/ void documentClosed();
-    /*virtual*/ void pageChanged(int page);
+
+protected:
+    /*virtual*/ void fillInfo();
 
 private:
     QTableWidget *m_table;
commit c03531d691e56aba2b4c6538cf9e2463e1e0aa29
Author: Pino Toscano <pino at kde.org>
Date:   Sat Feb 16 21:43:19 2008 +0100

    Introduce a base info dock for handling the "dirty" work.

diff --git a/qt4/demos/CMakeLists.txt b/qt4/demos/CMakeLists.txt
index ca3b828..0e206c2 100644
--- a/qt4/demos/CMakeLists.txt
+++ b/qt4/demos/CMakeLists.txt
@@ -9,6 +9,7 @@ include_directories(
 )
 
 set(poppler_qt4viewer_SRCS
+  abstractinfodock.cpp
   documentobserver.cpp
   fonts.cpp
   info.cpp
diff --git a/qt4/demos/Makefile.am b/qt4/demos/Makefile.am
index 33354a9..0dc27ec 100644
--- a/qt4/demos/Makefile.am
+++ b/qt4/demos/Makefile.am
@@ -21,6 +21,7 @@ SUFFIXES: .moc
 noinst_PROGRAMS = poppler_qt4viewer
 
 poppler_qt4viewer_SOURCES =			\
+	abstractinfodock.cpp			\
 	documentobserver.cpp			\
 	fonts.cpp				\
 	info.cpp				\
diff --git a/qt4/demos/abstractinfodock.cpp b/qt4/demos/abstractinfodock.cpp
new file mode 100644
index 0000000..7b306d8
--- /dev/null
+++ b/qt4/demos/abstractinfodock.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2008, Pino Toscano <pino at kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "fonts.h"
+
+AbstractInfoDock::AbstractInfoDock(QWidget *parent)
+    : QDockWidget(parent), m_filled(false)
+{
+    connect(this, SIGNAL(visibilityChanged(bool)), SLOT(slotVisibilityChanged(bool)));
+}
+
+AbstractInfoDock::~AbstractInfoDock()
+{
+}
+
+void AbstractInfoDock::documentLoaded()
+{
+    if (!isHidden()) {
+        fillInfo();
+        m_filled = true;
+    }
+}
+
+void AbstractInfoDock::documentClosed()
+{
+    m_filled = false;
+}
+
+void AbstractInfoDock::pageChanged(int page)
+{
+    Q_UNUSED(page)
+}
+
+void AbstractInfoDock::slotVisibilityChanged(bool visible)
+{
+    if (visible && document() && !m_filled) {
+        fillInfo();
+        m_filled = true;
+    }
+}
+
+#include "abstractinfodock.moc"
diff --git a/qt4/demos/abstractinfodock.h b/qt4/demos/abstractinfodock.h
new file mode 100644
index 0000000..2593325
--- /dev/null
+++ b/qt4/demos/abstractinfodock.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2008, Pino Toscano <pino at kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef ABSTRACTINFODOCK_H
+#define ABSTRACTINFODOCK_H
+
+#include <QtGui/QDockWidget>
+
+#include "documentobserver.h"
+
+class AbstractInfoDock : public QDockWidget, public DocumentObserver
+{
+    Q_OBJECT
+
+public:
+    AbstractInfoDock(QWidget *parent = 0);
+    ~AbstractInfoDock();
+
+    /*virtual*/ void documentLoaded();
+    /*virtual*/ void documentClosed();
+    /*virtual*/ void pageChanged(int page);
+
+protected:
+    virtual void fillInfo() = 0;
+
+private Q_SLOTS:
+    void slotVisibilityChanged(bool visible);
+
+private:
+    bool m_filled;
+};
+
+#endif


More information about the poppler mailing list