Patch: auto-open folder when dragging over it (KListView)
David Faure
faure at kde.org
Thu Nov 28 20:18:20 GMT 2002
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
This patch from Pascal Létourneau <pletourn at globetrotter.net>
makes KListView automatically open folders (items with children)
when dragging something onto them (and keeping the mouse button down
for QApplication::startDragTime()).
I could have sworn that QListView or KListView already did that, but
apparently not :)
(Ah, and the konq sidebar has its own timer, m_autoOpenTimer)
Question: do we want this behaviour in KListView, i.e. applied to all tree
views in KDE? I think so, but maybe I'm missing something.
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.
[Note: this patch doesn't fix konqueror's treeview yet, since
KonqBaseListViewWidget::viewportDragMoveEvent() shortcuts
KListView::contentsDragMoveEvent().]
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/28 19:44:54
@@ -115,6 +115,9 @@ public:
QTimer autoSelect;
int autoSelectDelay;
+ QTimer dragExpand;
+ QListViewItem* dragOverItem;
+
QPoint startDragPos;
int dragDelay;
@@ -408,7 +411,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 +860,8 @@ void KListView::contentsDropEvent(QDropE
{
cleanDropVisualizer();
cleanItemHighlighter();
- -
+ d->dragExpand.stop();
+
if (acceptDrag (e))
{
e->acceptAction();
@@ -933,6 +939,15 @@ void KListView::contentsDragMoveEvent(QD
//Clean up the view
findDrop(event->pos(), d->parentItemDrop, d->afterItemDrop);
+ QListViewItem *item = isExecuteArea( event->pos() ) ? itemAt(
event->pos() ) : 0L;
+
+ if ( item != d->dragOverItem )
+ {
+ d->dragExpand.stop();
+ d->dragOverItem = item;
+ 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 +973,14 @@ void KListView::contentsDragMoveEvent(QD
event->ignore();
}
+void KListView::slotDragExpand()
+{
+ 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/28 19:44:56
@@ -857,6 +857,8 @@ protected slots:
*/
void slotAutoSelect();
+ void slotDragExpand();
+
/**
* Reacts to header changes in full width mode
* @internal
- -------------------------------------------------------
- --
David FAURE, david at mandrakesoft.com, faure at kde.org
http://people.mandrakesoft.com/~david/
Contributing to: http://www.konqueror.org/, http://www.koffice.org/
Get the latest KOffice - http://download.kde.org/stable/koffice-1.2/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE95noM72KcVAmwbhARApStAKCv62jZrPWClCV8ZZQy1fio7pp4lgCdF0pI
OSZzCWbM+NQdVNHTrdi6I0M=
=hdOx
-----END PGP SIGNATURE-----
More information about the kde-core-devel
mailing list