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

List:       kde-core-devel
Subject:    [PATCH] Highlighting thumbnails in konqueror
From:       Martijn Klingens <mklingens () yahoo ! com>
Date:       2001-07-11 22:58:08
[Download RAW message or body]

Until now thumbnail icons in Konq didn't use the icon highlighting settings. 
For the default gamma effect that is not too annoying, but on LinuxTag I saw 
the effect when 'colorize' is used instead on Rob Malda's notebook: that's 
ugly!

Attached patch should enable highlighting for thumbs as well. To do this it 
stores the thumb internally in the KFileIVI object, so the KIconEffects can 
later be applied and undone again.

Carsten told me on #kde that libkonq will have to remain BC after 2.2, so I 
added a d-pointer here instead of a local data member. This way we can at 
least extend in the future ;-)

Please review. No objections == /me committing tomorrow.

Martijn

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

? konq_iconviewwidget.hmk
Index: kfileivi.cc
===================================================================
RCS file: /home/kde/kdebase/libkonq/kfileivi.cc,v
retrieving revision 1.50
diff -b -u -p -r1.50 kfileivi.cc
--- kfileivi.cc	2001/05/26 10:03:16	1.50
+++ kfileivi.cc	2001/07/11 22:52:12
@@ -36,6 +36,8 @@
 #include <kalphapainter.h>
 #include <kimageeffect.h>
 #include <kstaticdeleter.h>
+#include <kiconeffect.h>
+
 #undef Bool
 
 static QPixmap *konqiv_buffer_pixmap = 0;
@@ -53,6 +55,15 @@ static QPixmap *get_konqiv_buffer_pixmap
     return konqiv_buffer_pixmap;
 }
 
+/**
+ * Private data for KFileIVI
+ */
+class KFileIVI_Private
+{
+public:
+    QPixmap thumbPixmap;
+};
+
 KFileIVI::KFileIVI( KonqIconViewWidget *iconview, KonqFileItem* fileitem, int size )
     : QIconViewItem( iconview, fileitem->text(),
 		     fileitem->pixmap( size, KIcon::DefaultState ) ),
