Make the TOC highlight (well, just indicate with an arrow for the moment) the first entry for the current page.

Implements bug #127358.

svn path=/trunk/playground/graphics/okular/; revision=553236
remotes/origin/old/work/newpageview
Pino Toscano 20 years ago
parent 066beaa1dd
commit 8f32edb95e
  1. 39
      ui/toc.cpp
  2. 4
      ui/toc.h

@ -8,6 +8,7 @@
***************************************************************************/
// qt/kde includes
#include <qapplication.h>
#include <qheaderview.h>
#include <qlayout.h>
#include <qstringlist.h>
@ -53,11 +54,16 @@ class TOCItem : public QTreeWidgetItem
return m_element;
}
void setSelected( bool selected )
{
setIcon( 0, selected ? KIcon( QApplication::layoutDirection() == Qt::RightToLeft ? "1leftarrow" : "1rightarrow" ) : QIcon() );
}
private:
QDomElement m_element;
};
TOC::TOC(QWidget *parent, KPDFDocument *document) : QWidget(parent), m_document(document)
TOC::TOC(QWidget *parent, KPDFDocument *document) : QWidget(parent), m_document(document), m_current(0), m_currentPage(-1)
{
QVBoxLayout *mainlay = new QVBoxLayout( this );
mainlay->setMargin( 0 );
@ -111,6 +117,8 @@ void TOC::notifySetup( const QVector< KPDFPage * > & /*pages*/, bool documentCha
// clear contents
m_treeView->clear();
m_searchLine->clear();
m_current = 0;
m_currentPage = -1;
// request synopsis description (is a dom tree)
const DocumentSynopsis * syn = m_document->documentSynopsis();
@ -127,6 +135,35 @@ void TOC::notifySetup( const QVector< KPDFPage * > & /*pages*/, bool documentCha
emit hasTOC( true );
}
void TOC::notifyViewportChanged( bool /*smoothMove*/ )
{
int newpage = m_document->viewport().pageNumber;
if ( m_currentPage == newpage )
return;
m_currentPage = newpage;
if ( m_current )
{
m_current->setSelected( false );
m_current = 0;
}
QTreeWidgetItemIterator it( m_treeView );
while ( (*it) && !m_current )
{
TOCItem *tmp = dynamic_cast<TOCItem*>( *it );
int p = tmp ? getViewport( tmp->element() ).pageNumber : -1;
if ( p == newpage )
{
m_current = tmp;
m_current->setSelected( true );
}
++it;
}
}
void TOC::addChildren( const QDomNode & parentNode, QTreeWidgetItem * parentItem )
{
// keep track of the current listViewItem

@ -19,6 +19,7 @@ class QTreeWidget;
class QTreeWidgetItem;
class KTreeWidgetSearchLine;
class KPDFDocument;
class TOCItem;
class TOC : public QWidget, public DocumentObserver
{
@ -30,6 +31,7 @@ Q_OBJECT
// inherited from DocumentObserver
uint observerId() const;
void notifySetup( const QVector< KPDFPage * > & pages, bool documentChanged );
void notifyViewportChanged( bool smoothMove );
signals:
void hasTOC(bool has);
@ -43,6 +45,8 @@ Q_OBJECT
KPDFDocument *m_document;
QTreeWidget *m_treeView;
KTreeWidgetSearchLine *m_searchLine;
TOCItem *m_current;
int m_currentPage;
};
#endif

Loading…
Cancel
Save