From add8aa04504b9824474315490b4e63eb381b2a86 Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Mon, 11 Jul 2011 02:06:14 +0300 Subject: [PATCH] Changed: #1301 Improved Landscape plugin. --- .../src/plugins/CMakeLists.txt | 1 + .../plugins/landscape_editor/CMakeLists.txt | 2 +- .../plugins/landscape_editor/builder_zone.cpp | 129 +++++++++--------- .../plugins/landscape_editor/builder_zone.h | 4 +- .../landscape_editor_plugin.cpp | 2 +- .../landscape_editor_window.cpp | 34 ++--- .../landscape_editor_window.h | 2 +- .../landscape_editor_window.ui | 12 ++ .../landscape_editor/landscape_scene.cpp | 48 ++++++- .../landscape_editor/landscape_scene.h | 3 + 10 files changed, 138 insertions(+), 99 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/CMakeLists.txt index bec71cf94..880f49c74 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/CMakeLists.txt @@ -7,3 +7,4 @@ ADD_SUBDIRECTORY(disp_sheet_id) ADD_SUBDIRECTORY(object_viewer) ADD_SUBDIRECTORY(zone_painter) ADD_SUBDIRECTORY(georges_editor) +ADD_SUBDIRECTORY(world_editor) \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/CMakeLists.txt index 2f1d58c66..7ef0a11bf 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/CMakeLists.txt @@ -40,7 +40,7 @@ SOURCE_GROUP(QtGeneratedMocQrcSrc FILES ${OVQT_PLUGIN_LANDSCAPE_EDITOR_MOC_SRC} SOURCE_GROUP("Landscape Editor Plugin" FILES ${SRC}) SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC}) -ADD_LIBRARY(ovqt_plugin_landscape_editor MODULE ${SRC} +ADD_LIBRARY(ovqt_plugin_landscape_editor SHARED ${SRC} ${OVQT_PLUGIN_LANDSCAPE_EDITOR_MOC_SRC} ${OVQT_EXT_SYS_SRC} ${OVQT_PLUGIN_LANDSCAPE_EDITOR_UI_HDRS} 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 9550b1f76..b9ffe7151 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 @@ -26,11 +26,11 @@ // Qt includes #include #include -#include #include namespace LandscapeEditor { +int LandCounter = 0; ZoneBuilder::ZoneBuilder(LandscapeScene *landscapeScene, ListZonesWidget *listZonesWidget, QUndoStack *undoStack) : m_currentZoneRegion(-1), @@ -117,7 +117,7 @@ void ZoneBuilder::addZone(sint32 posX, sint32 posY) if ((m_listZonesWidget == 0) || (m_undoStack == 0)) return; - if (m_landscapeItems.empty()) + if (m_landscapeMap.empty()) return; // Check zone name @@ -125,7 +125,7 @@ void ZoneBuilder::addZone(sint32 posX, sint32 posY) if (zoneName.empty()) return; - BuilderZoneRegion *builderZoneRegion = m_landscapeItems.at(m_currentZoneRegion).builderZoneRegion; + BuilderZoneRegion *builderZoneRegion = m_landscapeMap.value(m_currentZoneRegion).builderZoneRegion; builderZoneRegion->init(this); uint8 rot = uint8(m_listZonesWidget->currentRot()); @@ -161,13 +161,13 @@ void ZoneBuilder::delZone(const sint32 posX, const sint32 posY) if ((m_listZonesWidget == 0) || (m_undoStack == 0)) return; - if (m_landscapeItems.empty()) + if (m_landscapeMap.empty()) return; m_titleAction = QString("Del zone %1,%2").arg(posX).arg(posY); m_createdAction = false; - BuilderZoneRegion *builderZoneRegion = m_landscapeItems.at(m_currentZoneRegion).builderZoneRegion; + BuilderZoneRegion *builderZoneRegion = m_landscapeMap.value(m_currentZoneRegion).builderZoneRegion; builderZoneRegion->init(this); builderZoneRegion->del(posX, posY); @@ -176,24 +176,22 @@ void ZoneBuilder::delZone(const sint32 posX, const sint32 posY) int ZoneBuilder::createZoneRegion() { - int newId = m_landscapeItems.size(); LandscapeItem landItem; landItem.zoneRegionObject = new ZoneRegionObject(); - landItem.builderZoneRegion = new BuilderZoneRegion(newId); + landItem.builderZoneRegion = new BuilderZoneRegion(LandCounter); landItem.builderZoneRegion->init(this); - landItem.rectItem = 0; + landItem.rectItem = m_landscapeScene->createLayerBlackout(landItem.zoneRegionObject->ligoZoneRegion()); - newZone(); - m_landscapeItems.push_back(landItem); + m_landscapeMap.insert(LandCounter, landItem); if (m_currentZoneRegion == -1) - setCurrentZoneRegion(newId); + setCurrentZoneRegion(LandCounter); - return newId; + calcMask(); + return LandCounter++; } int ZoneBuilder::createZoneRegion(const QString &fileName) { - int newId = m_landscapeItems.size(); LandscapeItem landItem; landItem.zoneRegionObject = new ZoneRegionObject(); landItem.zoneRegionObject->load(fileName.toStdString()); @@ -203,48 +201,52 @@ int ZoneBuilder::createZoneRegion(const QString &fileName) delete landItem.zoneRegionObject; return -1; } - landItem.builderZoneRegion = new BuilderZoneRegion(newId); + landItem.builderZoneRegion = new BuilderZoneRegion(LandCounter); landItem.builderZoneRegion->init(this); - newZone(); - m_landscapeItems.push_back(landItem); - m_landscapeScene->addZoneRegion(landItem.zoneRegionObject->ligoZoneRegion()); - m_landscapeItems.at(newId).rectItem = m_landscapeScene->createLayerBlackout(landItem.zoneRegionObject->ligoZoneRegion()); + landItem.rectItem = m_landscapeScene->createLayerBlackout(landItem.zoneRegionObject->ligoZoneRegion()); + m_landscapeMap.insert(LandCounter, landItem); if (m_currentZoneRegion == -1) - setCurrentZoneRegion(newId); + setCurrentZoneRegion(LandCounter); - return newId; + calcMask(); + return LandCounter++; } void ZoneBuilder::deleteZoneRegion(int id) { - if ((0 <= id) && (id < int(m_landscapeItems.size()))) + if (m_landscapeMap.contains(id)) { - 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; - m_landscapeItems.erase(m_landscapeItems.begin() + id); + if (m_landscapeMap.value(id).rectItem != 0) + delete m_landscapeMap.value(id).rectItem; + m_landscapeScene->delZoneRegion(m_landscapeMap.value(id).zoneRegionObject->ligoZoneRegion()); + delete m_landscapeMap.value(id).zoneRegionObject; + delete m_landscapeMap.value(id).builderZoneRegion; + m_landscapeMap.remove(id); calcMask(); } + else + nlwarning("Landscape (id %i) not found", id); } void ZoneBuilder::setCurrentZoneRegion(int id) { - if ((0 <= id) && (id < int(m_landscapeItems.size()))) + if (m_landscapeMap.contains(id)) { if (currentIdZoneRegion() != -1) { - NLLIGO::CZoneRegion &ligoRegion = m_landscapeItems.at(m_currentZoneRegion).zoneRegionObject->ligoZoneRegion(); - m_landscapeItems.at(m_currentZoneRegion).rectItem = m_landscapeScene->createLayerBlackout(ligoRegion); + NLLIGO::CZoneRegion &ligoRegion = m_landscapeMap.value(m_currentZoneRegion).zoneRegionObject->ligoZoneRegion(); + m_landscapeMap[m_currentZoneRegion].rectItem = m_landscapeScene->createLayerBlackout(ligoRegion); } - delete m_landscapeItems.at(id).rectItem; - m_landscapeItems.at(id).rectItem = 0; + delete m_landscapeMap.value(id).rectItem; + m_landscapeMap[id].rectItem = 0; m_currentZoneRegion = id; + calcMask(); } + else + nlwarning("Landscape (id %i) not found", id); } int ZoneBuilder::currentIdZoneRegion() const @@ -254,27 +256,27 @@ int ZoneBuilder::currentIdZoneRegion() const ZoneRegionObject *ZoneBuilder::currentZoneRegion() const { - return m_landscapeItems.at(m_currentZoneRegion).zoneRegionObject; + return m_landscapeMap.value(m_currentZoneRegion).zoneRegionObject; } int ZoneBuilder::countZoneRegion() const { - return m_landscapeItems.size(); + return m_landscapeMap.size(); } ZoneRegionObject *ZoneBuilder::zoneRegion(int id) const { - return m_landscapeItems.at(id).zoneRegionObject; + return m_landscapeMap.value(id).zoneRegionObject; } void ZoneBuilder::ligoData(LigoData &data, const ZonePosition &zonePos) { - m_landscapeItems.at(zonePos.region).zoneRegionObject->ligoData(data, zonePos.x, zonePos.y); + m_landscapeMap.value(zonePos.region).zoneRegionObject->ligoData(data, zonePos.x, zonePos.y); } void ZoneBuilder::setLigoData(LigoData &data, const ZonePosition &zonePos) { - m_landscapeItems.at(zonePos.region).zoneRegionObject->setLigoData(data, zonePos.x, zonePos.y); + m_landscapeMap.value(zonePos.region).zoneRegionObject->setLigoData(data, zonePos.x, zonePos.y); } bool ZoneBuilder::initZoneBank (const QString &pathName) @@ -307,25 +309,6 @@ QString ZoneBuilder::dataPath() const return m_lastPathName; } -void ZoneBuilder::newZone() -{ - // Select starting point for the moment 0,0 - sint32 x = 0, y = 0; - - // If there are some zone already present increase x until free - for (size_t i = 0; i < m_landscapeItems.size(); ++i) - { - const NLLIGO::CZoneRegion &zoneRegion = m_landscapeItems.at(i).zoneRegionObject->ligoZoneRegion(); - const std::string &zoneName = zoneRegion.getName (x, y); - if ((zoneName != STRING_OUT_OF_BOUND) && (zoneName != STRING_UNUSED)) - { - ++x; - i = -1; - } - } - calcMask(); -} - bool ZoneBuilder::getZoneMask(sint32 x, sint32 y) { if ((x < m_minX) || (x > m_maxX) || @@ -346,12 +329,14 @@ void ZoneBuilder::calcMask() m_minY = m_minX = 1000000; m_maxY = m_maxX = -1000000; - if (m_landscapeItems.size() == 0) + if (m_landscapeMap.size() == 0) return; - for (size_t i = 0; i < m_landscapeItems.size(); ++i) + QMapIterator i(m_landscapeMap); + while (i.hasNext()) { - const NLLIGO::CZoneRegion ®ion = m_landscapeItems.at(i).zoneRegionObject->ligoZoneRegion(); + i.next(); + const NLLIGO::CZoneRegion ®ion = i.value().zoneRegionObject->ligoZoneRegion(); if (m_minX > region.getMinX()) m_minX = region.getMinX(); @@ -370,10 +355,13 @@ void ZoneBuilder::calcMask() { m_zoneMask[x - m_minX + (y - m_minY) * stride] = true; - for (size_t i = 0; i < m_landscapeItems.size(); ++i) - if (int(i) != m_currentZoneRegion) + QMapIterator it(m_landscapeMap); + while (it.hasNext()) + { + it.next(); + if (int(it.key()) != m_currentZoneRegion) { - const NLLIGO::CZoneRegion ®ion = zoneRegion(i)->ligoZoneRegion(); + const NLLIGO::CZoneRegion ®ion = it.value().zoneRegionObject->ligoZoneRegion(); const std::string &rSZone = region.getName (x, y); if ((rSZone != STRING_OUT_OF_BOUND) && (rSZone != STRING_UNUSED)) @@ -381,21 +369,24 @@ void ZoneBuilder::calcMask() m_zoneMask[x - m_minX + (y - m_minY) * stride] = false; } } + } } } bool ZoneBuilder::getZoneAmongRegions(ZonePosition &zonePos, BuilderZoneRegion *builderZoneRegionFrom, sint32 x, sint32 y) { - for (size_t i = 0; i < m_landscapeItems.size(); ++i) + QMapIterator it(m_landscapeMap); + while (it.hasNext()) { - const NLLIGO::CZoneRegion ®ion = m_landscapeItems.at(i).zoneRegionObject->ligoZoneRegion(); + it.next(); + const NLLIGO::CZoneRegion ®ion = it.value().zoneRegionObject->ligoZoneRegion(); if ((x < region.getMinX()) || (x > region.getMaxX()) || (y < region.getMinY()) || (y > region.getMaxY())) continue; if (region.getName(x, y) != STRING_UNUSED) { - builderZoneRegionFrom = m_landscapeItems.at(i).builderZoneRegion; - zonePos = ZonePosition(x, y, i); + builderZoneRegionFrom = it.value().builderZoneRegion; + zonePos = ZonePosition(x, y, it.key()); return true; } } @@ -435,9 +426,11 @@ void ZoneBuilder::checkEndMacro() bool ZoneBuilder::checkOverlaps(const NLLIGO::CZoneRegion &newZoneRegion) { - for (size_t j = 0; j < m_landscapeItems.size(); ++j) + QMapIterator it(m_landscapeMap); + while (it.hasNext()) { - const NLLIGO::CZoneRegion &zoneRegion = m_landscapeItems.at(j).zoneRegionObject->ligoZoneRegion(); + it.next(); + const NLLIGO::CZoneRegion &zoneRegion = it.value().zoneRegionObject->ligoZoneRegion(); for (sint32 y = zoneRegion.getMinY(); y <= zoneRegion.getMaxY(); ++y) for (sint32 x = zoneRegion.getMinX(); x <= zoneRegion.getMaxX(); ++x) { diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/builder_zone.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/builder_zone.h index 17d5a6f7e..5fbd80832 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/builder_zone.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/builder_zone.h @@ -85,7 +85,6 @@ public: bool init(const QString &pathName, bool bMakeAZone); void calcMask(); - void newZone(); bool getZoneMask (sint32 x, sint32 y); bool getZoneAmongRegions(ZonePosition &zonePos, BuilderZoneRegion *builderZoneRegionFrom, sint32 x, sint32 y); @@ -150,7 +149,8 @@ private: QString m_lastPathName; int m_currentZoneRegion; - std::vector m_landscapeItems; + //std::vector m_landscapeItems; + QMap m_landscapeMap; bool m_createdAction; QString m_titleAction; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_plugin.cpp index ac7782343..401256ce6 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_plugin.cpp @@ -75,7 +75,7 @@ QString LandscapeEditorPlugin::name() const QString LandscapeEditorPlugin::version() const { - return "0.0.1"; + return "0.1"; } QString LandscapeEditorPlugin::vendor() const 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 da949fea5..4dd3163ba 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 @@ -46,7 +46,7 @@ QString _lastDir; LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent) : QMainWindow(parent), - m_currentRow(-1), + m_currentItem(0), m_landscapeScene(0), m_zoneBuilder(0), m_undoStack(0), @@ -65,8 +65,7 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent) m_landscapeScene->setZoneBuilder(m_zoneBuilder); m_ui.graphicsView->setScene(m_landscapeScene); //m_oglWidget = new QGLWidget(QGLFormat(QGL::DoubleBuffer)); - m_oglWidget = new QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::SampleBuffers)); - m_ui.graphicsView->setViewport(m_oglWidget); + //m_ui.graphicsView->setViewport(m_oglWidget); m_ui.newLandAction->setIcon(QIcon(Core::Constants::ICON_NEW)); m_ui.saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE)); @@ -128,7 +127,7 @@ void LandscapeEditorWindow::open() void LandscapeEditorWindow::save() { - saveLandscape(m_currentRow, true); + saveLandscape(m_ui.landscapesListWidget->row(m_currentItem), true); } void LandscapeEditorWindow::openProjectSettings() @@ -203,7 +202,9 @@ void LandscapeEditorWindow::customContextMenu() void LandscapeEditorWindow::newLand() { - createLandscape(QString()); + int row = createLandscape(QString()); + if (row != -1) + setActiveLandscape(row); } void LandscapeEditorWindow::setActiveLand() @@ -224,8 +225,9 @@ void LandscapeEditorWindow::saveAsSelectedLand() void LandscapeEditorWindow::deleteSelectedLand() { int row = m_ui.landscapesListWidget->currentRow(); + int current_row = m_ui.landscapesListWidget->row(m_currentItem); QListWidgetItem *item = m_ui.landscapesListWidget->item(row); - if (row == m_currentRow) + if (row == current_row) { if (row == 0) ++row; @@ -236,6 +238,7 @@ void LandscapeEditorWindow::deleteSelectedLand() 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); } @@ -276,15 +279,13 @@ 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)); - } + if (m_currentItem != 0) + m_currentItem->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; + m_currentItem = item; } } @@ -337,16 +338,11 @@ void LandscapeEditorWindow::createToolBars() 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); + action = menuManager->action(Core::Constants::UNDO); if (action != 0) m_ui.undoToolBar->addAction(action); - //action = menuManager->action(Core::Constants::REDO); - action = menuManager->action(REDO); + action = menuManager->action(Core::Constants::REDO); if (action != 0) m_ui.undoToolBar->addAction(action); 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 f3421f120..18ce670b7 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 @@ -69,7 +69,7 @@ private: void saveLandscape(int row, bool force); int createLandscape(const QString &fileName); - int m_currentRow; + QListWidgetItem *m_currentItem; 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 7d71acd49..b2db9dc42 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 @@ -38,6 +38,18 @@ QGraphicsView::NoDrag + + QGraphicsView::AnchorUnderMouse + + + QGraphicsView::AnchorUnderMouse + + + QGraphicsView::FullViewportUpdate + + + QGraphicsView::DontSavePainterState + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.cpp index 81a94fb1f..3b10d4fed 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.cpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace LandscapeEditor { @@ -34,11 +35,13 @@ static const int ZONE_NAME = 0; static const int LAYER_ZONES = 2; static const int LAYER_EMPTY_ZONES = 3; static const int LAYER_BLACKOUT = 4; +const char * const LAYER_BLACKOUT_NAME = "blackout"; LandscapeScene::LandscapeScene(QObject *parent) : QGraphicsScene(parent), m_mouseX(0.0), m_mouseY(0.0), + m_mouseButton(Qt::NoButton), m_zoneBuilder(0) { m_cellSize = 160; @@ -154,7 +157,7 @@ QGraphicsItem *LandscapeScene::createItemZone(const LigoData &data, const ZonePo // The size graphics item should be equal or proportional m_cellSize item->setScale(float(m_cellSize) / m_zoneBuilder->pixmapDatabase()->textureSize()); - //item->setData(ZONE_NAME, QString(data.zoneName.c_str())); + item->setData(ZONE_NAME, QString(data.zoneName.c_str())); // for not full item zone item->setZValue(LAYER_ZONES); @@ -198,13 +201,14 @@ QGraphicsRectItem *LandscapeScene::createLayerBlackout(const NLLIGO::CZoneRegion Qt::NoPen, QBrush(QColor(0, 0, 0, 50))); rectItem->setZValue(LAYER_BLACKOUT); + rectItem->setData(ZONE_NAME, QString(LAYER_BLACKOUT_NAME)); return rectItem; } void LandscapeScene::deleteItemZone(const ZonePosition &zonePos) { QGraphicsItem *item = itemAt(zonePos.x * m_cellSize, abs(zonePos.y) * m_cellSize); - if (item != 0) + if ((item != 0) && (item->data(ZONE_NAME).toString() != QString(LAYER_BLACKOUT_NAME))) { removeItem(item); delete item; @@ -282,30 +286,60 @@ void LandscapeScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) if ((x < 0) || (y < 0)) return; - sint32 posX = sint32(floor(x / m_cellSize)); - sint32 posY = sint32(-floor(y / m_cellSize)); + m_posX = sint32(floor(x / m_cellSize)); + m_posY = sint32(-floor(y / m_cellSize)); if (mouseEvent->button() == Qt::LeftButton) - m_zoneBuilder->addZone(posX, posY); + m_zoneBuilder->addZone(m_posX, m_posY); else if (mouseEvent->button() == Qt::RightButton) - m_zoneBuilder->delZone(posX, posY); + m_zoneBuilder->delZone(m_posX, m_posY); + + m_mouseButton = mouseEvent->button(); QGraphicsScene::mousePressEvent(mouseEvent); } void LandscapeScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent) { + qreal x = mouseEvent->scenePos().rx(); + qreal y = mouseEvent->scenePos().ry(); + + sint32 posX = sint32(floor(x / m_cellSize)); + sint32 posY = sint32(-floor(y / m_cellSize)); + + if ((m_posX != posX || m_posY != posY) && + (m_mouseButton == Qt::LeftButton || + m_mouseButton == Qt::RightButton)) + { + if (m_mouseButton == Qt::LeftButton) + m_zoneBuilder->addZone(posX, posY); + else if (m_mouseButton == Qt::RightButton) + m_zoneBuilder->delZone(posX, posY); + + m_posX = posX; + m_posY = posY; + QApplication::processEvents(); + } + m_mouseX = mouseEvent->scenePos().x(); m_mouseY = mouseEvent->scenePos().y(); QGraphicsScene::mouseMoveEvent(mouseEvent); } +void LandscapeScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) +{ + m_mouseButton = Qt::NoButton; +} + bool LandscapeScene::checkUnderZone(const int posX, const int posY) { QGraphicsItem *item = itemAt((posX * m_cellSize), abs(posY) * m_cellSize); if (item != 0) { - return true; + if (item->data(ZONE_NAME) == QString(LAYER_BLACKOUT_NAME)) + return false; + else + return true; } return false; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.h index 34fe50e05..39f81bf98 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.h @@ -62,6 +62,7 @@ public: protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent); virtual void drawForeground(QPainter *painter, const QRectF &rect); private: @@ -69,6 +70,8 @@ private: int m_cellSize; qreal m_mouseX, m_mouseY; + sint32 m_posX, m_posY; + Qt::MouseButton m_mouseButton; ZoneBuilder *m_zoneBuilder; };