-
Notifications
You must be signed in to change notification settings - Fork 0
/
dancerworkarea.cpp
88 lines (80 loc) · 2.81 KB
/
dancerworkarea.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "dancerworkarea.h"
#include "multiplechoicewidget.h"
#include <QMenu>
#include <QMessageBox>
DancerWorkArea::DancerWorkArea(QWidget *parent) :
QWidget(parent)
{
this->setAcceptDrops(true);
numChildren=0;
}
void DancerWorkArea::dragEnterEvent(QDragEnterEvent *event){
/* const QMimeData *mimeData = event->mimeData();
if(mimeData->hasFormat("application/x-dcomponent")){
event->setDropAction((Qt::MoveAction));
event->accept();
}
else event->ignore();*/
event->acceptProposedAction();
}
void DancerWorkArea::dragMoveEvent(QDragMoveEvent *event){
const QMimeData *mimeData = event->mimeData();
/*if(mimeData->hasFormat("application/x-dcomponent")){
event->setDropAction((Qt::MoveAction));
event->accept();
}
else event->ignore();*/
//this enables "smooth" dragging, but need to take care of offset...
/*
if(mimeData->hasFormat("application/x-dwidget")){
int wid;
QByteArray widgetData = mimeData->data("application/x-dwidget");
QDataStream dataStream(&widgetData, QIODevice::ReadOnly);
dataStream >> wid;
emit moveWidgetRequest(event->pos(),wid);
}*/
event->acceptProposedAction();
}
void DancerWorkArea::dropEvent(QDropEvent *event){
const QMimeData *mimeData = event->mimeData();
if(mimeData->hasFormat("application/x-dcomponent")){
QString componentType;
QByteArray itemData = mimeData->data("application/x-dcomponent");
QDataStream dataStream(&itemData, QIODevice::ReadOnly);
dataStream >> componentType;
if(componentType == "Multiple Choice"){
MultipleChoiceWidget *temp = new MultipleChoiceWidget(this, numChildren);
temp->setGeometry( *(new QRect(event->pos(),temp->size())));
temp->show();
connect(temp,SIGNAL(selectedWidget(int)), this, SLOT(receiveSelectedWidget(int)));
numChildren++;
}
}
else if (mimeData->hasFormat("application/x-dwidget")) {
int wid;
QByteArray widgetData = mimeData->data("application/x-dwidget");
QDataStream dataStream(&widgetData, QIODevice::ReadOnly);
dataStream >> wid;
emit moveWidgetRequest(event->pos(),wid);
}
else event->ignore();
}
void DancerWorkArea::mousePressEvent(QMouseEvent *event){
/*
QPoint pos = event->pos();
QWidget *target = this->childAt(pos);
if(!target)
return;
*/
}
void DancerWorkArea::receiveSelectedWidget(int id) {
QMimeData* mimeData = new QMimeData;
QByteArray widgetData;
QDataStream dataStream(&widgetData, QIODevice::WriteOnly);
dataStream << id;
mimeData->setData("application/x-dwidget", widgetData);
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
//drag->exec();
drag->exec(Qt::MoveAction,Qt::MoveAction);
}