diff --git a/sources/diagramcommands.cpp b/sources/diagramcommands.cpp index dad684b74..8037dd31b 100644 --- a/sources/diagramcommands.cpp +++ b/sources/diagramcommands.cpp @@ -1239,6 +1239,47 @@ void ChangeShapeStyleCommand::redo() { +/** + * @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 diff --git a/sources/diagramcommands.h b/sources/diagramcommands.h index 0fe5b0f22..b6a42e5f0 100644 --- a/sources/diagramcommands.h +++ b/sources/diagramcommands.h @@ -635,6 +635,24 @@ class ChangeShapeStyleCommand : public QUndoCommand { 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 diff --git a/sources/qetgraphicsitem/qetshapeitem.cpp b/sources/qetgraphicsitem/qetshapeitem.cpp index 7593de1cf..dcfc9d7ed 100644 --- a/sources/qetgraphicsitem/qetshapeitem.cpp +++ b/sources/qetgraphicsitem/qetshapeitem.cpp @@ -23,6 +23,15 @@ void QetShapeItem::setStyle(Qt::PenStyle newStyle) 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 @@ void QetShapeItem::editProperty() 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 @@ void QetShapeItem::editProperty() 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; } diff --git a/sources/qetgraphicsitem/qetshapeitem.h b/sources/qetgraphicsitem/qetshapeitem.h index 5bf85ec9e..b0eb836da 100644 --- a/sources/qetgraphicsitem/qetshapeitem.h +++ b/sources/qetgraphicsitem/qetshapeitem.h @@ -43,6 +43,7 @@ class QetShapeItem : public QetGraphicsItem void setWritingXml(bool writing) { _writingXml = writing; } virtual void editProperty(); QRectF boundingRect() const; + void scale(double factor); private: ShapeType _shapeType; @@ -51,10 +52,8 @@ class QetShapeItem : public QetGraphicsItem 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);