[qet] [3078] QetShapeItem: Add Scale option with UNDO/REDO

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


Revision: 3078
Author:   abhishekm71
Date:     2014-05-25 20:33:06 +0200 (Sun, 25 May 2014)
Log Message:
-----------
QetShapeItem: Add Scale option with UNDO/REDO

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

Modified: trunk/sources/diagramcommands.cpp
===================================================================
--- trunk/sources/diagramcommands.cpp	2014-05-25 14:59:42 UTC (rev 3077)
+++ trunk/sources/diagramcommands.cpp	2014-05-25 18:33:06 UTC (rev 3078)
@@ -1240,6 +1240,47 @@
 
 
 /**
+ * @brief ChangeShapeScaleCommand::ChangeShapeScaleCommand Constructor
+ * @param shape
+ * @param scale_factor
+ * @param parent undocommand parent
+ */
+ChangeShapeScaleCommand::ChangeShapeScaleCommand(QetShapeItem *shape, double scale_factor, QUndoCommand *parent):
+	QUndoCommand(parent),
+	shape_(shape),
+	factor (scale_factor),
+	diagram(shape->diagram())
+{}
+
+/**
+ * @brief ChangeShapeScaleCommand::~ChangeShapeScaleCommand destructor
+ */
+ChangeShapeScaleCommand::~ChangeShapeScaleCommand() {}
+
+/**
+ * @brief ChangeShapeScaleCommand::undo set the old size
+ */
+void ChangeShapeScaleCommand::undo() {
+	diagram -> removeItem(shape_);
+	shape_ -> scale(1/factor);
+	diagram -> addItem(shape_);
+	diagram -> showMe();
+	QUndoCommand::undo();
+}
+
+/**
+ * @brief ChangeShapeScaleCommand::redo set the new size
+ */
+void ChangeShapeScaleCommand::redo() {
+	diagram -> removeItem(shape_);
+	shape_ -> scale(factor);
+	diagram -> addItem(shape_);
+	diagram -> showMe();
+	QUndoCommand::redo();
+}
+
+
+/**
  * @brief LinkElementsCommand::LinkElementsCommand
  *Constructor
  * @param elmt1 element to Link

Modified: trunk/sources/diagramcommands.h
===================================================================
--- trunk/sources/diagramcommands.h	2014-05-25 14:59:42 UTC (rev 3077)
+++ trunk/sources/diagramcommands.h	2014-05-25 18:33:06 UTC (rev 3078)
@@ -635,6 +635,24 @@
 	Diagram *diagram;
 };
 
+class ChangeShapeScaleCommand : public QUndoCommand {
+	//constructor and destructor
+	public:
+	ChangeShapeScaleCommand (QetShapeItem *shape, double scale_factor, QUndoCommand *parent = 0);
+	virtual ~ChangeShapeScaleCommand();
+
+	//methods
+	public:
+	virtual void undo();
+	virtual void redo();
+
+	//attributes
+	private:
+	QetShapeItem *shape_;
+	double factor;
+	Diagram *diagram;
+};
+
 class LinkElementsCommand : public QUndoCommand {
 	public:
 	// constructor destructor

Modified: trunk/sources/qetgraphicsitem/qetshapeitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.cpp	2014-05-25 14:59:42 UTC (rev 3077)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.cpp	2014-05-25 18:33:06 UTC (rev 3078)
@@ -23,6 +23,15 @@
 	update();
 }
 
+void QetShapeItem::scale(double factor)
+{
+	QRectF bounding_rect = boundingRect();
+	bounding_rect.setWidth(bounding_rect.width() * factor);
+	bounding_rect.setHeight(bounding_rect.height() * factor);
+	setBoundingRect(bounding_rect);
+	update();
+}
+
 void QetShapeItem::setFullyBuilt(bool isBuilt)
 {
 	_isFullyBuilt = isBuilt;
@@ -224,6 +233,22 @@
 	dialog_layout.addWidget(&cb);
 	cb.setVisible(false);
 
+	//GroupBox for Scaling
+	QGroupBox scale_groupe(QObject::tr("Scale", "shape scale"));
+	dialog_layout.addWidget(&scale_groupe);
+	QHBoxLayout scale_layout(&scale_groupe);
+
+	QLabel scale_label(&property_dialog);
+	scale_label.setText(tr("Scale Factor"));
+
+	QLineEdit scale_lineedit(&property_dialog);
+	QDoubleValidator scale_val(0.0,1000,3, &property_dialog);
+	scale_lineedit.setValidator(&scale_val);
+	scale_lineedit.setText("1.0");
+
+	scale_layout.addWidget(&scale_label);
+	scale_layout.addWidget(&scale_lineedit);
+
 	//dialog button, box
 	QDialogButtonBox dbb(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
 	dialog_layout.addWidget(&dbb);
@@ -237,6 +262,9 @@
 		Qt::PenStyle new_style = Qt::PenStyle(style_combo.currentIndex() + 1);
 		if (new_style != _shapeStyle)
 			diagram()->undoStack().push(new ChangeShapeStyleCommand(this, _shapeStyle, new_style));
+		double scale_factor = scale_lineedit.text().toDouble();
+		if (scale_factor != 1 && scale_factor > 0 && scale_factor < 1000 )
+			diagram()->undoStack().push(new ChangeShapeScaleCommand(this, scale_factor));
 	}
 	return;
 }

Modified: trunk/sources/qetgraphicsitem/qetshapeitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.h	2014-05-25 14:59:42 UTC (rev 3077)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.h	2014-05-25 18:33:06 UTC (rev 3078)
@@ -43,6 +43,7 @@
 	void setWritingXml(bool writing)	{ _writingXml = writing;   }
 	virtual void editProperty();
 	QRectF boundingRect() const;
+	void scale(double factor);
 
 	private:
 	ShapeType    _shapeType;
@@ -51,10 +52,8 @@
 	bool		 _lineAngle;  // false if line from topleft corner to bottomright corner
 							  // and true if line from topright corner to bottomleft corner
 	bool		 _isFullyBuilt;
-	QPointF		 _lineP1;
-	QPointF		 _lineP2;
 	QPointF		 _origMousePress;
-	bool		_writingXml;
+	bool		 _writingXml;
 
 	protected:
 	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);


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