From 9e5f8163f7ebf64d1d5669e947444bfb4a51fafa Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sat, 3 Nov 2007 20:48:10 +0000 Subject: [PATCH] recalc correctly the width of the sidebar when changing the icon size or toggling the text svn path=/trunk/KDE/kdegraphics/okular/; revision=732427 --- ui/sidebar.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/ui/sidebar.cpp b/ui/sidebar.cpp index 2ffb3eb78..ca07e2d65 100644 --- a/ui/sidebar.cpp +++ b/ui/sidebar.cpp @@ -296,7 +296,7 @@ public: { } - void adjustListSize( bool expand = true ); + void adjustListSize( bool recalc, bool expand = true ); SidebarListWidget *list; QSplitter *splitter; @@ -312,12 +312,23 @@ public: SidebarDelegate *sideDelegate; }; -void Sidebar::Private::adjustListSize( bool expand ) +void Sidebar::Private::adjustListSize( bool recalc, bool expand ) { QRect bottomElemRect( QPoint( 0, 0 ), list->sizeHintForIndex( list->model()->index( list->count() - 1, 0 ) ) ); + if ( recalc ) + { + int w = 0; + for ( int i = 0; i < list->count(); ++i ) + { + QSize s = list->sizeHintForIndex( list->model()->index( i, 0 ) ); + if ( s.width() > w ) + w = s.width(); + } + bottomElemRect.setWidth( w ); + } bottomElemRect.translate( 0, bottomElemRect.height() * ( list->count() - 1 ) ); itemsHeight = bottomElemRect.height() * list->count(); list->setMinimumHeight( itemsHeight + list->frameWidth() * 2 ); @@ -398,7 +409,7 @@ int Sidebar::addItem( QWidget *widget, const QIcon &icon, const QString &text ) widget->setParent( d->stack ); d->stack->addWidget( widget ); // updating the minimum height of the icon view, so all are visible with no scrolling - d->adjustListSize( true ); + d->adjustListSize( false, true ); return d->pages.count() - 1; } @@ -589,7 +600,7 @@ void Sidebar::listContextMenu( const QPoint &pos ) void Sidebar::showTextToggled( bool on ) { d->sideDelegate->setShowText( on ); - d->adjustListSize( on ); + d->adjustListSize( true, on ); d->list->reset(); d->list->update(); Okular::Settings::setSidebarShowText( on ); @@ -601,7 +612,7 @@ void Sidebar::iconSizeChanged( QAction *action ) int size = action->data().toInt(); int oldSize = d->list->iconSize().width(); d->list->setIconSize( QSize( size, size ) ); - d->adjustListSize( size > oldSize ); + d->adjustListSize( true, size > oldSize ); d->list->reset(); d->list->update(); Okular::Settings::setSidebarIconSize( size );