From 90464fa2f288bf6b567d934ac909b9e7bcf0a468 Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Wed, 6 Jul 2011 18:52:10 +0300 Subject: [PATCH] Changed: #1301 Added dialog with a list of landscapes and operations (setActive, save, saveAs, delete). --- .../plugins/landscape_editor/builder_zone.cpp | 10 +- .../landscape_editor_window.cpp | 191 ++++++++++++++++-- .../landscape_editor_window.h | 11 + .../landscape_editor_window.ui | 81 +++++++- 4 files changed, 265 insertions(+), 28 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/builder_zone.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/builder_zone.cpp index 265e380ca..9550b1f76 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/builder_zone.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/builder_zone.cpp @@ -222,10 +222,11 @@ void ZoneBuilder::deleteZoneRegion(int id) { if ((0 <= id) && (id < int(m_landscapeItems.size()))) { + if (m_landscapeItems.at(id).rectItem != 0) + delete m_landscapeItems.at(id).rectItem; m_landscapeScene->delZoneRegion(m_landscapeItems.at(id).zoneRegionObject->ligoZoneRegion()); delete m_landscapeItems.at(id).zoneRegionObject; delete m_landscapeItems.at(id).builderZoneRegion; - delete m_landscapeItems.at(id).rectItem; m_landscapeItems.erase(m_landscapeItems.begin() + id); calcMask(); } @@ -236,10 +237,13 @@ void ZoneBuilder::setCurrentZoneRegion(int id) if ((0 <= id) && (id < int(m_landscapeItems.size()))) { if (currentIdZoneRegion() != -1) - m_landscapeItems.at(m_currentZoneRegion).rectItem = m_landscapeScene->createLayerBlackout(currentZoneRegion()->ligoZoneRegion()); - m_currentZoneRegion = id; + { + NLLIGO::CZoneRegion &ligoRegion = m_landscapeItems.at(m_currentZoneRegion).zoneRegionObject->ligoZoneRegion(); + m_landscapeItems.at(m_currentZoneRegion).rectItem = m_landscapeScene->createLayerBlackout(ligoRegion); + } delete m_landscapeItems.at(id).rectItem; m_landscapeItems.at(id).rectItem = 0; + m_currentZoneRegion = id; } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp index 5f5fad552..da949fea5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp @@ -33,15 +33,20 @@ // Qt includes #include +#include #include #include namespace LandscapeEditor { + +static const int LANDSCAPE_ID = 32; +int NewLandCounter = 0; QString _lastDir; LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent) : QMainWindow(parent), + m_currentRow(-1), m_landscapeScene(0), m_zoneBuilder(0), m_undoStack(0), @@ -53,7 +58,7 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent) m_landscapeScene = new LandscapeScene(this); m_zoneBuilder = new ZoneBuilder(m_landscapeScene, m_ui.zoneListWidget, m_undoStack); - m_zoneBuilder->init("e:/-nel-/install/continents/newbieland", true); + m_zoneBuilder->init("e:/-nel-/install/continents/newbieland", false); m_ui.zoneListWidget->setZoneBuilder(m_zoneBuilder); m_ui.zoneListWidget->updateUi(); @@ -63,6 +68,12 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent) m_oglWidget = new QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::SampleBuffers)); m_ui.graphicsView->setViewport(m_oglWidget); + m_ui.newLandAction->setIcon(QIcon(Core::Constants::ICON_NEW)); + m_ui.saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE)); + m_ui.saveLandAction->setIcon(QIcon(Core::Constants::ICON_SAVE)); + m_ui.saveAsLandAction->setIcon(QIcon(Core::Constants::ICON_SAVE_AS)); + m_ui.deleteLandAction->setEnabled(false); + createMenus(); createToolBars(); readSettings(); @@ -71,6 +82,16 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent) connect(m_ui.projectSettingsAction, SIGNAL(triggered()), this, SLOT(openProjectSettings())); connect(m_ui.snapshotAction, SIGNAL(triggered()), this, SLOT(openSnapshotDialog())); connect(m_ui.enableGridAction, SIGNAL(toggled(bool)), m_ui.graphicsView, SLOT(setVisibleGrid(bool))); + + connect(m_ui.newLandAction, SIGNAL(triggered()), this, SLOT(newLand())); + connect(m_ui.setActiveLandAction, SIGNAL(triggered()), this, SLOT(setActiveLand())); + connect(m_ui.saveLandAction, SIGNAL(triggered()), this, SLOT(saveSelectedLand())); + connect(m_ui.saveAsLandAction, SIGNAL(triggered()), this, SLOT(saveAsSelectedLand())); + connect(m_ui.deleteLandAction, SIGNAL(triggered()), this, SLOT(deleteSelectedLand())); + + connect(m_ui.landscapesListWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenu())); + m_ui.landscapesListWidget->setContextMenuPolicy(Qt::CustomContextMenu); + } LandscapeEditorWindow::~LandscapeEditorWindow() @@ -97,17 +118,9 @@ void LandscapeEditorWindow::open() _lastDir = QFileInfo(list.front()).absolutePath(); Q_FOREACH(QString fileName, fileNames) { - int id = m_zoneBuilder->createZoneRegion(fileName); - if (id == -1) - { - QMessageBox::critical(this, "Landscape Editor", "Cannot add this zone because it overlaps existing ones"); - continue; - } - ZoneRegionObject *zoneRegion = m_zoneBuilder->zoneRegion(id); - m_ui.graphicsView->centerOn(zoneRegion->ligoZoneRegion().getMinX() * m_landscapeScene->cellSize(), - abs(zoneRegion->ligoZoneRegion().getMinY()) * m_landscapeScene->cellSize()); - - m_zoneBuilder->setCurrentZoneRegion(id); + int row = createLandscape(fileName); + if (row != -1) + setActiveLandscape(row); } } setCursor(Qt::ArrowCursor); @@ -115,16 +128,7 @@ void LandscapeEditorWindow::open() void LandscapeEditorWindow::save() { - ZoneRegionObject *zoneRegion = m_zoneBuilder->currentZoneRegion(); - if (zoneRegion->fileName().empty()) - { - QString fileName = QFileDialog::getSaveFileName(this, - tr("Save NeL Ligo land file"), _lastDir, - tr("NeL Ligo land file (*.land)")); - if (!fileName.isEmpty()) - zoneRegion->setFileName(fileName.toStdString()); - } - zoneRegion->save(); + saveLandscape(m_currentRow, true); } void LandscapeEditorWindow::openProjectSettings() @@ -184,6 +188,133 @@ void LandscapeEditorWindow::openSnapshotDialog() delete dialog; } +void LandscapeEditorWindow::customContextMenu() +{ + if (m_ui.landscapesListWidget->currentRow() == -1) + return; + QMenu *popurMenu = new QMenu(this); + popurMenu->addAction(m_ui.setActiveLandAction); + popurMenu->addAction(m_ui.saveLandAction); + popurMenu->addAction(m_ui.saveAsLandAction); + popurMenu->addAction(m_ui.deleteLandAction); + popurMenu->exec(QCursor::pos()); + delete popurMenu; +} + +void LandscapeEditorWindow::newLand() +{ + createLandscape(QString()); +} + +void LandscapeEditorWindow::setActiveLand() +{ + setActiveLandscape(m_ui.landscapesListWidget->currentRow()); +} + +void LandscapeEditorWindow::saveSelectedLand() +{ + saveLandscape(m_ui.landscapesListWidget->currentRow(), true); +} + +void LandscapeEditorWindow::saveAsSelectedLand() +{ + saveLandscape(m_ui.landscapesListWidget->currentRow(), false); +} + +void LandscapeEditorWindow::deleteSelectedLand() +{ + int row = m_ui.landscapesListWidget->currentRow(); + QListWidgetItem *item = m_ui.landscapesListWidget->item(row); + if (row == m_currentRow) + { + if (row == 0) + ++row; + else + --row; + setActiveLandscape(row); + } + m_zoneBuilder->deleteZoneRegion(item->data(LANDSCAPE_ID).toInt()); + m_ui.landscapesListWidget->removeItemWidget(item); + delete item; + if (m_ui.landscapesListWidget->count() == 1) + m_ui.deleteLandAction->setEnabled(false); +} + +int LandscapeEditorWindow::createLandscape(const QString &fileName) +{ + int id; + if (fileName.isEmpty()) + id = m_zoneBuilder->createZoneRegion(); + else + id = m_zoneBuilder->createZoneRegion(fileName); + + if (id == -1) + { + QMessageBox::critical(this, "Landscape Editor", "Cannot add this zone because it overlaps existing ones"); + return -1; + } + ZoneRegionObject *zoneRegion = m_zoneBuilder->zoneRegion(id); + m_ui.graphicsView->centerOn(zoneRegion->ligoZoneRegion().getMinX() * m_landscapeScene->cellSize(), + abs(zoneRegion->ligoZoneRegion().getMinY()) * m_landscapeScene->cellSize()); + + QListWidgetItem *item; + if (fileName.isEmpty()) + item = new QListWidgetItem(QString("NewLandscape%1").arg(NewLandCounter++), m_ui.landscapesListWidget); + else + item = new QListWidgetItem(fileName, m_ui.landscapesListWidget); + + item->setData(LANDSCAPE_ID, id); + item->setFont(QFont("SansSerif", 9, QFont::Normal)); + + if (m_ui.landscapesListWidget->count() > 1) + m_ui.deleteLandAction->setEnabled(true); + + return m_ui.landscapesListWidget->count() - 1; +} + +void LandscapeEditorWindow::setActiveLandscape(int row) +{ + if ((0 <= row) && (row < m_ui.landscapesListWidget->count())) + { + if (m_currentRow != -1) + { + QListWidgetItem *item = m_ui.landscapesListWidget->item(m_currentRow); + item->setFont(QFont("SansSerif", 9, QFont::Normal)); + } + QListWidgetItem *item = m_ui.landscapesListWidget->item(row); + item->setFont(QFont("SansSerif", 9, QFont::Bold)); + m_zoneBuilder->setCurrentZoneRegion(item->data(LANDSCAPE_ID).toInt()); + m_currentRow = row; + } +} + +void LandscapeEditorWindow::saveLandscape(int row, bool force) +{ + if ((0 <= row) && (row < m_ui.landscapesListWidget->count())) + { + QListWidgetItem *item = m_ui.landscapesListWidget->item(row); + ZoneRegionObject *regionObject = m_zoneBuilder->zoneRegion(item->data(LANDSCAPE_ID).toInt()); + if ((!force) || (regionObject->fileName().empty())) + { + QString fileName = QFileDialog::getSaveFileName(this, + tr("Save NeL Ligo land file"), _lastDir, + tr("NeL Ligo land file (*.land)")); + if (!fileName.isEmpty()) + { + regionObject->setFileName(fileName.toStdString()); + regionObject->save(); + regionObject->setModified(false); + item->setText(fileName); + } + } + else + { + regionObject->save(); + regionObject->setModified(false); + } + } +} + void LandscapeEditorWindow::showEvent(QShowEvent *showEvent) { QMainWindow::showEvent(showEvent); @@ -202,7 +333,23 @@ void LandscapeEditorWindow::createToolBars() //QAction *action = menuManager->action(Core::Constants::NEW); //m_ui.fileToolBar->addAction(action); QAction *action = menuManager->action(Core::Constants::OPEN); + m_ui.fileToolBar->addAction(m_ui.newLandAction); m_ui.fileToolBar->addAction(action); + m_ui.fileToolBar->addAction(m_ui.saveAction); + + const char * const UNDO = "ObjectViewerQt.Undo"; + const char * const REDO = "ObjectViewerQt.Redo"; + + //action = menuManager->action(Core::Constants::UNDO); + action = menuManager->action(UNDO); + if (action != 0) + m_ui.undoToolBar->addAction(action); + + //action = menuManager->action(Core::Constants::REDO); + action = menuManager->action(REDO); + if (action != 0) + m_ui.undoToolBar->addAction(action); + //action = menuManager->action(Core::Constants::SAVE); //m_ui.fileToolBar->addAction(action); //action = menuManager->action(Core::Constants::SAVE_AS); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.h index ff9cfd273..f3421f120 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.h @@ -49,6 +49,12 @@ public Q_SLOTS: private Q_SLOTS: void openProjectSettings(); void openSnapshotDialog(); + void customContextMenu(); + void newLand(); + void setActiveLand(); + void saveSelectedLand(); + void saveAsSelectedLand(); + void deleteSelectedLand(); protected: virtual void showEvent(QShowEvent *showEvent); @@ -59,6 +65,11 @@ private: void readSettings(); void writeSettings(); + void setActiveLandscape(int row); + void saveLandscape(int row, bool force); + int createLandscape(const QString &fileName); + + int m_currentRow; LandscapeScene *m_landscapeScene; ZoneBuilder *m_zoneBuilder; QUndoStack *m_undoStack; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.ui index 57eadda73..7d71acd49 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.ui @@ -62,7 +62,7 @@ - + toolBar_2 @@ -72,9 +72,40 @@ false - - + + + + Landscapes + + + 1 + + + + + 3 + + + 3 + + + + + + + + + + toolBar + + + TopToolBarArea + + + false + + @@ -113,6 +144,50 @@ Save + + + + :/icons/ic_nel_zone.png:/icons/ic_nel_zone.png + + + Set active + + + Set active selected landscape + + + + + Save + + + Save selected landscape + + + + + Save As landscape + + + Save as selected landscape + + + + + Delete + + + Delete selected landscape + + + + + New + + + Create new landscape + +