[qet] [4049] Minor fix

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


Revision: 4049
Author:   blacksun
Date:     2015-07-13 14:01:02 +0200 (Mon, 13 Jul 2015)
Log Message:
-----------
Minor fix

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

Modified: trunk/sources/dvevent/dveventaddshape.cpp
===================================================================
--- trunk/sources/dvevent/dveventaddshape.cpp	2015-07-12 20:43:54 UTC (rev 4048)
+++ trunk/sources/dvevent/dveventaddshape.cpp	2015-07-13 12:01:02 UTC (rev 4049)
@@ -64,6 +64,8 @@
 	if (!m_dv->isInteractive() && m_diagram->isReadOnly()) return false;
 
 	QPointF pos = m_dv->mapToScene(event->pos());
+	if (event->modifiers() != Qt::ControlModifier)
+		pos = Diagram::snapToGrid(pos);
 
 		//Action for left mouse click
 	if (event -> button() == Qt::LeftButton)
@@ -112,7 +114,11 @@
 
 	if (m_shape_item && event -> buttons() == Qt::NoButton)
 	{
-		m_shape_item -> setP2 (m_dv -> mapToScene (event -> pos()));
+		QPointF pos = m_dv->mapToScene(event->pos());
+		if (event->modifiers() != Qt::ControlModifier)
+			pos = Diagram::snapToGrid(pos);
+
+		m_shape_item -> setP2 (pos);
 		return true;
 	}
 
@@ -136,7 +142,12 @@
 			if (m_shape_type == QetShapeItem::Polyline && (m_shape_item -> pointsCount() >= 3) )
 			{
 				m_shape_item -> removePoints();
-				m_shape_item -> setP2(m_dv -> mapToScene (event -> pos())); //Set the new last point under the cursor
+
+				QPointF pos = m_dv->mapToScene(event->pos());
+				if (event->modifiers() != Qt::ControlModifier)
+					pos = Diagram::snapToGrid(pos);
+
+				m_shape_item -> setP2(pos); //Set the new last point under the cursor
 				return true;
 			}
 
@@ -166,7 +177,9 @@
 		//If current item is a polyline, add it with an undo command
 	if (m_shape_item && m_shape_type == QetShapeItem::Polyline && event -> button() == Qt::LeftButton)
 	{
-		m_shape_item -> setP2 (m_dv -> mapToScene (event -> pos()));
+			//<double clic is used to finish polyline, but they also add two points at the same pos
+			//<(double clic is a double press event), so we remove the last point of polyline
+		m_shape_item->removePoints();
 		m_diagram -> undoStack().push (new AddItemCommand<QetShapeItem *> (m_shape_item, m_diagram));
 		m_shape_item = nullptr; //< set to nullptr for create new shape at next left clic
 		return true;

Modified: trunk/sources/qetgraphicsitem/qetshapeitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.cpp	2015-07-12 20:43:54 UTC (rev 4048)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.cpp	2015-07-13 12:01:02 UTC (rev 4049)
@@ -38,8 +38,8 @@
 	QetGraphicsItem(parent),
 	m_shapeType(type),
 	m_shapeStyle(Qt::DashLine),
-	m_P1 (Diagram::snapToGrid(p1)),
-	m_P2 (Diagram::snapToGrid(p2)),
+	m_P1 (p1),
+	m_P2 (p2),
 	m_hovered(false),
 	m_mouse_grab_handler(false),
 	m_undo_command(nullptr)
@@ -232,18 +232,6 @@
 }
 
 /**
- * @brief QetShapeItem::changeGraphicsItem
- * Change the curent type of this item to newtype
- * @param newtype
- */
-void QetShapeItem::changeGraphicsItem(const ShapeType &newtype) {
-	if (newtype == m_shapeType) return;
-	prepareGeometryChange();
-	m_shapeType = newtype;
-	setTransformOriginPoint(boundingRect().center());
-}
-
-/**
  * @brief QetShapeItem::paint
  * Paint this item
  * @param painter
@@ -508,7 +496,7 @@
 		}
 	}
 
-	changeGraphicsItem(QetShapeItem::ShapeType(e.attribute("type","0").toInt()));
+	m_shapeType = QetShapeItem::ShapeType(e.attribute("type","0").toInt());
 	return (true);
 }
 
@@ -518,23 +506,26 @@
  * @param document parent document xml
  * @return element xml where is write this item
  */
-QDomElement QetShapeItem::toXml(QDomDocument &document) const {
+QDomElement QetShapeItem::toXml(QDomDocument &document) const
+{
 	QDomElement result = document.createElement("shape");
 
-	//write some attribute
+		//write some attribute
 	result.setAttribute("type", QString::number(m_shapeType));
 	result.setAttribute("style", QString::number(m_shapeStyle));
 	result.setAttribute("is_movable", bool(is_movable_));
-	if (m_shapeType != Polyline) {
-		result.setAttribute("x1", mapToScene(m_P1).x());
-		result.setAttribute("y1", mapToScene(m_P1).y());
-		result.setAttribute("x2", mapToScene(m_P2).x());
-		result.setAttribute("y2", mapToScene(m_P2).y());
+	if (m_shapeType != Polyline)
+	{
+		result.setAttribute("x1", QString::number(mapToScene(m_P1).x()));
+		result.setAttribute("y1", QString::number(mapToScene(m_P1).y()));
+		result.setAttribute("x2", QString::number(mapToScene(m_P2).x()));
+		result.setAttribute("y2", QString::number(mapToScene(m_P2).y()));
 	}
-
-	else {
+	else
+	{
 		QDomElement points = document.createElement("points");
-		foreach(QPointF p, m_polygon) {
+		foreach(QPointF p, m_polygon)
+		{
 			QDomElement point = document.createElement("point");
 			QPointF pf = mapToScene(p);
 			point.setAttribute("x", pf.x());

Modified: trunk/sources/qetgraphicsitem/qetshapeitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.h	2015-07-12 20:43:54 UTC (rev 4048)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.h	2015-07-13 12:01:02 UTC (rev 4049)
@@ -84,9 +84,6 @@
 		virtual void mouseMoveEvent    (QGraphicsSceneMouseEvent *event);
 		virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
 
-	private:
-		void changeGraphicsItem (const ShapeType &newtype);
-
 		///ATTRIBUTES
 	private:
 		ShapeType    m_shapeType;


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