23 #include <Qt3Support/Q3Header>
24 #include <QtGui/QKeyEvent>
25 #include <QtCore/QTimer>
26 #include <QtCore/QDir>
27 #include <QtGui/QApplication>
42 m_wantOpenFolderPixmaps( true )
47 m_animationTimer =
new QTimer(
this );
48 connect( m_animationTimer, SIGNAL(
timeout()),
49 this, SLOT(slotAnimation()) );
51 m_currentBeforeDropItem = 0;
54 m_autoOpenTimer =
new QTimer(
this );
55 connect( m_autoOpenTimer, SIGNAL(
timeout()),
56 this, SLOT(slotAutoOpenFolder()) );
68 connect(
this, SIGNAL(selectionChanged()),
69 this, SLOT(slotSelectionChanged()) );
77 m_branches.setAutoDelete(
true );
98 Q3ListViewItemIterator it(
this );
99 while ( it.current() )
101 if ( it.current() == item )
115 ev->acceptProposedAction();
116 m_currentBeforeDropItem = selectedItem();
122 m_autoOpenTimer->start( (QApplication::startDragTime() * 3) / 2 );
137 e->acceptProposedAction();
143 findDrop( e->pos(), parent, afterme );
148 if( item && item->isSelectable() )
150 setSelected( item,
true );
151 if( item != m_dropItem ) {
152 m_autoOpenTimer->stop();
154 m_autoOpenTimer->start( (QApplication::startDragTime() * 3) / 2 );
159 m_autoOpenTimer->stop();
167 if ( isValidItem(m_currentBeforeDropItem) )
169 setSelected( m_currentBeforeDropItem,
true );
170 ensureItemVisible( m_currentBeforeDropItem );
172 else if ( isValidItem(m_dropItem) )
173 setSelected( m_dropItem,
false );
174 m_currentBeforeDropItem = 0;
182 m_autoOpenTimer->stop();
185 kDebug(250) <<
"contentsDropEvent !";
191 e->acceptProposedAction();
194 findDrop(e->pos(), parent, afterme);
204 emit
dropped(
this, e, afterme);
205 emit
dropped(e, parent, afterme);
206 emit
dropped(
this, e, parent, afterme);
209 if ( urls.isEmpty() )
221 emit
dropped( urls, parentURL );
222 emit
dropped(
this , e, urls, parentURL );
229 bool ancestOK= acceptDrops();
243 ( e->dropAction() == Qt::CopyAction
244 || e->dropAction() == Qt::MoveAction
245 || e->dropAction() == Qt::LinkAction );
255 for (
int i = 0; i < fileList.size(); ++i)
257 urls.append( static_cast<K3FileTreeViewItem*>(fileList.at(i))->url() );
261 if( urls.count() > 1 ){
264 if( pixmap.isNull() )
266 hotspot.setX( pixmap.width() / 2 );
267 hotspot.setY( pixmap.height() / 2 );
268 #if 0 // there is no more kurldrag, this should use urls.setInMimeData( mimeData ) instead
271 dragObject->setPixmap( pixmap, hotspot );
282 kDebug(250) <<
"hit slotCollapsed";
283 if( kftvi && kftvi->
isDir())
285 item->setPixmap( 0,
itemIcon(kftvi));
291 kDebug(250) <<
"slotExpanded here !";
299 if( it->
isDir() && branch && item->childCount() == 0 )
304 bool branchAnswer = branch->
populate( it->
url(), it );
305 kDebug(250) <<
"Branches answer: " << branchAnswer;
308 kDebug(250) <<
"ERR: Could not populate!";
314 if( it->
isDir() && isOpen( item ) )
316 kDebug(250)<<
"Setting open Pixmap";
317 item->setPixmap( 0,
itemIcon( it ));
330 if( static_cast<K3FileTreeViewItem*>(item)->isDir())
332 item->setOpen( !item->isOpen() );
337 void K3FileTreeView::slotAutoOpenFolder()
339 m_autoOpenTimer->stop();
341 if ( !isValidItem(m_dropItem) || m_dropItem->isOpen() )
344 m_dropItem->setOpen(
true );
345 m_dropItem->repaint();
349 void K3FileTreeView::slotSelectionChanged()
363 return addBranch( path, name, folderPix, showHidden);
367 const QPixmap& pix,
bool showHidden )
387 m_branches.append( newBranch );
394 Q3PtrListIterator<KFileTreeBranch> it( m_branches );
396 while ( (branch = it.current()) != 0 ) {
399 kDebug(250) <<
"This is the branches name: " << bname;
400 if( bname == searchName )
402 kDebug(250) <<
"Found branch " << bname <<
" and return ptr";
411 return( m_branches );
417 if(m_branches.contains(branch))
419 delete (branch->
root());
420 m_branches.remove( branch );
440 if( it && it->
isDir())
446 if( ! branch )
return;
447 kDebug(250) <<
"hitting slotNewTreeViewItems";
461 for( ; !end && it.current(); ++it )
467 setCurrentItem( static_cast<Q3ListViewItem*>(*it) );
478 kDebug(250) <<
"Setting icon for column " << gap;
484 if( item == brnch->
root() )
487 if( m_wantOpenFolderPixmaps && brnch->
root()->isOpen() )
499 if( item->
isDir() && m_wantOpenFolderPixmaps )
501 if( isOpen( static_cast<Q3ListViewItem*>(item)))
502 pix = m_openFolderPixmap;
511 void K3FileTreeView::slotAnimation()
513 MapCurrentOpeningFolders::Iterator it = m_mapCurrentOpeningFolders.begin();
514 MapCurrentOpeningFolders::Iterator
end = m_mapCurrentOpeningFolders.end();
518 if (!isValidItem(item))
521 m_mapCurrentOpeningFolders.remove(item);
525 uint & iconNumber = it.value().iconNumber;
526 QString icon = QString::fromLatin1( it.value().iconBaseName ).append( QString::number( iconNumber ) );
531 if ( iconNumber > it.value().iconCount )
544 kDebug(250) <<
" startAnimation Got called without valid item !";
548 m_mapCurrentOpeningFolders.insert( item,
549 AnimationInfo( iconBaseName,
552 if ( !m_animationTimer->isActive() )
553 m_animationTimer->start( 50 );
560 kDebug(250) <<
"Stoping Animation !";
562 MapCurrentOpeningFolders::Iterator it = m_mapCurrentOpeningFolders.find(item);
563 if ( it != m_mapCurrentOpeningFolders.end() )
565 if( item->
isDir() && isOpen( item) )
567 kDebug(250) <<
"Setting folder open pixmap !";
568 item->setPixmap( 0,
itemIcon( item ));
572 item->setPixmap( 0, it.value().originalPixmap );
574 m_mapCurrentOpeningFolders.remove( item );
581 kDebug(250)<<
"StopAnimation - item is zero !";
583 if (m_mapCurrentOpeningFolders.isEmpty())
584 m_animationTimer->stop();
617 kDebug(250) <<
"Do not bother: " << name << col;
633 if( ! relUrl.isEmpty() && QDir::isRelativePath(relUrl) )
637 if( partUrl.endsWith(
'/'))
638 partUrl.truncate( relUrl.length()-1 );
650 kDebug(250) <<
"Found item !" <<ret;
663 return m_wantOpenFolderPixmaps;
668 m_wantOpenFolderPixmaps = showIt;
680 #include "k3filetreeview.moc"