Commit 755ca482 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

- Adding table of contents

CCMAIL:78181-done@bugs.kde.org

svn path=/trunk/kdegraphics/kpdf/; revision=348286
parent 0bf49e55
......@@ -41,7 +41,7 @@ shellrc_DATA = kpdf_shell.rc
kde_module_LTLIBRARIES = libkpdfpart.la
# the Part's source, library search path, and link libraries
libkpdfpart_la_SOURCES = QOutputDev.cpp QOutputDevPixmap.cpp QOutputDevKPrinter.cpp kpdf_part.cpp kpdf_pagewidget.cc part.cpp thumbnail.cpp thumbnaillist.cpp kpdf_error.cpp xpdf_errors.cpp thumbnailgenerator.cpp
libkpdfpart_la_SOURCES = QOutputDev.cpp QOutputDevPixmap.cpp QOutputDevKPrinter.cpp kpdf_part.cpp kpdf_pagewidget.cc part.cpp thumbnail.cpp thumbnaillist.cpp kpdf_error.cpp xpdf_errors.cpp thumbnailgenerator.cpp toc.cpp
libkpdfpart_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
libkpdfpart_la_LIBADD = ../xpdf/libxpdf.la $(LIB_KPARTS) $(LIB_KFILE) $(LIB_KDEPRINT) $(LIB_KUTILS) -lm
......
......@@ -90,6 +90,8 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
pdfpartview = new PDFPartView(parentWidget, widgetName, &m_docMutex);
connect(pdfpartview, SIGNAL( clicked ( int ) ), this, SLOT( pageClicked ( int ) ));
connect(pdfpartview, SIGNAL( execute ( LinkAction* ) ), this, SLOT( executeAction ( LinkAction* ) ));
connect(pdfpartview, SIGNAL( hasTOC ( bool ) ), this, SLOT( hasTOC ( bool ) ));
m_outputDev = pdfpartview->outputdev;
connect(m_outputDev, SIGNAL(linkClicked(LinkAction*)), this, SLOT(executeAction(LinkAction*)));
......@@ -100,11 +102,17 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
m_showScrollBars = new KToggleAction( i18n( "Show &Scrollbars" ), 0,
actionCollection(), "show_scrollbars" );
m_showScrollBars->setCheckedState(i18n("Hide &Scrollbars"));
m_showTOC = new KToggleAction( i18n( "Show &Table of Contents" ), 0,
actionCollection(), "show_toc" );
m_showTOC->setCheckedState(i18n("Hide &Table of Contents"));
m_showTOC->setEnabled(false);
m_showPageList = new KToggleAction( i18n( "Show &Page List" ), 0,
actionCollection(), "show_page_list" );
m_showPageList->setCheckedState(i18n("Hide &Page List"));
connect( m_showScrollBars, SIGNAL( toggled( bool ) ),
SLOT( showScrollBars( bool ) ) );
connect( m_showTOC, SIGNAL( toggled( bool ) ),
SLOT( showTOC( bool ) ) );
connect( m_showPageList, SIGNAL( toggled( bool ) ),
SLOT( showMarkList( bool ) ) );
......@@ -292,6 +300,7 @@ void Part::writeSettings()
{
KConfigGroup general( KPDFPartFactory::instance()->config(), "General" );
general.writeEntry( "ShowScrollBars", m_showScrollBars->isChecked() );
general.writeEntry( "ShowTOC", m_showTOC->isChecked() );
general.writeEntry( "ShowPageList", m_showPageList->isChecked() );
general.sync();
}
......@@ -301,6 +310,8 @@ void Part::readSettings()
KConfigGroup general( KPDFPartFactory::instance()->config(), "General" );
m_showScrollBars->setChecked( general.readBoolEntry( "ShowScrollBars", true ) );
showScrollBars( m_showScrollBars->isChecked() );
m_showTOC->setChecked( general.readBoolEntry( "ShowTOC", true ) );
showTOC( m_showTOC->isChecked() );
m_showPageList->setChecked( general.readBoolEntry( "ShowPageList", true ) );
showMarkList( m_showPageList->isChecked() );
}
......@@ -315,6 +326,16 @@ void Part::showMarkList( bool show )
pdfpartview->showPageList(show);
}
void Part::showTOC( bool show )
{
pdfpartview->showTOC(show);
}
void Part::hasTOC( bool show )
{
m_showTOC->setEnabled(show);
}
void Part::slotGotoEnd()
{
if ( m_doc && m_doc->getNumPages() > 0 )
......@@ -405,6 +426,7 @@ Part::openFile()
// TODO take page rotation into acount for calculating aspect ratio
pdfpartview->setPages(m_doc->getNumPages(), m_doc->getPageHeight(1)/m_doc->getPageWidth(1));
pdfpartview->generateThumbnails(m_doc);
pdfpartview->generateTOC(m_doc);
m_outputDev->setPDFDocument(m_doc);
goToPage(1);
......
......@@ -120,6 +120,8 @@ namespace KPDF
void showScrollBars( bool );
void showMarkList( bool );
void showTOC( bool );
void hasTOC( bool );
void slotReadUp();
void slotReadDown();
void slotOpenUrlDropped( const KURL & );
......@@ -138,6 +140,7 @@ namespace KPDF
KAction *m_gotoPage;
KToggleAction* m_showScrollBars;
KToggleAction* m_showPageList;
KToggleAction* m_showTOC;
KSelectAction *m_zoomTo;
KToggleAction* m_fitToWidth;
KAction *m_find;
......
......@@ -27,6 +27,7 @@
</Menu>
<Menu name="settings"><text>&amp;Settings</text>
<Action name="show_scrollbars" group="show_merge"/>
<Action name="show_toc" group="show_merge"/>
<Action name="show_page_list" group="show_merge"/>
</Menu>
</MenuBar>
......
......@@ -10,31 +10,39 @@
#include "part.h"
#include <qlayout.h>
#include <qsplitter.h>
#include <qtable.h>
#include "kpdf_pagewidget.h"
#include "thumbnaillist.h"
#include "toc.h"
/*
* Constructs a PDFPartView as a child of 'parent', with the
* name 'name'
* name 'name'
*/
PDFPartView::PDFPartView(QWidget* parent, const char* name, QMutex *docMutex) : QWidget(parent, name)
{
PDFPartViewLayout = new QHBoxLayout( this, 3, 3, "PDFPartViewLayout");
QHBoxLayout* PDFPartViewLayout = new QHBoxLayout(this, 3, 3);
pagesList = new ThumbnailList(this, docMutex);
pagesList->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)7, 0, 0, pagesList->sizePolicy().hasHeightForWidth() ) );
pagesList->setMaximumSize( QSize( 75, 32767 ) );
pagesList->setMaximumSize(75, 32767);
pagesList->setColumnWidth(0, 75);
PDFPartViewLayout->addWidget( pagesList );
outputdev = new KPDF::PageWidget( this, "outputdev", docMutex );
PDFPartViewLayout->addWidget( outputdev );
resize( QSize(623, 381).expandedTo(minimumSizeHint()) );
clearWState( WState_Polished );
QSplitter *split = new QSplitter(this);
PDFPartViewLayout->addWidget(split);
toc = new TOC(split);
toc->hide();
outputdev = new KPDF::PageWidget( split, "outputdev", docMutex );
m_existsTOC = false;
connect(pagesList, SIGNAL(clicked(int)), this, SIGNAL(clicked(int)));
connect(toc, SIGNAL(execute(LinkAction*)), this, SIGNAL(execute(LinkAction*)));
}
/*
......@@ -66,10 +74,29 @@ void PDFPartView::stopThumbnailGeneration()
pagesList->stopThumbnailGeneration();
}
void PDFPartView::generateTOC(PDFDoc *doc)
{
m_existsTOC = toc->generate(doc);
emit hasTOC(m_existsTOC);
updateShowTOC();
}
void PDFPartView::showPageList(bool show)
{
if (show) pagesList->show();
else pagesList->hide();
}
void PDFPartView::showTOC(bool show)
{
m_showTOC = show;
updateShowTOC();
}
void PDFPartView::updateShowTOC()
{
if (m_showTOC && m_existsTOC) toc->show();
else toc->hide();
}
#include "part.moc"
......@@ -12,16 +12,17 @@
#include <qwidget.h>
class QHBoxLayout;
class QMutex;
namespace KPDF {
class PageWidget;
}
class LinkAction;
class PDFDoc;
class ThumbnailList;
class TOC;
class PDFPartView : public QWidget
{
......@@ -30,27 +31,33 @@ class PDFPartView : public QWidget
public:
PDFPartView(QWidget* parent, const char* name, QMutex *docMutex);
~PDFPartView();
// first page is page 1
void setCurrentThumbnail(int i);
void setPages(int i, double ar);
void setPages(int i, double ar);
void generateThumbnails(PDFDoc *doc);
void stopThumbnailGeneration();
void generateTOC(PDFDoc *doc);
void showPageList(bool show);
void showTOC(bool show);
// TODO make private
KPDF::PageWidget* outputdev;
signals:
void clicked(int);
protected:
QHBoxLayout* PDFPartViewLayout;
void execute(LinkAction*);
void hasTOC(bool);
private:
ThumbnailList* pagesList;
void updateShowTOC();
ThumbnailList *pagesList;
TOC *toc;
bool m_showTOC, m_existsTOC;
};
#endif // PDFPARTVIEW_H
/***************************************************************************
* Copyright (C) 2004 by Albert Astals Cid <tsdgeos@terra.es> *
* *
* 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 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include <qheader.h>
#include "goo/GList.h"
#include "xpdf/GlobalParams.h"
#include "xpdf/PDFDoc.h"
#include "xpdf/Outline.h"
#include "xpdf/UnicodeMap.h"
#include "toc.h"
class TOCItem : public KListViewItem
{
public:
TOCItem(KListView *parent, TOCItem *after, QString name, LinkAction *action) :
KListViewItem(parent, after, name), m_action(action)
{
}
TOCItem(KListViewItem *parent, TOCItem *after, QString name, LinkAction *action) :
KListViewItem(parent, after, name), m_action(action)
{
}
LinkAction *getAction() const
{
return m_action;
}
private:
LinkAction *m_action;
};
TOC::TOC(QWidget *parent) : KListView(parent)
{
addColumn("");
header() -> hide();
setSorting(-1);
setRootIsDecorated(true);
setResizeMode(AllColumns);
connect(this, SIGNAL(executed(QListViewItem *)), this, SLOT(slotExecuted(QListViewItem *)));
}
bool TOC::generate(PDFDoc *doc)
{
GList *items, *kids;
OutlineItem *item;
UnicodeMap *uMap;
GString *enc;
TOCItem *last;
clear();
last = 0;
items = doc->getOutline()->getItems();
if (items && items->getLength() > 0)
{
enc = new GString("Latin1");
uMap = globalParams->getUnicodeMap(enc);
delete enc;
for (int i = 0; i < items->getLength(); ++i)
{
item = (OutlineItem *)items->get(i);
last = new TOCItem(this, last, getTitle(item->getTitle(), item->getTitleLength(), uMap), item->getAction());
item->open();
if ((kids = item->getKids()))
{
addKids(last, kids, uMap);
}
}
return true;
}
return false;
}
void TOC::addKids(KListViewItem *parent, GList *items, UnicodeMap *uMap)
{
GList *kids;
OutlineItem *item;
TOCItem *last;
last = 0;
if (items && items->getLength() > 0)
{
for (int i = 0; i < items->getLength(); ++i)
{
item = (OutlineItem *)items->get(i);
last = new TOCItem(parent, last, getTitle(item->getTitle(), item->getTitleLength(), uMap), item->getAction());
item->open();
if ((kids = item->getKids()))
{
addKids(last, kids, uMap);
}
}
}
}
QString TOC::getTitle(Unicode *u, int length, UnicodeMap *uMap) const
{
GString *title;
QString s;
int n;
char buf[8];
title = new GString();
for (int j = 0; j < length; ++j)
{
n = uMap->mapUnicode(u[j], buf, sizeof(buf));
title->append(buf, n);
}
s = title->getCString();
delete title;
return s;
}
void TOC::slotExecuted(QListViewItem *i)
{
TOCItem *ti = dynamic_cast<TOCItem*>(i);
emit execute(ti -> getAction());
}
#include "toc.moc"
/***************************************************************************
* Copyright (C) 2004 by Albert Astals Cid <tsdgeos@terra.es> *
* *
* 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 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef TOC_H
#define TOC_H
#include <klistview.h>
class GList;
class PDFDoc;
class UnicodeMap;
class TOC : public KListView
{
Q_OBJECT
public:
TOC(QWidget *parent);
bool generate(PDFDoc *doc);
signals:
void execute(LinkAction *action);
private:
void addKids(KListViewItem *last, GList *items, UnicodeMap *uMap);
QString getTitle(Unicode *u, int length, UnicodeMap *uMap) const;
private slots:
void slotExecuted(QListViewItem *i);
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment