Patch: auto-open folder when dragging over it (KListView)

Pascal Létourneau pletourn at globetrotter.net
Fri Nov 29 06:32:22 GMT 2002


On November 28, 2002 16:34, Waldo Bastian wrote:
> On Thursday 28 November 2002 21:18, David Faure wrote:
> > A possible bug in this patch: an independent event (e.g. KDirWatch) could
> > delete the item under the mouse, and then dragOverItem would be a
> > dangling pointer... Hmm, QListView has no signal for "deleting this
> > item", and we can't rely on items being KListViewItems. Tricky.
>
> What about storing the last mouse position as well and newly looking up the
> QListViewItem when needed, comparing it with dragOverItem, and only using
> dragOverItem if it is still the same?
Good idea.
New patch attached.

Pascal Létourneau

Index: klistview.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/klistview.cpp,v
retrieving revision 1.185
diff -u -3 -p -r1.185 klistview.cpp
--- klistview.cpp       2002/08/25 01:28:12     1.185
+++ klistview.cpp       2002/11/29 06:24:48
@@ -115,6 +115,10 @@ public:
   QTimer autoSelect;
   int autoSelectDelay;

+  QTimer dragExpand;
+  QListViewItem* dragOverItem;
+  QPoint dragOverPoint;
+
   QPoint startDragPos;
   int dragDelay;

@@ -408,7 +412,9 @@ KListView::KListView( QWidget *parent, c

   connect(&d->autoSelect, SIGNAL( timeout() ),
                   this, SLOT( slotAutoSelect() ) );
-
+  connect(&d->dragExpand, SIGNAL( timeout() ),
+                  this, SLOT( slotDragExpand() ) );
+
   // context menu handling
   if (d->showContextMenusOnPress)
         {
@@ -855,7 +861,8 @@ void KListView::contentsDropEvent(QDropE
 {
   cleanDropVisualizer();
   cleanItemHighlighter();
-
+  d->dragExpand.stop();
+
   if (acceptDrag (e))
   {
     e->acceptAction();
@@ -933,6 +940,17 @@ void KListView::contentsDragMoveEvent(QD
     //Clean up the view

     findDrop(event->pos(), d->parentItemDrop, d->afterItemDrop);
+    QPoint vp = contentsToViewport( event->pos() );
+    QListViewItem *item = isExecuteArea( vp ) ? itemAt( vp ) : 0L;
+
+    if ( item != d->dragOverItem )
+    {
+      d->dragExpand.stop();
+      d->dragOverItem = item;
+      d->dragOverPoint = vp;
+      if ( d->dragOverItem && d->dragOverItem->isExpandable() && 
!d->dragOverItem->isOpen() )
+        d->dragExpand.start( QApplication::startDragTime(), true );
+    }
     if (dropVisualizer())
     {
       QRect tmpRect = drawDropVisualizer(0, d->parentItemDrop, 
d->afterItemDrop);
@@ -958,8 +976,15 @@ void KListView::contentsDragMoveEvent(QD
       event->ignore();
 }

+void KListView::slotDragExpand()
+{
+  if ( itemAt( d->dragOverPoint ) == d->dragOverItem )
+    d->dragOverItem->setOpen( true );
+}
+
 void KListView::contentsDragLeaveEvent (QDragLeaveEvent*)
 {
+  d->dragExpand.stop();
   cleanDropVisualizer();
   cleanItemHighlighter();
 }
Index: klistview.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/klistview.h,v
retrieving revision 1.92
diff -u -3 -p -r1.92 klistview.h
--- klistview.h 2002/09/28 15:16:22     1.92
+++ klistview.h 2002/11/29 06:24:50
@@ -857,6 +857,8 @@ protected slots:
    */
   void slotAutoSelect();

+  void slotDragExpand();
+
   /**
    * Reacts to header changes in full width mode
    * @internal





More information about the kde-core-devel mailing list