[qet] [2876] Basic Shapes: Dynamic Preview added when constructing the shape.

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


Revision: 2876
Author:   abhishekm71
Date:     2014-02-24 15:22:26 +0100 (Mon, 24 Feb 2014)
Log Message:
-----------
Basic Shapes: Dynamic Preview added when constructing the shape.

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

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2014-02-23 21:33:53 UTC (rev 2875)
+++ trunk/sources/diagramview.cpp	2014-02-24 14:22:26 UTC (rev 2876)
@@ -43,7 +43,6 @@
 #include <QGraphicsPixmapItem>
 #include <QGraphicsSceneMouseEvent>
 #include "factory/elementfactory.h"
-#include "qetgraphicsitem/qetshapeitem.h"
 
 
 /**
@@ -51,7 +50,7 @@
 	@param diagram Schema a afficher ; si diagram vaut 0, un nouveau Diagram est utilise
 	@param parent Le QWidget parent de cette vue de schema
 */
-DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : QGraphicsView(parent) {
+DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : QGraphicsView(parent), newItem(0){
 	setAttribute(Qt::WA_DeleteOnClose, true);
 	setInteractive(true);
 	current_behavior = noAction;
@@ -459,28 +458,19 @@
 				current_behavior = noAction;
 				break;
 			case addingLine:
-		//		if (!rubber_band) {
-					rubber_band_origin = mapToScene(e -> pos());
-			//		rubber_band = new QRubberBand(QRubberBand::Rectangle, this);
-				//}
-				//rubber_band->setGeometry(QRectF(rubber_band_origin, QSize()).toRect());
-				//rubber_band->show();
+				rubber_band_origin = mapToScene(e -> pos());
+				newItem = new QetShapeItem(rubber_band_origin, rubber_band_origin, QetShapeItem::Line, false);
+				scene -> addItem(newItem);
 				break;
 			case addingRectangle:
-				//if (!rubber_band) {
-					rubber_band_origin = mapToScene(e -> pos());
-					//rubber_band = new QRubberBand(QRubberBand::Rectangle, this);
-			//	}
-				//rubber_band->setGeometry(QRectF(rubber_band_origin, QSize()).toRect());
-				//rubber_band->show();
+				rubber_band_origin = mapToScene(e -> pos());
+				newItem = new QetShapeItem(rubber_band_origin, rubber_band_origin, QetShapeItem::Rectangle);
+				scene -> addItem(newItem);
 				break;
 			case addingEllipse:
-			//	if (!rubber_band) {
-					rubber_band_origin = mapToScene(e -> pos());
-				//	rubber_band = new QRubberBand(QRubberBand::Rectangle, this);
-				//}
-				//rubber_band->setGeometry(QRectF(rubber_band_origin, QSize()).toRect());
-				//rubber_band->show();
+				rubber_band_origin = mapToScene(e -> pos());
+				newItem = new QetShapeItem(rubber_band_origin, rubber_band_origin, QetShapeItem::Ellipse);
+				scene -> addItem(newItem);
 				break;
 			case dragView:
 				current_behavior = noAction;
@@ -512,9 +502,15 @@
 		center_view_ = mapToScene(this -> viewport() -> rect()).boundingRect().center();
 		return;
 	}
-	/*if ((e -> buttons() & Qt::LeftButton) &&
-		(current_behavior == addingLine || current_behavior == addingRectangle || current_behavior == addingEllipse))
-		rubber_band -> setGeometry(QRectF(rubber_band_origin, mapToScene(e->pos())).normalized().toRect());*/
+	if ((e -> buttons() & Qt::LeftButton) &&
+		(current_behavior == addingLine || current_behavior == addingRectangle || current_behavior == addingEllipse)) {
+		QRectF rec = QRectF(rubber_band_origin, mapToScene(e->pos())).normalized();
+		scene ->removeItem(newItem);
+		newItem -> setBoundingRect(rec);
+		if (current_behavior == addingLine)
+			newItem -> setLineAngle(rubber_band_origin != rec.topLeft() && rubber_band_origin != rec.bottomRight());
+		scene ->addItem(newItem);
+	}
 	QGraphicsView::mouseMoveEvent(e);
 }
 
@@ -528,26 +524,12 @@
 		return;
 	}
 	if (current_behavior == addingLine || current_behavior == addingRectangle || current_behavior == addingEllipse) {
-		QRectF rec = QRectF(rubber_band_origin, mapToScene(e->pos())).normalized();
-		if (current_behavior == addingLine) {
-			QetShapeItem *line;
-			if (rubber_band_origin == rec.topLeft() || rubber_band_origin == rec.bottomRight())
-				line = new QetShapeItem(rec.topLeft(), rec.bottomRight(), QetShapeItem::Line, false);
-			else
-				line = new QetShapeItem(rec.topLeft(), rec.bottomRight(), QetShapeItem::Line, true);
-			scene -> addItem(line);
+		if (current_behavior == addingLine)
 			emit(LineAdded(false));
-		} else if (current_behavior == addingRectangle) {
-			QetShapeItem *rect = new QetShapeItem(rec.topLeft(), rec.bottomRight(), QetShapeItem::Rectangle);
-			scene -> addItem(rect);
+		else if (current_behavior == addingRectangle)
 			emit(RectangleAdded(false));
-		} else { // ellipse
-			QetShapeItem *ellipse = new QetShapeItem(rec.topLeft(), rec.bottomRight(), QetShapeItem::Ellipse);
-			scene -> addItem(ellipse);
+		else // ellipse
 			emit(EllipseAdded(false));
-		}
-		//rubber_band -> hide();
-		//rubber_band = 0;
 		current_behavior = noAction;
 	}
 

Modified: trunk/sources/diagramview.h
===================================================================
--- trunk/sources/diagramview.h	2014-02-23 21:33:53 UTC (rev 2875)
+++ trunk/sources/diagramview.h	2014-02-24 14:22:26 UTC (rev 2876)
@@ -20,6 +20,7 @@
 #include <QtGui>
 #include "elementslocation.h"
 #include "templatelocation.h"
+#include "qetgraphicsitem/qetshapeitem.h"
 class Conductor;
 class Diagram;
 class Element;
@@ -57,7 +58,7 @@
 	QPointF reference_view_;
 	QPointF center_view_;
 	QImage image_to_add_;
-	QRubberBand *rubber_band;
+	QetShapeItem *newItem;
 	QPointF rubber_band_origin;
 	
 	// methods

Modified: trunk/sources/qetgraphicsitem/qetshapeitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.h	2014-02-23 21:33:53 UTC (rev 2875)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.h	2014-02-24 14:22:26 UTC (rev 2876)
@@ -16,6 +16,12 @@
 	QetShapeItem(QPointF, QPointF, ShapeType, bool lineAngle = false, QGraphicsItem *parent = 0);
 	virtual ~QetShapeItem();
 
+	void setStyle(Qt::PenStyle);
+	Qt::PenStyle getStyle() const	 { return _shapeStyle;	   }
+	ShapeType getType()		const	 { return _shapeType;	   }
+	void setBoundingRect(QRectF rec) { _boundingRect = rec;	   }
+	void setLineAngle(bool lineAngle){ _lineAngle = lineAngle; }
+
 	private:
 	ShapeType    _shapeType;
 	Qt::PenStyle _shapeStyle;
@@ -23,7 +29,6 @@
 	bool		 _lineAngle;  // false if line from topleft corner to bottomright corner
 							  // and true if line from topright corner to bottomleft corner
 
-	void setStyle(Qt::PenStyle);
 	virtual void editProperty() {}
 
 	protected:


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