Element editor : Add animation for some undo/redo

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4060 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2015-07-20 21:06:00 +00:00
parent 50d98b2167
commit 012ba2ccd7
17 changed files with 278 additions and 39 deletions

View File

@@ -103,13 +103,16 @@ bool ESEventAddPolygon::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
* @param event
* @return
*/
bool ESEventAddPolygon::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
if (event -> button() == Qt::LeftButton) {
if (m_polygon) {
m_polygon -> addPoint(m_scene -> snapToGrid(event -> scenePos()));
bool ESEventAddPolygon::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
if (event -> button() == Qt::LeftButton)
{
if (m_polygon)
{
m_polygon->removeLastPoint();
m_scene -> undoStack().push(new AddPartCommand(QObject::tr("Polygone"), m_scene, m_polygon));
//Set m_polygon to nullptr for create new polygon at next mouse press
//Set m_polygon to nullptr for create new polygon at next mouse press
m_polygon = nullptr;
return true;
}

View File

@@ -17,7 +17,7 @@
*/
#include "customelementgraphicpart.h"
#include "elementscene.h"
#include "editorcommands.h"
#include "QPropertyUndoCommand/qpropertyundocommand.h"
/**
* @brief CustomElementGraphicPart::CustomElementGraphicPart
@@ -40,7 +40,6 @@ CustomElementGraphicPart::CustomElementGraphicPart(QETElementEditor *editor, QGr
#if QT_VERSION >= 0x040600
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
#endif
setAcceptedMouseButtons(Qt::LeftButton);
setAcceptHoverEvents(true);
}
@@ -462,7 +461,12 @@ void CustomElementGraphicPart::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void CustomElementGraphicPart::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if((event->button() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable) && m_origin_pos != pos())
elementScene()->stackAction(new MovePartsCommand(pos() - m_origin_pos, 0, QList<QGraphicsItem*>{this}));
{
QPropertyUndoCommand *undo = new QPropertyUndoCommand(this, "pos", QVariant(m_origin_pos), QVariant(pos()));
undo->setText(tr("Déplacer une primitive"));
undo->enableAnimation();
elementScene()->undoStack().push(undo);
}
QGraphicsObject::mouseReleaseEvent(event);
}

View File

@@ -16,7 +16,9 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "partarc.h"
#include "editorcommands.h"
#include "QPropertyUndoCommand/qpropertyundocommand.h"
#include "elementscene.h"
/**
* @brief PartArc::PartArc
@@ -27,7 +29,8 @@
PartArc::PartArc(QETElementEditor *editor, QGraphicsItem *parent) :
AbstractPartEllipse(editor, parent),
m_handler(10),
m_handler_index(-1)
m_handler_index(-1),
m_undo_command(nullptr)
{
m_start_angle = 0;
m_span_angle = -1440;
@@ -152,7 +155,11 @@ void PartArc::mousePressEvent(QGraphicsSceneMouseEvent *event)
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
if(m_handler_index >= 0 && m_handler_index <= 7) //User click on an handler
m_undo_command = new ChangePartCommand(tr("Arc"), this, "rect", QVariant(m_rect));
{
m_undo_command = new QPropertyUndoCommand(this, "rect", QVariant(m_rect));
m_undo_command->setText(tr("Modifier un arc"));
m_undo_command->enableAnimation();
}
else
CustomElementGraphicPart::mousePressEvent(event);
}
@@ -190,7 +197,7 @@ void PartArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
m_rect = m_rect.normalized();
m_undo_command->setNewValue(QVariant(m_rect));
elementScene()->stackAction(m_undo_command);
elementScene()->undoStack().push(m_undo_command);
m_undo_command = nullptr;
m_handler_index = -1;
}

View File

@@ -21,7 +21,7 @@
#include "abstractpartellipse.h"
#include "QetGraphicsItemModeler/qetgraphicshandlerutility.h"
class ChangePartCommand;
class QPropertyUndoCommand;
/**
* @brief The PartArc class
@@ -65,6 +65,6 @@ class PartArc : public AbstractPartEllipse
private:
QetGraphicsHandlerUtility m_handler;
int m_handler_index;
ChangePartCommand *m_undo_command;
QPropertyUndoCommand *m_undo_command;
};
#endif

View File

@@ -16,7 +16,8 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "partellipse.h"
#include "editorcommands.h"
#include "QPropertyUndoCommand/qpropertyundocommand.h"
#include "elementscene.h"
/**
* @brief PartEllipse::PartEllipse
@@ -27,7 +28,8 @@
PartEllipse::PartEllipse(QETElementEditor *editor, QGraphicsItem *parent) :
AbstractPartEllipse(editor, parent),
m_handler(10),
m_handler_index(-1)
m_handler_index(-1),
m_undo_command(nullptr)
{}
/**
@@ -155,7 +157,11 @@ void PartEllipse::mousePressEvent(QGraphicsSceneMouseEvent *event)
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
if(m_handler_index >= 0 && m_handler_index <= 7) //User click on an handler
m_undo_command = new ChangePartCommand(tr("Ellipse"), this, "rect", QVariant(m_rect));
{
m_undo_command = new QPropertyUndoCommand(this, "rect", QVariant(m_rect));
m_undo_command->setText(tr("Modifier une ellipse"));
m_undo_command->enableAnimation();
}
else
CustomElementGraphicPart::mousePressEvent(event);
}
@@ -193,7 +199,7 @@ void PartEllipse::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
m_rect = m_rect.normalized();
m_undo_command->setNewValue(QVariant(m_rect));
elementScene()->stackAction(m_undo_command);
elementScene()->undoStack().push(m_undo_command);
m_undo_command = nullptr;
m_handler_index = -1;
}

View File

@@ -21,7 +21,7 @@
#include "abstractpartellipse.h"
#include "QetGraphicsItemModeler/qetgraphicshandlerutility.h"
class ChangePartCommand;
class QPropertyUndoCommand;
/**
* @brief The PartEllipse class
@@ -66,6 +66,6 @@ class PartEllipse : public AbstractPartEllipse
private:
QetGraphicsHandlerUtility m_handler;
int m_handler_index;
ChangePartCommand *m_undo_command;
QPropertyUndoCommand *m_undo_command;
};
#endif

View File

@@ -17,7 +17,8 @@
*/
#include "partline.h"
#include <cmath>
#include "editorcommands.h"
#include "elementscene.h"
#include "QPropertyUndoCommand/qpropertyundocommand.h"
/**
@@ -33,7 +34,8 @@ PartLine::PartLine(QETElementEditor *editor, QGraphicsItem *parent) :
second_end(Qet::None),
second_length(1.5),
m_handler(10),
m_handler_index(-1)
m_handler_index(-1),
m_undo_command(nullptr)
{}
/// Destructeur
@@ -189,7 +191,11 @@ void PartLine::mousePressEvent(QGraphicsSceneMouseEvent *event)
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForLine(m_line));
if(m_handler_index >= 0 && m_handler_index <= 1) //User click on an handler
m_undo_command = new ChangePartCommand(tr("Ligne"), this, "line", QVariant(m_line));
{
m_undo_command = new QPropertyUndoCommand(this, "line", QVariant(m_line));
m_undo_command->setText(tr("Modifier une ligne"));
m_undo_command->enableAnimation();
}
else
CustomElementGraphicPart::mousePressEvent(event);
}
@@ -224,7 +230,7 @@ void PartLine::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
if (m_handler_index >= 0 && m_handler_index <= 1)
{
m_undo_command->setNewValue(QVariant(m_line));
elementScene()->stackAction(m_undo_command);
elementScene()->undoStack().push(m_undo_command);
m_undo_command = nullptr;
m_handler_index = -1;
}

View File

@@ -22,7 +22,7 @@
#include "qet.h"
#include "QetGraphicsItemModeler/qetgraphicshandlerutility.h"
class ChangePartCommand;
class QPropertyUndoCommand;
/**
This class represents a line primitive which may be used to compose the
@@ -119,6 +119,6 @@ class PartLine : public CustomElementGraphicPart
QLineF m_line;
QetGraphicsHandlerUtility m_handler;
int m_handler_index;
ChangePartCommand *m_undo_command;
QPropertyUndoCommand *m_undo_command;
};
#endif

View File

@@ -16,7 +16,8 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "partpolygon.h"
#include "editorcommands.h"
#include "QPropertyUndoCommand/qpropertyundocommand.h"
#include "elementscene.h"
/**
@@ -29,13 +30,16 @@ PartPolygon::PartPolygon(QETElementEditor *editor, QGraphicsItem *parent) :
CustomElementGraphicPart(editor, parent),
m_closed(false),
m_handler(10),
m_handler_index(-1)
m_handler_index(-1),
m_undo_command(nullptr)
{}
/**
* @brief PartPolygon::~PartPolygon
*/
PartPolygon::~PartPolygon() {}
PartPolygon::~PartPolygon() {
if(m_undo_command) delete m_undo_command;
}
/**
* @brief PartPolygon::paint
@@ -247,7 +251,10 @@ void PartPolygon::mousePressEvent(QGraphicsSceneMouseEvent *event)
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_polygon);
if(m_handler_index >= 0) //User click on an handler
m_undo_command = new ChangePartCommand(tr("Polygone"), this, "polygon", QVariant(m_polygon));
{
m_undo_command = new QPropertyUndoCommand(this, "polygon", QVariant(m_polygon));
m_undo_command->setText(tr("Modifier un polygone"));
}
else
CustomElementGraphicPart::mousePressEvent(event);
}
@@ -282,7 +289,7 @@ void PartPolygon::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
if (m_handler_index >= 0)
{
m_undo_command->setNewValue(QVariant(m_polygon));
elementScene()->stackAction(m_undo_command);
elementScene()->undoStack().push(m_undo_command);
m_undo_command = nullptr;
m_handler_index = -1;
}

View File

@@ -23,7 +23,7 @@
#include "QetGraphicsItemModeler/qetgraphicshandlerutility.h"
class ChangePartCommand;
class QPropertyUndoCommand;
/**
* @brief The PartPolygon class
@@ -90,6 +90,6 @@ class PartPolygon : public CustomElementGraphicPart
QPolygonF m_polygon;
QetGraphicsHandlerUtility m_handler;
int m_handler_index;
ChangePartCommand *m_undo_command;
QPropertyUndoCommand *m_undo_command;
};
#endif

View File

@@ -17,7 +17,7 @@
*/
#include "partrectangle.h"
#include "elementscene.h"
#include "editorcommands.h"
#include "QPropertyUndoCommand/qpropertyundocommand.h"
/**
* @brief PartRectangle::PartRectangle
@@ -28,7 +28,8 @@
PartRectangle::PartRectangle(QETElementEditor *editor, QGraphicsItem *parent) :
CustomElementGraphicPart(editor, parent),
m_handler(10),
m_handler_index(-1)
m_handler_index(-1),
m_undo_command(nullptr)
{}
/**
@@ -268,7 +269,11 @@ void PartRectangle::mousePressEvent(QGraphicsSceneMouseEvent *event)
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
if(m_handler_index >= 0 && m_handler_index <= 7) //User click on an handler
m_undo_command = new ChangePartCommand(tr("Rectangle"), this, "rect", QVariant(m_rect));
{
m_undo_command = new QPropertyUndoCommand(this, "rect", QVariant(m_rect));
m_undo_command->setText(tr("Modifier un rectangle"));
m_undo_command->enableAnimation();
}
else
CustomElementGraphicPart::mousePressEvent(event);
}
@@ -306,7 +311,7 @@ void PartRectangle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
m_rect = m_rect.normalized();
m_undo_command->setNewValue(QVariant(m_rect));
elementScene()->stackAction(m_undo_command);
elementScene()->undoStack().push(m_undo_command);
m_undo_command = nullptr;
m_handler_index = -1;
}

View File

@@ -21,7 +21,7 @@
#include "customelementgraphicpart.h"
#include "QetGraphicsItemModeler/qetgraphicshandlerutility.h"
class ChangePartCommand;
class QPropertyUndoCommand;
/**
* This class represents a rectangle primitive which may be used to compose the
@@ -92,6 +92,6 @@ class PartRectangle : public CustomElementGraphicPart
QList<QPointF> saved_points_;
QetGraphicsHandlerUtility m_handler;
int m_handler_index;
ChangePartCommand *m_undo_command;
QPropertyUndoCommand *m_undo_command;
};
#endif