mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 14:50:53 +01:00
QetShapeItem: Add Scale option with UNDO/REDO
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3078 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,8 +52,6 @@ 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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user