mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-06 15:29:02 +00:00
Changed: #1301 Added max\min scale view. Improved drawing of the grid.
This commit is contained in:
parent
c3867d1699
commit
c0c6700dd0
8 changed files with 161 additions and 28 deletions
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -73,6 +73,7 @@
|
|||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="projectSettingsAction"/>
|
||||
<addaction name="enableGridAction"/>
|
||||
</widget>
|
||||
<action name="projectSettingsAction">
|
||||
<property name="icon">
|
||||
|
@ -83,6 +84,23 @@
|
|||
<string>Project settings</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="enableGridAction">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>EnableGrid</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Show/Hide Grid</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+G</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#define LANDSCAPE_VIEW_H
|
||||
|
||||
// Project includes
|
||||
#include "landscape_editor_global.h"
|
||||
|
||||
// Qt includes
|
||||
#include <QtGui/QGraphicsView>
|
||||
|
@ -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 */
|
||||
|
||||
|
|
Loading…
Reference in a new issue