hopefully draw the toc item correcty, this time

svn path=/trunk/playground/graphics/okular/; revision=615872
remotes/origin/KDE/4.0
Pino Toscano 19 years ago
parent e5ea578a9f
commit ab508c75a9
  1. 18
      ui/toc.cpp

@ -8,12 +8,13 @@
***************************************************************************/
// qt/kde includes
#include <qapplication.h>
#include <qdom.h>
#include <qfontmetrics.h>
#include <qheaderview.h>
#include <QItemDelegate>
#include <qlayout.h>
#include <qstringlist.h>
#include <QTextDocument>
#include <qtreewidget.h>
#include <kicon.h>
#include <klocale.h>
@ -52,16 +53,23 @@ class TOCDelegate : public QItemDelegate
return;
}
QString page = text.section( TOC_SEPARATOR, 0, 0 );
QFontMetrics fm( option.font );
int pageRectWidth = QFontMetrics( option.font ).boundingRect( page ).width();
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 );
QStyleOptionViewItem newoption( option );
QStyleOptionViewItemV2 newoption( option );
newoption.displayAlignment = ( option.displayAlignment & ~Qt::AlignHorizontal_Mask ) | Qt::AlignRight;
QItemDelegate::drawDisplay( painter, newoption, rect, page );
QItemDelegate::drawDisplay( painter, newoption, pageRect, page );
}
};

Loading…
Cancel
Save