KDevelop API Documentation

buildtools/autotools/kfiledndiconview.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * kfiledndiconview.cpp - description 00003 * ------------------- 00004 * begin : Wed Nov 1 2000 00005 * copyright : (C) 2000 by Björn Sahlström 00006 * email : kbjorn@users.sourceforge.net 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00019 // Qt specific includes 00020 #include <qptrlist.h> 00021 #include <qapplication.h> 00023 // KDE specific includes 00024 #include <kfileitem.h> 00025 #include <kiconloader.h> 00026 #include <kdebug.h> 00028 // Application specific includes 00029 #include "kfiledndiconview.h" 00030 00031 #ifndef AUTO_OPEN_TIME 00032 #define AUTO_OPEN_TIME 00033 static int autoOpenTime = 750; 00034 #endif 00035 //----------------------------------------------- 00036 KFileDnDIconView::KFileDnDIconView( QWidget *parent, const char *name ) 00037 : KFileIconView(parent,name), m_autoOpenTimer( this ), 00038 m_autoOpenTime( autoOpenTime ), m_useAutoOpenTimer( true ), 00039 m_dropItem(0), m_dndEnabled( true ) 00040 { 00041 setDnDEnabled( true ); 00042 setAutoUpdate( true ); 00043 useAutoOpenTimer( true ); 00044 } 00045 //----------------------------------------------- 00046 KFileDnDIconView::~KFileDnDIconView(){ 00047 } 00048 //----------------------------------------------- 00049 void KFileDnDIconView::readConfig( KConfig* config, const QString& group ) { 00050 KConfigGroupSaver cs( config, group ); 00051 bool dnd = config->readBoolEntry("EnableDND", true ); 00052 setDnDEnabled( dnd ); 00053 KFileIconView::readConfig( config, group ); 00054 } 00055 //----------------------------------------------- 00056 void KFileDnDIconView::writeConfig( KConfig* config, const QString& group ) { 00057 KConfigGroupSaver cs( config, group ); 00058 config->writeEntry("EnableDND", m_dndEnabled ); 00059 KFileIconView::writeConfig( config, group ); 00060 } 00061 //----------------------------------------------- 00062 void KFileDnDIconView::slotOpenFolder(){ 00063 if( m_useAutoOpenTimer ) { 00064 m_autoOpenTimer.stop(); 00065 if( !m_dropItem ) 00066 return; 00067 } 00068 KFileItemListIterator it( * KFileView::items() ); 00069 for( ; it.current() ;++it ){ 00070 if( (*it)->name() == m_dropItem->text() ) { 00071 if( (*it)->isFile() ) 00072 return; 00073 else if( (*it)->isDir() || (*it)->isLink()) { 00074 sig->activate( (*it) ); 00075 return; 00076 } 00077 } 00078 } 00079 } 00080 //----------------------------------------------- 00081 void KFileDnDIconView::contentsDragEnterEvent( QDragEnterEvent *e ) { 00082 if ( ! acceptDrag( e ) ) { // can we decode this ? 00083 e->accept( false ); // No 00084 return; 00085 } 00086 e->acceptAction(); // Yes 00087 QIconViewItem *i = findItem( contentsToViewport( e->pos() ) ); 00088 if ( i && m_useAutoOpenTimer) { // are we over an item ? 00089 m_dropItem = i; // set new m_dropItem 00090 m_autoOpenTimer.start( m_autoOpenTime ); // restart timer 00091 } 00092 } 00093 //----------------------------------------------- 00094 void KFileDnDIconView::contentsDragMoveEvent( QDragMoveEvent *e ) { 00095 if ( ! acceptDrag( e ) ) { // can we decode this ? 00096 e->accept( false ); // No 00097 return; 00098 } 00099 e->acceptAction(); // Yes 00100 QIconViewItem *i = findItem( contentsToViewport( e->pos() ) ); 00101 if( ! m_useAutoOpenTimer ) 00102 return; 00103 if ( i ) { // are we over an item ? 00104 if ( i != m_dropItem ) { // if so, is it a new one ? 00105 m_autoOpenTimer.stop(); // stop timer 00106 m_dropItem = i; // set new m_dropItem 00107 m_autoOpenTimer.start( m_autoOpenTime ); // restart timer 00108 } 00109 } 00110 else 00111 m_autoOpenTimer.stop(); // stop timer 00112 } 00113 //----------------------------------------------- 00114 void KFileDnDIconView::contentsDragLeaveEvent( QDragLeaveEvent* ) { 00115 if( m_useAutoOpenTimer ) { 00116 m_autoOpenTimer.stop(); 00117 m_dropItem = 0L; 00118 } 00119 } 00120 //----------------------------------------------- 00121 void KFileDnDIconView::contentsDropEvent( QDropEvent* e ) { 00122 if( m_useAutoOpenTimer ) { 00123 m_autoOpenTimer.stop(); 00124 m_dropItem = 0L; 00125 } 00126 if( ! acceptDrag( e ) ) { 00127 e->acceptAction( false ); 00128 return; 00129 } 00130 e->acceptAction(); 00131 // the drop was accepted so lets emit this 00132 KURL::List urls; 00133 KURLDrag::decode( e, urls ); 00134 emit dropped( e ); 00135 } 00136 //----------------------------------------------- 00137 void KFileDnDIconView::startDrag(){ 00138 if ( ! currentItem() ) // is there any selected items ? 00139 return; // nope 00140 dragObject()->dragCopy(); // start the drag 00141 } 00142 //----------------------------------------------- 00143 QDragObject* KFileDnDIconView::dragObject() { 00144 // create a list of the URL:s that we want to drag 00145 KURL::List urls; 00146 KFileItemListIterator it( * KFileView::selectedItems() ); 00147 for ( ; it.current(); ++it ){ 00148 urls.append( (*it)->url() ); 00149 } 00150 QPixmap pixmap; 00151 if( urls.count() > 1 ) 00152 pixmap = DesktopIcon( "kmultiple", iconSize() ); 00153 if( pixmap.isNull() ) 00154 pixmap = currentFileItem()->pixmap( iconSize() ); 00155 QPoint hotspot; 00156 hotspot.setX( pixmap.width() / 2 ); 00157 hotspot.setY( pixmap.height() / 2 ); 00158 QDragObject* myDragObject = KURLDrag::newDrag( urls, widget() ); 00159 myDragObject->setPixmap( pixmap, hotspot ); 00160 return myDragObject; 00161 } 00162 //----------------------------------------------- 00163 void KFileDnDIconView::setAutoOpenTime( const int& time ){ 00164 m_autoOpenTime = time; 00165 useAutoOpenTimer(); 00166 } 00167 //----------------------------------------------- 00168 void KFileDnDIconView::useAutoOpenTimer( bool use ){ 00169 m_useAutoOpenTimer = use; 00170 if ( use ) 00171 connect( &m_autoOpenTimer, SIGNAL( timeout() ),this, SLOT( slotOpenFolder() ) ); 00172 else { 00173 disconnect( &m_autoOpenTimer, SIGNAL( timeout() ),this, SLOT( slotOpenFolder() ) ); 00174 m_dropItem = 0L; 00175 m_autoOpenTimer.stop(); 00176 } 00177 } 00178 //----------------------------------------------- 00179 void KFileDnDIconView::setDnDEnabled( bool useDnD ){ 00180 m_dndEnabled = useDnD; 00181 setAcceptDrops( useDnD ); 00182 viewport()->setAcceptDrops( useDnD ); 00183 } 00184 //----------------------------------------------- 00185 bool KFileDnDIconView::acceptDrag(QDropEvent* e ) const { 00186 return KURLDrag::canDecode( e ) && 00187 ( e->action() == QDropEvent::Copy 00188 || e->action() == QDropEvent::Move 00189 || e->action() == QDropEvent::Link ); 00190 } 00191 //----------------------------------------------- 00192 #ifndef NO_INCLUDE_MOCFILES 00193 #include "kfiledndiconview.moc" 00194 #endif
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Oct 19 08:01:36 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003