Basic Shapes: Edit property(style) added, undo/redo style added

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2910 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
abhishekm71
2014-03-07 08:05:25 +00:00
parent dbd1607a7a
commit 82ad6168c1
7 changed files with 128 additions and 2 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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 <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

View File

@@ -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 &);

View File

@@ -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();
}
}

View File

@@ -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;
}

View File

@@ -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;