-
Notifications
You must be signed in to change notification settings - Fork 0
/
CStaticGeometryEntity.cpp
70 lines (62 loc) · 2.23 KB
/
CStaticGeometryEntity.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
#include "CStaticGeometryEntity.h"
#include <QGraphicsPixmapItem>
#include "CResource.h"
#include "Globals.h"
#include <QDebug>
const QString CStaticGeometryEntity::PROP_KEY_RESOURCE = "resource";
//----------------------------------------------------
CStaticGeometryEntity::CStaticGeometryEntity(long id, CResource* resource) :
CEntity(id), mResource(resource), mSceneItem(0)
{
QString filePath = resource->getProperty("file").toString();
qDebug() << "File path: " << filePath;
mTexturePixmap = QPixmap(Globals::getProjectPath() + "/" + filePath);
}
//----------------------------------------------------
CStaticGeometryEntity::~CStaticGeometryEntity()
{
if (mSceneItem)
delete mSceneItem;
}
//----------------------------------------------------
void CStaticGeometryEntity::addToScene(QGraphicsScene *scene)
{
// Memory management is tough here so we have to be careful. We keep a pointer to the
// PixmapItem generated when adding an element to renderView's QGraphicsView, so we make
// sure we have no duplicates when (re)adding to the scene.
if (mSceneItem)
delete mSceneItem;
mSceneItem = scene->addPixmap(mTexturePixmap);
mSceneItem->setPos(mPosition.x, mPosition.y);
}
//----------------------------------------------------
void CStaticGeometryEntity::setAngle(float angle)
{
CEntity::setAngle(angle);
mSceneItem->setRotation(angle);
}
//-----------------------------------------------------
void CStaticGeometryEntity::setPosition(const Vector2D &pos)
{
CEntity::setPosition(pos);
mSceneItem->setPos(pos.x, pos.y);
}
//-----------------------------------------------------
QVariantMap CStaticGeometryEntity::getProperties()
{
QVariantMap map = CEntity::getProperties();
map.insert(PROP_KEY_RESOURCE, mResource->getRelativeFilePath());
return map;
}
//-----------------------------------------------------
bool CStaticGeometryEntity::setProperty(const QString &key, const QVariant &value)
{
return CEntity::setProperty(key,value);
}
//-----------------------------------------------------
void CStaticGeometryEntity::setZIndex(unsigned short layer)
{
CEntity::setZIndex(layer);
mSceneItem->setZValue(layer);
}
//-----------------------------------------------------