[qet] [2553] element editor bug fix:

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


Revision: 2553
Author:   blacksun
Date:     2013-09-21 15:09:23 +0200 (Sat, 21 Sep 2013)
Log Message:
-----------
element editor bug fix:
at save, if element aren't drawn at the origin point (red cross),
we move element to the nearest point of origin

Modified Paths:
--------------
    trunk/sources/editor/elementscene.cpp
    trunk/sources/editor/elementscene.h
    trunk/sources/editor/elementview.cpp

Modified: trunk/sources/editor/elementscene.cpp
===================================================================
--- trunk/sources/editor/elementscene.cpp	2013-09-21 07:25:37 UTC (rev 2552)
+++ trunk/sources/editor/elementscene.cpp	2013-09-21 13:09:23 UTC (rev 2553)
@@ -385,9 +385,17 @@
 	representer tout l'element ou seulement les elements selectionnes
 	@return un document XML decrivant l'element
 */
-const QDomDocument ElementScene::toXml(bool all_parts) const {
+const QDomDocument ElementScene::toXml(bool all_parts) {
+	QRectF size= elementSceneGeometricRect();
+	//if the element doesn't contains the origin point of the scene
+	//we move the element to the origin for solve this default before saving
+	if (!size.contains(0,0) && all_parts) {
+		centerElementToOrigine();
+		//recalcul the size after movement
+		size= elementSceneGeometricRect();
+	}
+
 	//define the size of the element by the upper multiple of 10
-	QRectF size= elementSceneGeometricRect();
 	int upwidth = ((qRound(size.width())/10)*10)+10;
 	if ((qRound(size.width())%10) > 6) upwidth+=10;
 
@@ -1149,6 +1157,33 @@
 }
 
 /**
+ * @brief ElementScene::centerElementToOrigine
+ * try to center better is possible the element to the scene
+ * (the calcul isn't optimal but work good)
+ */
+void ElementScene::centerElementToOrigine() {
+	QRectF size= elementSceneGeometricRect();
+	int center_x = qRound(size.center().x());
+	int center_y = qRound(size.center().y());
+
+	//define the movement of translation
+	int move_x = center_x - (qRound(center_x) %10);
+	if (center_x < 0) move_x -= 10;
+	int move_y = center_y - (qRound(center_y) %10);
+	if (center_y < 0) move_y -= 10;
+
+		//move each primitive by @move
+		foreach (QGraphicsItem *qgi, items()) {
+			if (qgi -> type() == ElementPrimitiveDecorator::Type) continue;
+			if (qgi -> type() == QGraphicsRectItem::Type) continue;
+			//deselect item for disable decorator
+			qgi -> setSelected(false);
+			qgi -> moveBy(-(move_x), -(move_y));
+		}
+		emit (needZoomFit());
+}
+
+/**
 	Ensure the decorator is adequately shown, hidden or updated so it always
 	represents the current selection.
 */

Modified: trunk/sources/editor/elementscene.h
===================================================================
--- trunk/sources/editor/elementscene.h	2013-09-21 07:25:37 UTC (rev 2552)
+++ trunk/sources/editor/elementscene.h	2013-09-21 13:09:23 UTC (rev 2553)
@@ -121,7 +121,7 @@
 	virtual int xGrid() const;
 	virtual int yGrid() const;
 	virtual void setGrid(int, int);
-	virtual const QDomDocument toXml(bool = true) const;
+	virtual const QDomDocument toXml(bool = true);
 	virtual QRectF boundingRectFromXml(const QDomDocument &);
 	virtual void fromXml(const QDomDocument &, const QPointF & = QPointF(), bool = true, ElementContent * = 0);
 	virtual void reset();
@@ -159,6 +159,7 @@
 	bool mustSnapToGrid(QGraphicsSceneMouseEvent *);
 	static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *);
 	QMutex *decorator_lock_;
+	void centerElementToOrigine();
 	
 	public slots:
 	void slot_move();
@@ -200,6 +201,8 @@
 	void partsZValueChanged();
 	/// Signal emitted when users have defined the copy/paste area
 	void pasteAreaDefined(const QRectF &);
+	/// Signal emitted when need zoomFit
+	void needZoomFit();
 };
 
 Q_DECLARE_OPERATORS_FOR_FLAGS(ElementScene::ItemOptions)

Modified: trunk/sources/editor/elementview.cpp
===================================================================
--- trunk/sources/editor/elementview.cpp	2013-09-21 07:25:37 UTC (rev 2552)
+++ trunk/sources/editor/elementview.cpp	2013-09-21 13:09:23 UTC (rev 2553)
@@ -36,6 +36,7 @@
 	zoomReset();
 	connect(scene_, SIGNAL(pasteAreaDefined(const QRectF &)), this, SLOT(pasteAreaDefined(const QRectF &)));
 	connect(scene_, SIGNAL(partsAdded()), this, SLOT(adjustSceneRect()));
+	connect(scene_, SIGNAL(needZoomFit()), this, SLOT(zoomFit()));
 }
 
 /// Destructeur


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