[qet] [2912] Basic Shapes: Move coords corrected for XML, DXF export

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


Revision: 2912
Author:   abhishekm71
Date:     2014-03-07 13:34:47 +0100 (Fri, 07 Mar 2014)
Log Message:
-----------
Basic Shapes: Move coords corrected for XML, DXF export 
(Bounding Rectangle had to be updated with each move)

Modified Paths:
--------------
    trunk/sources/diagramcommands.cpp
    trunk/sources/qetgraphicsitem/qetshapeitem.cpp
    trunk/sources/qetgraphicsitem/qetshapeitem.h

Modified: trunk/sources/diagramcommands.cpp
===================================================================
--- trunk/sources/diagramcommands.cpp	2014-03-07 08:47:56 UTC (rev 2911)
+++ trunk/sources/diagramcommands.cpp	2014-03-07 12:34:47 UTC (rev 2912)
@@ -497,6 +497,10 @@
 	// deplace les shapes
 	foreach (QetShapeItem *dsi, content_to_move.shapes) {
 		dsi -> setPos(dsi -> pos() + actual_movement);
+		QRectF rec = dsi -> boundingRect();
+		rec.translate(actual_movement);
+		dsi -> setBoundingRect(rec);
+		dsi -> setPos(dsi -> pos() - actual_movement);
 	}
 }
 

Modified: trunk/sources/qetgraphicsitem/qetshapeitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.cpp	2014-03-07 08:47:56 UTC (rev 2911)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.cpp	2014-03-07 12:34:47 UTC (rev 2912)
@@ -124,7 +124,32 @@
 	}
 }
 
+void QetShapeItem::mousePressEvent(QGraphicsSceneMouseEvent *e)
+{
+	_origMousePress = mapToScene(e -> pos());
+	first_move_ = true;
+	if (e -> modifiers() & Qt::ControlModifier) {
+		setSelected(!isSelected());
+	}
+	QGraphicsItem::mousePressEvent(e);
+}
 
+void QetShapeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
+{
+	if (diagram()) diagram() -> endMoveElements();
+	QPointF newCoord = mapToScene(e -> pos());
+	if (newCoord != _origMousePress) {
+		//translate bounding rectangle
+		QRectF rec = boundingRect();
+		rec.translate(newCoord - _origMousePress);
+		setBoundingRect(rec);
+		setPos(pos() - newCoord + _origMousePress);
+	}
+
+	if (!(e -> modifiers() & Qt::ControlModifier)) QGraphicsItem::mouseReleaseEvent(e);
+}
+
+
 bool QetShapeItem::fromXml(const QDomElement &e)
 {
 	if (!_writingXml) {

Modified: trunk/sources/qetgraphicsitem/qetshapeitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.h	2014-03-07 08:47:56 UTC (rev 2911)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.h	2014-03-07 12:34:47 UTC (rev 2912)
@@ -42,6 +42,7 @@
 	virtual QDomElement toXml(QDomDocument &document) const;
 	void setWritingXml(bool writing)	{ _writingXml = writing;   }
 	virtual void editProperty();
+	QRectF boundingRect() const;
 
 	private:
 	ShapeType    _shapeType;
@@ -52,11 +53,13 @@
 	bool		 _isFullyBuilt;
 	QPointF		 _lineP1;
 	QPointF		 _lineP2;
+	QPointF		 _origMousePress;
 	bool		_writingXml;
 
 	protected:
 	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
-	QRectF boundingRect() const;
+	virtual void mousePressEvent(QGraphicsSceneMouseEvent *e);
+	virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *e);
 	QPainterPath shape() const;
 
 };


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