-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathshovel.cpp
59 lines (51 loc) · 1.46 KB
/
shovel.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
#include "shovel.h"
Shovel::Shovel()
{
}
QRectF Shovel::boundingRect() const
{
return QRectF(-40, -40, 80, 80);
}
void Shovel::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
painter->drawPixmap(QRect(-40, -40, 80, 80), QPixmap(":/images/ShovelBank.png"));
painter->drawPixmap(QRect(-35, -35, 70, 70), QPixmap(":/images/Shovel.png"));
}
void Shovel::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_UNUSED(event)
setCursor(Qt::ArrowCursor);
}
void Shovel::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)).length()
< QApplication::startDragDistance())
return;
QDrag *drag = new QDrag(event->widget());
QMimeData *mime = new QMimeData;
QImage image(":/images/Shovel.png");
mime->setText("Shovel");
mime->setImageData(image);
drag->setMimeData(mime);
drag->setPixmap(QPixmap::fromImage(image).scaled(70, 70));
drag->setHotSpot(QPoint(35, 35));
drag->exec();
setCursor(Qt::ArrowCursor);
}
void Shovel::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Q_UNUSED(event)
setCursor(Qt::ArrowCursor);
}
void Shovel::removePlant(QPointF pos)
{
QList<QGraphicsItem *> items = scene()->items(pos);
foreach (QGraphicsItem *item, items)
if (item->type() == Plant::Type)
{
delete item;
return;
}
}