mirror of
https://invent.kde.org/graphics/okular
synced 2024-10-05 23:49:20 +00:00
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:
parent
e6cc48a009
commit
b163e04115
|
@ -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;
|
||||
|
|
10
core/page.h
10
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.
|
||||
*/
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue