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-02-18 22:13:02 +0000
committerStijn Buys <ingar@osirion.org>2012-02-18 22:13:02 +0000
commit698f901a6d983f3f44b07f6560b1370850483fa0 (patch)
tree405ac907b9ff4a1ea1af1320f55ac30b3545244a /src
parent89c0d325d049666a07994c1a53461b8d7bb0d887 (diff)
Added map entities, added ini file reader.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am3
-rw-r--r--src/editor.cc2
-rw-r--r--src/editorwindow.cc99
-rw-r--r--src/editorwindow.h6
-rw-r--r--src/inistream.cc261
-rw-r--r--src/inistream.h105
-rw-r--r--src/mainwindow.cc20
-rw-r--r--src/mainwindow.h6
-rw-r--r--src/mapentity.cc51
-rw-r--r--src/mapentity.h94
-rw-r--r--src/mapwidget.cc50
-rw-r--r--src/mapwidget.h16
-rw-r--r--src/sidebar.cc41
-rw-r--r--src/sidebar.h23
14 files changed, 750 insertions, 27 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index e492b45..d556a38 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,7 +5,9 @@ bin_PROGRAMS = editor
editor_SOURCES = \
editor.cc \
editorwindow.cc \
+ inistream.cc \
mainwindow.cc \
+ mapentity.cc \
mapwidget.cc \
sidebar.cc
@@ -14,6 +16,7 @@ editor_SOURCES = \
nodist_editor_SOURCES = \
moc_editorwindow.cc \
moc_mainwindow.cc \
+ moc_mapentity.cc \
moc_mapwidget.cc \
moc_sidebar.cc
diff --git a/src/editor.cc b/src/editor.cc
index 28f75a7..7b99435 100644
--- a/src/editor.cc
+++ b/src/editor.cc
@@ -1,6 +1,6 @@
/*
editor.cc
- This file is part of the Project::OSiRiON zone editor
+ This file is part of the Project::OSiRiON world editor
and is distributed under the terms and conditions of
the GNU General Public License version 2
*/
diff --git a/src/editorwindow.cc b/src/editorwindow.cc
index 6a72654..20e8403 100644
--- a/src/editorwindow.cc
+++ b/src/editorwindow.cc
@@ -1,14 +1,21 @@
/*
editorwindow.h
- This file is part of the Project::OSiRiON zone editor
+ This file is part of the Project::OSiRiON world editor
and is distributed under the terms and conditions of
the GNU General Public License version 2
*/
#include "editorwindow.h"
+#include "inistream.h"
#include "mapwidget.h"
+#include "mapentity.h"
#include "sidebar.h"
+#include <QtGui>
+#include <QFile>
+#include <QTextStream>
+#include <QDebug>
+
namespace editor
{
@@ -27,4 +34,94 @@ void EditorWindow::resizeEvent (QResizeEvent *event)
);
}
+bool EditorWindow::loadFile(const QString &filename)
+{
+ QFile file(filename);
+ if (!file.open(QFile::ReadOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("Open Zone"),
+ tr("Could not open file %1:\n%2.")
+ .arg(filename)
+ .arg(file.errorString()));
+ return false;
+ }
+
+ QTextStream textstream(&file);
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+
+ IniStream ini;
+
+ MapEntity *entity = 0;
+ bool in_entity = false;
+ float x, y, z;
+ QString str;
+
+ while (ini.getline(textstream)) {
+
+ if (ini.got_section()) {
+
+ qDebug() << "got section" << ini.section();
+
+ if (ini.got_section("zone")) {
+ in_entity = false;
+
+ } else if (ini.got_section("entity")) {
+ in_entity = true;
+
+ } else if (ini.got_section("jumpgate")) {
+ in_entity = true;
+
+ } else if (ini.got_section("jumpoint")) {
+ in_entity = true;
+
+ } else if (ini.got_section("navpoint")) {
+ in_entity = true;
+
+ } else if (ini.got_section("station")) {
+ in_entity = true;
+
+ } else if (ini.got_section("star")) {
+ in_entity = true;
+
+ } else if (ini.got_section("planet")) {
+ in_entity = true;
+ } else {
+ entity = 0;
+ in_entity = false;
+ }
+
+ if (in_entity) {
+ entity = editorwindow_mapwidget->addEntity();
+ }
+
+ } else if(ini.got_key()) {
+
+ if (in_entity) {
+ if (ini.got_key_vector3f("location" , x, y, z)) {
+ entity->set_location(x, y, z);
+ //qDebug() << "got location " << x << " " << y << " " << z;
+ }
+ } else if (ini.in_section("zone")) {
+
+ if (ini.got_key_string("name", str)) {
+ editorwindow_sidebar->setZoneName(str);
+ }
+ }
+
+ }
+ }
+
+ QApplication::restoreOverrideCursor();
+
+ //setCurrentFile(fileName);
+ //connect(document(), SIGNAL(contentsChanged()),this, SLOT(documentWasModified()));
+
+ return true;
+}
+
+bool EditorWindow::saveFile(const QString &filename)
+{
+
+
+}
+
}
diff --git a/src/editorwindow.h b/src/editorwindow.h
index 3a9d704..dc1ed6e 100644
--- a/src/editorwindow.h
+++ b/src/editorwindow.h
@@ -1,6 +1,6 @@
/*
editorwindow.h
- This file is part of the Project::OSiRiON zone editor
+ This file is part of the Project::OSiRiON world editor
and is distributed under the terms and conditions of
the GNU General Public License version 2
*/
@@ -26,6 +26,10 @@ class EditorWindow : public QWidget
public:
EditorWindow(QWidget *parent = 0);
+public slots:
+ bool loadFile(const QString &filename);
+
+ bool saveFile(const QString &filename);
protected:
virtual void resizeEvent (QResizeEvent *event);
diff --git a/src/inistream.cc b/src/inistream.cc
new file mode 100644
index 0000000..1e76ab8
--- /dev/null
+++ b/src/inistream.cc
@@ -0,0 +1,261 @@
+/*
+ inistream.cc
+ This file is part of the Project::OSiRiON world editor
+ and is distributed under the terms and conditions of
+ the GNU General Public License version 2
+*/
+
+#include "inistream.h"
+
+namespace editor
+{
+
+IniStream::IniStream()
+{
+ clear();
+}
+
+IniStream::~IniStream()
+{
+ clear();
+}
+
+void IniStream::clear() {
+ last_read_was_section = false;
+ last_read_was_key = false;
+
+ key_current.clear();
+ value_current.clear();
+ section_current.clear();
+
+ line_number = 0;
+}
+
+bool IniStream::getline(QTextStream &textstream)
+{
+ if (textstream.atEnd())
+ return false;
+
+ QString line;
+
+ last_read_was_section = false;
+ last_read_was_key = false;
+ key_current = "";
+ value_current = "";
+
+ line = textstream.readLine(1023);
+ line = line.trimmed();
+
+ if (line.size()) {
+ line_number++;
+
+ if (line[0] == '#' || line[0] == ';') {
+ // line with comment
+ } else {
+ // section header
+ if (line.size() > 2 && line.startsWith('[') && line.endsWith(']')) {
+ section_current = line;
+ section_current.remove(0, 1);
+ section_current.remove(line.size()-2, 1);
+
+ section_current = section_current.trimmed();
+ section_current.toLower();
+
+ last_read_was_section = true;
+ return true;
+ } else {
+ // key=value pair
+ int found = line.indexOf('=');
+ if (found > -1) {
+ // make lowercase and strip spaces
+ key_current = line;
+ key_current.remove(found, line.size() - found);
+ key_current = key_current.trimmed();
+ key_current.toLower();
+
+ if (key_current.size()) {
+ value_current = line;
+ value_current.remove(0, key_current.size() + 1);
+ value_current = value_current.trimmed();
+
+ last_read_was_key = true;
+ return true;
+ }
+
+ }
+ }
+ }
+ }
+
+ return true;
+}
+
+bool IniStream::got_section() const
+{
+ return last_read_was_section;
+}
+
+bool IniStream::got_section(const char *sectionlabel) const
+{
+ return (last_read_was_section && (section_current.compare(sectionlabel) == 0));
+}
+
+bool IniStream::in_section(const char *sectionlabel) const
+{
+ return ((section_current.compare(sectionlabel) == 0));
+}
+
+bool IniStream::got_key(const char *keylabel)
+{
+ return (last_read_was_key && (key_current.compare(keylabel) == 0));
+}
+
+bool IniStream::got_key() const
+{
+ return last_read_was_key;
+}
+
+
+bool IniStream::got_key_string(const char *keylabel, QString &valuestring)
+{
+ if (last_read_was_key && (key_current.compare(keylabel) == 0)) {
+ valuestring = value_current;
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool IniStream::got_key_vector3f(const char *keylabel, float &x, float &y, float &z)
+{
+ if (last_read_was_key && (key_current.compare(keylabel) == 0)) {
+ QTextStream ts(&value_current, QIODevice::ReadOnly);
+ x = y = z = 0;
+ ts >> x;
+ ts >> y;
+ ts >> z;
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/*
+bool IniStream::got_key_label(const char * keylabel, QString & labelstring)
+{
+ if (last_read_was_key && (key_current.compare(keylabel) == 0)) {
+ labelstring = value_current.trimmed();
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool IniStream::got_key_float(const char * keylabel, float & f)
+{
+ if (last_read_was_key && (key_current.compare(keylabel) == 0)) {
+ std::istringstream is(value_current);
+ if (!(is >> f)) {
+ f = 0;
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool IniStream::got_key_long(const char * keylabel, long & l)
+{
+ if (last_read_was_key && (key_current.compare(keylabel) == 0)) {
+ std::istringstream is(value_current);
+ if (!(is >> l)) {
+ l = 0;
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool IniStream::got_key_angle(const char *keylabel, float &f)
+{
+ if (last_read_was_key && (key_current.compare(keylabel) == 0)) {
+ std::istringstream is(value_current);
+ if ((is >> f)) {
+ f = math::degrees360f(f);
+ } else {
+ f = 0;
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool IniStream::got_key_color(const char *keylabel, QColor & color)
+{
+ if (last_read_was_key && (key_current.compare(keylabel) == 0)) {
+ std::istringstream is(value_current);
+ float r, g, b, a;
+ if ((is >> r) && (is >> g) && (is >> b)) {
+ if ((r > 1.0f) || (g > 1.0f) || (b > 1.0f)) {
+ if (is >> a) {
+ a /= 255.0f;
+ }
+ r /= 255.0f;
+ g /= 255.0f;
+ b /= 255.0f;
+ } else {
+ if (!(is >> a)) {
+ a = 1.0f;
+ }
+ }
+ color = QColor(r, g, b, a);
+ } else {
+ color = QColor();
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool IniStream::got_key_bool(const char *keylabel, bool & b)
+{
+ if (last_read_was_key && (key_current.compare(keylabel) == 0)) {
+ std::istringstream is(value_current);
+
+ unsigned int i;
+ if (is >> i) {
+ if (i > 0 ) {
+ b = true;
+ } else {
+ b = false;
+ }
+ return true;
+ }
+
+ QString val(value_current);
+ aux::trim(val);
+ aux::lowercase(val);
+
+ if (val.compare("yes") == 0) {
+ b = true;
+ return true;
+ } else if (val.compare("true") == 0) {
+ b = true;
+ return true;
+ } else if (val.compare("no") == 0) {
+ b = false;
+ return true;
+ } else if (val.compare("false") == 0) {
+ b = false;
+ return true;
+ }
+ }
+
+ return false;
+}
+*/
+
+} // namespace editor
diff --git a/src/inistream.h b/src/inistream.h
new file mode 100644
index 0000000..724c598
--- /dev/null
+++ b/src/inistream.h
@@ -0,0 +1,105 @@
+/*
+ inistream.h
+ This file is part of the Project::OSiRiON world editor
+ and is distributed under the terms and conditions of
+ the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_EDITOR_INISTREAM__
+#define __INCLUDED_EDITOR_INISTREAM__
+
+#include <QColor>
+#include <QString>
+#include <QTextStream>
+
+namespace editor
+{
+
+/// a class to read ini streams
+/**
+ * The IniStream class is able to decode the structure of a windows-like
+ * .ini file from a text stream.
+ **/
+class IniStream
+{
+public:
+ IniStream();
+
+ ~IniStream();
+
+ /// parse one line, returns false on end-of-file
+ bool getline(QTextStream &textstream);
+
+ /// current section label
+ inline QString section() const {
+ return section_current;
+ }
+
+ /// current key
+ inline QString key() const {
+ return key_current;
+ }
+
+ /// current value
+ inline QString value() const {
+ return value_current;
+ }
+
+ /// current line number
+ inline unsigned int line() const {
+ return line_number;
+ }
+
+ /// true if the last read statement was a section header
+ bool got_section() const;
+
+ /// true if the current section matches
+ bool in_section(const char *sectionlabel) const;
+
+ /// true if the last read statement was a certain section header
+ bool got_section(const char * sectionlabel) const;
+
+ /// true if the last read statement was a key=value pair
+ bool got_key() const;
+
+ bool got_key(const char * keylabel);
+
+ /// check if the last read key=value pair matches keylabel and store the value in valuestring
+ bool got_key_string(const char * keylabel, QString & valuestring);
+
+ /// check if the last read key=value pair matches keylabel and store the value in x y and z
+ bool got_key_vector3f(const char *keylabel, float &x, float &y, float &z);
+
+ /*
+ /// check if the last read key=value pair matches keylabel and store the value in valuestring, converted to label
+ bool got_key_label(const char * keylabel, QString & labelstring);
+
+ bool got_key_color(const char * keylabel, QColor & color);
+
+ bool got_key_float(const char * keylabel, float & f);
+
+ bool got_key_angle(const char * keylabel, float & f);
+
+ bool got_key_long(const char * keylabel, long & l);
+
+ bool got_key_vector3f(const char * keylabel, math::Vector3f & v);
+
+ bool got_key_bool(const char * keylabel, bool & b);
+ */
+
+ void clear();
+
+private:
+ QString section_current;
+ QString key_current;
+ QString value_current;
+
+ bool last_read_was_key;
+ bool last_read_was_section;
+
+ unsigned int line_number;
+};
+
+} // namespace editor
+
+#endif // __INCLUDED_EDITOR_INISTREAM__
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index 5dbc226..f80f0ab 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -1,6 +1,6 @@
/*
mainwindow.cc
- This file is part of the Project::OSiRiON zone editor
+ This file is part of the Project::OSiRiON world editor
and is distributed under the terms and conditions of
the GNU General Public License version 2
*/
@@ -18,7 +18,7 @@ namespace editor
MainWindow::MainWindow()
{
// set window title
- setWindowTitle(tr("Project::OSiRiON zone editor"));
+ setWindowTitle(tr("Project::OSiRiON world editor"));
// initialize MDI (multiple document interface) area
mainwindow_mdiarea = new QMdiArea();
@@ -66,29 +66,35 @@ void MainWindow::init_menu()
mainwindow_editmenu = menuBar()->addMenu(tr("&Edit"));
}
-void MainWindow::add_child()
+EditorWindow *MainWindow::addEditorWindow()
{
// create a child widget
EditorWindow *child_widget = new EditorWindow();
// add the widget to the MDI area,
// this will wrap an QMdiSubWindow around it
- mainwindow_mdiarea->addSubWindow(child_widget);
+ QMdiSubWindow *subwindow = mainwindow_mdiarea->addSubWindow(child_widget);
child_widget->show();
+
+ // FIXME check if maximized
+ subwindow->resize(768, 512);
+
+ return child_widget;
}
void MainWindow::slot_new()
{
- add_child();
+ addEditorWindow();
}
void MainWindow::slot_open()
{
- QString filename = QFileDialog::getOpenFileName(this);
+ QString filename = QFileDialog::getOpenFileName(this, tr("Open file"));
if (!filename.isEmpty()) {
- add_child();
+ EditorWindow *editorwindow = addEditorWindow();
+ editorwindow->loadFile(filename);
}
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index d2b385a..82a14db 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -18,7 +18,9 @@ class QMdiArea;
namespace editor
{
-
+
+class EditorWindow;
+
class MainWindow : public QMainWindow
{
Q_OBJECT
@@ -34,7 +36,7 @@ private:
void init_actions();
void init_menu();
- void add_child();
+ EditorWindow *addEditorWindow();
QMdiArea *mainwindow_mdiarea;
QMenu *mainwindow_filemenu;
diff --git a/src/mapentity.cc b/src/mapentity.cc
new file mode 100644
index 0000000..516b0b6
--- /dev/null
+++ b/src/mapentity.cc
@@ -0,0 +1,51 @@
+/*
+ mapentity.cc
+ This file is part of the Project::OSiRiON world editor
+ and is distributed under the terms and conditions of
+ the GNU General Public License version 2
+*/
+
+#include <mapentity.h>
+
+#include <QPainter>
+
+namespace editor
+{
+
+MapEntity::MapEntity(QWidget *parent) : QWidget(parent)
+{
+}
+
+void MapEntity::set_label(const QString &label)
+{
+ entity_label = label;
+}
+
+void MapEntity::set_name(const QString &name)
+{
+ entity_name = name;
+}
+
+void MapEntity::set_radius(const float radius)
+{
+ entity_radius = radius;
+
+}
+
+void MapEntity::set_location(const float x, const float y, const float z)
+{
+ entity_location[0] = x;
+ entity_location[1] = y;
+ entity_location[2] = z;
+}
+
+void MapEntity::paintEvent(QPaintEvent *event)
+{
+ QPen pen(Qt::black, 1, Qt::SolidLine);
+ QPainter painter(this);
+
+ painter.setPen(pen);
+ painter.drawRect(0, 0, width() - 1 , height() - 1);
+}
+
+}
diff --git a/src/mapentity.h b/src/mapentity.h
new file mode 100644
index 0000000..788e02d
--- /dev/null
+++ b/src/mapentity.h
@@ -0,0 +1,94 @@
+/*
+ mapentity.h
+ This file is part of the Project::OSiRiON world editor
+ and is distributed under the terms and conditions of
+ the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_EDITOR_MAPENTITY__
+#define __INCLUDED_EDITOR_MAPENTITY__
+
+#include <QWidget>
+#include <QList>
+#include <QString>
+
+namespace editor
+{
+
+/**
+ * @brief MapEntity is an entity on the map
+ * */
+class MapEntity : public QWidget
+{
+ Q_OBJECT
+
+public:
+ MapEntity(QWidget *parent = 0);
+
+ /**
+ * @brief returns the entity label
+ * */
+ inline const QString &label() const {
+ return entity_label;
+ }
+
+ /**
+ * @brief returns the entity name
+ * */
+ inline const QString &name() const {
+ return entity_name;
+ }
+
+ /**
+ * @brief returns the entity radius
+ * */
+ inline const float radius() const {
+ return entity_radius;
+ }
+
+ /**
+ * @brief returns the x, y, or z coordinate of the entity location
+ * */
+ inline const float location(int index) const {
+ return entity_location[index];
+ }
+
+public slots:
+
+ /**
+ * @brief set the entity name
+ * */
+ void set_label(const QString &label);
+
+ /**
+ * @brief set the entity label
+ * */
+ void set_name(const QString &name);
+
+ /**
+ * @brief set the entity radius
+ * */
+ void set_radius(const float radius);
+
+ /**
+ * @brief set the entity location
+ * */
+ void set_location(const float x, const float y, const float z);
+
+protected:
+ virtual void paintEvent(QPaintEvent *event);
+
+private:
+ QString entity_label;
+ QString entity_name;
+ QString entity_type;
+
+ float entity_location[3];
+ float entity_radius;
+
+ QColor entity_color;
+};
+
+}
+
+#endif // __INCLUDED_EDITOR_MAPENTITY__ \ No newline at end of file
diff --git a/src/mapwidget.cc b/src/mapwidget.cc
index 0eb745f..32ec3a0 100644
--- a/src/mapwidget.cc
+++ b/src/mapwidget.cc
@@ -1,21 +1,23 @@
/*
mapwidget.cc
- This file is part of the Project::OSiRiON zone editor
+ This file is part of the Project::OSiRiON world editor
and is distributed under the terms and conditions of
the GNU General Public License version 2
*/
-#include <mapwidget.h>
+#include "mapwidget.h"
+#include "mapentity.h"
#include <QPainter>
#include <QWheelEvent>
+#include <QDebug>
namespace editor
{
MapWidget::MapWidget(QWidget *parent) : QWidget(parent)
{
- setMinimumSize(256,256);
+ //setMinimumSize(256,256);
// zoom sucks but it works
mapwidget_zoom = 16;
@@ -30,11 +32,34 @@ void MapWidget::wheelEvent(QWheelEvent *event)
else if (mapwidget_zoom > 64) {
mapwidget_zoom = 64;
}
- repaint();
- event->accept();
+
+ resizeChildren();
+ update();
+ event->accept();
}
}
+void MapWidget::resizeChildren()
+{
+ const float scale = (float) width() / (float) (mapwidget_zoom * 256);
+
+ for (int i = 0; i < mapwidget_enties.size(); ++i) {
+ MapEntity * entity = mapwidget_enties.at(i);
+ int iconsize = 12;
+ int x = width() / 2 + (int) (entity->location(0) * scale) - iconsize /2;
+ int y = height() / 2 + (int)(entity->location(1) * scale) - iconsize /2;
+
+ entity->setGeometry(x, y, iconsize, iconsize);
+ //qDebug() << "Moving entity to " << x << " " << y;
+ }
+
+}
+
+void MapWidget::resizeEvent (QResizeEvent *event)
+{
+ resizeChildren();
+}
+
void MapWidget::paintEvent(QPaintEvent *event)
{
QPen pen(Qt::blue, 1, Qt::SolidLine);
@@ -68,6 +93,21 @@ void MapWidget::paintEvent(QPaintEvent *event)
painter.drawLine(0, y, width(), y);
y += gridsize;
}
+
+ QWidget::paintEvent(event);
+}
+
+MapEntity *MapWidget::addEntity()
+{
+ MapEntity *mapentity = new MapEntity(this);
+ mapwidget_enties.append(mapentity);
+
+ mapentity->show();
+
+ resizeChildren();
+ update();
+
+ return mapentity;
}
}
diff --git a/src/mapwidget.h b/src/mapwidget.h
index 532ddc0..f698a1c 100644
--- a/src/mapwidget.h
+++ b/src/mapwidget.h
@@ -1,6 +1,6 @@
/*
mapwidget.h
- This file is part of the Project::OSiRiON zone editor
+ This file is part of the Project::OSiRiON world editor
and is distributed under the terms and conditions of
the GNU General Public License version 2
*/
@@ -9,10 +9,13 @@
#define __INCLUDED_EDITOR_MAPWIDGET__
#include <QWidget>
+#include <QList>
namespace editor
{
+class MapEntity;
+
/**
* @brief MapWidget shows the zone map with the blue grid line
* */
@@ -22,14 +25,23 @@ class MapWidget : public QWidget
public:
MapWidget(QWidget *parent = 0);
+
+ /**
+ * @brief add an entity to the map
+ * */
+ MapEntity *addEntity();
protected:
-
+ virtual void resizeEvent (QResizeEvent *event);
virtual void paintEvent(QPaintEvent *event);
virtual void wheelEvent(QWheelEvent *event);
private:
+ void resizeChildren();
+
int mapwidget_zoom;
+
+ QList<MapEntity *> mapwidget_enties;
};
}
diff --git a/src/sidebar.cc b/src/sidebar.cc
index 9dfa682..0a99fd8 100644
--- a/src/sidebar.cc
+++ b/src/sidebar.cc
@@ -1,6 +1,6 @@
/*
sidebar.h
- This file is part of the Project::OSiRiON zone editor
+ This file is part of the Project::OSiRiON world editor
and is distributed under the terms and conditions of
the GNU General Public License version 2
*/
@@ -10,32 +10,65 @@
#include <QLineEdit>
#include "sidebar.h"
+#include "mapentity.h"
namespace editor
{
SideBar::SideBar(QWidget *parent) : QWidget(parent)
{
+ // zone name
+ label_zone = new QLabel(tr("Zone Name"));
+ label_zone->setAlignment(Qt::AlignHCenter);
+
// entity label
QHBoxLayout *box_entitylabel = new QHBoxLayout();
QLabel *label_entitylabel = new QLabel(tr("label"));
- QLineEdit *edit_entitylabel = new QLineEdit(tr("entity_label"));
+
+ edit_entitylabel = new QLineEdit(tr("entity_label"));
box_entitylabel->addWidget(label_entitylabel);
box_entitylabel->addWidget(edit_entitylabel);
// entity name
QHBoxLayout *box_entityname = new QHBoxLayout();
QLabel *label_entityname = new QLabel(tr("name"));
- QLineEdit *edit_entityname = new QLineEdit(tr("Entity Name"));
+
+ edit_entityname = new QLineEdit(tr("Entity Name"));
box_entityname->addWidget(label_entityname);
box_entityname->addWidget(edit_entityname);
// global vertical layout
QVBoxLayout *box_global = new QVBoxLayout();
+
+ box_global->addWidget(label_zone);
+ box_global->addSpacing(8);
box_global->addLayout(box_entitylabel);
box_global->addLayout(box_entityname);
+ box_global->addStretch(1);
- setLayout(box_global);
+ setLayout(box_global);
+}
+
+void SideBar::setEntity(MapEntity *entity)
+{
+ if (entity) {
+ edit_entitylabel->setEnabled(false);
+ edit_entitylabel->clear();
+
+ edit_entityname->setEnabled(false);
+ edit_entityname->clear();
+ } else {
+ edit_entitylabel->setEnabled(true);
+ edit_entitylabel->setText(entity->label());
+
+ edit_entityname->setEnabled(true);
+ edit_entityname->setText(entity->name());
+ }
+}
+
+void SideBar::setZoneName(const QString &name)
+{
+ label_zone->setText(name);
}
} \ No newline at end of file
diff --git a/src/sidebar.h b/src/sidebar.h
index c7dbb5a..9117a84 100644
--- a/src/sidebar.h
+++ b/src/sidebar.h
@@ -1,6 +1,6 @@
/*
sidebar.h
- This file is part of the Project::OSiRiON zone editor
+ This file is part of the Project::OSiRiON world editor
and is distributed under the terms and conditions of
the GNU General Public License version 2
*/
@@ -10,13 +10,18 @@
#include <QWidget>
+class QLabel;
+class QLineEdit;
+
namespace editor
{
-
+
+class MapEntity;
+
/**
* @brief Sidebar is the EditorWindow sidebar
* The sidebar show the properties of the currently
- * selected entity
+ * selected map entity
* */
class SideBar : public QWidget
{
@@ -24,8 +29,18 @@ class SideBar : public QWidget
public:
SideBar(QWidget *parent = 0);
+
+public slots:
+ void setEntity(MapEntity *entity);
+
+ void setZoneName(const QString &name);
+
+private:
+ QLabel *label_zone;
+ QLineEdit *edit_entitylabel;
+ QLineEdit *edit_entityname;
};
}
-#endif // __INCLUDED_EDITOR_SIDEBAR__ \ No newline at end of file
+#endif // __INCLUDED_EDITOR_SIDEBAR__