From bd0f3345a938b35ce6a12f6150373b0955b8dd12 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 10 Jul 2011 15:24:15 -0500 Subject: Add Qt3 development HEAD version --- examples/demo/dnd/listview.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 examples/demo/dnd/listview.cpp (limited to 'examples/demo/dnd/listview.cpp') diff --git a/examples/demo/dnd/listview.cpp b/examples/demo/dnd/listview.cpp new file mode 100644 index 0000000..8c87b23 --- /dev/null +++ b/examples/demo/dnd/listview.cpp @@ -0,0 +1,72 @@ +#include +#include +#include "listview.h" +#include "dnd.h" + +ListView::ListView( QWidget* parent, const char* name ) + : QListView( parent, name ) +{ + setAcceptDrops( TRUE ); + setSorting( -1, FALSE ); + dragging = FALSE; +} + +ListView::~ListView() +{ + +} + +void ListView::dragEnterEvent( QDragEnterEvent *e ) +{ + if ( e->provides( "text/dragdemotag" ) ) + e->accept(); +} + +void ListView::dropEvent( QDropEvent *e ) +{ + if ( !e->provides( "text/dragdemotag" ) ) + return; + + QString tag; + + if ( QTextDrag::decode( e, tag ) ) { + IconItem item = ((DnDDemo*) parentWidget())->findItem( tag ); + QListViewItem *after = itemAt( viewport()->mapFromParent( e->pos() ) ); + ListViewItem *litem = new ListViewItem( this, after, item.name(), tag ); + litem->setPixmap( 0, *item.pixmap() ); + } +} + +void ListView::contentsMousePressEvent( QMouseEvent *e ) +{ + QListView::contentsMousePressEvent( e ); + dragging = TRUE; + pressPos = e->pos(); +} + +void ListView::contentsMouseMoveEvent( QMouseEvent *e ) +{ + QListView::contentsMouseMoveEvent( e ); + + if ( ! dragging ) return; + + if ( !currentItem() ) return; + + if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) { + QTextDrag *drg = new QTextDrag( ((ListViewItem*)currentItem())->tag(), this ); + + const QPixmap *p = ((ListViewItem*)currentItem())->pixmap( 0 ); + if (p) + drg->setPixmap(*p); + drg->setSubtype( "dragdemotag" ); + drg->dragCopy(); + dragging = FALSE; + } +} + +void ListView::contentsMouseReleaseEvent( QMouseEvent *e ) +{ + QListView::contentsMouseReleaseEvent( e ); + dragging = FALSE; +} + -- cgit v1.2.3