[qet] [4060] Element editor : Add animation for some undo/redo

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 4060
Author:   blacksun
Date:     2015-07-20 23:06:00 +0200 (Mon, 20 Jul 2015)
Log Message:
-----------
Element editor : Add animation for some undo/redo

Modified Paths:
--------------
    trunk/dev_doc/ID_of_QUndoCommand.txt
    trunk/qelectrotech.pro
    trunk/sources/editor/esevent/eseventaddpolygon.cpp
    trunk/sources/editor/graphicspart/customelementgraphicpart.cpp
    trunk/sources/editor/graphicspart/partarc.cpp
    trunk/sources/editor/graphicspart/partarc.h
    trunk/sources/editor/graphicspart/partellipse.cpp
    trunk/sources/editor/graphicspart/partellipse.h
    trunk/sources/editor/graphicspart/partline.cpp
    trunk/sources/editor/graphicspart/partline.h
    trunk/sources/editor/graphicspart/partpolygon.cpp
    trunk/sources/editor/graphicspart/partpolygon.h
    trunk/sources/editor/graphicspart/partrectangle.cpp
    trunk/sources/editor/graphicspart/partrectangle.h

Added Paths:
-----------
    trunk/sources/QPropertyUndoCommand/
    trunk/sources/QPropertyUndoCommand/QPropertyUndoCommand.pri
    trunk/sources/QPropertyUndoCommand/qpropertyundocommand.cpp
    trunk/sources/QPropertyUndoCommand/qpropertyundocommand.h

Modified: trunk/dev_doc/ID_of_QUndoCommand.txt
===================================================================
--- trunk/dev_doc/ID_of_QUndoCommand.txt	2015-07-20 19:16:12 UTC (rev 4059)
+++ trunk/dev_doc/ID_of_QUndoCommand.txt	2015-07-20 21:06:00 UTC (rev 4060)
@@ -3,3 +3,4 @@
 ItemResizerCommand = 3
 ChangeShapeStyleCommand = 4
 QetShapeGeometryCommand = 5
+QPropertyUndoCommand = 10 000

Modified: trunk/qelectrotech.pro
===================================================================
--- trunk/qelectrotech.pro	2015-07-20 19:16:12 UTC (rev 4059)
+++ trunk/qelectrotech.pro	2015-07-20 21:06:00 UTC (rev 4060)
@@ -63,6 +63,7 @@
 
 include(sources/PropertiesEditor/PropertiesEditor.pri)
 include(sources/QetGraphicsItemModeler/QetGraphicsItemModeler.pri)
+include(sources/QPropertyUndoCommand/QPropertyUndoCommand.pri)
 
 TEMPLATE = app
 DEPENDPATH += .

Added: trunk/sources/QPropertyUndoCommand/QPropertyUndoCommand.pri
===================================================================
--- trunk/sources/QPropertyUndoCommand/QPropertyUndoCommand.pri	                        (rev 0)
+++ trunk/sources/QPropertyUndoCommand/QPropertyUndoCommand.pri	2015-07-20 21:06:00 UTC (rev 4060)
@@ -0,0 +1,5 @@
+HEADERS += \
+    $$PWD/qpropertyundocommand.h
+
+SOURCES += \
+    $$PWD/qpropertyundocommand.cpp


Property changes on: trunk/sources/QPropertyUndoCommand/QPropertyUndoCommand.pri
___________________________________________________________________
Added: svn:executable
   + *

