diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-03-29 15:08:24 -0400 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-03-29 15:08:24 -0400 |
| commit | f78f246f76ac717d58d3aa476dc097ea330eab63 (patch) | |
| tree | ab8157079341aee6465ee625e7fa295195767c57 | |
| parent | 14cb70200abbb52e00d1d3d68258936a8fbb279b (diff) | |
Add a width and height editor to the MapEditor and also draw a bounding box for the map
| -rw-r--r-- | sigmodr/widgets/gui/mapeditor.ui | 59 | ||||
| -rw-r--r-- | sigmodr/widgets/mapeditor/MapEditor.cpp | 34 | ||||
| -rw-r--r-- | sigmodr/widgets/mapeditor/MapEditor.h | 8 |
3 files changed, 89 insertions, 12 deletions
diff --git a/sigmodr/widgets/gui/mapeditor.ui b/sigmodr/widgets/gui/mapeditor.ui index 015dea38..311c52e9 100644 --- a/sigmodr/widgets/gui/mapeditor.ui +++ b/sigmodr/widgets/gui/mapeditor.ui @@ -8,7 +8,7 @@ </sizepolicy> </property> <layout class="QGridLayout" name="gridLayout" > - <item rowspan="6" row="0" column="0" colspan="3" > + <item rowspan="8" row="0" column="0" colspan="3" > <widget class="QGraphicsView" name="varView" > <property name="toolTip" > <string/> @@ -22,6 +22,38 @@ </widget> </item> <item row="0" column="3" > + <widget class="KIntNumInput" name="varWidth" > + <property name="toolTip" > + <string/> + </property> + <property name="statusTip" > + <string/> + </property> + <property name="whatsThis" > + <string/> + </property> + <property name="minimum" > + <number>1</number> + </property> + </widget> + </item> + <item row="1" column="3" > + <widget class="KIntNumInput" name="varHeight" > + <property name="toolTip" > + <string/> + </property> + <property name="statusTip" > + <string/> + </property> + <property name="whatsThis" > + <string/> + </property> + <property name="minimum" > + <number>1</number> + </property> + </widget> + </item> + <item row="2" column="3" > <widget class="KPushButton" name="buttonAdd" > <property name="toolTip" > <string/> @@ -37,7 +69,7 @@ </property> </widget> </item> - <item row="1" column="3" > + <item row="3" column="3" > <widget class="KPushButton" name="buttonRemove" > <property name="toolTip" > <string/> @@ -53,7 +85,7 @@ </property> </widget> </item> - <item row="2" column="3" > + <item row="4" column="3" > <widget class="KPushButton" name="buttonTop" > <property name="toolTip" > <string/> @@ -66,7 +98,7 @@ </property> </widget> </item> - <item row="3" column="3" > + <item row="5" column="3" > <widget class="KPushButton" name="buttonUp" > <property name="toolTip" > <string/> @@ -79,7 +111,7 @@ </property> </widget> </item> - <item row="4" column="3" > + <item row="6" column="3" > <widget class="KPushButton" name="buttonDown" > <property name="toolTip" > <string/> @@ -92,7 +124,7 @@ </property> </widget> </item> - <item row="5" column="3" > + <item row="7" column="3" > <widget class="KPushButton" name="buttonBottom" > <property name="toolTip" > <string/> @@ -105,7 +137,7 @@ </property> </widget> </item> - <item row="6" column="0" > + <item row="8" column="0" > <widget class="QCheckBox" name="varShowEffects" > <property name="toolTip" > <string/> @@ -127,7 +159,7 @@ </property> </widget> </item> - <item row="6" column="1" > + <item row="8" column="1" > <widget class="QCheckBox" name="varShowTiles" > <property name="toolTip" > <string/> @@ -149,7 +181,7 @@ </property> </widget> </item> - <item row="6" column="2" > + <item row="8" column="2" > <widget class="QCheckBox" name="varShowTrainers" > <property name="toolTip" > <string/> @@ -171,7 +203,7 @@ </property> </widget> </item> - <item row="6" column="3" > + <item row="8" column="3" > <widget class="QCheckBox" name="varShowWarps" > <property name="toolTip" > <string/> @@ -197,6 +229,11 @@ </widget> <customwidgets> <customwidget> + <class>KIntNumInput</class> + <extends>QWidget</extends> + <header location="global" >KIntNumInput</header> + </customwidget> + <customwidget> <class>KPushButton</class> <extends>QPushButton</extends> <header location="global" >KPushButton</header> @@ -204,6 +241,8 @@ </customwidgets> <tabstops> <tabstop>varView</tabstop> + <tabstop>varWidth</tabstop> + <tabstop>varHeight</tabstop> <tabstop>buttonAdd</tabstop> <tabstop>buttonRemove</tabstop> <tabstop>buttonTop</tabstop> 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); } diff --git a/sigmodr/widgets/mapeditor/MapEditor.h b/sigmodr/widgets/mapeditor/MapEditor.h index 9d85342c..8b830e9c 100644 --- a/sigmodr/widgets/mapeditor/MapEditor.h +++ b/sigmodr/widgets/mapeditor/MapEditor.h @@ -25,8 +25,10 @@ #include <QtGui/QWidget> // Forward declarations +class QGraphicsRectItem; class QGraphicsView; class KComboBox; +class KIntNumInput; class KPushButton; namespace Sigmod { @@ -56,10 +58,16 @@ class SIGMODRWIDGETS_NO_EXPORT MapEditor : public QWidget void showWarps(const bool show); void changed(); + protected slots: + void setMapWidth(const int width); + void setMapHeight(const int height); private: Sigmod::Map* m_map; MapScene* m_scene; + QGraphicsRectItem* m_rect; + KIntNumInput* ui_width; + KIntNumInput* ui_height; QGraphicsView* ui_view; }; } |
