Commit 545117b3 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Here comes the TOC

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=348922
parent a7202a70
......@@ -4,7 +4,7 @@ INCLUDES = -I$(srcdir)/.. -I$(srcdir)/../splash -I$(srcdir)/../goo -I$(srcdir)/.
# let automoc handle all of the meta source files (moc)
METASOURCES = AUTO
messages: rc.cpp
messages: rc.cpp
$(XGETTEXT) *.cpp -o $(podir)/kpdf.pot
# TODO: fix the code!
......@@ -38,11 +38,11 @@ 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 QOutputDevKPrinter.cpp kpdf_part.cpp kpdf_pagewidget.cc thumbnail.cpp thumbnaillist.cpp kpdf_error.cpp xpdf_errors.cpp thumbnailgenerator.cpp document.cpp page.cpp searchwidget.cpp
libkpdfpart_la_SOURCES = QOutputDev.cpp QOutputDevKPrinter.cpp kpdf_part.cpp kpdf_pagewidget.cc thumbnail.cpp thumbnaillist.cpp kpdf_error.cpp xpdf_errors.cpp thumbnailgenerator.cpp document.cpp page.cpp searchwidget.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
# this is where the desktop file will go
# this is where the desktop file will go
partdesktopdir = $(kde_servicesdir)
partdesktop_DATA = kpdf_part.desktop
......
/***************************************************************************
* Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
* 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 *
......@@ -177,6 +178,11 @@ const KPDFPage * KPDFDocument::page( uint n ) const
return ( n < d->pages.count() ) ? d->pages[n] : 0;
}
Outline * KPDFDocument::outline() const
{
return d->pdfdoc ? d->pdfdoc->getOutline() : 0;
}
void KPDFDocument::addObserver( KPDFDocumentObserver * pObserver )
{
......@@ -220,7 +226,7 @@ void KPDFDocument::requestPixmap( int id, uint page, int width, int height, bool
}
}
// BEGIN slots
// BEGIN slots
void KPDFDocument::slotSetCurrentPage( int page )
{
slotSetCurrentPagePosition( page, 0.0 );
......@@ -316,7 +322,7 @@ void KPDFDocument::slotFind( const QString & string, bool keepCase )
void KPDFDocument::slotGoToLink( /* QString anchor */ )
{
}
//END slots
//END slots
void KPDFDocument::processPageList( bool documentChanged )
{
......@@ -431,7 +437,7 @@ void ThumbnailList::customEvent(QCustomEvent *e)
if (e->type() == 65432 && !m_ignoreNext)
{
QImage *i = (QImage*)(e -> data());
setThumbnail(m_nextThumbnail, i);
m_nextThumbnail++;
if (m_nextThumbnail <= m_doc->getNumPages()) generateNextThumbnail();
......
/***************************************************************************
* Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
* 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 *
......@@ -13,6 +14,8 @@
#include <qobject.h>
#include <qvaluevector.h>
class Outline;
class KPDFPage;
/**
......@@ -37,6 +40,7 @@ public:
#define PAGEWIDGET_ID 1
#define THUMBNAILS_ID 2
#define TOC_ID 2
/**
* @short The information container. Actions (like open,find) take place here.
......@@ -62,6 +66,7 @@ public:
bool atBegin() const;
bool atEnd() const;
const KPDFPage * page( uint page ) const;
Outline * outline() const;
// observers related methods
void addObserver( KPDFDocumentObserver * pObserver );
......
......@@ -53,6 +53,7 @@
#include "searchwidget.h"
#include "thumbnaillist.h"
#include "document.h"
#include "toc.h"
typedef KParts::GenericFactory<KPDF::Part> KPDFPartFactory;
K_EXPORT_COMPONENT_FACTORY(libkpdfpart, KPDFPartFactory)
......@@ -93,7 +94,9 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
toolBox->setMinimumWidth( 60 );
toolBox->setMaximumWidth( 200 );
QFrame * tocFrame = new QFrame( toolBox );
// TODO when links following is done connect the execute(LinkAction *action) signal from
// tocFrame to the same slot
TOC * tocFrame = new TOC( toolBox, document );
toolBox->addItem( tocFrame, QIconSet(SmallIcon("text_left")), i18n("Contents") );
QVBox * thumbsBox = new ThumbnailsBox( toolBox );
......@@ -119,6 +122,7 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
// add document observers
document->addObserver( m_thumbnailList );
document->addObserver( m_pageView );
document->addObserver( tocFrame );
// ACTIONS
KActionCollection * ac = actionCollection();
......@@ -177,6 +181,7 @@ Part::~Part()
delete globalParams;
}
//TODO does that really goes somewhere???
KAboutData* Part::createAboutData()
{
// the non-i18n name here must be the same as the directory in
......
......@@ -40,7 +40,7 @@ class TOCItem : public KListViewItem
LinkAction *m_action;
};
TOC::TOC(QWidget *parent) : KListView(parent)
TOC::TOC(QWidget *parent, KPDFDocument *document) : KListView(parent), m_document(document)
{
addColumn("");
header() -> hide();
......@@ -50,39 +50,50 @@ TOC::TOC(QWidget *parent) : KListView(parent)
connect(this, SIGNAL(executed(QListViewItem *)), this, SLOT(slotExecuted(QListViewItem *)));
}
bool TOC::generate(PDFDoc *doc)
uint TOC::observerId()
{
GList *items, *kids;
OutlineItem *item;
UnicodeMap *uMap;
GString *enc;
TOCItem *last;
return TOC_ID;
}
clear();
last = 0;
items = doc->getOutline()->getItems();
if (items && items->getLength() > 0)
void TOC::pageSetup( const QValueVector<KPDFPage*> & /*pages*/, bool documentChanged)
{
if (documentChanged)
{
enc = new GString("Latin1");
uMap = globalParams->getUnicodeMap(enc);
delete enc;
for (int i = 0; i < items->getLength(); ++i)
GList *items, *kids;
OutlineItem *item;
UnicodeMap *uMap;
GString *enc;
TOCItem *last;
clear();
last = 0;
Outline *out = m_document->outline();
if (out) items = out->getItems();
else items = 0;
if (items && items->getLength() > 0)
{
item = (OutlineItem *)items->get(i);
enc = new GString("Latin1");
uMap = globalParams->getUnicodeMap(enc);
delete enc;
last = new TOCItem(this, last, getTitle(item->getTitle(), item->getTitleLength(), uMap), item->getAction());
item->open();
if ((kids = item->getKids()))
for (int i = 0; i < items->getLength(); ++i)
{
addKids(last, kids, uMap);
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);
}
}
// inform we have TOC
}
return true;
// inform we DO NOT have TOC
}
return false;
}
void TOC::addKids(KListViewItem *parent, GList *items, UnicodeMap *uMap)
{
GList *kids;
......
......@@ -12,28 +12,33 @@
#include <klistview.h>
#include "document.h"
class GList;
class PDFDoc;
class UnicodeMap;
class TOC : public KListView
class TOC : public KListView, public KPDFDocumentObserver
{
Q_OBJECT
public:
TOC(QWidget *parent);
TOC(QWidget *parent, KPDFDocument *document);
bool generate(PDFDoc *doc);
uint observerId();
void pageSetup( const QValueVector<KPDFPage*> & /*pages*/, bool documentChanged);
signals:
void execute(LinkAction *action);
private slots:
void slotExecuted(QListViewItem *i);
private:
void addKids(KListViewItem *last, GList *items, UnicodeMap *uMap);
QString getTitle(Unicode *u, int length, UnicodeMap *uMap) const;
private slots:
void slotExecuted(QListViewItem *i);
KPDFDocument *m_document;
};
#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