-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.cpp
More file actions
67 lines (59 loc) · 1.6 KB
/
Copy pathmap.cpp
File metadata and controls
67 lines (59 loc) · 1.6 KB
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
#include "map.h"
Map::Map()
{
dragOver = false;
setAcceptDrops(true);
}
QRectF Map::boundingRect() const
{
return QRectF(-369, -235, 738, 470);
}
void Map::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(painter)
Q_UNUSED(option)
Q_UNUSED(widget)
}
void Map::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
if (event->mimeData()->hasText() && event->mimeData()->text() == "Shovel")
{
event->setAccepted(true);
dragOver = true;
update();
}
else
event->setAccepted(false);
}
void Map::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
Q_UNUSED(event);
dragOver = false;
update();
}
void Map::dropEvent(QGraphicsSceneDragDropEvent *event)
{
dragOver = false;
if (event->mimeData()->hasText() && event->mimeData()->text() == "Shovel")
{
QPointF pos = mapToScene(event->pos());
pos.setX((int(pos.x()) - 249) / 82 * 82 + 290);
pos.setY((int(pos.y()) - 81) / 98 * 98 + 130);
Shovel *shovel = qgraphicsitem_cast<Shovel *>(scene()->items(QPointF(830, 15))[0]);
shovel->removePlant(pos);
}
update();
}
void Map::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QPointF pos = mapToScene(event->pos());
pos.setX((int(pos.x()) - 249) / 82 * 82 + 290);
pos.setY((int(pos.y()) - 81) / 98 * 98 + 130);
Shop *shop = qgraphicsitem_cast<Shop *>(scene()->items(QPointF(300, 15))[0]);
if (shop->selectedCard != "")
{
shop->addPlant(shop->selectedCard, pos);
shop->selectedCard = "";
shop->update();
}
}