@@ -60,6 +71,12 @@ KFileIVI::KFileIVI( KonqIconViewWidget *
     m_bDisabled( false ), m_bThumbnail( false ), m_fileitem( fileitem )
 {
     setDropEnabled( S_ISDIR( m_fileitem->mode() ) );
+    d = new KFileIVI_Private;
+}
+
+KFileIVI::~KFileIVI()
+{
+    delete d;
 }
 
 void KFileIVI::setIcon( int size, int state, bool recalc, bool redraw )
@@ -86,9 +103,16 @@ void KFileIVI::setDisabled( bool disable
 void KFileIVI::setThumbnailPixmap( const QPixmap & pixmap )
 {
     m_bThumbnail = true;
+    d->thumbPixmap = pixmap;
     QIconViewItem::setPixmap( pixmap, true /* recalc */ );
 }
 
+void KFileIVI::setThumbnailEffect( int group, int state )
+{
+    QIconViewItem::setPixmap( KGlobal::iconLoader()->iconEffect()->
+            apply( d->thumbPixmap, group, state ) );
+}
+
 void KFileIVI::setThumbnailName( const QString & name )
 {
     m_thumbnailName = name;
@@ -159,6 +183,16 @@ void KFileIVI::paintItem( QPainter *p, c
         f.setItalic( TRUE );
         p->setFont( f );
     }
+
+		//*** TEMPORARY CODE - MUST BE MADE CONFIGURABLE FIRST - Martijn
+		// SET UNDERLINE ON HOVER ONLY
+/*    if ( ( ( KonqIconViewWidget* ) iconView() )->m_pActiveItem == this )
+    {
+        QFont f( p->font() );
+        f.setUnderline( TRUE );
+        p->setFont( f );
+    }*/
+		//***
 
     if (!KGlobal::iconLoader()->alphaBlending(KIcon::Desktop))
     {
Index: kfileivi.h
===================================================================
RCS file: /home/kde/kdebase/libkonq/kfileivi.h,v
retrieving revision 1.31
diff -b -u -p -r1.31 kfileivi.h
--- kfileivi.h	2001/05/14 01:47:45	1.31
+++ kfileivi.h	2001/07/11 22:52:13
@@ -28,6 +28,12 @@
 class KonqIconViewWidget;
 
 /**
+ * Private data for KFileIVI
+ * Implementation in kfileivi.cc
+ */
+class KFileIVI_Private;
+
+/**
  * KFileIVI (short form of "Konq - File - IconViewItem")
  * is, as expected, an improved QIconViewItem, because
  * it represents a file.
@@ -44,7 +50,7 @@ public:
      * @param size the icon size
      */
     KFileIVI( KonqIconViewWidget *iconview, KonqFileItem* fileitem, int size );
-    virtual ~KFileIVI() { }
+    virtual ~KFileIVI();
 
     /**
      * Handler for return (or single/double click) on ONE icon.
@@ -92,6 +98,11 @@ public:
     void setThumbnailPixmap( const QPixmap & pixmap );
 
     /**
+     * Set the thumbnail to use the specified KIconEffect
+     */
+    void setThumbnailEffect( int group, int state );
+    
+    /**
      * @return true if this item is a thumbnail
      */
     bool isThumbnail() const { return m_bThumbnail; }
@@ -152,6 +163,7 @@ private:
     QString m_thumbnailName; // ### KDE 3.0 remove
     /** Pointer to the file item in KonqDirLister's list */
     KonqFileItem* m_fileitem;
+    KFileIVI_Private *d;
 };
 
 #endif
Index: konq_iconviewwidget.cc
===================================================================
RCS file: /home/kde/kdebase/libkonq/konq_iconviewwidget.cc,v
retrieving revision 1.151
diff -b -u -p -r1.151 konq_iconviewwidget.cc
--- konq_iconviewwidget.cc	2001/06/28 20:21:45	1.151
+++ konq_iconviewwidget.cc	2001/07/11 22:52:20
@@ -139,8 +139,19 @@ void KonqIconViewWidget::slotIconChanged
 void KonqIconViewWidget::slotOnItem( QIconViewItem *item )
 {
     // Reset icon of previous item
-    if (d->pActiveItem != 0L)
-        d->pActiveItem->setIcon( m_size, KIcon::DefaultState, false, true );
+    if ( d->pActiveItem != 0L && d->pActiveItem != item )
+    {
+    	KFileIVI *oldItem = d->pActiveItem;
+	d->pActiveItem = 0L;
+
+	// Changing icons does not work for thumbnails, instead force a
+	// repaint of the same thumbnail there:
+	if( oldItem->isThumbnail() )
+	    oldItem->setThumbnailEffect(
+				KIcon::Desktop, KIcon::DefaultState );
+	else
+	    oldItem->setIcon( m_size, KIcon::DefaultState, false, true );
+    }
 
     // Stop sound
     if (d->pSoundPlayer != 0 && static_cast<KFileIVI *>(item) != d->pSoundItem)
@@ -153,19 +164,51 @@ void KonqIconViewWidget::slotOnItem( QIc
     	    d->pSoundTimer->stop();
     }
 
-    if ( !m_bMousePressed &&
-         !static_cast<KFileIVI *>(item)->isThumbnail() &&
-         (KGlobal::iconLoader()->iconEffect()->fingerprint(KIcon::Desktop, \
                KIcon::DefaultState) !=
-          KGlobal::iconLoader()->iconEffect()->fingerprint(KIcon::Desktop, \
KIcon::ActiveState) ) ) +    if ( !m_bMousePressed )
+    {
+	if( KGlobal::iconLoader()->iconEffect()->
+		fingerprint( KIcon::Desktop, KIcon::DefaultState ) !=
+	    KGlobal::iconLoader()->iconEffect()->
+		fingerprint( KIcon::Desktop, KIcon::ActiveState ) )
     {
+	    if( static_cast<KFileIVI *>( item )->isThumbnail() )
+	    {
+		// Set active item in this case, because we want the effects
+		// on hover also for thumbs!
+		d->pActiveItem = static_cast<KFileIVI *>(item);
+		d->pActiveItem->setThumbnailEffect(
+					KIcon::Desktop, KIcon::ActiveState );
+	    }
+	    else
+	    {
+		// No thumb, normal icon
       d->pActiveItem = static_cast<KFileIVI *>(item);
-      d->pActiveItem->setIcon( m_size, KIcon::ActiveState, false, true );
-      //kdDebug(1203) << "desktop;defaultstate=" << \
KGlobal::iconLoader()->iconEffect()->fingerprint(KIcon::Desktop, KIcon::DefaultState) \
                << endl;
-      //kdDebug(1203) << "desktop;activestate=" << \
KGlobal::iconLoader()->iconEffect()->fingerprint(KIcon::Desktop, KIcon::ActiveState) \
                << endl;
-    } else
-      // Feature disabled during mouse clicking, e.g. rectangular selection
-      // also disabled if the item is a thumbnail
+		d->pActiveItem->setIcon( m_size, KIcon::ActiveState,
+					 false, true );
+		//kdDebug(1203) << "desktop;defaultstate=" <<
+		//      KGlobal::iconLoader()->iconEffect()->
+		//      fingerprint(KIcon::Desktop, KIcon::DefaultState) <<
+		//      endl;
+		//kdDebug(1203) << "desktop;activestate=" <<
+		//      KGlobal::iconLoader()->iconEffect()->
+		//      fingerprint(KIcon::Desktop, KIcon::ActiveState) <<
+		//      endl;
+	    }
+	}
+	else
+	{
+	    // No effect. If we want to underline on hover, we should
+	    // force the IVI to repaint here, though!
+	    d->pActiveItem = 0L;
+	}
+    }	// bMousePressed
+    else
+    {
+      // All features disabled during mouse clicking, e.g. rectangular
+      // selection
       d->pActiveItem = 0L;
+    }
+    
     if (d->bSoundPreviews && static_cast<KFileIVI \
*>(item)->item()->mimetype().startsWith("audio/"))  {
       d->pSoundItem = static_cast<KFileIVI *>(item);
@@ -204,8 +247,17 @@ void KonqIconViewWidget::slotOnViewport(
 
     if (d->pActiveItem == 0L)
         return;
-    d->pActiveItem->setIcon( m_size, KIcon::DefaultState, false, true );
+				
+    KFileIVI *oldItem = d->pActiveItem;
     d->pActiveItem = 0L;
+		
+    // Changing icons does not work for thumbnails, instead force a repaint
+    // of the same thumbnail there:
+    if( oldItem->isThumbnail() )
+	oldItem->setThumbnailEffect(
+			KIcon::Desktop, KIcon::DefaultState );
+    else
+	oldItem->setIcon( m_size, KIcon::DefaultState, false, true );
 }
 
 void KonqIconViewWidget::slotStartSoundPreview()



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

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