Dans l'editeur d'elements, les changements de dimensions et de point de saisie sont desormais annulables

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@119 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavierqet
2007-09-10 21:12:49 +00:00
parent 2e3afaa13d
commit b1ea7d6249
5 changed files with 129 additions and 12 deletions

View File

@@ -163,6 +163,13 @@ void ChangePartCommand::redo() {
cep -> setProperty(property, new_value); cep -> setProperty(property, new_value);
} }
/**
Constructeur
@param p Polygone edite
@param o_points points avant le changement
@param n_points points apres le changement
@param parent QUndoCommand parent
*/
ChangePolygonPointsCommand::ChangePolygonPointsCommand( ChangePolygonPointsCommand::ChangePolygonPointsCommand(
PartPolygon *p, PartPolygon *p,
const QVector<QPointF> &o_points, const QVector<QPointF> &o_points,
@@ -176,13 +183,83 @@ ChangePolygonPointsCommand::ChangePolygonPointsCommand(
{ {
} }
/// Destructeur
ChangePolygonPointsCommand::~ChangePolygonPointsCommand() { ChangePolygonPointsCommand::~ChangePolygonPointsCommand() {
} }
/// Annule le changement
void ChangePolygonPointsCommand::undo() { void ChangePolygonPointsCommand::undo() {
polygon -> setPolygon(old_points); polygon -> setPolygon(old_points);
} }
/// Refait le changement
void ChangePolygonPointsCommand::redo() { void ChangePolygonPointsCommand::redo() {
polygon -> setPolygon(new_points); polygon -> setPolygon(new_points);
} }
/**
Constructeur
@param element_scene Element edite
@param size_1 Dimensions de l'element avant le changement
@param size_2 Dimensions de l'element apres le changement
@param hotspot_1 Point de saisie de l'element avant le changement
@param hotspot_2 Point de saisie de l'element apres le changement
@param o Eventuel decalage a appliquer aux parties de l'element edite
@param parent QUndoCommand parent
*/
ChangeHotspotCommand::ChangeHotspotCommand(
ElementScene *element_scene,
const QSize &size_1,
const QSize &size_2,
const QPoint &hotspot_1,
const QPoint &hotspot_2,
const QPoint &o,
QUndoCommand *parent
) :
QUndoCommand(QObject::tr("modification dimensions/hotspot"), parent),
element(element_scene),
size_before(size_1),
size_after(size_2),
hotspot_before(hotspot_1),
hotspot_after(hotspot_2),
offset(o)
{
}
/// Destructeur
ChangeHotspotCommand::~ChangeHotspotCommand() {
}
/// Annule le changement
void ChangeHotspotCommand::undo() {
QRectF sc(element -> sceneContent());
element -> setWidth(size_before.width());
element -> setHeight(size_before.height());
element -> setHotspot(hotspot_before);
if (!offset.isNull()) applyOffset(-offset);
element -> update(element -> sceneContent().unite(sc));
}
/// Refait le changement
void ChangeHotspotCommand::redo() {
QRectF sc(element -> sceneContent());
element -> setWidth(size_after.width());
element -> setHeight(size_after.height());
element -> setHotspot(hotspot_after);
if (!offset.isNull()) applyOffset(offset);
element -> update(element -> sceneContent().unite(sc));
}
/**
Applique une translation aux parties de l'element edite
@param o Translation a appliquer
*/
void ChangeHotspotCommand::applyOffset(const QPointF &o) {
foreach(QGraphicsItem *qgi, element -> items()) {
qgi -> translate(o.x(), o.y());
}
}

View File

@@ -134,4 +134,38 @@ class ChangePolygonPointsCommand : public QUndoCommand {
/// nouveaux points /// nouveaux points
QVector<QPointF> new_points; QVector<QPointF> new_points;
}; };
/**
Cette classe represente l'action de modifier les dimensions et le point de saisie d'un element
*/
class ChangeHotspotCommand : public QUndoCommand {
// constructeurs, destructeur
public:
ChangeHotspotCommand(ElementScene *, const QSize &, const QSize &, const QPoint &, const QPoint &, const QPoint & = QPoint(), QUndoCommand * = 0);
virtual ~ChangeHotspotCommand();
private:
ChangeHotspotCommand(const ChangeHotspotCommand &);
// methodes
public:
virtual void undo();
virtual void redo();
private:
void applyOffset(const QPointF &);
// attributs
/// Element edite auquel il faut appliquer les modifications
ElementScene *element;
/// dimensions avant l'action
QSize size_before;
/// dimensions apres l'action
QSize size_after;
/// point de saisie avant l'action
QPoint hotspot_before;
/// point de saisie apres l'action
QPoint hotspot_after;
/// decalage a appliquer aux elements
QPoint offset;
};
#endif #endif

View File

@@ -384,6 +384,10 @@ void ElementScene::fromXml(const QDomDocument &xml_document) {
} }
} }
QRectF ElementScene::sceneContent() const {
return(itemsBoundingRect().unite(QRectF(-_hotspot, QSizeF(width(), height()))));
}
QUndoStack &ElementScene::undoStack() { QUndoStack &ElementScene::undoStack() {
return(undo_stack); return(undo_stack);
} }
@@ -446,15 +450,16 @@ void ElementScene::slot_editSizeHotSpot() {
// lance le dialogue // lance le dialogue
if (dialog_sh.exec() == QDialog::Accepted) { if (dialog_sh.exec() == QDialog::Accepted) {
setWidth(hotspot_editor -> elementWidth()); undo_stack.push(
setHeight(hotspot_editor -> elementHeight()); new ChangeHotspotCommand(
setHotspot(hotspot_editor -> hotspot()); this,
if (hotspot_editor -> mustTranslateParts()) { QSize(width(), height()),
QPoint translation = hotspot_editor -> offsetParts(); hotspot_editor -> elementSize(),
foreach(QGraphicsItem *qgi, items()) { _hotspot,
qgi -> translate(translation.x(), translation.y()); hotspot_editor -> hotspot(),
} hotspot_editor -> mustTranslateParts() ? hotspot_editor -> offsetParts() : QPoint()
} )
);
} }
} }

