[qet] qet/qet: [5050] Element editor : When open a .elmt file in the element editor, the texts field are converted to dynamic text field, except for text field with tagg : label, function and tension/protocol.

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


Revision: 5050
Author:   blacksun
Date:     2017-09-27 17:26:47 +0200 (Wed, 27 Sep 2017)
Log Message:
-----------
Element editor : When open a .elmt file in the element editor, the texts field are converted to dynamic text field, except for text field with tagg : label, function and tension/protocol.
In other words every text without tagg are converted.

Modified Paths:
--------------
    trunk/sources/editor/graphicspart/partdynamictextfield.cpp
    trunk/sources/editor/graphicspart/partdynamictextfield.h
    trunk/sources/editor/graphicspart/parttextfield.cpp
    trunk/sources/editor/graphicspart/parttextfield.h

Modified: trunk/sources/editor/graphicspart/partdynamictextfield.cpp
===================================================================
--- trunk/sources/editor/graphicspart/partdynamictextfield.cpp	2017-09-26 20:40:10 UTC (rev 5049)
+++ trunk/sources/editor/graphicspart/partdynamictextfield.cpp	2017-09-27 15:26:47 UTC (rev 5050)
@@ -23,12 +23,26 @@
 #include <QGraphicsSceneMouseEvent>
 #include <QFont>
 #include <QColor>
+#include <QMatrix>
 
 /**
  * @brief PartDynamicTextField::PartDynamicTextField
+ * Return if a dynamic text field can import information from the xml definition of a text field
  * @param editor
  * @param parent
  */
+bool PartDynamicTextField::canImportFromTextField(const QDomElement &dom_element)
+{
+	if(dom_element.tagName() != "input")
+		return false;
+	
+	QString tagg = dom_element.attribute("tagg", "none");
+	if(tagg == "none")
+		return true;
+	else
+		return false;
+}
+
 PartDynamicTextField::PartDynamicTextField(QETElementEditor *editor, QGraphicsItem *parent) :
 	QGraphicsTextItem(parent),
 	CustomElementPart(editor),
@@ -185,6 +199,35 @@
 }
 
 /**
+ * @brief PartDynamicTextField::fromTextFieldXml
+ * Setup this text from the xml definition of a text field (The xml tagg of a text field is "input");
+ * @param dom_element
+ */
+void PartDynamicTextField::fromTextFieldXml(const QDomElement &dom_element)
+{
+	if(canImportFromTextField(dom_element))
+	{
+		setFont(QETApp::diagramTextsFont(dom_element.attribute("size", QString::number(9)).toInt()));
+		setTextFrom(DynamicElementTextItem::UserText);
+		setText(dom_element.attribute("text", "_"));
+		QGraphicsTextItem::setRotation(dom_element.attribute("rotation", "0").toDouble());
+		
+			//the origin transformation point of PartDynamicTextField is the top left corner, no matter the font size
+			//The origin transformation point of PartTextField is the middle of left edge, and so by definition, change with the size of the font
+			//We need to use a QMatrix to find the pos of this text from the saved pos of text item 
+		QMatrix matrix;
+			//First make the rotation
+		matrix.rotate(dom_element.attribute("rotation", "0").toDouble());
+		QPointF pos = matrix.map(QPointF(0, -boundingRect().height()/2));
+		matrix.reset();
+			//Second translate to the pos
+		matrix.translate(dom_element.attribute("x", QString::number(0)).toDouble(),
+						 dom_element.attribute("y", QString::number(0)).toDouble());
+		QGraphicsTextItem::setPos(matrix.map(pos));
+	}
+}
+
+/**
  * @brief PartDynamicTextField::textFrom
  * @return what the final text is created from.
  */
@@ -358,12 +401,10 @@
  */
 QVariant PartDynamicTextField::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
 {
-	if (change == QGraphicsItem::ItemPositionHasChanged || change == QGraphicsItem::ItemSceneHasChanged) {
+	if (change == QGraphicsItem::ItemPositionHasChanged || change == QGraphicsItem::ItemSceneHasChanged)
 		updateCurrentPartEditor();
-	} else if (change == QGraphicsItem::ItemSelectedHasChanged) {
-		if (value.toBool() == true) {
-			updateCurrentPartEditor();
-		}
-	}
+	else if ((change == QGraphicsItem::ItemSelectedHasChanged) && (value.toBool() == true))
+		updateCurrentPartEditor();
+	
 	return(QGraphicsTextItem::itemChange(change, value));
 }

Modified: trunk/sources/editor/graphicspart/partdynamictextfield.h
===================================================================
--- trunk/sources/editor/graphicspart/partdynamictextfield.h	2017-09-26 20:40:10 UTC (rev 5049)
+++ trunk/sources/editor/graphicspart/partdynamictextfield.h	2017-09-27 15:26:47 UTC (rev 5050)
@@ -42,6 +42,9 @@
 	Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
 	
 	public:
+		static bool canImportFromTextField(const QDomElement &dom_element);
+	
+	public:
 			///PROPERTY
 		void setProperty(const char *name, const QVariant &value) override {QGraphicsTextItem::setProperty(name, value);}
 		QVariant property(const char *name) const override {return QGraphicsTextItem::property(name);}
@@ -70,6 +73,7 @@
 		
 		const QDomElement toXml(QDomDocument &dom_doc) const override;
 		void fromXml(const QDomElement &dom_elmt) override;
+		void fromTextFieldXml(const QDomElement &dom_element);
 		
 		DynamicElementTextItem::TextFrom textFrom() const;
 		void setTextFrom (DynamicElementTextItem::TextFrom text_from);

Modified: trunk/sources/editor/graphicspart/parttextfield.cpp
===================================================================
--- trunk/sources/editor/graphicspart/parttextfield.cpp	2017-09-26 20:40:10 UTC (rev 5049)
+++ trunk/sources/editor/graphicspart/parttextfield.cpp	2017-09-27 15:26:47 UTC (rev 5050)
@@ -102,14 +102,6 @@
 	return(xml_element);
 }
 
-/**
-	@return le decalage entre l'origine du QGraphicsItem et l'origine du champ de
-	texte.
-*/
-QPointF PartTextField::margin() const {
-	return(QPointF(0.0, boundingRect().bottom() / 2.0));
-}
-
 void PartTextField::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
 {
     if((event->buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable))

Modified: trunk/sources/editor/graphicspart/parttextfield.h
===================================================================
--- trunk/sources/editor/graphicspart/parttextfield.h	2017-09-26 20:40:10 UTC (rev 5049)
+++ trunk/sources/editor/graphicspart/parttextfield.h	2017-09-27 15:26:47 UTC (rev 5050)
@@ -108,7 +108,6 @@
         QRectF boundingRect() const override;
 	
 	private:
-        QPointF margin() const;
         QString previous_text;
         qreal real_font_size_;
         QPointF saved_point_;


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