summaryrefslogtreecommitdiffstats
path: root/examples/demo/dnd/listview.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2011-11-08 12:31:36 -0600
committerTimothy Pearson <[email protected]>2011-11-08 12:31:36 -0600
commitd796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch)
tree6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/demo/dnd/listview.cpp
downloadtqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz
tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/demo/dnd/listview.cpp')
-rw-r--r--examples/demo/dnd/listview.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/examples/demo/dnd/listview.cpp b/examples/demo/dnd/listview.cpp
new file mode 100644
index 000000000..443bb7e50
--- /dev/null
+++ b/examples/demo/dnd/listview.cpp
@@ -0,0 +1,72 @@
+#include <qdragobject.h>
+#include <qapplication.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;
+}
+