mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-24 18:35:37 +00:00
move the delegate used to draw the side page numbers in an own file
svn path=/trunk/playground/graphics/okular/; revision=616662
This commit is contained in:
parent
77f96ebfe2
commit
349dfb7eb1
|
@ -82,6 +82,7 @@ set(okularpart_SRCS
|
|||
ui/annotationwidgets.cpp
|
||||
ui/minibar.cpp
|
||||
ui/newstuff.cpp
|
||||
ui/pageitemdelegate.cpp
|
||||
ui/pagepainter.cpp
|
||||
ui/pagesizelabel.cpp
|
||||
ui/pageviewannotator.cpp
|
||||
|
|
59
ui/pageitemdelegate.cpp
Normal file
59
ui/pageitemdelegate.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2006 by Pino Toscano <pino@kde.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
***************************************************************************/
|
||||
|
||||
// qt/kde includes
|
||||
#include <qapplication.h>
|
||||
#include <QItemDelegate>
|
||||
#include <QTextDocument>
|
||||
|
||||
// local includes
|
||||
#include "pageitemdelegate.h"
|
||||
#include "settings.h"
|
||||
|
||||
#define PAGEITEMDELEGATE_INTERNALMARGIN 3
|
||||
|
||||
PageItemDelegate::PageItemDelegate( QObject * parent )
|
||||
: QItemDelegate( parent )
|
||||
{
|
||||
}
|
||||
|
||||
void PageItemDelegate::drawDisplay( QPainter *painter, const QStyleOptionViewItem & option, const QRect & rect, const QString & text ) const
|
||||
{
|
||||
if ( text.indexOf( PAGEITEMDELEGATE_SEPARATOR ) == -1 )
|
||||
{
|
||||
QItemDelegate::drawDisplay( painter, option, rect, text );
|
||||
return;
|
||||
}
|
||||
QString realText = text.section( PAGEITEMDELEGATE_SEPARATOR, 1 );
|
||||
if ( !Okular::Settings::tocPageColumn() )
|
||||
{
|
||||
QItemDelegate::drawDisplay( painter, option, rect, realText );
|
||||
return;
|
||||
}
|
||||
QString page = text.section( PAGEITEMDELEGATE_SEPARATOR, 0, 0 );
|
||||
QTextDocument document;
|
||||
document.setPlainText( page );
|
||||
document.setDefaultFont( option.font );
|
||||
int margindelta = QApplication::style()->pixelMetric( QStyle::PM_FocusFrameHMargin ) + 1;
|
||||
int pageRectWidth = (int)document.size().width();
|
||||
QRect newRect( rect );
|
||||
QRect pageRect( rect );
|
||||
pageRect.setWidth( pageRectWidth + 2 * margindelta );
|
||||
newRect.setWidth( newRect.width() - pageRectWidth - PAGEITEMDELEGATE_INTERNALMARGIN );
|
||||
if ( option.direction == Qt::RightToLeft )
|
||||
newRect.translate( pageRectWidth + PAGEITEMDELEGATE_INTERNALMARGIN, 0 );
|
||||
else
|
||||
pageRect.translate( newRect.width() + PAGEITEMDELEGATE_INTERNALMARGIN - 2 * margindelta, 0 );
|
||||
QItemDelegate::drawDisplay( painter, option, newRect, realText );
|
||||
QStyleOptionViewItemV2 newoption( option );
|
||||
newoption.displayAlignment = ( option.displayAlignment & ~Qt::AlignHorizontal_Mask ) | Qt::AlignRight;
|
||||
QItemDelegate::drawDisplay( painter, newoption, pageRect, page );
|
||||
}
|
||||
|
||||
#include "pageitemdelegate.moc"
|
28
ui/pageitemdelegate.h
Normal file
28
ui/pageitemdelegate.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2006 by Pino Toscano <pino@kde.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef PAGEITEMDELEGATE_H
|
||||
#define PAGEITEMDELEGATE_H
|
||||
|
||||
#include <QItemDelegate>
|
||||
|
||||
#define PAGEITEMDELEGATE_SEPARATOR "@@@@@@@@@@"
|
||||
|
||||
class PageItemDelegate : public QItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PageItemDelegate( QObject * parent = 0 );
|
||||
|
||||
protected:
|
||||
virtual void drawDisplay( QPainter *painter, const QStyleOptionViewItem & option, const QRect & rect, const QString & text ) const;
|
||||
};
|
||||
|
||||
#endif
|
56
ui/toc.cpp
56
ui/toc.cpp
|
@ -8,72 +8,22 @@
|
|||
***************************************************************************/
|
||||
|
||||
// qt/kde includes
|
||||
#include <qapplication.h>
|
||||
#include <qdom.h>
|
||||
#include <qheaderview.h>
|
||||
#include <QItemDelegate>
|
||||
#include <qlayout.h>
|
||||
#include <qstringlist.h>
|
||||
#include <QTextDocument>
|
||||
#include <qtreewidget.h>
|
||||
#include <kicon.h>
|
||||
#include <klocale.h>
|
||||
#include <ktreewidgetsearchline.h>
|
||||
|
||||
// local includes
|
||||
#include "pageitemdelegate.h"
|
||||
#include "toc.h"
|
||||
#include "core/document.h"
|
||||
#include "core/page.h"
|
||||
#include "settings.h"
|
||||
#include "core/link.h"
|
||||
|
||||
#define TOC_SEPARATOR "@@@@@@@@@@"
|
||||
#define TOC_DELEGATE_INTERNALMARGIN 3
|
||||
|
||||
class TOCDelegate : public QItemDelegate
|
||||
{
|
||||
public:
|
||||
TOCDelegate( QObject * parent = 0 )
|
||||
: QItemDelegate( parent )
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void drawDisplay( QPainter *painter, const QStyleOptionViewItem & option, const QRect & rect, const QString & text ) const
|
||||
{
|
||||
if ( text.indexOf( TOC_SEPARATOR ) == -1 )
|
||||
{
|
||||
QItemDelegate::drawDisplay( painter, option, rect, text );
|
||||
return;
|
||||
}
|
||||
QString realText = text.section( TOC_SEPARATOR, 1 );
|
||||
if ( !Okular::Settings::tocPageColumn() )
|
||||
{
|
||||
QItemDelegate::drawDisplay( painter, option, rect, realText );
|
||||
return;
|
||||
}
|
||||
QString page = text.section( TOC_SEPARATOR, 0, 0 );
|
||||
QTextDocument document;
|
||||
document.setPlainText( page );
|
||||
document.setDefaultFont( option.font );
|
||||
int margindelta = QApplication::style()->pixelMetric( QStyle::PM_FocusFrameHMargin ) + 1;
|
||||
int pageRectWidth = (int)document.size().width();
|
||||
QRect newRect( rect );
|
||||
QRect pageRect( rect );
|
||||
pageRect.setWidth( pageRectWidth + 2 * margindelta );
|
||||
newRect.setWidth( newRect.width() - pageRectWidth - TOC_DELEGATE_INTERNALMARGIN );
|
||||
if ( option.direction == Qt::RightToLeft )
|
||||
newRect.translate( pageRectWidth + TOC_DELEGATE_INTERNALMARGIN, 0 );
|
||||
else
|
||||
pageRect.translate( newRect.width() + TOC_DELEGATE_INTERNALMARGIN - 2 * margindelta, 0 );
|
||||
QItemDelegate::drawDisplay( painter, option, newRect, realText );
|
||||
QStyleOptionViewItemV2 newoption( option );
|
||||
newoption.displayAlignment = ( option.displayAlignment & ~Qt::AlignHorizontal_Mask ) | Qt::AlignRight;
|
||||
QItemDelegate::drawDisplay( painter, newoption, pageRect, page );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class TOCItem : public QTreeWidgetItem
|
||||
{
|
||||
public:
|
||||
|
@ -108,7 +58,7 @@ class TOCItem : public QTreeWidgetItem
|
|||
|
||||
QString text = e.tagName();
|
||||
if ( m_viewport.pageNumber != -1 )
|
||||
text.prepend( QString::number( m_viewport.pageNumber + 1 ) + TOC_SEPARATOR );
|
||||
text.prepend( QString::number( m_viewport.pageNumber + 1 ) + PAGEITEMDELEGATE_SEPARATOR );
|
||||
setText( 0, text );
|
||||
}
|
||||
|
||||
|
@ -153,7 +103,7 @@ TOC::TOC(QWidget *parent, Okular::Document *document) : QWidget(parent), m_docum
|
|||
m_treeView->setSortingEnabled( false );
|
||||
m_treeView->setRootIsDecorated( true );
|
||||
m_treeView->setAlternatingRowColors( true );
|
||||
m_treeView->setItemDelegate( new TOCDelegate( m_treeView ) );
|
||||
m_treeView->setItemDelegate( new PageItemDelegate( m_treeView ) );
|
||||
m_treeView->header()->hide();
|
||||
m_treeView->setSelectionBehavior( QAbstractItemView::SelectRows );
|
||||
connect( m_treeView, SIGNAL( itemClicked( QTreeWidgetItem *, int ) ), this, SLOT( slotExecuted( QTreeWidgetItem * ) ) );
|
||||
|
|
Loading…
Reference in a new issue