1 | #include <qdragobject.h>
|
---|
2 | #include <qapplication.h>
|
---|
3 | #include "listview.h"
|
---|
4 | #include "dnd.h"
|
---|
5 |
|
---|
6 | ListView::ListView( QWidget* parent, const char* name )
|
---|
7 | : QListView( parent, name )
|
---|
8 | {
|
---|
9 | setAcceptDrops( TRUE );
|
---|
10 | setSorting( -1, FALSE );
|
---|
11 | dragging = FALSE;
|
---|
12 | }
|
---|
13 |
|
---|
14 | ListView::~ListView()
|
---|
15 | {
|
---|
16 |
|
---|
17 | }
|
---|
18 |
|
---|
19 | void ListView::dragEnterEvent( QDragEnterEvent *e )
|
---|
20 | {
|
---|
21 | if ( e->provides( "text/dragdemotag" ) )
|
---|
22 | e->accept();
|
---|
23 | }
|
---|
24 |
|
---|
25 | void 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 |
|
---|
40 | void ListView::contentsMousePressEvent( QMouseEvent *e )
|
---|
41 | {
|
---|
42 | QListView::contentsMousePressEvent( e );
|
---|
43 | dragging = TRUE;
|
---|
44 | pressPos = e->pos();
|
---|
45 | }
|
---|
46 |
|
---|
47 | void 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 |
|
---|
67 | void ListView::contentsMouseReleaseEvent( QMouseEvent *e )
|
---|
68 | {
|
---|
69 | QListView::contentsMouseReleaseEvent( e );
|
---|
70 | dragging = FALSE;
|
---|
71 | }
|
---|
72 |
|
---|