forked from analogdevicesinc/scopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdragzone.cpp
78 lines (68 loc) · 1.63 KB
/
dragzone.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
#include "dragzone.h"
#include "ui_dragzone.h"
using namespace adiscope;
DragZone::DragZone(QWidget *parent) :
QWidget(parent),
ui(new Ui::DragZone)
{
ui->setupUi(this);
position = 8;
setAcceptDrops(true);
this->installEventFilter(this);
}
DragZone::~DragZone()
{
delete ui;
this->removeEventFilter(this);
}
void DragZone::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasFormat("menu/option")){
short from = (short)event->mimeData()->data("menu/option")[1];
if (from == position){
event->ignore();
return;
}
}
event->accept();
}
void DragZone::dragMoveEvent(QDragMoveEvent *event)
{
Q_EMIT highlightLastSeparator(true);
event->accept();
}
void DragZone::dragLeaveEvent(QDragLeaveEvent *event)
{
Q_EMIT highlightLastSeparator(false);
event->accept();
}
void DragZone::dropEvent(QDropEvent *event)
{
Q_EMIT highlightLastSeparator(false);
short from, to;
if (event->source() == this && event->possibleActions() & Qt::MoveAction){
return;
}
if (event->mimeData()->hasFormat("menu/option")){
from = (short)event->mimeData()->data("menu/option")[1];
to = (short)position;
Q_EMIT requestPositionChange(from, to, true);
}
}
int DragZone::getPosition() const
{
return position;
}
void DragZone::setPosition(int value)
{
position = value;
}
bool DragZone::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::DragEnter){
QDragEnterEvent *enterEvent = static_cast<QDragEnterEvent *>(event);
if (!enterEvent->mimeData()->hasFormat("menu/option"))
return true;
}
return QWidget::event(event);
}