diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/entityproperties.cc | 4 | ||||
-rw-r--r-- | src/entitywidget.cc | 14 | ||||
-rw-r--r-- | src/entitywidget.h | 10 | ||||
-rw-r--r-- | src/mainwindow.cc | 4 | ||||
-rw-r--r-- | src/mapwidget.cc | 19 |
5 files changed, 50 insertions, 1 deletions
diff --git a/src/entityproperties.cc b/src/entityproperties.cc index 08c5088..9efae42 100644 --- a/src/entityproperties.cc +++ b/src/entityproperties.cc @@ -30,6 +30,8 @@ EntityProperties::~EntityProperties() void EntityProperties::assign(const EntityProperties & other) { + Properties::assign(other); + properties_radius = other.properties_radius; properties_subsections = other.properties_subsections; @@ -38,7 +40,7 @@ void EntityProperties::assign(const EntityProperties & other) properties_angles = other.properties_angles; properties_template_type = other.properties_template_type; - properties_template_type = other.properties_template_type; + properties_template_label = other.properties_template_label; } void EntityProperties::add_subsection_header(const QString &header, const QString &comment) diff --git a/src/entitywidget.cc b/src/entitywidget.cc index b589063..6878b28 100644 --- a/src/entitywidget.cc +++ b/src/entitywidget.cc @@ -22,12 +22,26 @@ EntityWidget::EntityWidget(QWidget *parent) : QWidget(parent) is_dragging = false; } +EntityWidget::EntityWidget(EntityWidget &entity_widget, QWidget *parent) : QWidget(parent) +{ + is_selected = false; + is_dragging = false; + + assign(entity_widget); +} + void EntityWidget::set_selected(const bool selected) { is_selected = selected; update(); } +void EntityWidget::assign(EntityWidget &other) +{ + EntityProperties properties = *(other.properties()); + entitywidget_entityproperties.assign(properties); +} + void EntityWidget::paintEvent(QPaintEvent *event) { QPen pen(Qt::black, 1, Qt::SolidLine); diff --git a/src/entitywidget.h b/src/entitywidget.h index 2eb1a42..e284650 100644 --- a/src/entitywidget.h +++ b/src/entitywidget.h @@ -28,6 +28,11 @@ public: EntityWidget(QWidget *parent = 0); /** + * @brief copy another EntityWidget + * */ + EntityWidget(EntityWidget &entity_widget, QWidget *parent = 0); + + /** * @brief returns the entity propertie * */ inline EntityProperties *properties() { @@ -38,6 +43,11 @@ public: return is_selected; } + /** + * @brief assignment operator + * */ + void assign(EntityWidget &other); + signals: /** * @brief this signal is emitted if the entity is clicked with the left mouse button diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 0a39b0a..4a0f84a 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -70,9 +70,13 @@ void MainWindow::initActions() // Edit -> Add action_add = new QAction(tr("&Add"), this); connect(action_add, SIGNAL(triggered()), this, SLOT(slot_add())); + action_delete = new QAction(tr("&Delete"), this); + action_delete->setShortcuts(QKeySequence::Delete); connect(action_delete, SIGNAL(triggered()), this, SLOT(slot_delete())); + action_duplicate = new QAction(tr("D&uplicate"), this); + action_duplicate->setShortcut(QKeySequence(Qt::Key_Space)); connect(action_duplicate, SIGNAL(triggered()), this, SLOT(slot_duplicate())); } diff --git a/src/mapwidget.cc b/src/mapwidget.cc index 2ce1def..d960c0a 100644 --- a/src/mapwidget.cc +++ b/src/mapwidget.cc @@ -290,15 +290,34 @@ EntityWidget *MapWidget::addEntity() void MapWidget::duplicateSelected() { + std::vector<EntityWidget *> new_widgets; + for (int i = 0; i < mapwidget_enties.size(); ++i) { EntityWidget *entitywidget = mapwidget_enties.at(i); if (entitywidget->selected()) { // duplicate the child widget + EntityWidget *new_entitywidget = addEntity(); + new_widgets.push_back(new_entitywidget); + new_entitywidget->assign(*entitywidget); + + // offset the new widget's position + const int offset = 32; + Vector3f location = new_entitywidget->properties()->location(); + new_entitywidget->properties()->set_location(location.x() + offset, location.y() - offset, location.z()); + // deselect the old widgets + entitywidget->set_selected(false); } else { } } + + // select the new widgets + for(int i = 0; i < new_widgets.size(); ++i) + new_widgets.at(i)->set_selected(true); + + resizeChildren(); + update(); } void MapWidget::deleteSelected() |