Added: trunk/sources/QPropertyUndoCommand/qpropertyundocommand.cpp
===================================================================
--- trunk/sources/QPropertyUndoCommand/qpropertyundocommand.cpp	                        (rev 0)
+++ trunk/sources/QPropertyUndoCommand/qpropertyundocommand.cpp	2015-07-20 21:06:00 UTC (rev 4060)
@@ -0,0 +1,138 @@
+/*
+	Copyright 2006-2015 The QElectroTech Team
+	This file is part of QElectroTech.
+
+	QElectroTech is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	QElectroTech is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "qpropertyundocommand.h"
+#include <QAnimationGroup>
+
+/**
+ * @brief QPropertyUndoCommand::QPropertyUndoCommand
+ * Default constructor with old and new value
+ * This command don't take ownership of @object
+ * @param object
+ * @param old_value
+ * @param new_value
+ */
+QPropertyUndoCommand::QPropertyUndoCommand(QObject *object, const char *property_name, const QVariant &old_value, const QVariant &new_value, QUndoCommand *parent) :
+	QUndoCommand(parent),
+	m_object(object),
+	m_property_name(property_name),
+	m_old_value(old_value),
+	m_new_value(new_value),
+	m_animate(false)
+{
+	m_animation.setTargetObject(object);
+	m_animation.setPropertyName(property_name);
+	m_animation.setStartValue(old_value);
+	m_animation.setEndValue(new_value);
+}
+
+/**
+ * @brief QPropertyUndoCommand::QPropertyUndoCommand
+ * Default constructor with old value.
+ * Call setNewValue to setup the new value of the edited QObject
+ * This command don't take ownership of @object
+ * @param object
+ * @param old_value
+ * @param parent
+ */
+QPropertyUndoCommand::QPropertyUndoCommand(QObject *object, const char *property_name, const QVariant &old_value, QUndoCommand *parent) :
+	QUndoCommand(parent),
+	m_object(object),
+	m_property_name(property_name),
+	m_old_value(old_value),
+	m_animate(false)
+{
+	m_animation.setTargetObject(object);
+	m_animation.setPropertyName(property_name);
+	m_animation.setStartValue(old_value);
+}
+
+/**
+ * @brief QPropertyUndoCommand::setNewValue
+ * Set the new value of the property (set with redo) to @new_value
+ * @param new_value
+ */
+void QPropertyUndoCommand::setNewValue(const QVariant &new_value)
+{
+	m_new_value = new_value;
+	m_animation.setEndValue(new_value);
+}
+
+/**
+ * @brief QPropertyUndoCommand::enableAnimation
+ * True to enable animation
+ * @param animate
+ */
+void QPropertyUndoCommand::enableAnimation (bool animate) {
+	m_animate = animate;
+}
+
+/**
+ * @brief QPropertyUndoCommand::mergeWith
+ * Try to merge this command with other command
+ * @param other
+ * @return true if was merged, else false
+ */
+bool QPropertyUndoCommand::mergeWith(const QUndoCommand *other)
+{
+	if (id() != other->id() || other->childCount()) return false;
+	QPropertyUndoCommand const *undo = static_cast<const QPropertyUndoCommand *>(other);
+	if (m_object != undo->m_object || m_property_name != undo->m_property_name) return false;
+	m_new_value = undo->m_new_value;
+	m_animation.setEndValue(m_new_value);
+	return true;
+}
+
+/**
+ * @brief QPropertyUndoCommand::redo
+ * Redo this command
+ */
+void QPropertyUndoCommand::redo()
+{
+	if (m_object->property(m_property_name) != m_new_value)
+	{
+		if (m_animate)
+		{
+			m_animation.setDirection(QAnimationGroup::Forward);
+			m_animation.start();
+		}
+		else
+			m_object->setProperty(m_property_name, m_new_value);
+	}
+
+	QUndoCommand::redo();
+}
+
+/**
+ * @brief QPropertyUndoCommand::undo
+ * Undo this command
+ */
+void QPropertyUndoCommand::undo()
+{
+	if (m_object->property(m_property_name) != m_old_value)
+	{
+		if (m_animate)
+		{
+			m_animation.setDirection(QAnimationGroup::Backward);
+			m_animation.start();
+		}
+		else
+			m_object->setProperty(m_property_name, m_old_value);
+	}
+
+	QUndoCommand::undo();
+}

