summaryrefslogtreecommitdiff
path: root/qt4/demos
diff options
context:
space:
mode:
authorPino Toscano <pino@kde.org>2008-02-16 22:25:11 +0100
committerPino Toscano <pino@kde.org>2008-02-16 22:25:11 +0100
commit3abb8703d7d8b7a5fbcbb3c19d8e84d640abe88c (patch)
treeceb3294f76af80a689f335a49999f055c1d3214d /qt4/demos
parent80925f06d125ebfc9909e36bdbe5d37fd0e48bdc (diff)
Add a TOC info dock.
Diffstat (limited to 'qt4/demos')
-rw-r--r--qt4/demos/CMakeLists.txt1
-rw-r--r--qt4/demos/Makefile.am1
-rw-r--r--qt4/demos/toc.cpp90
-rw-r--r--qt4/demos/toc.h43
-rw-r--r--qt4/demos/viewer.cpp7
5 files changed, 142 insertions, 0 deletions
diff --git a/qt4/demos/CMakeLists.txt b/qt4/demos/CMakeLists.txt
index 0e206c25..bcf5cab5 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 0dc27ec0..b53e2fa9 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 00000000..7c0de9a9
--- /dev/null
+++ b/qt4/demos/toc.cpp
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2008, Pino Toscano <pino@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 00000000..bbc90827
--- /dev/null
+++ b/qt4/demos/toc.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2008, Pino Toscano <pino@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 79cd0ff4..f81fdea0 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();