|
|
@ -202,17 +202,6 @@ void removeGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QList<Path> graphicsItemsToPaths(const QList<QGraphicsItem *> &items, PrimitivesTreeModel *model)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QList<Path> result;
|
|
|
|
|
|
|
|
Q_FOREACH(QGraphicsItem *item, items)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Node *node = qvariant_cast<Node *>(item->data(Constants::WORLD_EDITOR_NODE));
|
|
|
|
|
|
|
|
result.push_back(model->pathFromNode(node));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QList<QPolygonF> polygonsFromItems(const QList<QGraphicsItem *> &items)
|
|
|
|
QList<QPolygonF> polygonsFromItems(const QList<QGraphicsItem *> &items)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QList<QPolygonF> result;
|
|
|
|
QList<QPolygonF> result;
|
|
|
@ -224,49 +213,6 @@ QList<QPolygonF> polygonsFromItems(const QList<QGraphicsItem *> &items)
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void updateGraphicsData(AbstractWorldItem *item)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
float cellSize = Utils::ligoConfig()->CellSize;
|
|
|
|
|
|
|
|
Node *node = qvariant_cast<Node *>(item->data(Constants::WORLD_EDITOR_NODE));
|
|
|
|
|
|
|
|
PrimitiveNode *primitiveNode = static_cast<PrimitiveNode *>(node);
|
|
|
|
|
|
|
|
if (primitiveNode != 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
NLLIGO::IPrimitive *primitive = primitiveNode->primitive();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<NLLIGO::CPrimVector> vPoints;
|
|
|
|
|
|
|
|
QPolygonF polygon = item->polygon();
|
|
|
|
|
|
|
|
polygon.translate(item->pos());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < polygon.size(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
NLMISC::CVector vec(polygon.at(i).x(), cellSize - polygon.at(i).y(), 0.0);
|
|
|
|
|
|
|
|
vPoints.push_back(NLLIGO::CPrimVector(vec));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (primitiveNode->primitiveClass()->Type)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case NLLIGO::CPrimitiveClass::Point:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
NLLIGO::CPrimPoint *point = static_cast<NLLIGO::CPrimPoint *>(primitive);
|
|
|
|
|
|
|
|
point->Point = vPoints.front();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case NLLIGO::CPrimitiveClass::Path:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
NLLIGO::CPrimPath *path = static_cast<NLLIGO::CPrimPath *>(primitive);
|
|
|
|
|
|
|
|
path->VPoints = vPoints;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case NLLIGO::CPrimitiveClass::Zone:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
NLLIGO::CPrimZone *zone = static_cast<NLLIGO::CPrimZone *>(primitive);
|
|
|
|
|
|
|
|
zone->VPoints = vPoints;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CreateWorldCommand::CreateWorldCommand(const QString &fileName, PrimitivesTreeModel *model, QUndoCommand *parent)
|
|
|
|
CreateWorldCommand::CreateWorldCommand(const QString &fileName, PrimitivesTreeModel *model, QUndoCommand *parent)
|
|
|
|
: QUndoCommand(parent),
|
|
|
|
: QUndoCommand(parent),
|
|
|
|
m_fileName(fileName),
|
|
|
|
m_fileName(fileName),
|
|
|
@ -484,23 +430,23 @@ void AddPrimitiveByClassCommand::redo()
|
|
|
|
addNewGraphicsItems(m_model->pathToIndex(m_newPrimIndex), m_model, m_scene);
|
|
|
|
addNewGraphicsItems(m_model->pathToIndex(m_newPrimIndex), m_model, m_scene);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MoveWorldItemsCommand::MoveWorldItemsCommand(const QList<QGraphicsItem *> &items, const QPointF &offset,
|
|
|
|
AbstractWorldItemCommand::AbstractWorldItemCommand(const QList<QGraphicsItem *> &items,
|
|
|
|
WorldEditorScene *scene, PrimitivesTreeModel *model, QUndoCommand *parent)
|
|
|
|
WorldEditorScene *scene,
|
|
|
|
|
|
|
|
PrimitivesTreeModel *model,
|
|
|
|
|
|
|
|
QUndoCommand *parent)
|
|
|
|
: QUndoCommand(parent),
|
|
|
|
: QUndoCommand(parent),
|
|
|
|
m_listPaths(graphicsItemsToPaths(items, model)),
|
|
|
|
m_listPaths(graphicsItemsToPaths(items, model)),
|
|
|
|
m_offset(offset),
|
|
|
|
|
|
|
|
m_model(model),
|
|
|
|
m_model(model),
|
|
|
|
m_scene(scene),
|
|
|
|
m_scene(scene),
|
|
|
|
m_firstRun(true)
|
|
|
|
m_firstRun(true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setText("Move item(s)");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MoveWorldItemsCommand::~MoveWorldItemsCommand()
|
|
|
|
AbstractWorldItemCommand::~AbstractWorldItemCommand()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MoveWorldItemsCommand::undo()
|
|
|
|
void AbstractWorldItemCommand::undo()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool pointsMode = m_scene->isEnabledEditPoints();
|
|
|
|
bool pointsMode = m_scene->isEnabledEditPoints();
|
|
|
|
m_scene->setEnabledEditPoints(false);
|
|
|
|
m_scene->setEnabledEditPoints(false);
|
|
|
@ -508,13 +454,13 @@ void MoveWorldItemsCommand::undo()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
item->moveBy(-m_offset.x(), -m_offset.y());
|
|
|
|
undoChangeItem(i, item);
|
|
|
|
updateGraphicsData(item);
|
|
|
|
updatePrimitiveData(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_scene->setEnabledEditPoints(pointsMode);
|
|
|
|
m_scene->setEnabledEditPoints(pointsMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MoveWorldItemsCommand::redo()
|
|
|
|
void AbstractWorldItemCommand::redo()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!m_firstRun)
|
|
|
|
if (!m_firstRun)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -524,8 +470,8 @@ void MoveWorldItemsCommand::redo()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
item->moveBy(m_offset.x(), m_offset.y());
|
|
|
|
redoChangeItem(i, item);
|
|
|
|
updateGraphicsData(item);
|
|
|
|
updatePrimitiveData(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_scene->setEnabledEditPoints(pointsMode);
|
|
|
|
m_scene->setEnabledEditPoints(pointsMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -535,81 +481,117 @@ void MoveWorldItemsCommand::redo()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
updateGraphicsData(item);
|
|
|
|
updatePrimitiveData(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_firstRun = false;
|
|
|
|
m_firstRun = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RotateWorldItemsCommand::RotateWorldItemsCommand(const QList<QGraphicsItem *> &items, const qreal angle,
|
|
|
|
void AbstractWorldItemCommand::updatePrimitiveData(AbstractWorldItem *item)
|
|
|
|
const QPointF &pivot, WorldEditorScene *scene, PrimitivesTreeModel *model, QUndoCommand *parent)
|
|
|
|
|
|
|
|
: QUndoCommand(parent),
|
|
|
|
|
|
|
|
m_listPaths(graphicsItemsToPaths(items, model)),
|
|
|
|
|
|
|
|
m_angle(angle),
|
|
|
|
|
|
|
|
m_pivot(pivot),
|
|
|
|
|
|
|
|
m_model(model),
|
|
|
|
|
|
|
|
m_scene(scene),
|
|
|
|
|
|
|
|
m_firstRun(true)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setText("Rotate item(s)");
|
|
|
|
float cellSize = Utils::ligoConfig()->CellSize;
|
|
|
|
|
|
|
|
Node *node = qvariant_cast<Node *>(item->data(Constants::WORLD_EDITOR_NODE));
|
|
|
|
|
|
|
|
PrimitiveNode *primitiveNode = static_cast<PrimitiveNode *>(node);
|
|
|
|
|
|
|
|
if (primitiveNode != 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
NLLIGO::IPrimitive *primitive = primitiveNode->primitive();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<NLLIGO::CPrimVector> vPoints;
|
|
|
|
|
|
|
|
QPolygonF polygon = item->polygon();
|
|
|
|
|
|
|
|
polygon.translate(item->pos());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < polygon.size(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
NLMISC::CVector vec(polygon.at(i).x(), cellSize - polygon.at(i).y(), 0.0);
|
|
|
|
|
|
|
|
vPoints.push_back(NLLIGO::CPrimVector(vec));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RotateWorldItemsCommand::~RotateWorldItemsCommand()
|
|
|
|
switch (primitiveNode->primitiveClass()->Type)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case NLLIGO::CPrimitiveClass::Point:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
NLLIGO::CPrimPoint *point = static_cast<NLLIGO::CPrimPoint *>(primitive);
|
|
|
|
|
|
|
|
point->Point = vPoints.front();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case NLLIGO::CPrimitiveClass::Path:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
NLLIGO::CPrimPath *path = static_cast<NLLIGO::CPrimPath *>(primitive);
|
|
|
|
|
|
|
|
path->VPoints = vPoints;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case NLLIGO::CPrimitiveClass::Zone:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
NLLIGO::CPrimZone *zone = static_cast<NLLIGO::CPrimZone *>(primitive);
|
|
|
|
|
|
|
|
zone->VPoints = vPoints;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RotateWorldItemsCommand::undo()
|
|
|
|
QList<Path> AbstractWorldItemCommand::graphicsItemsToPaths(const QList<QGraphicsItem *> &items, PrimitivesTreeModel *model)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool pointsMode = m_scene->isEnabledEditPoints();
|
|
|
|
QList<Path> result;
|
|
|
|
m_scene->setEnabledEditPoints(false);
|
|
|
|
Q_FOREACH(QGraphicsItem *item, items)
|
|
|
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
Node *node = qvariant_cast<Node *>(item->data(Constants::WORLD_EDITOR_NODE));
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
result.push_back(model->pathFromNode(node));
|
|
|
|
item->rotateOn(m_pivot, -m_angle);
|
|
|
|
|
|
|
|
updateGraphicsData(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_scene->setEnabledEditPoints(pointsMode);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RotateWorldItemsCommand::redo()
|
|
|
|
MoveWorldItemsCommand::MoveWorldItemsCommand(const QList<QGraphicsItem *> &items, const QPointF &offset,
|
|
|
|
|
|
|
|
WorldEditorScene *scene, PrimitivesTreeModel *model, QUndoCommand *parent)
|
|
|
|
|
|
|
|
: AbstractWorldItemCommand(items, scene, model, parent),
|
|
|
|
|
|
|
|
m_offset(offset)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!m_firstRun)
|
|
|
|
setText("Move item(s)");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MoveWorldItemsCommand::~MoveWorldItemsCommand()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool pointsMode = m_scene->isEnabledEditPoints();
|
|
|
|
}
|
|
|
|
m_scene->setEnabledEditPoints(false);
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
|
|
|
void MoveWorldItemsCommand::undoChangeItem(int i, AbstractWorldItem *item)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
item->moveBy(-m_offset.x(), -m_offset.y());
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
|
|
|
|
item->rotateOn(m_pivot, m_angle);
|
|
|
|
|
|
|
|
updateGraphicsData(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_scene->setEnabledEditPoints(pointsMode);
|
|
|
|
|
|
|
|
|
|
|
|
void MoveWorldItemsCommand::redoChangeItem(int i, AbstractWorldItem *item)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
item->moveBy(m_offset.x(), m_offset.y());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
|
|
RotateWorldItemsCommand::RotateWorldItemsCommand(const QList<QGraphicsItem *> &items, const qreal angle,
|
|
|
|
|
|
|
|
const QPointF &pivot, WorldEditorScene *scene, PrimitivesTreeModel *model, QUndoCommand *parent)
|
|
|
|
|
|
|
|
: AbstractWorldItemCommand(items, scene, model, parent),
|
|
|
|
|
|
|
|
m_angle(angle),
|
|
|
|
|
|
|
|
m_pivot(pivot)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
|
|
|
setText("Rotate item(s)");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RotateWorldItemsCommand::~RotateWorldItemsCommand()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
|
|
|
|
updateGraphicsData(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RotateWorldItemsCommand::undoChangeItem(int i, AbstractWorldItem *item)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
item->rotateOn(m_pivot, -m_angle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_firstRun = false;
|
|
|
|
void RotateWorldItemsCommand::redoChangeItem(int i, AbstractWorldItem *item)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
item->rotateOn(m_pivot, m_angle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ScaleWorldItemsCommand::ScaleWorldItemsCommand(const QList<QGraphicsItem *> &items, const QPointF &factor,
|
|
|
|
ScaleWorldItemsCommand::ScaleWorldItemsCommand(const QList<QGraphicsItem *> &items, const QPointF &factor,
|
|
|
|
const QPointF &pivot, WorldEditorScene *scene, PrimitivesTreeModel *model, QUndoCommand *parent)
|
|
|
|
const QPointF &pivot, WorldEditorScene *scene, PrimitivesTreeModel *model, QUndoCommand *parent)
|
|
|
|
: QUndoCommand(parent),
|
|
|
|
: AbstractWorldItemCommand(items, scene, model, parent),
|
|
|
|
m_listPaths(graphicsItemsToPaths(items, model)),
|
|
|
|
|
|
|
|
m_factor(factor),
|
|
|
|
m_factor(factor),
|
|
|
|
m_pivot(pivot),
|
|
|
|
m_pivot(pivot)
|
|
|
|
m_model(model),
|
|
|
|
|
|
|
|
m_scene(scene),
|
|
|
|
|
|
|
|
m_firstRun(true)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setText("Scale item(s)");
|
|
|
|
setText("Scale item(s)");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -618,57 +600,21 @@ ScaleWorldItemsCommand::~ScaleWorldItemsCommand()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ScaleWorldItemsCommand::undo()
|
|
|
|
void ScaleWorldItemsCommand::undoChangeItem(int i, AbstractWorldItem *item)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool pointsMode = m_scene->isEnabledEditPoints();
|
|
|
|
|
|
|
|
m_scene->setEnabledEditPoints(false);
|
|
|
|
|
|
|
|
QPointF m_invertFactor(1 / m_factor.x(), 1 / m_factor.y());
|
|
|
|
QPointF m_invertFactor(1 / m_factor.x(), 1 / m_factor.y());
|
|
|
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
|
|
|
|
item->scaleOn(m_pivot, m_invertFactor);
|
|
|
|
item->scaleOn(m_pivot, m_invertFactor);
|
|
|
|
updateGraphicsData(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
m_scene->setEnabledEditPoints(pointsMode);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ScaleWorldItemsCommand::redo()
|
|
|
|
void ScaleWorldItemsCommand::redoChangeItem(int i, AbstractWorldItem *item)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!m_firstRun)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bool pointsMode = m_scene->isEnabledEditPoints();
|
|
|
|
|
|
|
|
m_scene->setEnabledEditPoints(false);
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
|
|
|
|
item->scaleOn(m_pivot, m_factor);
|
|
|
|
item->scaleOn(m_pivot, m_factor);
|
|
|
|
updateGraphicsData(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
m_scene->setEnabledEditPoints(pointsMode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
|
|
|
|
updateGraphicsData(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_firstRun = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TurnWorldItemsCommand::TurnWorldItemsCommand(const QList<QGraphicsItem *> &items, const qreal angle,
|
|
|
|
TurnWorldItemsCommand::TurnWorldItemsCommand(const QList<QGraphicsItem *> &items, const qreal angle,
|
|
|
|
WorldEditorScene *scene, PrimitivesTreeModel *model, QUndoCommand *parent)
|
|
|
|
WorldEditorScene *scene, PrimitivesTreeModel *model, QUndoCommand *parent)
|
|
|
|
: QUndoCommand(parent),
|
|
|
|
: AbstractWorldItemCommand(items, scene, model, parent),
|
|
|
|
m_listPaths(graphicsItemsToPaths(items, model)),
|
|
|
|
m_angle(angle)
|
|
|
|
m_angle(angle),
|
|
|
|
|
|
|
|
m_model(model),
|
|
|
|
|
|
|
|
m_scene(scene),
|
|
|
|
|
|
|
|
m_firstRun(true)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setText("Turn item(s)");
|
|
|
|
setText("Turn item(s)");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -677,58 +623,22 @@ TurnWorldItemsCommand::~TurnWorldItemsCommand()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TurnWorldItemsCommand::undo()
|
|
|
|
void TurnWorldItemsCommand::undoChangeItem(int i, AbstractWorldItem *item)
|
|
|
|
{
|
|
|
|
|
|
|
|
bool pointsMode = m_scene->isEnabledEditPoints();
|
|
|
|
|
|
|
|
m_scene->setEnabledEditPoints(false);
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
|
|
|
|
item->turnOn(-m_angle);
|
|
|
|
item->turnOn(-m_angle);
|
|
|
|
updateGraphicsData(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
m_scene->setEnabledEditPoints(pointsMode);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TurnWorldItemsCommand::redo()
|
|
|
|
void TurnWorldItemsCommand::redoChangeItem(int i, AbstractWorldItem *item)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!m_firstRun)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool pointsMode = m_scene->isEnabledEditPoints();
|
|
|
|
|
|
|
|
m_scene->setEnabledEditPoints(false);
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
|
|
|
|
item->turnOn(m_angle);
|
|
|
|
item->turnOn(m_angle);
|
|
|
|
updateGraphicsData(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
m_scene->setEnabledEditPoints(pointsMode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
|
|
|
|
updateGraphicsData(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_firstRun = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ShapeWorldItemsCommand::ShapeWorldItemsCommand(const QList<QGraphicsItem *> &items, const QList<QPolygonF> &polygons,
|
|
|
|
ShapeWorldItemsCommand::ShapeWorldItemsCommand(const QList<QGraphicsItem *> &items, const QList<QPolygonF> &polygons,
|
|
|
|
WorldEditorScene *scene, PrimitivesTreeModel *model,
|
|
|
|
WorldEditorScene *scene, PrimitivesTreeModel *model,
|
|
|
|
QUndoCommand *parent)
|
|
|
|
QUndoCommand *parent)
|
|
|
|
: QUndoCommand(parent),
|
|
|
|
: AbstractWorldItemCommand(items, scene, model, parent),
|
|
|
|
m_listPaths(graphicsItemsToPaths(items, model)),
|
|
|
|
|
|
|
|
m_redoPolygons(polygons),
|
|
|
|
m_redoPolygons(polygons),
|
|
|
|
m_undoPolygons(polygonsFromItems(items)),
|
|
|
|
m_undoPolygons(polygonsFromItems(items))
|
|
|
|
m_model(model),
|
|
|
|
|
|
|
|
m_scene(scene),
|
|
|
|
|
|
|
|
m_firstRun(true)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setText("Change shape");
|
|
|
|
setText("Change shape");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -737,49 +647,14 @@ ShapeWorldItemsCommand::~ShapeWorldItemsCommand()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ShapeWorldItemsCommand::undo()
|
|
|
|
void ShapeWorldItemsCommand::undoChangeItem(int i, AbstractWorldItem *item)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool pointsMode = m_scene->isEnabledEditPoints();
|
|
|
|
|
|
|
|
m_scene->setEnabledEditPoints(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
|
|
|
|
item->setPolygon(m_redoPolygons.at(i));
|
|
|
|
item->setPolygon(m_redoPolygons.at(i));
|
|
|
|
updateGraphicsData(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_scene->setEnabledEditPoints(pointsMode);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ShapeWorldItemsCommand::redo()
|
|
|
|
void ShapeWorldItemsCommand::redoChangeItem(int i, AbstractWorldItem *item)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!m_firstRun)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bool pointsMode = m_scene->isEnabledEditPoints();
|
|
|
|
|
|
|
|
m_scene->setEnabledEditPoints(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
|
|
|
|
item->setPolygon(m_undoPolygons.at(i));
|
|
|
|
item->setPolygon(m_undoPolygons.at(i));
|
|
|
|
updateGraphicsData(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
m_scene->setEnabledEditPoints(pointsMode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (int i = 0; i < m_listPaths.count(); ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Node *node = m_model->pathToNode(m_listPaths.at(i));
|
|
|
|
|
|
|
|
AbstractWorldItem *item = qvariant_cast<AbstractWorldItem *>(node->data(Constants::GRAPHICS_DATA_QT4_2D));
|
|
|
|
|
|
|
|
updateGraphicsData(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_firstRun = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} /* namespace WorldEditor */
|
|
|
|
} /* namespace WorldEditor */
|
|
|
|