Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/mapwidget.cc')
-rw-r--r--src/mapwidget.cc38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/mapwidget.cc b/src/mapwidget.cc
index 94bed61..a33cf65 100644
--- a/src/mapwidget.cc
+++ b/src/mapwidget.cc
@@ -9,8 +9,10 @@
#include "mapentity.h"
#include <QPainter>
+#include <QMouseEvent>
#include <QWheelEvent>
#include <QDebug>
+#include <QtGui>
namespace editor
{
@@ -21,6 +23,8 @@ MapWidget::MapWidget(QWidget *parent) : QWidget(parent)
// zoom sucks but it works
mapwidget_zoom = 16;
+
+ // center of the map (used for dragging)
}
void MapWidget::wheelEvent(QWheelEvent *event)
@@ -45,16 +49,39 @@ void MapWidget::resizeChildren()
for (int i = 0; i < mapwidget_enties.size(); ++i) {
MapEntity * entity = mapwidget_enties.at(i);
- int iconsize = 12;
- int x = width() / 2 - (int) (entity->location(1) * scale) - iconsize /2;
- int y = height() / 2 - (int)(entity->location(0) * scale) - iconsize /2;
+ int radius = (int) (entity->radius() * scale);
+ if (radius < 6)
+ radius = 6;
+
+ int x = width() / 2 - (int) (entity->location(1) * scale) - radius;
+ int y = height() / 2 - (int)(entity->location(0) * scale) - radius;
- entity->setGeometry(x, y, iconsize, iconsize);
+ entity->setGeometry(x, y, radius * 2 , radius * 2);
//qDebug() << "Moving entity to " << x << " " << y;
}
}
+void MapWidget::select(MapEntity *entity)
+{
+ for (int i = 0; i < mapwidget_enties.size(); ++i) {
+
+ MapEntity *mapentity = mapwidget_enties.at(i);
+
+ if (entity == mapentity) {
+
+ entity->set_selected(true);
+ qDebug() << "selected entity " << entity->name();
+ emit selected(entity);
+
+ } else {
+
+ mapentity->set_selected(false);
+ }
+ }
+ update();
+}
+
void MapWidget::resizeEvent (QResizeEvent *event)
{
resizeChildren();
@@ -102,6 +129,9 @@ MapEntity *MapWidget::addEntity()
MapEntity *mapentity = new MapEntity(this);
mapwidget_enties.append(mapentity);
+ // connect the MapEntity::clicked() signal to the MapWidget::selected() slot
+ connect(mapentity, SIGNAL(clicked(MapEntity *)), this, SLOT(select(MapEntity *)));
+
mapentity->show();
resizeChildren();