Added: trunk/sources/QPropertyUndoCommand/qpropertyundocommand.h
===================================================================
--- trunk/sources/QPropertyUndoCommand/qpropertyundocommand.h	                        (rev 0)
+++ trunk/sources/QPropertyUndoCommand/qpropertyundocommand.h	2015-07-20 21:06:00 UTC (rev 4060)
@@ -0,0 +1,56 @@
+/*
+	Copyright 2006-2015 The QElectroTech Team
+	This file is part of QElectroTech.
+
+	QElectroTech is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	QElectroTech is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef QPROPERTYUNDOCOMMAND_H
+#define QPROPERTYUNDOCOMMAND_H
+
+#include <QUndoCommand>
+#include <QVariant>
+#include <QPropertyAnimation>
+
+class QObject;
+
+/**
+ * @brief The QPropertyUndoCommand class
+ * This undo command manage QProperty of a QObject.
+ * This undo command can use QPropertyAnimation to animate the change when undo/redo is call
+ * To use animation call setAnimated(true). By default animation is disable.
+ * Some QVariant date can't be animated and result this command don't work.
+ */
+class QPropertyUndoCommand : public QUndoCommand
+{
+	public:
+		QPropertyUndoCommand(QObject *object, const char *property_name, const QVariant &old_value, const QVariant &new_value, QUndoCommand *parent = 0);
+		QPropertyUndoCommand(QObject *object, const char *property_name, const QVariant &old_value, QUndoCommand *parent = 0);
+
+		void setNewValue(const QVariant &new_value);
+		void enableAnimation (bool animate = true);
+
+		int id() const{return 10000;}
+		virtual bool mergeWith(const QUndoCommand *other);
+		void redo();
+		void undo();
+
+	private:
+		QObject *m_object;
+		const char *m_property_name;
+		QVariant m_old_value, m_new_value;
+		bool m_animate;
+		QPropertyAnimation m_animation;
+};
+
+#endif // QPROPERTYUNDOCOMMAND_H

Modified: trunk/sources/editor/esevent/eseventaddpolygon.cpp
===================================================================
--- trunk/sources/editor/esevent/eseventaddpolygon.cpp	2015-07-20 19:16:12 UTC (rev 4059)
+++ trunk/sources/editor/esevent/eseventaddpolygon.cpp	2015-07-20 21:06:00 UTC (rev 4060)
@@ -103,13 +103,16 @@
  * @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;
 		}

Modified: trunk/sources/editor/graphicspart/customelementgraphicpart.cpp
===================================================================
--- trunk/sources/editor/graphicspart/customelementgraphicpart.cpp	2015-07-20 19:16:12 UTC (rev 4059)
+++ trunk/sources/editor/graphicspart/customelementgraphicpart.cpp	2015-07-20 21:06:00 UTC (rev 4060)
@@ -17,7 +17,7 @@
 */
 #include "customelementgraphicpart.h"
 #include "elementscene.h"
-#include "editorcommands.h"
+#include "QPropertyUndoCommand/qpropertyundocommand.h"
 
 /**
  * @brief CustomElementGraphicPart::CustomElementGraphicPart
@@ -40,7 +40,6 @@
 #if QT_VERSION >= 0x040600
 	setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
 #endif
-	setAcceptedMouseButtons(Qt::LeftButton);
 	setAcceptHoverEvents(true);
 }
 
@@ -462,7 +461,12 @@
 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);
 }

Modified: trunk/sources/editor/graphicspart/partarc.cpp
===================================================================
--- trunk/sources/editor/graphicspart/partarc.cpp	2015-07-20 19:16:12 UTC (rev 4059)
+++ trunk/sources/editor/graphicspart/partarc.cpp	2015-07-20 21:06:00 UTC (rev 4060)
@@ -16,8 +16,10 @@
 	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
  * Constructor
@@ -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 @@
 		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 @@
 			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;
 	}

Modified: trunk/sources/editor/graphicspart/partarc.h
===================================================================
--- trunk/sources/editor/graphicspart/partarc.h	2015-07-20 19:16:12 UTC (rev 4059)
+++ trunk/sources/editor/graphicspart/partarc.h	2015-07-20 21:06:00 UTC (rev 4060)
@@ -21,7 +21,7 @@
 #include "abstractpartellipse.h"
 #include "QetGraphicsItemModeler/qetgraphicshandlerutility.h"
 
-class ChangePartCommand;
+class QPropertyUndoCommand;
 
 /**
  * @brief The PartArc class
@@ -65,6 +65,6 @@
 	private:
 		QetGraphicsHandlerUtility m_handler;
 		int m_handler_index;
-		ChangePartCommand *m_undo_command;
+		QPropertyUndoCommand *m_undo_command;
 };
 #endif

Modified: trunk/sources/editor/graphicspart/partellipse.cpp
===================================================================
--- trunk/sources/editor/graphicspart/partellipse.cpp	2015-07-20 19:16:12 UTC (rev 4059)
+++ trunk/sources/editor/graphicspart/partellipse.cpp	2015-07-20 21:06:00 UTC (rev 4060)
@@ -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 @@
 		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 @@
 			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;
 	}

Modified: trunk/sources/editor/graphicspart/partellipse.h
===================================================================
--- trunk/sources/editor/graphicspart/partellipse.h	2015-07-20 19:16:12 UTC (rev 4059)
+++ trunk/sources/editor/graphicspart/partellipse.h	2015-07-20 21:06:00 UTC (rev 4060)
@@ -21,7 +21,7 @@
 #include "abstractpartellipse.h"
 #include "QetGraphicsItemModeler/qetgraphicshandlerutility.h"
 
-class ChangePartCommand;
+class QPropertyUndoCommand;
 
 /**
  * @brief The PartEllipse class
@@ -66,6 +66,6 @@
 	private:
 		QetGraphicsHandlerUtility m_handler;
 		int m_handler_index;
-		ChangePartCommand *m_undo_command;
+		QPropertyUndoCommand *m_undo_command;
 };
 #endif

Modified: trunk/sources/editor/graphicspart/partline.cpp
===================================================================
--- trunk/sources/editor/graphicspart/partline.cpp	2015-07-20 19:16:12 UTC (rev 4059)
+++ trunk/sources/editor/graphicspart/partline.cpp	2015-07-20 21:06:00 UTC (rev 4060)
@@ -17,7 +17,8 @@
 */
 #include "partline.h"
 #include <cmath>
