-
Notifications
You must be signed in to change notification settings - Fork 4
/
spriteview.cpp
24 lines (22 loc) · 1.05 KB
/
spriteview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <QDrag>
#include "spriteview.h"
void SpriteView::startDrag( Qt::DropActions supportedActions )
{
QModelIndexList indexes = selectedIndexes();
if( indexes.count() > 0 ) {
QMimeData *data = model()->mimeData( indexes );
if( !data)
return;
QPixmap pixmap = QPixmap::fromImage( indexes.first().data( Qt::DecorationRole ).value<QImage>() );
QDrag *drag = new QDrag( this );
drag->setPixmap( pixmap );
drag->setMimeData( data );
drag->setHotSpot( QPoint( pixmap.width() / 2, pixmap.height() / 2) );
Qt::DropAction defaultDropAction = Qt::IgnoreAction;
if( QAbstractItemView::defaultDropAction() != Qt::IgnoreAction && ( supportedActions & QAbstractItemView::defaultDropAction() ) )
defaultDropAction = QAbstractItemView::defaultDropAction();
else if( supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove )
defaultDropAction = Qt::CopyAction;
drag->exec( supportedActions, defaultDropAction );
}
}