Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-03-10 13:38:43 +0000
committerStijn Buys <ingar@osirion.org>2012-03-10 13:38:43 +0000
commit4add647f4c002b6d6a5e3d8dcb80467899f70abe (patch)
treefef2cb125e70f3bc95433c16f0755567ad7c4413 /src
parent1f74e66bb12d9ed9655012301fe660203d0f660e (diff)
Have MapWidget remember the last selected Entity, implemented MapWidget::deleteSelected().
Diffstat (limited to 'src')
-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;
};