[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    Icons Layout and Previews
From:       Benoit Walter <b.walter () free ! fr>
Date:       2003-11-02 22:01:04
[Download RAW message or body]

Hi,

I have tried to improve the painting of thumbnails during preview generation. 
The problem of overlapped icons has been partially adressed by updating the 
iconview every 500ms (kfileivi.cc revision 1.250). This does not really solve 
the problem because the display remains ugly while generating preview during 
500ms.
With the following patch, the icon view is updated when a new thumbnail has 
been generated, but only if the update is needed (in most cases once for each 
row). Otherwise, the icon is moved. This avoids having a messy icon layout 
during generation of thumbnails.

Possible improvement:
Update the view less frequently when the generated thumbnail is not visible.

This solution is not yet perfect and it would be great if someone could try 
the patch and give some comments.

Cheers,
Benoit.

["libkonq_preview.diff" (text/x-diff)]

? add
? kfileivi.moc.loT
? libkonq_preview.diff
Index: kfileivi.cc
===================================================================
RCS file: /home/kde/kdebase/libkonq/kfileivi.cc,v
retrieving revision 1.80
diff -u -3 -p -r1.80 kfileivi.cc
--- kfileivi.cc	30 Aug 2003 16:40:14 -0000	1.80
+++ kfileivi.cc	2 Nov 2003 21:39:27 -0000
@@ -23,6 +23,7 @@
 #include "konq_operations.h"
 
 #include <qpainter.h>
+#include <qtimer.h>
 
 #include <kurldrag.h>
 #include <kiconeffect.h>
@@ -206,9 +207,57 @@ void KFileIVI::setThumbnailPixmap( const
 
     m_state = KIcon::DefaultState;
 
-    // Recalc when setting this pixmap!
+    // Look for highest icon of the current line
+    int maxHeight = 0;
+    int maxTop = 0;
+
+    if ( iconView()->itemTextPos() == QIconView::Bottom ) {
+       KFileIVI* thumb = static_cast<KFileIVI*> ( prevItem() );
+       while ( thumb && thumb->x() < x() ) {
+          int currentHeight = thumb->pixmap()->height();
+          if ( currentHeight > maxHeight ) {
+             maxHeight = currentHeight;
+             maxTop = thumb->rect().top();
+          }
+          thumb = static_cast<KFileIVI*> ( thumb->prevItem() );
+       }
+       thumb = static_cast<KFileIVI*> ( nextItem() );
+       while ( thumb && thumb->x() > x() ) {
+          int currentHeight = thumb->pixmap()->height();
+          if ( currentHeight > maxHeight ) {
+             maxHeight = currentHeight;
+             maxTop = thumb->rect().top();
+          }
+          thumb = static_cast<KFileIVI*> ( thumb->nextItem() );
+       }
+    }
+
+    else {
+       maxHeight = this->pixmap()->height();
+       maxTop = rect().top();
+    }
+
+    // If an icon of the row is higher, move and resize current item
+    bool needUpdate = false;
+    int currentHeight = pixmap.height();
+    if ( maxHeight >= currentHeight ) {
+       QRect tmpRect = rect();
+       // Center icon horizontally
+       if ( textRect().width() < pixmap.width() ) {
+          tmpRect.setLeft(
+             tmpRect.left() - ( pixmap.width() - tmpRect.width() ) / 2 );
+       }
+       tmpRect.setTop( maxTop + maxHeight - currentHeight );
+       setItemRect( tmpRect );
+    }
+    else
+       needUpdate = true;
+
     QIconViewItem::setPixmap( d->icons.pixmap( QIconSet::Large,
-			      QIconSet::Normal ), true );
+                              QIconSet::Normal ), true );
+
+    if ( needUpdate )
+       QTimer::singleShot( 1, iconView(), SLOT( arrangeItemsInGrid() ) );
 }
 
 void KFileIVI::setActive( bool active )
Index: konq_iconviewwidget.cc
===================================================================
RCS file: /home/kde/kdebase/libkonq/konq_iconviewwidget.cc,v
retrieving revision 1.266
diff -u -3 -p -r1.266 konq_iconviewwidget.cc
--- konq_iconviewwidget.cc	24 Oct 2003 20:46:48 -0000	1.266
+++ konq_iconviewwidget.cc	2 Nov 2003 21:39:33 -0000
@@ -337,7 +337,7 @@ struct KonqIconViewWidgetPrivate
         pSoundTimer = 0;
         pPreviewJob = 0;
         bAllowSetWallpaper = false;
-	gridXspacing = 50;
+        gridXspacing = 50;
 
         doAnimations = true;
         m_movie = 0L;
@@ -363,8 +363,6 @@ struct KonqIconViewWidgetPrivate
     bool bAllowSetWallpaper;
     int gridXspacing;
 
-    QTimer* rearrangeIconsTimer;
-
     // Animated icons support
     bool doAnimations;
     QMovie* m_movie;
@@ -389,7 +387,6 @@ KonqIconViewWidget::KonqIconViewWidget( 
       m_bSetGridX( !kdesktop ) /* No line breaking on the desktop */
 {
     d = new KonqIconViewWidgetPrivate;
-    d->rearrangeIconsTimer = new QTimer( this );
     connect( this, SIGNAL( dropped( QDropEvent *, const QValueList<QIconDragItem> & \
                ) ),
              this, SLOT( slotDropped( QDropEvent*, const QValueList<QIconDragItem> & \
) ) );  
@@ -402,8 +399,6 @@ KonqIconViewWidget::KonqIconViewWidget( 
     connect( this, SIGNAL(onViewport()), SLOT(slotOnViewport()) );
     connect( this, SIGNAL(itemRenamed(QIconViewItem *, const QString &)), \
SLOT(slotItemRenamed(QIconViewItem *, const QString &)) );  
-    connect( d->rearrangeIconsTimer, SIGNAL( timeout() ), SLOT( slotRearrangeIcons() \
                ) );
-
     // hardcoded settings
     setSelectionMode( QIconView::Extended );
     setItemTextPos( QIconView::Bottom );
@@ -686,7 +681,6 @@ void KonqIconViewWidget::slotPreview(con
         KFileIVI* current = static_cast<KFileIVI *>(it);
         if (current->item() == item)
         {
-            bool needsUpdate = ( !current->pixmap() || current->pixmap()->width() < \
pix.width() || current->pixmap()->height() < pix.height() );  if(item->overlays() & \
KIcon::HiddenOverlay)  {
                 QPixmap p(pix);
@@ -696,11 +690,6 @@ void KonqIconViewWidget::slotPreview(con
             } else {
                 current->setThumbnailPixmap(pix);
             }
-            if ( needsUpdate
-                    && autoArrange()
-                    && !d->rearrangeIconsTimer->isActive() ) {
-                d->rearrangeIconsTimer->start( 500, true );
-            }
         }
     }
 }
@@ -708,10 +697,6 @@ void KonqIconViewWidget::slotPreview(con
 void KonqIconViewWidget::slotPreviewResult()
 {
     d->pPreviewJob = 0;
-    if ( d->rearrangeIconsTimer->isActive() ) {
-        d->rearrangeIconsTimer->stop();
-        slotRearrangeIcons();
-    }
     emit imagePreviewFinished();
 }
 



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic