Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mapwidget.cc48
-rw-r--r--src/mapwidget.h12
2 files changed, 50 insertions, 10 deletions
diff --git a/src/mapwidget.cc b/src/mapwidget.cc
index 44ed785..581f57f 100644
--- a/src/mapwidget.cc
+++ b/src/mapwidget.cc
@@ -35,6 +35,8 @@ MapWidget::MapWidget(QWidget *parent) : QWidget(parent)
is_dragging = false;
+ mapwidget_selected = 0;
+
setFocusPolicy(Qt::ClickFocus);
}
@@ -134,6 +136,7 @@ void MapWidget::deselect()
entitywidget->set_selected(false);
}
+ mapwidget_selected = 0;
emit propertiesChanged(0);
mapwidget_manipulator->setMode(Manipulator::None);
}
@@ -158,7 +161,9 @@ void MapWidget::dragEntity(EntityWidget *entity, int x, int y)
void MapWidget::select(EntityWidget *entity)
{
+ mapwidget_selected = 0;
mapwidget_manipulator->setMode(Manipulator::None);
+
for (int i = 0; i < mapwidget_enties.size(); ++i) {
EntityWidget *entitywidget = mapwidget_enties.at(i);
@@ -171,7 +176,7 @@ void MapWidget::select(EntityWidget *entity)
mapwidget_manipulator->setMode(Manipulator::Select);
mapwidget_manipulator->setProperties(entity->properties());
mapwidget_manipulator->setSize(entity);
-
+ mapwidget_selected = entity;
} else {
entitywidget->set_selected(false);
@@ -254,6 +259,16 @@ void MapWidget::paintEvent(QPaintEvent *event)
}
}
+
+void MapWidget::save(QTextStream &textstream)
+{
+ for (int i = 0; i < mapwidget_enties.size(); ++i) {
+
+ EntityWidget *entitywidget = mapwidget_enties.at(i);
+ entitywidget->properties()->save(textstream);
+ }
+}
+
EntityWidget *MapWidget::addEntity()
{
EntityWidget *entitywidget = new EntityWidget(this);
@@ -271,23 +286,38 @@ EntityWidget *MapWidget::addEntity()
return entitywidget;
}
-void MapWidget::save(QTextStream &textstream)
+void MapWidget::duplicateSelected()
{
for (int i = 0; i < mapwidget_enties.size(); ++i) {
EntityWidget *entitywidget = mapwidget_enties.at(i);
- entitywidget->properties()->save(textstream);
+ if (entitywidget->selected()) {
+ // duplicate the child widget
+
+ } else {
+ }
}
}
-void MapWidget::duplicateSelected()
-{
-
-}
-
void MapWidget::deleteSelected()
{
-
+ Entities::iterator i = mapwidget_enties.begin();
+
+ while (i != mapwidget_enties.end()) {
+ EntityWidget *entitywidget = (*i);
+
+ if (entitywidget->selected()) {
+ // delete the child widget
+ delete entitywidget;
+ // set the pointer in the list to NULL
+ (*i) = 0;
+ // remove the actual list entry
+ i = mapwidget_enties.erase(i);
+ } else {
+ ++i;
+ }
+ }
+ deselect();
}
}
diff --git a/src/mapwidget.h b/src/mapwidget.h
index 8d09209..2dde34f 100644
--- a/src/mapwidget.h
+++ b/src/mapwidget.h
@@ -35,6 +35,13 @@ public:
EntityWidget *addEntity();
void save(QTextStream &textstream);
+
+ /**
+ * @brief return the currently selected entity
+ * */
+ inline EntityWidget *selected() {
+ return mapwidget_selected;
+ }
protected:
@@ -113,6 +120,8 @@ private slots:
void dragEntity(EntityWidget *entity, int x, int y);
private:
+ typedef QList<EntityWidget *> Entities;
+
int mapwidget_zoom;
int dragstart_x;
int dragstart_y;
@@ -122,7 +131,8 @@ private:
bool is_dragging;
- QList<EntityWidget *> mapwidget_enties;
+ Entities mapwidget_enties;
+ EntityWidget *mapwidget_selected;
Manipulator *mapwidget_manipulator;
};