home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / examples / demo / dnd / listview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-12  |  1.5 KB  |  70 lines

  1. #include <iostream.h>
  2. #include <qdragobject.h>
  3. #include <qapplication.h>
  4. #include "listview.h"
  5. #include "dnd.h"
  6.  
  7. ListView::ListView( QWidget* parent, const char* name )
  8.     : QListView( parent, name )
  9. {
  10.     setAcceptDrops( TRUE );
  11.     setSorting( -1, FALSE );
  12.     dragging = FALSE;
  13. }
  14.  
  15. ListView::~ListView()
  16. {
  17.  
  18. }
  19.  
  20. void ListView::dragEnterEvent( QDragEnterEvent *e )
  21. {
  22.     if ( e->provides( "text/dragdemotag" ) )
  23.     e->accept();
  24. }
  25.  
  26. void ListView::dropEvent( QDropEvent *e )
  27. {
  28.     if ( !e->provides( "text/dragdemotag" ) )
  29.          return;
  30.  
  31.     QString tag;
  32.  
  33.     if ( QTextDrag::decode( e, tag ) ) {
  34.         IconItem item = ((DnDDemo*) parentWidget())->findItem( tag );
  35.         QListViewItem *after = itemAt( viewport()->mapFromParent( e->pos() ) );
  36.         ListViewItem *litem = new ListViewItem( this, after, item.name(), tag );
  37.         litem->setPixmap( 0, *item.pixmap() );
  38.     }
  39. }
  40.  
  41. void ListView::mousePressEvent( QMouseEvent *e )
  42. {
  43.     QListView::mousePressEvent( e );
  44.     dragging = TRUE;
  45.     pressPos = e->pos();
  46. }
  47.  
  48. void ListView::mouseMoveEvent( QMouseEvent *e )
  49. {
  50.     QListView::mouseMoveEvent( e );
  51.  
  52.     if ( ! dragging ) return;
  53.  
  54.     if ( !currentItem() ) return;
  55.  
  56.     if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) {
  57.         QTextDrag *drg = new QTextDrag( ((ListViewItem*)currentItem())->tag(), this );
  58.         drg->setSubtype( "dragdemotag" );
  59.         drg->dragCopy();
  60.         dragging = FALSE;
  61.     }
  62. }
  63.  
  64. void ListView::mouseReleaseEvent( QMouseEvent *e )
  65. {
  66.     QListView::mouseReleaseEvent( e );
  67.     dragging = FALSE;
  68. }
  69.  
  70.