/* editorwindow.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 */ #include "editorwindow.h" #include "entitywidget.h" #include "inistream.h" #include "mapwidget.h" #include "sidebar.h" #include #include #include #include namespace editor { EditorWindow::EditorWindow(QWidget *parent) : QWidget(parent) { editorwindow_mapwidget = new MapWidget(this); editorwindow_sidebar = new SideBar(this); connect(editorwindow_mapwidget, SIGNAL(selected(EntityWidget *)), editorwindow_sidebar, SLOT(setEntity(EntityWidget *))); connect(editorwindow_sidebar, SIGNAL(entityChanged()), editorwindow_mapwidget, SLOT(resizeChildren())); } void EditorWindow::resizeEvent (QResizeEvent *event) { editorwindow_sidebar->resize(256, height()); editorwindow_mapwidget->setGeometry( editorwindow_sidebar->width(), 0, width() - editorwindow_sidebar->width(), height() ); } 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; EntityWidget *entity = 0; bool in_entity = false; float x, y, z; float f; 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) { // read entity properties into the MapWidget instance if (ini.got_key_vector3f("location" , x, y, z)) { entity->set_location(x, y, z); //qDebug() << "got location " << x << " " << y << " " << z; } else if (ini.got_key_string("label", str)) { entity->set_label(str); } else if (ini.got_key_string("name", str)) { entity->set_name(str); } else if (ini.got_key_float("radius", f)) { entity->set_radius(f); } else if (ini.got_key()) { entity->add_property(ini.key(), ini.value()); } } 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) { } }