source: trunk/examples/demo/dnd/listview.cpp

Last change on this file was 160, checked in by dmik, 19 years ago

Imported table and iconview modules and a bunch of dependent examples from the official release 3.3.1 from Trolltech.

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