summaryrefslogtreecommitdiffstats
path: root/examples/demo/dnd/iconview.cpp
blob: c7c184edb3d31680a75fb913e7c2e49cfb5da462 (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
#include <qdragobject.h>

#include "dnd.h"
#include "iconview.h"


IconView::IconView( QWidget* parent, const char* name )
    : QIconView( parent, name )
{
    connect( this, SIGNAL(dropped(QDropEvent*, const QValueList<QIconDragItem>&)),
             SLOT(slotNewItem(QDropEvent*, const QValueList<QIconDragItem>&)));
}

IconView::~IconView()
{

}


QDragObject *IconView::dragObject()
{
    if ( !currentItem() ) return 0;

    QTextDrag * drg = new QTextDrag( ((IconViewItem*)currentItem())->tag(), this );
    drg->setSubtype("dragdemotag");
    drg->setPixmap( *currentItem()->pixmap() );

    return drg;
}

void IconView::slotNewItem( QDropEvent *e, const QValueList<QIconDragItem>& )
{
    QString tag;
    if ( !e->provides( "text/dragdemotag" ) ) return;

    if ( QTextDrag::decode( e, tag ) ) {
        IconItem item = ((DnDDemo*) parentWidget())->findItem( tag );
        IconViewItem *iitem = new IconViewItem( this, item.name(), *item.pixmap(), tag );
        iitem->setRenameEnabled( TRUE );
    }
    e->acceptAction();
}