Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 0a17e63e09ba48d76eb5983814a12211b296ff0b (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
   mapentity.cc
   This file is part of the Project::OSiRiON world editor 
   and is distributed under the terms and conditions of 
   the GNU General Public License version 2
*/

#include <mapentity.h>

#include <QPainter>
#include <QMouseEvent>
#include <QDebug>

namespace editor
{

MapEntity::MapEntity(QWidget *parent) : QWidget(parent)
{
	is_selected = false;
	
	entity_radius = 0;
}

void MapEntity::set_selected(const bool selected)
{
	is_selected = selected;
	update();
}

void MapEntity::set_label(const QString &label)
{
	entity_label = label;
}

void MapEntity::set_name(const QString &name)
{
	entity_name = name;
}

void MapEntity::set_radius(const float radius)
{
	entity_radius = radius;
	
}

void MapEntity::set_location(const float x, const float y, const float z)
{
	entity_location[0] = x;
	entity_location[1] = y;
	entity_location[2] = z;
}

void MapEntity::set_properties(const QString &properties)
{
	entity_properties = properties;
}
void MapEntity::add_property(const QString &key, const QString &value)
{
	if (entity_properties.size()) {
		entity_properties += '\n';
	}
	entity_properties += key;
	entity_properties += '=';
	entity_properties += value;
}

void MapEntity::paintEvent(QPaintEvent *event)
{	
	QPen pen(Qt::black, 1, Qt::SolidLine);
	QPainter painter(this);
	
	if (is_selected) {
		pen.setColor(Qt::red);
		painter.setPen(pen);
	}
	
	painter.setPen(pen);
	painter.drawEllipse(0, 0, width() - 1 , height() - 1);
}

void MapEntity::mousePressEvent(QMouseEvent *event)
{
	if (event->button() == Qt::LeftButton) {
		//qDebug() << "clicked entity " << name();
		event->accept();
		
		emit clicked(this);
	}
}

}