From ab508c75a92766e8b13d8a7137aa3dc03cdcf4d8 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sat, 23 Dec 2006 00:34:40 +0000 Subject: [PATCH] hopefully draw the toc item correcty, this time svn path=/trunk/playground/graphics/okular/; revision=615872 --- ui/toc.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ui/toc.cpp b/ui/toc.cpp index d506c8072..48af0e64f 100644 --- a/ui/toc.cpp +++ b/ui/toc.cpp @@ -8,12 +8,13 @@ ***************************************************************************/ // qt/kde includes +#include #include -#include #include #include #include #include +#include #include #include #include @@ -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 ); } };