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
This commit is contained in:
Pino Toscano 2007-01-19 23:30:32 +00:00
parent e6cc48a009
commit b163e04115
5 changed files with 31 additions and 2 deletions

View file

@ -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;

View file

@ -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.
*/

View file

@ -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 );

View file

@ -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;

View file

@ -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() );
}