diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_actions.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_actions.cpp
index 14cdb4f4b..5582de2d7 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_actions.cpp
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_actions.cpp
@@ -27,7 +27,42 @@
namespace LandscapeEditor
{
-ActionLigoTile::ActionLigoTile(const LigoData &data, ZoneBuilder *zoneBuilder, QGraphicsScene *scene, QUndoCommand *parent)
+OpenLandscapeCommand::OpenLandscapeCommand(const QString &fileName, QUndoCommand *parent)
+ : QUndoCommand(parent),
+ m_fileName(fileName)
+{
+}
+
+OpenLandscapeCommand::~OpenLandscapeCommand()
+{
+}
+
+void OpenLandscapeCommand::undo()
+{
+}
+
+void OpenLandscapeCommand::redo()
+{
+}
+
+NewLandscapeCommand::NewLandscapeCommand(QUndoCommand *parent)
+ : QUndoCommand(parent)
+{
+}
+
+NewLandscapeCommand::~NewLandscapeCommand()
+{
+}
+
+void NewLandscapeCommand::undo()
+{
+}
+
+void NewLandscapeCommand::redo()
+{
+}
+
+LigoTileCommand::LigoTileCommand(const LigoData &data, ZoneBuilder *zoneBuilder, QGraphicsScene *scene, QUndoCommand *parent)
: QUndoCommand(parent),
m_item(0),
m_zoneBuilder(zoneBuilder),
@@ -36,23 +71,24 @@ ActionLigoTile::ActionLigoTile(const LigoData &data, ZoneBuilder *zoneBuilder, Q
m_ligoData = data;
}
-ActionLigoTile::~ActionLigoTile()
+LigoTileCommand::~LigoTileCommand()
{
}
-void ActionLigoTile::undo()
+void LigoTileCommand::undo()
{
m_scene->removeItem(m_item);
delete m_item;
m_item = 0;
}
-void ActionLigoTile::redo()
+void LigoTileCommand::redo()
{
QPixmap *pixmap = m_zoneBuilder->pixmapDatabase()->pixmap(QString(m_ligoData.ZoneName.c_str()));
m_item = new QGraphicsPixmapItem(*pixmap, 0, m_scene);
m_item->setPos(m_ligoData.PosX, m_ligoData.PosY);
m_item->setScale(m_ligoData.Scale);
+ m_item->setTransformationMode(Qt::SmoothTransformation);
setText(QObject::tr("Add tile(%1, %2)").arg(m_ligoData.PosX).arg(m_ligoData.PosY));
}
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_actions.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_actions.h
index 76cb92762..ff9c9dde0 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_actions.h
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_actions.h
@@ -32,11 +32,33 @@ namespace LandscapeEditor
{
class ZoneBuilder;
-class ActionLigoTile : public QUndoCommand
+class OpenLandscapeCommand: public QUndoCommand
{
public:
- ActionLigoTile(const LigoData &data, ZoneBuilder *zoneBuilder, QGraphicsScene *scene, QUndoCommand *parent = 0);
- ~ActionLigoTile();
+ OpenLandscapeCommand(const QString &fileName, QUndoCommand *parent = 0);
+ ~OpenLandscapeCommand();
+ virtual void undo();
+ virtual void redo();
+private:
+
+ QString m_fileName;
+};
+
+class NewLandscapeCommand: public QUndoCommand
+{
+public:
+ NewLandscapeCommand(QUndoCommand *parent = 0);
+ ~NewLandscapeCommand();
+ virtual void undo();
+ virtual void redo();
+private:
+};
+
+class LigoTileCommand: public QUndoCommand
+{
+public:
+ LigoTileCommand(const LigoData &data, ZoneBuilder *zoneBuilder, QGraphicsScene *scene, QUndoCommand *parent = 0);
+ ~LigoTileCommand();
virtual void undo();
virtual void redo();
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 90c712e6c..59a4553b9 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
@@ -51,13 +51,14 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
m_landscapeScene = new LandscapeScene(m_undoStack, m_ui.zoneListWidget, m_zoneBuilder, this);
m_ui.graphicsView->setScene(m_landscapeScene);
- //m_ui.graphicsView->setViewport(new QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::SampleBuffers)));
+ m_ui.graphicsView->setViewport(new QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::SampleBuffers)));
createMenus();
createToolBars();
readSettings();
connect(m_ui.projectSettingsAction, SIGNAL(triggered()), this, SLOT(openProjectSettings()));
+ connect(m_ui.enableGridAction, SIGNAL(toggled(bool)), m_ui.graphicsView, SLOT(setVisibleGrid(bool)));
}
LandscapeEditorWindow::~LandscapeEditorWindow()
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 bb14576a2..ff3121d04 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
@@ -73,6 +73,7 @@
false
+
@@ -83,6 +84,23 @@
Project settings
+
+
+ true
+
+
+ true
+
+
+ EnableGrid
+
+
+ Show/Hide Grid
+
+
+ Ctrl+G
+
+
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 993b6ec9c..3b1ddd9fb 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
@@ -38,7 +38,6 @@ LandscapeScene::LandscapeScene(QUndoStack *undoStack, ListZonesWidget *listZones
m_zoneBuilder(zoneBuilder)
{
m_cellSize = 160;
- createBackgroundPixmap();
}
LandscapeScene::~LandscapeScene()
@@ -63,22 +62,10 @@ void LandscapeScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
ligoData.PosY = m_cellSize * int(y / m_cellSize);
ligoData.Scale = m_cellSize / 256.0;
- ActionLigoTile *action = new ActionLigoTile(ligoData, m_zoneBuilder, this);
+ LigoTileCommand *action = new LigoTileCommand(ligoData, m_zoneBuilder, this);
m_undoStack->push(action);
QGraphicsScene::mousePressEvent(mouseEvent);
}
-void LandscapeScene::createBackgroundPixmap()
-{
- QPixmap pixmap(QSize(m_cellSize, m_cellSize));
- QPainter painter(&pixmap);
- //painter.setRenderHint(QPainter::Antialiasing, true);
- painter.setBrush(QBrush(Qt::lightGray));
- painter.setPen(QPen(Qt::black, 3, Qt::DotLine));
- painter.drawRect(0, 0, pixmap.width(), pixmap.height());
-
- setBackgroundBrush(pixmap);
-}
-
} /* namespace LandscapeEditor */
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 b4a7a68de..80417d4ff 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
@@ -41,10 +41,9 @@ public:
virtual ~LandscapeScene();
protected:
- void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
private:
- void createBackgroundPixmap();
int m_cellSize;
ListZonesWidget *m_listZonesWidget;
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.cpp
index 4bd202b7c..26dd386ed 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.cpp
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.cpp
@@ -33,21 +33,55 @@ namespace LandscapeEditor
LandscapeView::LandscapeView(QWidget *parent)
: QGraphicsView(parent),
+ m_visibleGrid(true),
m_moveMouse(false)
{
setDragMode(ScrollHandDrag);
setTransformationAnchor(AnchorUnderMouse);
+ setBackgroundBrush(QBrush(Qt::lightGray));
+ //setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
+ //setRenderHints(QPainter::Antialiasing);
+ m_cellSize = 160;
+ m_numSteps = 0;
+ m_maxSteps = 20;
}
LandscapeView::~LandscapeView()
{
}
+bool LandscapeView::isVisibleGrid() const
+{
+ return m_visibleGrid;
+}
+
+void LandscapeView::setVisibleGrid(bool visible)
+{
+ m_visibleGrid = visible;
+
+ // hack for repaint view
+ translate(0.0001, 0.0001);
+}
+
void LandscapeView::wheelEvent(QWheelEvent *event)
{
double numDegrees = event->delta() / 8.0;
double numSteps = numDegrees / 15.0;
double factor = std::pow(1.125, numSteps);
+ if (factor > 1.0)
+ {
+ // check max scale view
+ if (m_numSteps > m_maxSteps)
+ return;
+ ++m_numSteps;
+ }
+ else
+ {
+ // check min scale view
+ if (m_numSteps < -m_maxSteps)
+ return;
+ --m_numSteps;
+ }
scale(factor, factor);
}
@@ -74,4 +108,31 @@ void LandscapeView::mouseReleaseEvent(QMouseEvent *event)
QGraphicsView::mouseReleaseEvent(event);
}
+void LandscapeView::drawForeground(QPainter *painter, const QRectF &rect)
+{
+ if (!m_visibleGrid)
+ return;
+
+ qreal scaleFactor = transform().m11();
+ painter->setPen(QPen(Qt::white, 1 / scaleFactor, Qt::SolidLine));
+
+ // draw grid
+ qreal left = m_cellSize * int(rect.left() / m_cellSize);
+ qreal top = m_cellSize * int(rect.top() / m_cellSize);
+
+ // draw vertical lines
+ while (left < rect.right())
+ {
+ painter->drawLine(int(left), int(rect.bottom()), int(left), int(rect.top()));
+ left += m_cellSize;
+ }
+
+ // draw horizontal lines
+ while (top < rect.bottom())
+ {
+ painter->drawLine(int(rect.left()), int(top), int(rect.right()), int(top));
+ top += m_cellSize;
+ }
+}
+
} /* namespace LandscapeEditor */
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.h
index 4ac090af6..2ae251fee 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.h
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.h
@@ -19,6 +19,7 @@
#define LANDSCAPE_VIEW_H
// Project includes
+#include "landscape_editor_global.h"
// Qt includes
#include
@@ -27,24 +28,32 @@
namespace LandscapeEditor
{
-class LandscapeView: public QGraphicsView
+class LANDSCAPE_EDITOR_EXPORT LandscapeView: public QGraphicsView
{
Q_OBJECT
public:
LandscapeView(QWidget *parent = 0);
- ~LandscapeView();
+ virtual ~LandscapeView();
+ bool isVisibleGrid() const;
+
+public Q_SLOTS:
+ void setVisibleGrid(bool visible);
+
+private Q_SLOTS:
protected:
virtual void wheelEvent(QWheelEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
-
-private Q_SLOTS:
+ virtual void drawForeground(QPainter *painter, const QRectF &rect);
private:
+ bool m_visibleGrid;
+ int m_numSteps, m_maxSteps;
+ int m_cellSize;
bool m_moveMouse;
}; /* class LandscapeView */