mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01:00
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:
@@ -163,6 +163,13 @@ void ChangePartCommand::redo() {
|
||||
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(
|
||||
PartPolygon *p,
|
||||
const QVector<QPointF> &o_points,
|
||||
@@ -176,13 +183,83 @@ ChangePolygonPointsCommand::ChangePolygonPointsCommand(
|
||||
{
|
||||
}
|
||||
|
||||
/// Destructeur
|
||||
ChangePolygonPointsCommand::~ChangePolygonPointsCommand() {
|
||||
}
|
||||
|
||||
/// Annule le changement
|
||||
void ChangePolygonPointsCommand::undo() {
|
||||
polygon -> setPolygon(old_points);
|
||||
}
|
||||
|
||||
/// Refait le changement
|
||||
void ChangePolygonPointsCommand::redo() {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,4 +134,38 @@ class ChangePolygonPointsCommand : public QUndoCommand {
|
||||
/// nouveaux 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
|
||||
|
||||
@@ -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() {
|
||||
return(undo_stack);
|
||||
}
|
||||
@@ -446,15 +450,16 @@ void ElementScene::slot_editSizeHotSpot() {
|
||||
|
||||
// lance le dialogue
|
||||
if (dialog_sh.exec() == QDialog::Accepted) {
|
||||
setWidth(hotspot_editor -> elementWidth());
|
||||
setHeight(hotspot_editor -> elementHeight());
|
||||
setHotspot(hotspot_editor -> hotspot());
|
||||
if (hotspot_editor -> mustTranslateParts()) {
|
||||
QPoint translation = hotspot_editor -> offsetParts();
|
||||
foreach(QGraphicsItem *qgi, items()) {
|
||||
qgi -> translate(translation.x(), translation.y());
|
||||
}
|
||||
}
|
||||
undo_stack.push(
|
||||
new ChangeHotspotCommand(
|
||||
this,
|
||||
QSize(width(), height()),
|
||||
hotspot_editor -> elementSize(),
|
||||
_hotspot,
|
||||
hotspot_editor -> hotspot(),
|
||||
hotspot_editor -> mustTranslateParts() ? hotspot_editor -> offsetParts() : QPoint()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ class ElementScene : public QGraphicsScene {
|
||||
void setOrientations(const OrientationSet &);
|
||||
virtual const QDomDocument toXml() const;
|
||||
virtual void fromXml(const QDomDocument &);
|
||||
QRectF sceneContent() const;
|
||||
QUndoStack &undoStack();
|
||||
QGIManager &qgiManager();
|
||||
|
||||
|
||||
@@ -96,12 +96,12 @@ uint HotspotEditor::elementHeight10px() const {
|
||||
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 {
|
||||
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 {
|
||||
return(sb_height -> value() * 10);
|
||||
}
|
||||
@@ -117,7 +117,7 @@ QSize HotspotEditor::elementSize10px() const {
|
||||
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 {
|
||||
return(QSize(elementWidth(), elementHeight()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user