summaryrefslogtreecommitdiffstats
path: root/sigmodr/widgets/mapeditor/MapEditor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sigmodr/widgets/mapeditor/MapEditor.cpp')
-rw-r--r--sigmodr/widgets/mapeditor/MapEditor.cpp34
1 files changed, 32 insertions, 2 deletions
diff --git a/sigmodr/widgets/mapeditor/MapEditor.cpp b/sigmodr/widgets/mapeditor/MapEditor.cpp
index 39bc136c..d3a7e3be 100644
--- a/sigmodr/widgets/mapeditor/MapEditor.cpp
+++ b/sigmodr/widgets/mapeditor/MapEditor.cpp
@@ -21,9 +21,13 @@
// Sigmodr widget includes
#include "MapScene.h"
+// Sigmod includes
+#include <sigmod/Map.h>
+
// KDE includes
#include <KAction>
#include <KIcon>
+#include <KIntNumInput>
#include <KMenu>
#include <KPushButton>
@@ -31,6 +35,7 @@
#include <QtCore/QFile>
#include <QtCore/QSignalMapper>
#include <QtGui/QCheckBox>
+#include <QtGui/QGraphicsRectItem>
#include <QtGui/QGraphicsView>
#include <QtGui/QVBoxLayout>
#include <QtUiTools/QUiLoader>
@@ -41,7 +46,8 @@ using namespace Sigmodr::Widgets;
MapEditor::MapEditor(Map* map, QWidget* parent) :
QWidget(parent),
m_map(map),
- m_scene(NULL)
+ m_scene(NULL),
+ m_rect(NULL)
{
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
QFile file(":/gui/mapeditor.ui");
@@ -49,7 +55,8 @@ MapEditor::MapEditor(Map* map, QWidget* parent) :
QWidget *formWidget = QUiLoader().load(&file, this);
file.close();
ui_view = formWidget->findChild<QGraphicsView*>("varView");
- reset();
+ ui_width = formWidget->findChild<KIntNumInput*>("varWidth");
+ ui_height = formWidget->findChild<KIntNumInput*>("varHeight");
KPushButton* buttonAdd = formWidget->findChild<KPushButton*>("buttonAdd");
KPushButton* buttonRemove = formWidget->findChild<KPushButton*>("buttonRemove");
KPushButton* buttonTop = formWidget->findChild<KPushButton*>("buttonTop");
@@ -66,6 +73,9 @@ MapEditor::MapEditor(Map* map, QWidget* parent) :
buttonUp->setIcon(KIcon("arrow-up"));
buttonDown->setIcon(KIcon("arrow-down"));
buttonBottom->setIcon(KIcon("arrow-down-double"));
+ connect(ui_width, SIGNAL(valueChanged(int)), this, SLOT(setMapWidth(int)));
+ connect(ui_height, SIGNAL(valueChanged(int)), this, SLOT(setMapHeight(int)));
+ reset();
connect(buttonAdd, SIGNAL(pressed()), m_scene, SLOT(addTile()));
connect(buttonRemove, SIGNAL(pressed()), m_scene, SLOT(removeSelected()));
connect(m_scene, SIGNAL(itemsSelected(bool)), buttonRemove, SLOT(setEnabled(bool)));
@@ -89,6 +99,7 @@ MapEditor::MapEditor(Map* map, QWidget* parent) :
void MapEditor::setMap(Map* map)
{
m_map = map;
+ delete m_rect;
delete m_scene;
reset();
}
@@ -96,6 +107,25 @@ void MapEditor::setMap(Map* map)
void MapEditor::reset()
{
m_scene = new MapScene(m_map, this);
+ m_rect = new QGraphicsRectItem;
connect(m_scene, SIGNAL(changed()), this, SIGNAL(changed()));
+ m_rect->setRect(0, 0, m_map->width(), m_map->height());
+ m_scene->addItem(m_rect);
ui_view->setScene(m_scene);
+ ui_width->setValue(m_map->width());
+ ui_height->setValue(m_map->height());
+}
+
+void MapEditor::setMapWidth(const int width)
+{
+ m_map->setWidth(width);
+ m_rect->setRect(0, 0, m_map->width(), m_map->height());
+ ui_view->setSceneRect(-10, -10, m_map->width() + 10, m_map->height() + 10);
+}
+
+void MapEditor::setMapHeight(const int height)
+{
+ m_map->setHeight(height);
+ m_rect->setRect(0, 0, m_map->width(), m_map->height());
+ ui_view->setSceneRect(-10, -10, m_map->width() + 10, m_map->height() + 10);
}