1 /***************************************************************************
2 * Copyright (C) 2004-2006 by Albert Astals Cid <tsdgeos@terra.es> *
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 ***************************************************************************/
14 #include <qheaderview.h>
16 #include <qtreeview.h>
18 #include <klineedit.h>
21 #include "ktreeviewsearchline.h"
22 #include "pageitemdelegate.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
);
53 m_document
->removeObserver( this );
56 uint
TOC::observerId() const
61 void TOC::notifySetup( const QVector
< Okular::Page
* > & /*pages*/, int setupFlags
)
63 if ( !( setupFlags
& Okular::DocumentObserver::DocumentChanged
) )
70 // request synopsis description (is a dom tree)
71 const Okular::DocumentSynopsis
* syn
= m_document
->documentSynopsis();
73 // if not present, disable the contents tab
80 // else populate the listview and enable the tab
82 emit
hasTOC( !m_model
->isEmpty() );
85 void TOC::notifyViewportChanged( bool /*smoothMove*/ )
87 int newpage
= m_document
->viewport().pageNumber
;
88 if ( m_currentPage
== newpage
)
91 m_currentPage
= newpage
;
93 m_model
->setCurrentViewport( m_document
->viewport() );
97 void TOC::reparseConfig()
103 void TOC::slotExecuted( const QModelIndex
&index
)
105 if ( !index
.isValid() )
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
);
117 m_document
->setViewport( viewport
);