compile
[kdegraphics.git] / okular / ui / toc.cpp
blobff25d9010c8adcfe65bd2a37f750044af165b0a6
1 /***************************************************************************
2 * Copyright (C) 2004-2006 by Albert Astals Cid <tsdgeos@terra.es> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 ***************************************************************************/
10 #include "toc.h"
12 // qt/kde includes
13 #include <qdom.h>
14 #include <qheaderview.h>
15 #include <qlayout.h>
16 #include <qtreeview.h>
18 #include <klineedit.h>
20 // local includes
21 #include "ktreeviewsearchline.h"
22 #include "pageitemdelegate.h"
23 #include "tocmodel.h"
24 #include "core/action.h"
25 #include "core/document.h"
27 TOC::TOC(QWidget *parent, Okular::Document *document) : QWidget(parent), m_document(document), m_currentPage(-1)
29 QVBoxLayout *mainlay = new QVBoxLayout( this );
30 mainlay->setMargin( 0 );
31 mainlay->setSpacing( 6 );
33 m_searchLine = new KTreeViewSearchLine( this );
34 mainlay->addWidget( m_searchLine );
36 m_treeView = new QTreeView( this );
37 mainlay->addWidget( m_treeView );
38 m_model = new TOCModel( document, m_treeView );
39 m_treeView->setModel( m_model );
40 m_treeView->setSortingEnabled( false );
41 m_treeView->setRootIsDecorated( true );
42 m_treeView->setAlternatingRowColors( true );
43 m_treeView->setItemDelegate( new PageItemDelegate( m_treeView ) );
44 m_treeView->header()->hide();
45 m_treeView->setSelectionBehavior( QAbstractItemView::SelectRows );
46 connect( m_treeView, SIGNAL( clicked( const QModelIndex & ) ), this, SLOT( slotExecuted( const QModelIndex & ) ) );
47 connect( m_treeView, SIGNAL( activated( const QModelIndex & ) ), this, SLOT( slotExecuted( const QModelIndex & ) ) );
48 m_searchLine->addTreeView( m_treeView );
51 TOC::~TOC()
53 m_document->removeObserver( this );
56 uint TOC::observerId() const
58 return TOC_ID;
61 void TOC::notifySetup( const QVector< Okular::Page * > & /*pages*/, int setupFlags )
63 if ( !( setupFlags & Okular::DocumentObserver::DocumentChanged ) )
64 return;
66 // clear contents
67 m_model->clear();
68 m_currentPage = -1;
70 // request synopsis description (is a dom tree)
71 const Okular::DocumentSynopsis * syn = m_document->documentSynopsis();
73 // if not present, disable the contents tab
74 if ( !syn )
76 emit hasTOC( false );
77 return;
80 // else populate the listview and enable the tab
81 m_model->fill( syn );
82 emit hasTOC( !m_model->isEmpty() );
85 void TOC::notifyViewportChanged( bool /*smoothMove*/ )
87 int newpage = m_document->viewport().pageNumber;
88 if ( m_currentPage == newpage )
89 return;
91 m_currentPage = newpage;
93 m_model->setCurrentViewport( m_document->viewport() );
97 void TOC::reparseConfig()
99 m_treeView->update();
103 void TOC::slotExecuted( const QModelIndex &index )
105 if ( !index.isValid() )
106 return;
108 QString externalFileName = m_model->externalFileNameForIndex( index );
109 Okular::DocumentViewport viewport = m_model->viewportForIndex( index );
110 if ( !externalFileName.isEmpty() )
112 Okular::GotoAction action( externalFileName, viewport );
113 m_document->processAction( &action );
115 else
117 m_document->setViewport( viewport );
121 #include "toc.moc"