summaryrefslogtreecommitdiffstats
path: root/examples/demo/dnd/listview.cpp
blob: e97a03ea055b1ab5a501e01fe74627e6b8e3c85e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <tqdragobject.h>
#include <ntqapplication.h>
#include "listview.h"
#include "dnd.h"

ListView::ListView( TQWidget* parent, const char* name )
    : TQListView( parent, name )
{
    setAcceptDrops( TRUE );
    setSorting( -1, FALSE );
    dragging = FALSE;
}

ListView::~ListView()
{

}

void ListView::dragEnterEvent( TQDragEnterEvent *e )
{
    if ( e->provides( "text/dragdemotag" ) )
	e->accept();
}

void ListView::dropEvent( TQDropEvent *e )
{
    if ( !e->provides( "text/dragdemotag" ) )
         return;

    TQString tag;

    if ( TQTextDrag::decode( e, tag ) ) {
        IconItem item = ((DnDDemo*) parentWidget())->findItem( tag );
        TQListViewItem *after = itemAt( viewport()->mapFromParent( e->pos() ) );
        ListViewItem *litem = new ListViewItem( this, after, item.name(), tag );
        litem->setPixmap( 0, *item.pixmap() );
    }
}

void ListView::contentsMousePressEvent( TQMouseEvent *e )
{
    TQListView::contentsMousePressEvent( e );
    dragging = TRUE;
    pressPos = e->pos();
}

void ListView::contentsMouseMoveEvent( TQMouseEvent *e )
{
    TQListView::contentsMouseMoveEvent( e );

    if ( ! dragging ) return;

    if ( !currentItem() ) return;

    if ( ( pressPos - e->pos() ).manhattanLength() > TQApplication::startDragDistance() ) {
        TQTextDrag *drg = new TQTextDrag( ((ListViewItem*)currentItem())->tag(), this );

	const TQPixmap *p = ((ListViewItem*)currentItem())->pixmap( 0 );
	if (p)
	    drg->setPixmap(*p);
        drg->setSubtype( "dragdemotag" );
        drg->dragCopy();
        dragging = FALSE;
    }
}

void ListView::contentsMouseReleaseEvent( TQMouseEvent *e )
{
    TQListView::contentsMouseReleaseEvent( e );
    dragging = FALSE;
}