-#include "editorcommands.h"
+#include "elementscene.h"
+#include "QPropertyUndoCommand/qpropertyundocommand.h"
 
 
 /**
@@ -33,7 +34,8 @@
 	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 @@
 		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 @@
 	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;
 	}

Modified: trunk/sources/editor/graphicspart/partline.h
===================================================================
--- trunk/sources/editor/graphicspart/partline.h	2015-07-20 19:16:12 UTC (rev 4059)
+++ trunk/sources/editor/graphicspart/partline.h	2015-07-20 21:06:00 UTC (rev 4060)
@@ -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 @@
 		QLineF m_line;
 		QetGraphicsHandlerUtility m_handler;
 		int m_handler_index;
-		ChangePartCommand *m_undo_command;
+		QPropertyUndoCommand *m_undo_command;
 };
 #endif

Modified: trunk/sources/editor/graphicspart/partpolygon.cpp
===================================================================
--- trunk/sources/editor/graphicspart/partpolygon.cpp	2015-07-20 19:16:12 UTC (rev 4059)
+++ trunk/sources/editor/graphicspart/partpolygon.cpp	2015-07-20 21:06:00 UTC (rev 4060)
@@ -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 @@
 	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 @@
 		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 @@
 	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;
 	}

Modified: trunk/sources/editor/graphicspart/partpolygon.h
===================================================================
--- trunk/sources/editor/graphicspart/partpolygon.h	2015-07-20 19:16:12 UTC (rev 4059)
+++ trunk/sources/editor/graphicspart/partpolygon.h	2015-07-20 21:06:00 UTC (rev 4060)
@@ -23,7 +23,7 @@
 #include "QetGraphicsItemModeler/qetgraphicshandlerutility.h"
 
 
-class ChangePartCommand;
+class QPropertyUndoCommand;
 
 /**
  * @brief The PartPolygon class
@@ -90,6 +90,6 @@
 		QPolygonF m_polygon;
 		QetGraphicsHandlerUtility m_handler;
 		int m_handler_index;
-		ChangePartCommand *m_undo_command;
+		QPropertyUndoCommand *m_undo_command;
 };
 #endif

Modified: trunk/sources/editor/graphicspart/partrectangle.cpp
===================================================================
--- trunk/sources/editor/graphicspart/partrectangle.cpp	2015-07-20 19:16:12 UTC (rev 4059)
+++ trunk/sources/editor/graphicspart/partrectangle.cpp	2015-07-20 21:06:00 UTC (rev 4060)
@@ -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 @@
 		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 @@
 			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;
 	}

Modified: trunk/sources/editor/graphicspart/partrectangle.h
===================================================================
--- trunk/sources/editor/graphicspart/partrectangle.h	2015-07-20 19:16:12 UTC (rev 4059)
+++ trunk/sources/editor/graphicspart/partrectangle.h	2015-07-20 21:06:00 UTC (rev 4060)
@@ -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 @@
 		QList<QPointF> saved_points_;
 		QetGraphicsHandlerUtility m_handler;
 		int m_handler_index;
-		ChangePartCommand *m_undo_command;
+		QPropertyUndoCommand *m_undo_command;
 };
 #endif


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/