[qet] qet/qet: [5273] Minor : dynamic element text item, the undo is now animated when user edit the text from the dock widget

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


Revision: 5273
Author:   blacksun
Date:     2018-03-24 14:45:48 +0100 (Sat, 24 Mar 2018)
Log Message:
-----------
Minor : dynamic element text item, the undo is now animated when user edit the text from the dock widget 

Modified Paths:
--------------
    trunk/sources/QPropertyUndoCommand/qpropertyundocommand.cpp
    trunk/sources/QPropertyUndoCommand/qpropertyundocommand.h
    trunk/sources/ui/dynamicelementtextmodel.cpp

Modified: trunk/sources/QPropertyUndoCommand/qpropertyundocommand.cpp
===================================================================
--- trunk/sources/QPropertyUndoCommand/qpropertyundocommand.cpp	2018-03-20 10:59:39 UTC (rev 5272)
+++ trunk/sources/QPropertyUndoCommand/qpropertyundocommand.cpp	2018-03-24 13:45:48 UTC (rev 5273)
@@ -31,8 +31,7 @@
 	m_object(object),
 	m_property_name(property_name),
 	m_old_value(old_value),
-	m_new_value(new_value),
-	m_animate(false)
+	m_new_value(new_value)
 {}
 
 /**
@@ -48,8 +47,7 @@
 	QUndoCommand(parent),
 	m_object(object),
 	m_property_name(property_name),
-	m_old_value(old_value),
-	m_animate(false)
+	m_old_value(old_value)
 {}
 
 QPropertyUndoCommand::QPropertyUndoCommand(const QPropertyUndoCommand *other)
@@ -59,6 +57,7 @@
 	m_old_value     = other->m_old_value;
 	m_new_value     = other->m_new_value;
 	m_animate       = other->m_animate;
+	m_first_time    = other->m_first_time;
 	setText(other->text());
 }
 
@@ -81,6 +80,18 @@
 }
 
 /**
+ * @brief QPropertyUndoCommand::setAnimated
+ * @param animate = true for animate this undo
+ * @param first_time = if true, the first animation is done at the first call of redo  
+ * if false, the first animation is done at the second call of redo.
+ */
+void QPropertyUndoCommand::setAnimated(bool animate, bool first_time)
+{
+	m_animate = animate;
+	m_first_time = first_time;
+}
+
+/**
  * @brief QPropertyUndoCommand::mergeWith
  * Try to merge this command with other command
  * @param other
@@ -103,7 +114,7 @@
 {
 	if (m_object->property(m_property_name) != m_new_value)
 	{
-		if (m_animate)
+		if (m_animate && m_first_time)
 		{
 			QPropertyAnimation *animation = new QPropertyAnimation(m_object, m_property_name);
 			animation->setStartValue(m_old_value);
@@ -111,7 +122,10 @@
 			animation->start(QAbstractAnimation::DeleteWhenStopped);
 		}
 		else
+		{
 			m_object->setProperty(m_property_name, m_new_value);
+			m_first_time = true;
+		}
 	}
 
 	QUndoCommand::redo();

Modified: trunk/sources/QPropertyUndoCommand/qpropertyundocommand.h
===================================================================
--- trunk/sources/QPropertyUndoCommand/qpropertyundocommand.h	2018-03-20 10:59:39 UTC (rev 5272)
+++ trunk/sources/QPropertyUndoCommand/qpropertyundocommand.h	2018-03-24 13:45:48 UTC (rev 5273)
@@ -39,6 +39,7 @@
 
 		void setNewValue(const QVariant &new_value);
 		void enableAnimation (bool animate = true);
+		void setAnimated(bool animate = true, bool first_time = true);
 
 		int id() const override{return 10000;}
 		bool mergeWith(const QUndoCommand *other) override;
@@ -46,10 +47,11 @@
 		void undo() override;
 
 	private:
-		QObject *m_object;
+		QObject *m_object = nullptr;
 		const char *m_property_name;
 		QVariant m_old_value, m_new_value;
-		bool m_animate;
+		bool m_animate = false,
+			 m_first_time = true;
 };
 
 #endif // QPROPERTYUNDOCOMMAND_H

Modified: trunk/sources/ui/dynamicelementtextmodel.cpp
===================================================================
--- trunk/sources/ui/dynamicelementtextmodel.cpp	2018-03-20 10:59:39 UTC (rev 5272)
+++ trunk/sources/ui/dynamicelementtextmodel.cpp	2018-03-24 13:45:48 UTC (rev 5273)
@@ -454,7 +454,8 @@
 	int fs = text_qsi->child(size_txt_row,1)->data(Qt::EditRole).toInt();
 	if (fs != deti->fontSize())
 	{
-		QUndoCommand *quc = new QPropertyUndoCommand(deti, "fontSize", QVariant(deti->fontSize()), QVariant(fs), undo);
+		QPropertyUndoCommand *quc = new QPropertyUndoCommand(deti, "fontSize", QVariant(deti->fontSize()), QVariant(fs), undo);
+		quc->setAnimated(true, false);
 		quc->setText(tr("Modifier la taille d'un texte d'élément"));
 	}
 	
@@ -475,7 +476,8 @@
 	qreal text_width = text_qsi->child(width_txt_row, 1)->data(Qt::EditRole).toDouble();
 	if(text_width != deti->textWidth())
 	{
-		QUndoCommand *quc = new QPropertyUndoCommand(deti, "textWidth", QVariant(deti->textWidth()), QVariant(text_width), undo);
+		QPropertyUndoCommand *quc = new QPropertyUndoCommand(deti, "textWidth", QVariant(deti->textWidth()), QVariant(text_width), undo);
+		quc->setAnimated(true, false);
 		quc->setText(tr("Modifier la largeur d'un texte d'élément"));
 	}
 	
@@ -487,6 +489,7 @@
 		if(p != deti->pos())
 		{
 			QPropertyUndoCommand *quc = new QPropertyUndoCommand(deti, "pos", QVariant(deti->pos()), QVariant(p), undo);
+			quc->setAnimated(true, false);
 			quc->setText(tr("Déplacer un texte d'élément"));
 		}
 	}
@@ -498,6 +501,7 @@
 		if(rot != deti->rotation())
 		{
 			QPropertyUndoCommand *quc = new QPropertyUndoCommand(deti, "rotation", QVariant(deti->rotation()), QVariant(rot), undo);
+			quc->setAnimated(true, false);
 			quc->setText(tr("Pivoter un texte d'élément"));
 		}
 	}
@@ -536,7 +540,10 @@
 	
 	qreal rotation = group_qsi->child(rot_grp_row,1)->data(Qt::EditRole).toDouble();
 	if(group->rotation() != rotation)
-		new QPropertyUndoCommand(group, "rotation", QVariant(group->rotation()), QVariant(rotation), undo);
+	{
+		QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(group, "rotation", QVariant(group->rotation()), QVariant(rotation), undo);
+		qpuc->enableAnimation();
+	}
 	
 	int v_adjustment = group_qsi->child(adjust_grp_row,1)->data(Qt::EditRole).toInt();
 	if(group->verticalAdjustment() != v_adjustment)


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