From 08b5b5fc82cae92bc167cf372412c7960bb0bfcc Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sat, 7 Feb 2009 16:14:44 +0000 Subject: [PATCH] Properly keep the vertical position on horizontal resize. BUG: 183475 svn path=/trunk/KDE/kdegraphics/okular/; revision=922822 --- ui/thumbnaillist.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ui/thumbnaillist.cpp b/ui/thumbnaillist.cpp index b32ef41b6..35fe76eed 100644 --- a/ui/thumbnaillist.cpp +++ b/ui/thumbnaillist.cpp @@ -526,14 +526,15 @@ void ThumbnailListPrivate::viewportResizeEvent( QResizeEvent * e ) // update scrollview's contents size (sets scrollbars limits) newHeight -= KDialog::spacingHint(); + const int oldHeight = q->widget()->height(); + const int oldYCenter = q->verticalScrollBar()->value() + q->viewport()->height() / 2; q->widget()->resize( newWidth, newHeight ); // enable scrollbar when there's something to scroll q->verticalScrollBar()->setEnabled( q->viewport()->height() < newHeight ); - // ensure selected item remains visible - if ( m_selected ) - q->ensureVisible( 0, m_selected->pos().y() + m_selected->height() / 2, 0, q->viewport()->height() / 2 ); + // ensure that what was visibile before remains visible now + q->ensureVisible( 0, int( (qreal)oldYCenter * q->widget()->height() / oldHeight ), 0, q->viewport()->height() / 2 ); } else if ( e->size().height() <= e->oldSize().height() ) return;