From b163e0411548ad76ab376fb7c663142269ed588a Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Fri, 19 Jan 2007 23:30:32 +0000 Subject: [PATCH] Support for labelling the pages, and for displaying the page label (if any) in the table of contents side pane. svn path=/trunk/playground/graphics/okular/; revision=625312 --- core/page.cpp | 11 +++++++++++ core/page.h | 10 ++++++++++ ui/pageitemdelegate.cpp | 6 ++++-- ui/pageitemdelegate.h | 1 + ui/toc.cpp | 5 +++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/core/page.cpp b/core/page.cpp index ab6b9d30e..81048fd9d 100644 --- a/core/page.cpp +++ b/core/page.cpp @@ -84,6 +84,7 @@ class Page::Private Link * m_openingAction; Link * m_closingAction; double m_duration; + QString m_label; }; void Page::Private::imageRotationDone() @@ -450,6 +451,16 @@ double Page::duration() const return d->m_duration; } +void Page::setLabel( const QString& label ) +{ + d->m_label = label; +} + +QString Page::label() const +{ + return d->m_label; +} + const RegularAreaRect * Page::textSelection() const { return m_textSelections; diff --git a/core/page.h b/core/page.h index e6f4cae9c..c687efea1 100644 --- a/core/page.h +++ b/core/page.h @@ -244,6 +244,16 @@ class OKULAR_EXPORT Page : public QObject */ double duration() const; + /** + * Sets the labels for the page to @p label . + */ + void setLabel( const QString& label ); + + /** + * Returns the label of the page, or a null string if not set. + */ + QString label() const; + /** * Returns the current text selection. */ diff --git a/ui/pageitemdelegate.cpp b/ui/pageitemdelegate.cpp index 7ff353813..cf939f8ba 100644 --- a/ui/pageitemdelegate.cpp +++ b/ui/pageitemdelegate.cpp @@ -48,12 +48,14 @@ void PageItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem & op void PageItemDelegate::drawDisplay( QPainter *painter, const QStyleOptionViewItem & option, const QRect & rect, const QString & text ) const { QVariant pageVariant = d->index.data( PageRole ); - if ( !pageVariant.canConvert( QVariant::String ) || !Okular::Settings::tocPageColumn() ) + QVariant labelVariant = d->index.data( PageLabelRole ); + if ( ( labelVariant.type() != QVariant::String && !pageVariant.canConvert( QVariant::String ) ) || !Okular::Settings::tocPageColumn() ) { QItemDelegate::drawDisplay( painter, option, rect, text ); return; } - QString page = pageVariant.toString(); + QString label = labelVariant.toString(); + QString page = label.isEmpty() ? pageVariant.toString() : label; QTextDocument document; document.setPlainText( page ); document.setDefaultFont( option.font ); diff --git a/ui/pageitemdelegate.h b/ui/pageitemdelegate.h index 9930982fc..0b425d00b 100644 --- a/ui/pageitemdelegate.h +++ b/ui/pageitemdelegate.h @@ -21,6 +21,7 @@ class PageItemDelegate : public QItemDelegate virtual ~PageItemDelegate(); static const int PageRole = 0x000f0001; + static const int PageLabelRole = 0x000f0002; virtual void paint( QPainter *painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; diff --git a/ui/toc.cpp b/ui/toc.cpp index eac32cbb5..e0b76da95 100644 --- a/ui/toc.cpp +++ b/ui/toc.cpp @@ -57,7 +57,12 @@ class TOCItem : public QTreeWidgetItem } if ( m_viewport.isValid() ) + { setData( 0, PageItemDelegate::PageRole, QString::number( m_viewport.pageNumber + 1 ) ); + QString label = document->page( m_viewport.pageNumber )->label(); + if ( !label.isEmpty() ) + setData( 0, PageItemDelegate::PageLabelRole, label ); + } setText( 0, e.tagName() ); }