From 8f32edb95e7a3887ad0ce867b11bb43e5dcc68b2 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Tue, 20 Jun 2006 13:59:08 +0000 Subject: [PATCH] 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 --- ui/toc.cpp | 39 ++++++++++++++++++++++++++++++++++++++- ui/toc.h | 4 ++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/ui/toc.cpp b/ui/toc.cpp index 507a6e265..03a7ed1ed 100644 --- a/ui/toc.cpp +++ b/ui/toc.cpp @@ -8,6 +8,7 @@ ***************************************************************************/ // qt/kde includes +#include #include #include #include @@ -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( *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 diff --git a/ui/toc.h b/ui/toc.h index 74fe1841c..ee063498c 100644 --- a/ui/toc.h +++ b/ui/toc.h @@ -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