This repository has been archived by the owner on Oct 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dragreceiveritem.cpp
66 lines (56 loc) · 1.69 KB
/
dragreceiveritem.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
#include "dragreceiveritem.h"
#include <QPainter>
#include <QDebug>
#include <QGraphicsSceneDragDropEvent>
#include <QMimeData>
DragReceiverItem::DragReceiverItem(uint colv,uint rowv,qreal cellW,qreal cellH,Sprite *parent) :
Sprite(parent),
col(colv),
row(rowv),
cellWidth(cellW),
cellHeight(cellH)
{
setAcceptDrops(true);
this->setWidth(cellWidth * col);
this->setHeight(cellHeight * row);
for(uint i = 0; i <= col ; i++ ){
//画线 对应 col 画 y 轴 直线
vector.append(QPoint(i*cellWidth,0));
vector.append(QPoint(i*cellWidth,row*cellHeight));
}
for(uint i = 0; i <= row ; i++ ){
//画线 对应 row 画 x 轴 直线
vector.append(QPoint(0,i*cellHeight));
vector.append(QPoint(col*cellWidth,i*cellHeight));
}
}
DragReceiverItem::~DragReceiverItem()
{
}
void DragReceiverItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
//qDebug() << "drag enter evnet";
}
void DragReceiverItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
//qDebug() << "drag leave evnet";
}
void DragReceiverItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
{
}
void DragReceiverItem::dropEvent(QGraphicsSceneDragDropEvent *event)
{
/*
qDebug() << "drop event " ;
qDebug() << "pos = " << event->pos();
qDebug() << "scene pos = " << event->scenePos();
qDebug() << "screen pos = " << event->screenPos();
qDebug() << "mime data = " << event->mimeData();
*/
emit onDrop(event->scenePos(),event->mimeData());
}
void DragReceiverItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setPen(QPen(Qt::yellow));
painter->drawLines(vector);
}