2004-09-21 20:38:22 +00:00
|
|
|
/***************************************************************************
|
2006-02-18 12:06:52 +00:00
|
|
|
* Copyright (C) 2004-2006 by Albert Astals Cid <tsdgeos@terra.es> *
|
2004-09-21 20:38:22 +00:00
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2007-04-19 18:30:20 +00:00
|
|
|
#include "toc.h"
|
|
|
|
|
2004-12-12 11:11:57 +00:00
|
|
|
// qt/kde includes
|
2006-12-22 19:26:28 +00:00
|
|
|
#include <qdom.h>
|
2006-05-19 11:32:08 +00:00
|
|
|
#include <qheaderview.h>
|
2006-05-28 17:27:24 +00:00
|
|
|
#include <qlayout.h>
|
2007-09-09 16:15:33 +00:00
|
|
|
#include <qtreeview.h>
|
|
|
|
|
|
|
|
#include <klineedit.h>
|
2004-09-21 20:38:22 +00:00
|
|
|
|
2004-12-12 11:11:57 +00:00
|
|
|
// local includes
|
2007-09-09 16:15:33 +00:00
|
|
|
#include "ktreeviewsearchline.h"
|
2006-12-26 12:01:30 +00:00
|
|
|
#include "pageitemdelegate.h"
|
2007-09-09 16:15:33 +00:00
|
|
|
#include "tocmodel.h"
|
2007-04-20 11:26:05 +00:00
|
|
|
#include "core/action.h"
|
2005-01-02 14:37:49 +00:00
|
|
|
#include "core/document.h"
|
2004-09-21 20:38:22 +00:00
|
|
|
|
2007-09-09 16:15:33 +00:00
|
|
|
TOC::TOC(QWidget *parent, Okular::Document *document) : QWidget(parent), m_document(document), m_currentPage(-1)
|
2004-09-21 20:38:22 +00:00
|
|
|
{
|
2006-05-28 17:27:24 +00:00
|
|
|
QVBoxLayout *mainlay = new QVBoxLayout( this );
|
|
|
|
mainlay->setMargin( 0 );
|
2007-08-24 14:20:03 +00:00
|
|
|
mainlay->setSpacing( 6 );
|
2006-05-28 17:27:24 +00:00
|
|
|
|
2007-09-09 16:15:33 +00:00
|
|
|
m_searchLine = new KTreeViewSearchLine( this );
|
2007-08-24 14:20:03 +00:00
|
|
|
mainlay->addWidget( m_searchLine );
|
2006-05-28 17:27:24 +00:00
|
|
|
|
2007-09-09 16:15:33 +00:00
|
|
|
m_treeView = new QTreeView( this );
|
2006-05-28 17:27:24 +00:00
|
|
|
mainlay->addWidget( m_treeView );
|
2007-09-09 16:15:33 +00:00
|
|
|
m_model = new TOCModel( document, m_treeView );
|
|
|
|
m_treeView->setModel( m_model );
|
2006-05-28 17:27:24 +00:00
|
|
|
m_treeView->setSortingEnabled( false );
|
|
|
|
m_treeView->setRootIsDecorated( true );
|
|
|
|
m_treeView->setAlternatingRowColors( true );
|
2006-12-26 12:01:30 +00:00
|
|
|
m_treeView->setItemDelegate( new PageItemDelegate( m_treeView ) );
|
2006-05-28 17:27:24 +00:00
|
|
|
m_treeView->header()->hide();
|
|
|
|
m_treeView->setSelectionBehavior( QAbstractItemView::SelectRows );
|
2007-09-09 16:15:33 +00:00
|
|
|
connect( m_treeView, SIGNAL( clicked( const QModelIndex & ) ), this, SLOT( slotExecuted( const QModelIndex & ) ) );
|
|
|
|
connect( m_treeView, SIGNAL( activated( const QModelIndex & ) ), this, SLOT( slotExecuted( const QModelIndex & ) ) );
|
|
|
|
m_searchLine->addTreeView( m_treeView );
|
2004-09-21 20:38:22 +00:00
|
|
|
}
|
|
|
|
|
2006-02-18 12:06:52 +00:00
|
|
|
TOC::~TOC()
|
|
|
|
{
|
|
|
|
m_document->removeObserver( this );
|
|
|
|
}
|
|
|
|
|
2004-10-24 13:08:31 +00:00
|
|
|
uint TOC::observerId() const
|
2004-09-21 20:38:22 +00:00
|
|
|
{
|
2004-12-11 17:25:03 +00:00
|
|
|
return TOC_ID;
|
2004-09-23 21:33:53 +00:00
|
|
|
}
|
2004-09-21 20:38:22 +00:00
|
|
|
|
2007-09-09 10:50:36 +00:00
|
|
|
void TOC::notifySetup( const QVector< Okular::Page * > & /*pages*/, int setupFlags )
|
2004-09-23 21:33:53 +00:00
|
|
|
{
|
2007-09-09 10:50:36 +00:00
|
|
|
if ( !( setupFlags & Okular::DocumentObserver::DocumentChanged ) )
|
2004-12-11 17:25:03 +00:00
|
|
|
return;
|
2004-09-23 21:33:53 +00:00
|
|
|
|
2004-12-12 11:11:57 +00:00
|
|
|
// clear contents
|
2007-09-09 16:15:33 +00:00
|
|
|
m_model->clear();
|
2006-06-20 13:59:08 +00:00
|
|
|
m_currentPage = -1;
|
2004-12-12 11:11:57 +00:00
|
|
|
|
|
|
|
// request synopsis description (is a dom tree)
|
2006-09-21 08:45:36 +00:00
|
|
|
const Okular::DocumentSynopsis * syn = m_document->documentSynopsis();
|
2004-12-12 11:11:57 +00:00
|
|
|
|
|
|
|
// if not present, disable the contents tab
|
|
|
|
if ( !syn )
|
2004-12-11 17:25:03 +00:00
|
|
|
{
|
2004-12-12 11:11:57 +00:00
|
|
|
emit hasTOC( false );
|
|
|
|
return;
|
2004-12-11 17:25:03 +00:00
|
|
|
}
|
2004-09-21 20:38:22 +00:00
|
|
|
|
2004-12-12 11:11:57 +00:00
|
|
|
// else populate the listview and enable the tab
|
2007-09-09 16:15:33 +00:00
|
|
|
m_model->fill( syn );
|
2004-12-12 11:11:57 +00:00
|
|
|
emit hasTOC( true );
|
|
|
|
}
|
|
|
|
|
2006-06-20 13:59:08 +00:00
|
|
|
void TOC::notifyViewportChanged( bool /*smoothMove*/ )
|
|
|
|
{
|
|
|
|
int newpage = m_document->viewport().pageNumber;
|
|
|
|
if ( m_currentPage == newpage )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_currentPage = newpage;
|
|
|
|
|
2007-09-09 16:15:33 +00:00
|
|
|
m_model->setCurrentViewport( m_document->viewport() );
|
2006-06-20 13:59:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-22 20:42:36 +00:00
|
|
|
void TOC::reparseConfig()
|
|
|
|
{
|
|
|
|
m_treeView->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-09 16:15:33 +00:00
|
|
|
void TOC::slotExecuted( const QModelIndex &index )
|
2004-09-21 20:38:22 +00:00
|
|
|
{
|
2007-09-09 16:15:33 +00:00
|
|
|
if ( !index.isValid() )
|
2005-06-13 16:35:31 +00:00
|
|
|
return;
|
2005-07-15 17:32:46 +00:00
|
|
|
|
2007-09-09 16:15:33 +00:00
|
|
|
QString externalFileName = m_model->externalFileNameForIndex( index );
|
|
|
|
Okular::DocumentViewport viewport = m_model->viewportForIndex( index );
|
2005-07-15 17:32:46 +00:00
|
|
|
if ( !externalFileName.isEmpty() )
|
2005-01-07 13:07:29 +00:00
|
|
|
{
|
2007-09-09 16:15:33 +00:00
|
|
|
Okular::GotoAction action( externalFileName, viewport );
|
2007-04-20 12:49:17 +00:00
|
|
|
m_document->processAction( &action );
|
2005-01-07 13:07:29 +00:00
|
|
|
}
|
2005-07-15 17:32:46 +00:00
|
|
|
else
|
2005-01-07 13:07:29 +00:00
|
|
|
{
|
2007-09-09 16:15:33 +00:00
|
|
|
m_document->setViewport( viewport );
|
2005-01-07 13:07:29 +00:00
|
|
|
}
|
2004-09-21 20:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "toc.moc"
|