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

List:       kde-commits
Subject:    kdelibs/kdeui
From:       Kévin Ottens <ervin () tuxfamily ! org>
Date:       2004-05-26 18:43:02
Message-ID: 20040526184302.06CA79079 () office ! kde ! org
[Download RAW message or body]

CVS commit by ervin: 

Spring Loading Folders (part 1)

Add the Drag'n'Hold semantic to KIconview. Now a held() signal is emited
when the user drag something hover an icon and wait for a delay.


  M +55 -0     kiconview.cpp   1.73
  M +13 -0     kiconview.h   1.43


--- kdelibs/kdeui/kiconview.cpp  #1.72:1.73
@@ -52,4 +52,5 @@ public:
         doAutoSelect = true;
         textHeight = 0;
+        dragHoldItem = 0L;
     }
     KIconView::Mode mode;
@@ -58,4 +59,6 @@ public:
     QPixmapCache maskCache;
     int textHeight;
+    QIconViewItem *dragHoldItem;
+    QTimer dragHoldTimer;
 };
 
@@ -82,4 +85,6 @@ KIconView::KIconView( QWidget *parent, c
     connect( m_pAutoSelect, SIGNAL( timeout() ),
              this, SLOT( slotAutoSelect() ) );
+
+    connect( &d->dragHoldTimer, SIGNAL(timeout()), this, SLOT(slotDragHoldTimeout()) );
 }
 
@@ -338,4 +343,54 @@ void KIconView::contentsMouseReleaseEven
 }
 
+void KIconView::contentsDragEnterEvent( QDragEnterEvent *e )
+{
+    QIconViewItem *item = findItem( e->pos() );
+
+    if ( d->dragHoldItem != item)
+    {
+        d->dragHoldItem = item;
+        if( item != 0L )
+        {
+            d->dragHoldTimer.start( 1000, true );
+        }
+        else
+        {
+            d->dragHoldTimer.stop();
+        }
+    }
+
+    QIconView::contentsDragEnterEvent( e );
+}
+
+void KIconView::contentsDragMoveEvent( QDragMoveEvent *e )
+{
+    QIconViewItem *item = findItem( e->pos() );
+
+    if ( d->dragHoldItem != item)
+    {
+        d->dragHoldItem = item;
+        if( item != 0L )
+        {
+            d->dragHoldTimer.start( 1000, true );
+        }
+        else
+        {
+            d->dragHoldTimer.stop();
+        }
+    }
+
+    QIconView::contentsDragMoveEvent( e );
+}
+
+void KIconView::slotDragHoldTimeout()
+{
+    QIconViewItem *tmp = d->dragHoldItem;
+    d->dragHoldItem = 0L;
+
+    emit held( tmp );
+}
+
+
+
 void KIconView::setFont( const QFont &font )
 {

--- kdelibs/kdeui/kiconview.h  #1.42:1.43
@@ -121,4 +121,14 @@ signals:
 
   /**
+   * This signal is emitted whenever the user hold something on an iconview
+   * during a drag'n'drop.
+   * @param item is the pointer to the iconview item the hold event occur.
+   *
+   * Note that you may not delete any QIconViewItem objects in slots
+   * connected to this signal.
+   */
+  void held( QIconViewItem *item );
+
+  /**
    * This signal gets emitted whenever the user double clicks into the
    * iconview.
@@ -153,7 +163,10 @@ protected:
   virtual void contentsMouseDoubleClickEvent ( QMouseEvent * e );
   virtual void contentsMouseReleaseEvent( QMouseEvent *e );
+  virtual void contentsDragEnterEvent( QDragEnterEvent *e );
+  virtual void contentsDragMoveEvent( QDragMoveEvent *e );
 
 private slots:
   void slotMouseButtonClicked( int btn, QIconViewItem *item, const QPoint &pos );
+  void slotDragHoldTimeout();
 
 private:


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

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