View File

@@ -65,6 +65,7 @@ class ElementScene : public QGraphicsScene {
void setOrientations(const OrientationSet &); void setOrientations(const OrientationSet &);
virtual const QDomDocument toXml() const; virtual const QDomDocument toXml() const;
virtual void fromXml(const QDomDocument &); virtual void fromXml(const QDomDocument &);
QRectF sceneContent() const;
QUndoStack &undoStack(); QUndoStack &undoStack();
QGIManager &qgiManager(); QGIManager &qgiManager();

View File

@@ -96,12 +96,12 @@ uint HotspotEditor::elementHeight10px() const {
return(sb_height -> value()); return(sb_height -> value());
} }
/// @return la Largeur de l'element en dizaines de pixels /// @return la Largeur de l'element en pixels
uint HotspotEditor::elementWidth() const { uint HotspotEditor::elementWidth() const {
return(sb_width -> value() * 10); return(sb_width -> value() * 10);
} }
/// @return la hauteur de l'element en dizaines de pixels /// @return la hauteur de l'element en pixels
uint HotspotEditor::elementHeight() const { uint HotspotEditor::elementHeight() const {
return(sb_height -> value() * 10); return(sb_height -> value() * 10);
} }
@@ -117,7 +117,7 @@ QSize HotspotEditor::elementSize10px() const {
return(QSize(elementWidth10px(), elementHeight10px())); return(QSize(elementWidth10px(), elementHeight10px()));
} }
/// @return la taille de l'element, en dizaines de pixels /// @return la taille de l'element, en pixels
QSize HotspotEditor::elementSize() const { QSize HotspotEditor::elementSize() const {
return(QSize(elementWidth(), elementHeight())); return(QSize(elementWidth(), elementHeight()));
} }