diff --git a/sources/diagramcommands.cpp b/sources/diagramcommands.cpp index e7793ba36..b3cc1e2bb 100644 --- a/sources/diagramcommands.cpp +++ b/sources/diagramcommands.cpp @@ -1188,6 +1188,47 @@ void ImageResizerCommand::redo() { image_ -> setScale(new_size); } + +/** + * @brief ChangeShapeStyleCommand::ChangeShapeStyleCommand Constructor + * @param shape + * @param old_ old style of shape + * @param new_ new style of shape + * @param parent undocommand parent + */ +ChangeShapeStyleCommand::ChangeShapeStyleCommand(QetShapeItem *shape, Qt::PenStyle &old_, Qt::PenStyle &new_, QUndoCommand *parent): + QUndoCommand(parent), + shape_(shape), + old_style (old_), + new_style (new_), + diagram(shape->diagram()) +{} + +/** + * @brief ChangeShapeStyleCommand::~ChangeShapeStyleCommand destructor + */ +ChangeShapeStyleCommand::~ChangeShapeStyleCommand() {} + +/** + * @brief ChangeShapeStyleCommand::undo set the old style + */ +void ChangeShapeStyleCommand::undo() { + shape_ -> setStyle(old_style); + diagram -> showMe(); + QUndoCommand::undo(); +} + +/** + * @brief ChangeShapeStyleCommand::redo set the new style + */ +void ChangeShapeStyleCommand::redo() { + shape_ -> setStyle(new_style); + diagram -> showMe(); + QUndoCommand::redo(); +} + + + /** * @brief LinkElementsCommand::LinkElementsCommand *Constructor diff --git a/sources/diagramcommands.h b/sources/diagramcommands.h index f89ce0b72..206f81d59 100644 --- a/sources/diagramcommands.h +++ b/sources/diagramcommands.h @@ -616,6 +616,25 @@ class ImageResizerCommand : public QUndoCommand { Diagram *diagram; }; + +class ChangeShapeStyleCommand : public QUndoCommand { + //constructor and destructor + public: + ChangeShapeStyleCommand (QetShapeItem *shape, Qt::PenStyle &old_, Qt::PenStyle &new_, QUndoCommand *parent = 0); + virtual ~ChangeShapeStyleCommand(); + + //methods + public: + virtual void undo(); + virtual void redo(); + + //attributes + private: + QetShapeItem *shape_; + Qt::PenStyle old_style, new_style; + Diagram *diagram; +}; + class LinkElementsCommand : public QUndoCommand { public: // constructor destructor diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 1303f0546..9174ee5a0 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -1272,6 +1272,20 @@ void DiagramView::editImage() { } } +/** + * @brief DiagramView::editShape + * open edit image dialog if only one shape is selected + */ +void DiagramView::editShape() { + if (scene -> isReadOnly()) return; + QList shapes = diagram() -> selectedContent().items(DiagramContent::Shapes); + if (shapes.count() != 1) return; + QetShapeItem *shape; + if ((shape = qgraphicsitem_cast (shapes.first()))) { + shape -> editProperty(); + } +} + /** * @brief DiagramView::addDiagramImageAtPos * @param pos diff --git a/sources/diagramview.h b/sources/diagramview.h index e355183ff..cbd169d24 100644 --- a/sources/diagramview.h +++ b/sources/diagramview.h @@ -82,6 +82,7 @@ class DiagramView : public QGraphicsView { void addRectangle(); void addEllipse(); void editImage(); + void editShape(); IndependentTextItem *addDiagramTextAtPos(const QPointF &, const QString &text = 0); DiagramImageItem *addDiagramImageAtPos(const QPointF &); diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index a478df4ff..eb2d905ba 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -1599,6 +1599,7 @@ void QETDiagramEditor::slot_editSelection() { } else if (dc.count(DiagramContent::TextFields)) dv -> editText(); else if (dc.count(DiagramContent::Images)) dv -> editImage(); + else if (dc.count(DiagramContent::Shapes)) dv -> editShape(); } } diff --git a/sources/qetgraphicsitem/qetshapeitem.cpp b/sources/qetgraphicsitem/qetshapeitem.cpp index 5819ae717..860f81696 100644 --- a/sources/qetgraphicsitem/qetshapeitem.cpp +++ b/sources/qetgraphicsitem/qetshapeitem.cpp @@ -1,4 +1,5 @@ #include "qetshapeitem.h" +#include "diagramcommands.h" QetShapeItem::QetShapeItem(QPointF p1, QPointF p2, ShapeType type, bool lineAngle,QGraphicsItem *parent) : @@ -19,6 +20,7 @@ QetShapeItem::~QetShapeItem() void QetShapeItem::setStyle(Qt::PenStyle newStyle) { _shapeStyle = newStyle; + update(); } void QetShapeItem::setFullyBuilt(bool isBuilt) @@ -158,3 +160,52 @@ QDomElement QetShapeItem::toXml(QDomDocument &document) const { return(result); } + +void QetShapeItem::editProperty() +{ + if (diagram() -> isReadOnly()) return; + + //the dialog + QDialog property_dialog(diagram()->views().at(0)); + property_dialog.setWindowTitle(tr("\311diter les propri\351t\351s d'une shape", "window title")); + //the main layout + QVBoxLayout dialog_layout(&property_dialog); + + //GroupBox for resizer image + QGroupBox restyle_groupe(tr("Shape Line Style", "shape style")); + dialog_layout.addWidget(&restyle_groupe); + QHBoxLayout restyle_layout(&restyle_groupe); + + QComboBox style_combo(&property_dialog); + style_combo.addItem(tr("Solid Line")); + style_combo.addItem(tr("Dash Line")); + style_combo.addItem(tr("Dot Line")); + style_combo.addItem(tr("DashDot Line")); + style_combo.addItem(tr("DashDotDot Line")); + + // The items have been added in order accordance with Qt::PenStyle. + style_combo.setCurrentIndex(int(_shapeStyle) - 1); + + restyle_layout.addWidget(&style_combo); + + //check box for disable move + QCheckBox cb(tr("Verrouiller la position"), &property_dialog); + cb.setChecked(!is_movable_); + dialog_layout.addWidget(&cb); + + //dialog button, box + QDialogButtonBox dbb(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + dialog_layout.addWidget(&dbb); + connect(&dbb, SIGNAL(accepted()), &property_dialog, SLOT(accept())); + connect(&dbb, SIGNAL(rejected()), &property_dialog, SLOT(reject())); + + //dialog is accepted... + if (property_dialog.exec() == QDialog::Accepted) { + cb.isChecked() ? is_movable_=false : is_movable_=true; + + Qt::PenStyle new_style = Qt::PenStyle(style_combo.currentIndex() + 1); + if (new_style != _shapeStyle) + diagram()->undoStack().push(new ChangeShapeStyleCommand(this, _shapeStyle, new_style)); + } + return; +} diff --git a/sources/qetgraphicsitem/qetshapeitem.h b/sources/qetgraphicsitem/qetshapeitem.h index f05b9a8c7..28c7181c8 100644 --- a/sources/qetgraphicsitem/qetshapeitem.h +++ b/sources/qetgraphicsitem/qetshapeitem.h @@ -41,6 +41,7 @@ class QetShapeItem : public QetGraphicsItem virtual bool fromXml(const QDomElement &); virtual QDomElement toXml(QDomDocument &document) const; void setWritingXml(bool writing) { _writingXml = writing; } + virtual void editProperty(); private: ShapeType _shapeType; @@ -53,8 +54,6 @@ class QetShapeItem : public QetGraphicsItem QPointF _lineP2; bool _writingXml; - virtual void editProperty() {} - protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); QRectF boundingRect() const;