TOC displays the Synopsis DomTree and reacts on clicks. Viewport changes

moved to #1 in TODO list. Let's hope next items won't start from #2..

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=370056
This commit is contained in:
Enrico Ros 2004-12-12 11:11:57 +00:00
parent 246d0b5e78
commit 8aaec0dd08
3 changed files with 83 additions and 27 deletions

View file

@ -7,9 +7,10 @@ Legend:
(*) - Some parts of this item are already done
In progress on the branch (first item comes first):
-> Abstract contents generation [70% missing TextPage only!]
-> FIX: viewport changes the right way when clicking links and TOC items (also
suggested by Mikolaj Machowski). Create a great viewport definition and merge
it inside the synopsis too. [70% done]
-> memory manager with different profiles (mem/cpu tradeoff: {memory saving, normal, memory aggressive}) [20%]
-> ADD: viewport changes the right way when clicking links (also suggested by Mikolaj Machowski) [65% done]
Things to do in order to merge in HEAD (first item has highest priority):
-> take care of naming on merge, too differences (remove some kpdf_* prefixes
@ -31,6 +32,8 @@ More items (first items will enter 'In progress list' first):
-> display current page / total pages (with analog indicator too (progressbar/...))
maybe this can be done on a small widget at the top of the toolbox, displaying
'document' informations (pages, current pg, some metadata, etc..)
-> abstract TextPage generation (the last xpdf dependant class!). then go dancing in the
streets.
-> right click and drag while in 'scroll' mode changes to 'selection' mode and selects
-> add kpdf manual in PDF format loaded on the first startup or on menu->help->manual
this visually explains basic usage, mouse buttons functions & more..

View file

@ -7,38 +7,57 @@
* (at your option) any later version. *
***************************************************************************/
// qt/kde includes
#include <qheader.h>
#include <klocale.h>
// local includes
#include "toc.h"
#include "page.h"
#include "document.h"
// uncomment following to enable a 2nd column showing the page referred by
// each tree entry
//#define TOC_ENABLE_PAGE_COLUMN
class TOCItem : public KListViewItem
{
public:
TOCItem(KListView *parent, TOCItem *after, QString name, const QDomElement & e) :
KListViewItem(parent, after, name), m_element(e)
{
}
public:
TOCItem( KListView *parent, TOCItem *after, const QDomElement & e )
: KListViewItem( parent, after, e.tagName() ), m_element( e )
{
#ifdef TOC_ENABLE_PAGE_COLUMN
if ( e.hasAttribute( "Page" ) )
setText( 1, e.attribute( "Page" ) );
#endif
}
TOCItem(KListViewItem *parent, TOCItem *after, QString name, const QDomElement & e) :
KListViewItem(parent, after, name), m_element(e)
{
}
TOCItem( KListViewItem *parent, TOCItem *after, const QDomElement & e )
: KListViewItem( parent, after, e.tagName() ), m_element( e )
{
#ifdef TOC_ENABLE_PAGE_COLUMN
if ( e.hasAttribute( "Page" ) )
setText( 1, e.attribute( "Page" ) );
#endif
}
const QDomElement & element() const
{
return m_element;
}
const QDomElement & element() const
{
return m_element;
}
private:
QDomElement m_element;
private:
QDomElement m_element;
};
TOC::TOC(QWidget *parent, KPDFDocument *document) : KListView(parent), m_document(document)
{
addColumn("");
addColumn( i18n("Topic") );
#ifdef TOC_ENABLE_PAGE_COLUMN
addColumn( i18n("Page") );
#else
header() -> hide();
#endif
setSorting(-1);
setRootIsDecorated(true);
setResizeMode(AllColumns);
@ -50,27 +69,60 @@ uint TOC::observerId() const
return TOC_ID;
}
void TOC::pageSetup( const QValueVector<KPDFPage*> & pages, bool documentChanged)
void TOC::pageSetup( const QValueVector<KPDFPage*> & pages, bool documentChanged )
{
if ( !documentChanged || pages.size() < 1 )
return;
// clear contents
clear();
// request synopsis description (is a dom tree)
const DocumentSynopsis * syn = m_document->documentSynopsis();
if ( syn )
// if not present, disable the contents tab
if ( !syn )
{
emit hasTOC( false );
return;
}
emit hasTOC( syn );
// else populate the listview and enable the tab
addChildren( *syn );
emit hasTOC( true );
}
void TOC::slotExecuted(QListViewItem *i)
void TOC::addChildren( const QDomNode & parentNode, KListViewItem * parentItem )
{
// TOCItem *ti = dynamic_cast<TOCItem*>(i);
//FIXME
//KPDFLink l( ti->getAction() );
//m_document->processLink( &l );
// keep track of the current listViewItem
TOCItem * currentItem = 0;
QDomNode n = parentNode.firstChild();
while( !n.isNull() )
{
// convert the node to an element (sure it is)
QDomElement e = n.toElement();
// insert the entry as top level (listview parented) or 2nd+ level
if ( !parentItem )
currentItem = new TOCItem( this, currentItem, e );
else
currentItem = new TOCItem( parentItem, currentItem, e );
// descend recursively and advance to the next node
if ( e.hasChildNodes() )
addChildren( n, currentItem );
n = n.nextSibling();
}
}
void TOC::slotExecuted( QListViewItem *i )
{
const QDomElement & e = static_cast< TOCItem* >( i )->element();
// if the node has a referred page, jump to it
if ( e.hasAttribute( "Page" ) )
m_document->setCurrentPage( e.attribute( "Page" ).toUInt() );
// may check for other properties here
// ...
}
#include "toc.moc"

View file

@ -31,6 +31,7 @@ Q_OBJECT
void slotExecuted(QListViewItem *i);
private:
void addChildren( const QDomNode & parentNode, KListViewItem * parentItem = 0 );
KPDFDocument *m_document;
};