[qet] [2910] Basic Shapes: Edit property(style) added, undo/redo style added |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 2910
Author: abhishekm71
Date: 2014-03-07 09:05:25 +0100 (Fri, 07 Mar 2014)
Log Message:
-----------
Basic Shapes: Edit property(style) added, undo/redo style added
Modified Paths:
--------------
trunk/sources/diagramcommands.cpp
trunk/sources/diagramcommands.h
trunk/sources/diagramview.cpp
trunk/sources/diagramview.h
trunk/sources/qetdiagrameditor.cpp
trunk/sources/qetgraphicsitem/qetshapeitem.cpp
trunk/sources/qetgraphicsitem/qetshapeitem.h
Modified: trunk/sources/diagramcommands.cpp
===================================================================
--- trunk/sources/diagramcommands.cpp 2014-03-06 15:40:18 UTC (rev 2909)
+++ trunk/sources/diagramcommands.cpp 2014-03-07 08:05:25 UTC (rev 2910)
@@ -1188,7 +1188,48 @@
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
* @param elmt1 element to Link
Modified: trunk/sources/diagramcommands.h
===================================================================
--- trunk/sources/diagramcommands.h 2014-03-06 15:40:18 UTC (rev 2909)
+++ trunk/sources/diagramcommands.h 2014-03-07 08:05:25 UTC (rev 2910)
@@ -616,6 +616,25 @@
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
Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp 2014-03-06 15:40:18 UTC (rev 2909)
+++ trunk/sources/diagramview.cpp 2014-03-07 08:05:25 UTC (rev 2910)
@@ -1273,6 +1273,20 @@
}
/**
+ * @brief DiagramView::editShape
+ * open edit image dialog if only one shape is selected
+ */
+void DiagramView::editShape() {
+ if (scene -> isReadOnly()) return;
+ QList <QGraphicsItem *> shapes = diagram() -> selectedContent().items(DiagramContent::Shapes);
+ if (shapes.count() != 1) return;
+ QetShapeItem *shape;
+ if ((shape = qgraphicsitem_cast<QetShapeItem *> (shapes.first()))) {
+ shape -> editProperty();
+ }
+}
+
+/**
* @brief DiagramView::addDiagramImageAtPos
* @param pos
* @return
Modified: trunk/sources/diagramview.h
===================================================================
--- trunk/sources/diagramview.h 2014-03-06 15:40:18 UTC (rev 2909)
+++ trunk/sources/diagramview.h 2014-03-07 08:05:25 UTC (rev 2910)
@@ -82,6 +82,7 @@
void addRectangle();
void addEllipse();
void editImage();
+ void editShape();
IndependentTextItem *addDiagramTextAtPos(const QPointF &, const QString &text = 0);
DiagramImageItem *addDiagramImageAtPos(const QPointF &);
Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp 2014-03-06 15:40:18 UTC (rev 2909)
+++ trunk/sources/qetdiagrameditor.cpp 2014-03-07 08:05:25 UTC (rev 2910)
@@ -1599,6 +1599,7 @@
}
else if (dc.count(DiagramContent::TextFields)) dv -> editText();
else if (dc.count(DiagramContent::Images)) dv -> editImage();
+ else if (dc.count(DiagramContent::Shapes)) dv -> editShape();
}
}
Modified: trunk/sources/qetgraphicsitem/qetshapeitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.cpp 2014-03-06 15:40:18 UTC (rev 2909)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.cpp 2014-03-07 08:05:25 UTC (rev 2910)
@@ -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 @@
void QetShapeItem::setStyle(Qt::PenStyle newStyle)
{
_shapeStyle = newStyle;
+ update();
}
void QetShapeItem::setFullyBuilt(bool isBuilt)
@@ -158,3 +160,52 @@
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;
+}
Modified: trunk/sources/qetgraphicsitem/qetshapeitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.h 2014-03-06 15:40:18 UTC (rev 2909)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.h 2014-03-07 08:05:25 UTC (rev 2910)
@@ -41,6 +41,7 @@
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 @@
QPointF _lineP2;
bool _writingXml;
- virtual void editProperty() {}
-
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QRectF boundingRect() const;