From 5210bd7a1d98ee73d66029397d0c843df79d3f2a Mon Sep 17 00:00:00 2001 From: xavierqet Date: Sat, 25 Aug 2007 03:43:05 +0000 Subject: [PATCH] Classe CustomElementEditor renommee en QETElementEditor. Classe EditorScene renommee en ElementScene. Ajout de la classe ElementView. Ajout de la classe ElementItemeditor, classe parente des widgets d'edition. Modification des classes relatives a l'editeur afin que toutes aient acces a l'editeur, a la scene et au QUndoStack. Tous les widgets d'edition heritent donc de ElementItemEditor. Ajout des methodes abstraites property() et setproperty() dans la classe CustomElementPart et de leur implementation dans les classes qui en derivent. Sont desormais annulables les modifications : de style, sur les arcs, sur les bornes, sur les ellipses, sur les cercles, sur les champs de texte, sur les textes et sur les lignes. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@104 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- customelement.cpp | 2 +- editor/arceditor.cpp | 66 +++++++----- editor/arceditor.h | 14 ++- editor/circleeditor.cpp | 45 ++++---- editor/circleeditor.h | 11 +- editor/customelementgraphicpart.cpp | 29 +++++ editor/customelementgraphicpart.h | 8 +- editor/customelementpart.cpp | 16 +++ editor/customelementpart.h | 11 +- editor/editorcommands.cpp | 49 ++++++++- editor/editorcommands.h | 41 +++++-- editor/elementitemeditor.cpp | 61 +++++++++++ editor/elementitemeditor.h | 30 ++++++ editor/{editorscene.cpp => elementscene.cpp} | 96 +++++++++-------- editor/{editorscene.h => elementscene.h} | 34 +++--- editor/elementview.cpp | 35 ++++++ editor/elementview.h | 24 +++++ editor/ellipseeditor.cpp | 55 +++++----- editor/ellipseeditor.h | 12 ++- editor/lineeditor.cpp | 28 +++-- editor/lineeditor.h | 12 ++- editor/partarc.cpp | 59 ++++++++++- editor/partarc.h | 4 +- editor/partcircle.cpp | 44 +++++++- editor/partcircle.h | 4 +- editor/partellipse.cpp | 49 ++++++++- editor/partellipse.h | 4 +- editor/partline.cpp | 65 +++++++----- editor/partline.h | 4 +- editor/partpolygon.cpp | 22 +++- editor/partpolygon.h | 4 +- editor/partterminal.cpp | 31 +++++- editor/partterminal.h | 5 +- editor/parttext.cpp | 40 ++++++- editor/parttext.h | 7 +- editor/parttextfield.cpp | 47 +++++++- editor/parttextfield.h | 8 +- editor/polygoneditor.cpp | 17 ++- editor/polygoneditor.h | 6 +- ...elementeditor.cpp => qetelementeditor.cpp} | 63 +++++------ ...stomelementeditor.h => qetelementeditor.h} | 38 ++++--- editor/styleeditor.cpp | 35 ++++-- editor/styleeditor.h | 13 ++- editor/terminaleditor.cpp | 30 ++++-- editor/terminaleditor.h | 11 +- editor/texteditor.cpp | 48 ++++++--- editor/texteditor.h | 12 ++- editor/textfieldeditor.cpp | 47 +++++--- editor/textfieldeditor.h | 13 ++- elementspanel.cpp | 8 +- newelementwizard.cpp | 4 +- qelectrotech.pro | 100 +++++++++--------- 52 files changed, 1131 insertions(+), 390 deletions(-) create mode 100644 editor/elementitemeditor.cpp create mode 100644 editor/elementitemeditor.h rename editor/{editorscene.cpp => elementscene.cpp} (87%) rename editor/{editorscene.h => elementscene.h} (76%) create mode 100644 editor/elementview.cpp create mode 100644 editor/elementview.h rename editor/{customelementeditor.cpp => qetelementeditor.cpp} (90%) rename editor/{customelementeditor.h => qetelementeditor.h} (73%) diff --git a/customelement.cpp b/customelement.cpp index 14ea347b7..db0f99717 100644 --- a/customelement.cpp +++ b/customelement.cpp @@ -384,7 +384,7 @@ bool CustomElement::parseInput(QDomElement &e, Diagram *s) { ElementTextItem *eti = new ElementTextItem(e.attribute("text"), this, s); eti -> setFont(QFont("Sans Serif", size)); eti -> setPos(pos_x, pos_y); - if (e.attribute("rotate") == "false") eti -> setFollowParentRotations(true); + if (e.attribute("rotate") == "true") eti -> setFollowParentRotations(true); return(true); } diff --git a/editor/arceditor.cpp b/editor/arceditor.cpp index 758442975..4435254d8 100644 --- a/editor/arceditor.cpp +++ b/editor/arceditor.cpp @@ -1,7 +1,7 @@ #include "arceditor.h" #include "partarc.h" -ArcEditor::ArcEditor(PartArc *arc, QWidget *parent) : QWidget(parent) { +ArcEditor::ArcEditor(QETElementEditor *editor, PartArc *arc, QWidget *parent) : ElementItemEditor(editor, parent) { part = arc; @@ -31,12 +31,7 @@ ArcEditor::ArcEditor(PartArc *arc, QWidget *parent) : QWidget(parent) { grid -> addWidget(angle, 6, 1); updateForm(); - connect(x, SIGNAL(editingFinished()), this, SLOT(updateArc())); - connect(y, SIGNAL(editingFinished()), this, SLOT(updateArc())); - connect(h, SIGNAL(editingFinished()), this, SLOT(updateArc())); - connect(v, SIGNAL(editingFinished()), this, SLOT(updateArc())); - connect(start_angle, SIGNAL(valueChanged(int)), this, SLOT(updateArc())); - connect(angle, SIGNAL(valueChanged(int)), this, SLOT(updateArc())); + activeConnections(true); } ArcEditor::~ArcEditor() { @@ -44,33 +39,46 @@ ArcEditor::~ArcEditor() { } void ArcEditor::updateArc() { - qreal _x = x -> text().toDouble(); - qreal _y = y -> text().toDouble(); - qreal _h = h -> text().toDouble(); - qreal _v = v -> text().toDouble(); - _v = _v < 0 ? -_v : _v; - part -> setRect( - QRectF( - part -> mapFromScene(QPointF(_x - (_h / 2.0), _y - (_v / 2.0))), - QSizeF(_h, _v) - ) - ); + part -> setProperty("x", x -> text().toDouble()); + part -> setProperty("y", y -> text().toDouble()); + part -> setProperty("diameter_h", h -> text().toDouble()); + part -> setProperty("diameter_v", v -> text().toDouble()); part -> setStartAngle(-start_angle -> value() + 90); part -> setAngle(-angle -> value()); } +void ArcEditor::updateArcX() { addChangePartCommand(tr("abscisse"), part, "x", x -> text().toDouble()); } +void ArcEditor::updateArcY() { addChangePartCommand(tr("ordonn\351e"), part, "y", y -> text().toDouble()); } +void ArcEditor::updateArcH() { addChangePartCommand(tr("diam\350tre horizontal"), part, "diameter_h", h -> text().toDouble()); } +void ArcEditor::updateArcV() { addChangePartCommand(tr("diam\350tre vertical"), part, "diameter_v", v -> text().toDouble()); } +void ArcEditor::updateArcS() { addChangePartCommand(tr("angle de d\351part"), part, "start_angle", -start_angle -> value() + 90); } +void ArcEditor::updateArcA() { addChangePartCommand(tr("angle"), part, "angle", -angle -> value()); } + void ArcEditor::updateForm() { - qreal _h = part -> rect().width(); - qreal _v = part -> rect().height(); - QPointF top_left(part -> sceneTopLeft()); - x -> setText(QString("%1").arg(top_left.x() + (_h / 2.0))); - y -> setText(QString("%1").arg(top_left.y() + (_v / 2.0))); - h -> setText(QString("%1").arg(_h)); - v -> setText(QString("%1").arg(_v)); - disconnect(start_angle, SIGNAL(valueChanged(int)), this, SLOT(updateArc())); - disconnect(angle, SIGNAL(valueChanged(int)), this, SLOT(updateArc())); + activeConnections(false); + x -> setText(part -> property("x").toString()); + y -> setText(part -> property("y").toString()); + h -> setText(part -> property("diameter_h").toString()); + v -> setText(part -> property("diameter_v").toString()); start_angle -> setValue(-part -> startAngle() + 90); angle -> setValue(-part -> angle()); - connect(start_angle, SIGNAL(valueChanged(int)), this, SLOT(updateArc())); - connect(angle, SIGNAL(valueChanged(int)), this, SLOT(updateArc())); + activeConnections(true); +} + +void ArcEditor::activeConnections(bool active) { + if (active) { + connect(x, SIGNAL(editingFinished()), this, SLOT(updateArcX())); + connect(y, SIGNAL(editingFinished()), this, SLOT(updateArcY())); + connect(h, SIGNAL(editingFinished()), this, SLOT(updateArcH())); + connect(v, SIGNAL(editingFinished()), this, SLOT(updateArcV())); + connect(start_angle, SIGNAL(editingFinished()), this, SLOT(updateArcS())); + connect(angle, SIGNAL(editingFinished()), this, SLOT(updateArcA())); + } else { + disconnect(x, SIGNAL(editingFinished()), this, SLOT(updateArcX())); + disconnect(y, SIGNAL(editingFinished()), this, SLOT(updateArcY())); + disconnect(h, SIGNAL(editingFinished()), this, SLOT(updateArcH())); + disconnect(v, SIGNAL(editingFinished()), this, SLOT(updateArcV())); + disconnect(start_angle, SIGNAL(editingFinished()), this, SLOT(updateArcS())); + disconnect(angle, SIGNAL(editingFinished()), this, SLOT(updateArcA())); + } } diff --git a/editor/arceditor.h b/editor/arceditor.h index 1e9974ded..58c4e663a 100644 --- a/editor/arceditor.h +++ b/editor/arceditor.h @@ -1,12 +1,13 @@ #ifndef ARC_EDITOR_H #define ARC_EDITOR_H #include +#include "elementitemeditor.h" class PartArc; -class ArcEditor : public QWidget { +class ArcEditor : public ElementItemEditor { Q_OBJECT //constructeurs, destructeur public: - ArcEditor(PartArc *, QWidget * = 0); + ArcEditor(QETElementEditor *, PartArc *, QWidget * = 0); ~ArcEditor(); private: ArcEditor(const ArcEditor &); @@ -20,6 +21,15 @@ class ArcEditor : public QWidget { // methodes public slots: void updateArc(); + void updateArcX(); + void updateArcY(); + void updateArcH(); + void updateArcV(); + void updateArcS(); + void updateArcA(); void updateForm(); + + private: + void activeConnections(bool); }; #endif diff --git a/editor/circleeditor.cpp b/editor/circleeditor.cpp index fc5d0045b..fc8eca73e 100644 --- a/editor/circleeditor.cpp +++ b/editor/circleeditor.cpp @@ -1,7 +1,7 @@ #include "circleeditor.h" #include "partcircle.h" -CircleEditor::CircleEditor(PartCircle *circle, QWidget *parent) : QWidget(parent) { +CircleEditor::CircleEditor(QETElementEditor *editor, PartCircle *circle, QWidget *parent) : ElementItemEditor(editor, parent) { part = circle; @@ -24,11 +24,8 @@ CircleEditor::CircleEditor(PartCircle *circle, QWidget *parent) : QWidget(parent grid -> addWidget(new QLabel(tr("Diam\350tre : ")), 2, 0); grid -> addWidget(r, 2, 1); + activeConnections(true); updateForm(); - - connect(x, SIGNAL(editingFinished()), this, SLOT(updateCircle())); - connect(y, SIGNAL(editingFinished()), this, SLOT(updateCircle())); - connect(r, SIGNAL(editingFinished()), this, SLOT(updateCircle())); } CircleEditor::~CircleEditor() { @@ -36,21 +33,31 @@ CircleEditor::~CircleEditor() { } void CircleEditor::updateCircle() { - qreal _x = x -> text().toDouble(); - qreal _y = y -> text().toDouble(); - qreal _d = r -> text().toDouble(); - part -> setRect( - QRectF( - part -> mapFromScene(QPointF(_x - _d / 2.0, _y - _d / 2.0)), - QSizeF(_d, _d) - ) - ); + part -> setProperty("x", x -> text().toDouble()); + part -> setProperty("y", y -> text().toDouble()); + part -> setProperty("diameter", r -> text().toDouble()); } +void CircleEditor::updateCircleX() { addChangePartCommand(tr("abscisse"), part, "x", x -> text().toDouble()); } +void CircleEditor::updateCircleY() { addChangePartCommand(tr("ordonn\351e"), part, "y", y -> text().toDouble()); } +void CircleEditor::updateCircleD() { addChangePartCommand(tr("diam\350tre"), part, "diameter", r -> text().toDouble()); } + void CircleEditor::updateForm() { - qreal _d = part -> rect().width(); - QPointF top_left(part -> sceneTopLeft()); - x -> setText(QString("%1").arg(top_left.x() + _d / 2.0)); - y -> setText(QString("%1").arg(top_left.y() + _d / 2.0)); - r -> setText(QString("%1").arg(_d)); + activeConnections(false); + x -> setText(part -> property("x").toString()); + y -> setText(part -> property("y").toString()); + r -> setText(part -> property("diameter").toString()); + activeConnections(true); +} + +void CircleEditor::activeConnections(bool active) { + if (active) { + connect(x, SIGNAL(editingFinished()), this, SLOT(updateCircleX())); + connect(y, SIGNAL(editingFinished()), this, SLOT(updateCircleY())); + connect(r, SIGNAL(editingFinished()), this, SLOT(updateCircleD())); + } else { + disconnect(x, SIGNAL(editingFinished()), this, SLOT(updateCircleX())); + disconnect(y, SIGNAL(editingFinished()), this, SLOT(updateCircleY())); + disconnect(r, SIGNAL(editingFinished()), this, SLOT(updateCircleD())); + } } diff --git a/editor/circleeditor.h b/editor/circleeditor.h index 12a795361..fa1dadc4b 100644 --- a/editor/circleeditor.h +++ b/editor/circleeditor.h @@ -1,17 +1,18 @@ #ifndef CIRCLE_EDITOR_H #define CIRCLE_EDITOR_H #include +#include "elementitemeditor.h" class PartCircle; /** Cette classe represente un editeur de cercle. Elle permet d'editer a travers une interface graphique les proprietes d'une cercle composant le dessin d'un element. */ -class CircleEditor : public QWidget { +class CircleEditor : public ElementItemEditor { Q_OBJECT // Constructeurs, destructeur public: - CircleEditor(PartCircle *, QWidget * = 0); + CircleEditor(QETElementEditor *, PartCircle *, QWidget * = 0); virtual ~CircleEditor(); private: CircleEditor(const CircleEditor &); @@ -24,6 +25,12 @@ class CircleEditor : public QWidget { // methodes public slots: void updateCircle(); + void updateCircleX(); + void updateCircleY(); + void updateCircleD(); void updateForm(); + + private: + void activeConnections(bool); }; #endif diff --git a/editor/customelementgraphicpart.cpp b/editor/customelementgraphicpart.cpp index 411536f75..102188699 100644 --- a/editor/customelementgraphicpart.cpp +++ b/editor/customelementgraphicpart.cpp @@ -131,3 +131,32 @@ void CustomElementGraphicPart::applyStylesToQPainter(QPainter &painter) const { QWidget *CustomElementGraphicPart::elementInformations() { return(style_editor); } + +void CustomElementGraphicPart::setProperty(const QString &property, const QVariant &value) { + if (property == "line-style") { + setLineStyle(static_cast(value.toInt())); + } else if (property == "line-weight") { + setLineWeight(static_cast(value.toInt())); + } else if (property == "filling") { + setFilling(static_cast(value.toInt())); + } else if (property == "color") { + setColor(static_cast(value.toInt())); + } else if (property == "antialias") { + setAntialiased(value.toBool()); + } +} + +QVariant CustomElementGraphicPart::property(const QString &property) { + if (property == "line-style") { + return(lineStyle()); + } else if (property == "line-weight") { + return(lineWeight()); + } else if (property == "filling") { + return(filling()); + } else if (property == "color") { + return(color()); + } else if (property == "antialias") { + return(antialiased()); + } + return(QVariant()); +} diff --git a/editor/customelementgraphicpart.h b/editor/customelementgraphicpart.h index d4c8b9c22..414fdff7a 100644 --- a/editor/customelementgraphicpart.h +++ b/editor/customelementgraphicpart.h @@ -3,6 +3,7 @@ #include #include "customelementpart.h" #include "styleeditor.h" +class QETElementEditor; /** Cette classe represente une partie graphique d'element Elle encapsule des methodes afin de gerer les attributs de style communs @@ -18,14 +19,15 @@ class CustomElementGraphicPart : public CustomElementPart { // constructeurs, destructeur public: - CustomElementGraphicPart() : + CustomElementGraphicPart(QETElementEditor *editor) : + CustomElementPart(editor), _linestyle(NormalStyle), _lineweight(NormalWeight), _filling(NoneFilling), _color(BlackColor), _antialiased(false) { - style_editor = new StyleEditor(this); + style_editor = new StyleEditor(elementEditor(), this); }; virtual ~CustomElementGraphicPart() { @@ -59,6 +61,8 @@ class CustomElementGraphicPart : public CustomElementPart { bool antialiased() const; QWidget *elementInformations(); + void setProperty(const QString &, const QVariant &); + QVariant property(const QString &); protected: void stylesToXml(QDomElement &) const; diff --git a/editor/customelementpart.cpp b/editor/customelementpart.cpp index 990173907..c316731d5 100644 --- a/editor/customelementpart.cpp +++ b/editor/customelementpart.cpp @@ -1,6 +1,22 @@ #include "customelementpart.h" #include "customelement.h" +#include "qetelementeditor.h" QPicture *CustomElementPart::getCustomElementQPicture(CustomElement &ce) const { return(&(ce.dessin)); } + +/// @return le QETElementEditor auquel cet editeur appartient +QETElementEditor *CustomElementPart::elementEditor() const { + return(element_editor); +} + +/// @return l'ElementScene contenant les parties editees par cet editeur +ElementScene *CustomElementPart::elementScene() const { + return(element_editor -> elementScene()); +} + +/// @return la QUndoStack a utiliser pour les annulations +QUndoStack &CustomElementPart::undoStack() const { + return(elementScene() -> undoStack()); +} diff --git a/editor/customelementpart.h b/editor/customelementpart.h index a46c52238..3a94b4efb 100644 --- a/editor/customelementpart.h +++ b/editor/customelementpart.h @@ -4,6 +4,8 @@ #include #include class CustomElement; +class QETElementEditor; +class ElementScene; /** Cette classe abstraite represente une partie de la representation graphique d'un element de schema electrique. Les attributs et methodes qu'elle @@ -15,7 +17,7 @@ class CustomElement; class CustomElementPart { // constructeurs, destructeur public: - CustomElementPart() {}; + CustomElementPart(QETElementEditor *editor) : element_editor(editor) {}; virtual ~CustomElementPart() { qDebug() << "~CustomElementPart()"; }; @@ -24,6 +26,7 @@ class CustomElementPart { // attributs private: + QETElementEditor *element_editor; // methodes public: @@ -33,6 +36,12 @@ class CustomElementPart { //virtual void renderToCustomElement(CustomElement &) const = 0; //virtual void toEditorPart(const EditorPart &); //virtual void fromEditorPart(const EditorPart &) = 0; + virtual void setProperty(const QString &, const QVariant &) = 0; + virtual QVariant property(const QString &) = 0; + virtual QETElementEditor *elementEditor() const; + virtual ElementScene *elementScene() const; + virtual QUndoStack &undoStack() const; + protected: QPicture *getCustomElementQPicture(CustomElement &ce) const; }; diff --git a/editor/editorcommands.cpp b/editor/editorcommands.cpp index 5486aad20..6f40b5a57 100644 --- a/editor/editorcommands.cpp +++ b/editor/editorcommands.cpp @@ -3,12 +3,12 @@ /*** DeletePartsCommand ***/ /** Constructeur - @param scene EditorScene concernee + @param scene ElementScene concernee @param parts Liste des parties supprimees @param parent QUndoCommand parent */ DeletePartsCommand::DeletePartsCommand( - EditorScene *scene, + ElementScene *scene, const QList parts, QUndoCommand *parent ) : @@ -46,13 +46,13 @@ void DeletePartsCommand::redo() { /** Constructeur @param m Mouvement sous forme de QPointF - @param scene EditorScene concernee + @param scene ElementScene concernee @param parts Liste des parties deplacees @param parent QUndoCommand parent */ MovePartsCommand::MovePartsCommand( const QPointF &m, - EditorScene *scene, + ElementScene *scene, const QList parts, QUndoCommand *parent ) : @@ -92,7 +92,7 @@ void MovePartsCommand::redo() { */ AddPartCommand::AddPartCommand( const QString &name, - EditorScene *scene, + ElementScene *scene, QGraphicsItem *p, QUndoCommand *parent ) : @@ -123,3 +123,42 @@ void AddPartCommand::redo() { } editor_scene -> addItem(part); } + +/** + Constructeur + @param name nom de la propriete modifiee + @param part partie modifiee + @param prop propriete modifiee + @param old_v ancienne valeur + @param new_v nouvelle valeur + @param parent qUndoCommand parent +*/ +ChangePartCommand::ChangePartCommand( + const QString &name, + CustomElementPart *part, + const QString &prop, + const QVariant &old_v, + const QVariant &new_v, + QUndoCommand *parent +) : + QUndoCommand(QObject::tr("modification ") + name, parent), + cep(part), + property(prop), + old_value(old_v), + new_value(new_v) +{ +} + +/// Destructeur +ChangePartCommand::~ChangePartCommand() { +} + +/// Annule le changement +void ChangePartCommand::undo() { + cep -> setProperty(property, old_value); +} + +/// Refait le changement +void ChangePartCommand::redo() { + cep -> setProperty(property, new_value); +} diff --git a/editor/editorcommands.h b/editor/editorcommands.h index 0e1479024..c09e28db6 100644 --- a/editor/editorcommands.h +++ b/editor/editorcommands.h @@ -1,7 +1,7 @@ #ifndef EDITOR_COMMANDS_H #define EDITOR_COMMANDS_H #include "customelementpart.h" -#include "editorscene.h" +#include "elementscene.h" #include "qgimanager.h" #include /** @@ -11,7 +11,7 @@ class DeletePartsCommand : public QUndoCommand { // constructeurs, destructeur public: - DeletePartsCommand(EditorScene *, const QList, QUndoCommand * = 0); + DeletePartsCommand(ElementScene *, const QList, QUndoCommand * = 0); virtual ~DeletePartsCommand(); private: DeletePartsCommand(const DeletePartsCommand &); @@ -25,7 +25,7 @@ class DeletePartsCommand : public QUndoCommand { /// Liste des parties supprimees QList deleted_parts; /// scene sur laquelle se produisent les actions - EditorScene *editor_scene; + ElementScene *editor_scene; }; /** @@ -35,7 +35,7 @@ class DeletePartsCommand : public QUndoCommand { class MovePartsCommand : public QUndoCommand { // constructeurs, destructeur public: - MovePartsCommand(const QPointF &, EditorScene *, const QList, QUndoCommand * = 0); + MovePartsCommand(const QPointF &, ElementScene *, const QList, QUndoCommand * = 0); virtual ~MovePartsCommand(); private: MovePartsCommand(const MovePartsCommand &); @@ -49,7 +49,7 @@ class MovePartsCommand : public QUndoCommand { /// Liste des parties supprimees QList moved_parts; /// scene sur laquelle se produisent les actions - EditorScene *editor_scene; + ElementScene *editor_scene; /// translation appliquee QPointF movement; /// booleen pour eviter d'appeler redo() lors de la construction de l'objet @@ -63,7 +63,7 @@ class MovePartsCommand : public QUndoCommand { class AddPartCommand : public QUndoCommand { // constructeurs, destructeur public: - AddPartCommand(const QString &, EditorScene *, QGraphicsItem *, QUndoCommand * = 0); + AddPartCommand(const QString &, ElementScene *, QGraphicsItem *, QUndoCommand * = 0); virtual ~AddPartCommand(); private: AddPartCommand(const AddPartCommand &); @@ -77,9 +77,36 @@ class AddPartCommand : public QUndoCommand { /// Liste des parties supprimees QGraphicsItem *part; /// scene sur laquelle se produisent les actions - EditorScene *editor_scene; + ElementScene *editor_scene; /// booleen pour eviter d'appeler redo() lors de la construction de l'objet bool first_redo; }; +/** + Cette classe represente l'action de modifier une propriete d'une partie + lors de l'edition d'un element +*/ +class ChangePartCommand : public QUndoCommand { + // constructeurs, destructeur + public: + ChangePartCommand(const QString &, CustomElementPart *, const QString &, const QVariant &, const QVariant &, QUndoCommand * = 0); + virtual ~ChangePartCommand(); + private: + ChangePartCommand(const ChangePartCommand &); + + // methodes + virtual void undo(); + virtual void redo(); + + // attributs + private: + /// Partie modifiee + CustomElementPart *cep; + /// Propriete modifiee + QString property; + /// ancienne valeur + QVariant old_value; + /// nouvelle valeur + QVariant new_value; +}; #endif diff --git a/editor/elementitemeditor.cpp b/editor/elementitemeditor.cpp new file mode 100644 index 000000000..8a8a942a1 --- /dev/null +++ b/editor/elementitemeditor.cpp @@ -0,0 +1,61 @@ +#include "elementitemeditor.h" +#include "qetelementeditor.h" +#include "editorcommands.h" + +/** + Constructeur + @param editor QETElementEditor auquel cet editeur appartient + @param parent QWidget parent de cet editeur +*/ +ElementItemEditor::ElementItemEditor(QETElementEditor *editor, QWidget *parent) : + QWidget(parent), + element_editor(editor) +{ +} + +/// @return le QETElementEditor auquel cet editeur appartient +QETElementEditor *ElementItemEditor::elementEditor() const { + return(element_editor); +} + +/// @return l'ElementScene contenant les parties editees par cet editeur +ElementScene *ElementItemEditor::elementScene() const { + return(element_editor -> elementScene()); +} + +/// @return la QUndoStack a utiliser pour les annulations +QUndoStack &ElementItemEditor::undoStack() const { + return(elementScene() -> undoStack()); +} + +/** + Ajoute une ChangePartCommand a l'UndoStack. L'ancienne valeur sera + automatiquement recuperee. + @param name nom de la propriete modifiee + @param part partie modifiee + @param prop propriete modifiee + @param new_v nouvelle valeur +*/ +void ElementItemEditor::addChangePartCommand(const QString &desc, CustomElementPart *part, const QString &prop, const QVariant &new_v) { + QVariant old_v = part -> property(prop); + if (old_v == new_v) return; + undoStack().push( + new ChangePartCommand( + desc + " " + element_type_name, + part, + prop, + old_v, + new_v + ) + ); +} + +/// @return Le nom du type d'element edite +QString ElementItemEditor::elementTypeName() const { + return(element_type_name); +} + +/// @param name Nom du type d'element edite +void ElementItemEditor::setElementTypeName(const QString &name) { + element_type_name = name; +} diff --git a/editor/elementitemeditor.h b/editor/elementitemeditor.h new file mode 100644 index 000000000..88b7398db --- /dev/null +++ b/editor/elementitemeditor.h @@ -0,0 +1,30 @@ +#ifndef ELEMENT_ITEM_EDITOR_H +#define ELEMENT_ITEM_EDITOR_H +#include +class QETElementEditor; +class ElementScene; +class CustomElementPart; +class ElementItemEditor : public QWidget { + Q_OBJECT + // constructeurs, destructeur + public: + ElementItemEditor(QETElementEditor *, QWidget * = 0); + virtual ~ElementItemEditor() {}; + private: + ElementItemEditor(const ElementItemEditor &); + + // methodes + public: + virtual QETElementEditor *elementEditor() const; + virtual ElementScene *elementScene() const; + virtual QUndoStack &undoStack() const; + virtual void addChangePartCommand(const QString &, CustomElementPart *, const QString &, const QVariant &); + virtual QString elementTypeName() const; + virtual void setElementTypeName(const QString &); + + // attributs + private: + QETElementEditor *element_editor; + QString element_type_name; +}; +#endif diff --git a/editor/editorscene.cpp b/editor/elementscene.cpp similarity index 87% rename from editor/editorscene.cpp rename to editor/elementscene.cpp index d9ed6ded1..75c99adb8 100644 --- a/editor/editorscene.cpp +++ b/editor/elementscene.cpp @@ -1,4 +1,5 @@ -#include "editorscene.h" +#include "elementscene.h" +#include "qetelementeditor.h" #include #include "partline.h" #include "partellipse.h" @@ -13,58 +14,59 @@ #define GRILLE_X 10 #define GRILLE_Y 10 -EditorScene::EditorScene(QObject *parent) : +ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) : QGraphicsScene(parent), _width(3), _height(7), _hotspot(15, 35), - qgi_manager(this) + qgi_manager(this), + element_editor(editor) { current_polygon = NULL; connect(this, SIGNAL(changed(const QList &)), this, SLOT(slot_checkSelectionChanged())); } -EditorScene::~EditorScene() { - qDebug() << "~EditorScene()"; +ElementScene::~ElementScene() { + qDebug() << "~ElementScene()"; } -void EditorScene::slot_move() { +void ElementScene::slot_move() { behavior = Normal; } -void EditorScene::slot_addLine() { +void ElementScene::slot_addLine() { behavior = Line; } -void EditorScene::slot_addCircle() { +void ElementScene::slot_addCircle() { behavior = Circle; } -void EditorScene::slot_addEllipse() { +void ElementScene::slot_addEllipse() { behavior = Ellipse; } -void EditorScene::slot_addPolygon() { +void ElementScene::slot_addPolygon() { behavior = Polygon; } -void EditorScene::slot_addText() { +void ElementScene::slot_addText() { behavior = Text; } -void EditorScene::slot_addTerminal() { +void ElementScene::slot_addTerminal() { behavior = Terminal; } -void EditorScene::slot_addArc() { +void ElementScene::slot_addArc() { behavior = Arc; } -void EditorScene::slot_addTextField() { +void ElementScene::slot_addTextField() { behavior = TextField; } -void EditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { +void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { if (behavior != Polygon && current_polygon != NULL) current_polygon = NULL; QRectF temp_rect; qreal radius; @@ -116,7 +118,7 @@ void EditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { } else QGraphicsScene::mouseMoveEvent(e); } -void EditorScene::mousePressEvent(QGraphicsSceneMouseEvent *e) { +void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e) { if (behavior != Polygon && current_polygon != NULL) current_polygon = NULL; QPolygonF temp_polygon; if (e -> button() & Qt::LeftButton) { @@ -125,24 +127,24 @@ void EditorScene::mousePressEvent(QGraphicsSceneMouseEvent *e) { QGraphicsScene::mousePressEvent(e); break; case Line: - current_line = new PartLine(0, this); + current_line = new PartLine(element_editor, 0, this); current_line -> setLine(QLineF(e -> scenePos(), e -> scenePos())); break; case Ellipse: - current_ellipse = new PartEllipse(0, this); + current_ellipse = new PartEllipse(element_editor, 0, this); current_ellipse -> setRect(QRectF(e -> scenePos(), QSizeF(0.0, 0.0))); break; case Arc: - current_arc = new PartArc(0, this); + current_arc = new PartArc(element_editor, 0, this); current_arc -> setRect(QRectF(e -> scenePos(), QSizeF(0.0, 0.0))); break; case Circle: - current_circle = new PartCircle(0, this); + current_circle = new PartCircle(element_editor, 0, this); current_circle -> setRect(QRectF(e -> scenePos(), QSizeF(0.0, 0.0))); break; case Polygon: if (current_polygon == NULL) { - current_polygon = new PartPolygon(0, this); + current_polygon = new PartPolygon(element_editor, 0, this); temp_polygon = QPolygonF(0); } else temp_polygon = current_polygon -> polygon(); // au debut, on insere deux points @@ -156,7 +158,7 @@ void EditorScene::mousePressEvent(QGraphicsSceneMouseEvent *e) { } else QGraphicsScene::mousePressEvent(e); } -void EditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { +void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { PartTerminal *terminal; PartText *text; PartTextField *textfield; @@ -179,17 +181,17 @@ void EditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { undo_stack.push(new AddPartCommand(tr("cercle"), this, current_circle)); break; case Terminal: - terminal = new PartTerminal(0, this); + terminal = new PartTerminal(element_editor, 0, this); terminal -> setPos(e -> scenePos()); undo_stack.push(new AddPartCommand(tr("borne"), this, terminal)); break; case Text: - text = new PartText(0, this); + text = new PartText(element_editor, 0, this); text -> setPos(e -> scenePos()); undo_stack.push(new AddPartCommand(tr("texte"), this, text)); break; case TextField: - textfield = new PartTextField(0, this); + textfield = new PartTextField(element_editor, 0, this); textfield -> setPos(e -> scenePos()); undo_stack.push(new AddPartCommand(tr("champ de texte"), this, textfield)); break; @@ -219,7 +221,7 @@ void EditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { @param p Le QPainter a utiliser pour dessiner @param r Le rectangle de la zone a dessiner */ -void EditorScene::drawBackground(QPainter *p, const QRectF &r) { +void ElementScene::drawBackground(QPainter *p, const QRectF &r) { p -> save(); // desactive tout antialiasing, sauf pour le texte @@ -264,7 +266,7 @@ void EditorScene::drawBackground(QPainter *p, const QRectF &r) { @param p Le QPainter a utiliser pour dessiner @param r Le rectangle de la zone a dessiner */ -void EditorScene::drawForeground(QPainter *p, const QRectF &) { +void ElementScene::drawForeground(QPainter *p, const QRectF &) { p -> save(); // desactive tout antialiasing, sauf pour le texte @@ -279,7 +281,7 @@ void EditorScene::drawForeground(QPainter *p, const QRectF &) { p -> restore(); } -const QDomDocument EditorScene::toXml() const { +const QDomDocument ElementScene::toXml() const { // document XML QDomDocument xml_document; @@ -308,7 +310,7 @@ const QDomDocument EditorScene::toXml() const { return(xml_document); } -void EditorScene::fromXml(const QDomDocument &xml_document) { +void ElementScene::fromXml(const QDomDocument &xml_document) { QString error_message; bool state = true; @@ -365,14 +367,14 @@ void EditorScene::fromXml(const QDomDocument &xml_document) { QDomElement qde = n.toElement(); if (qde.isNull()) continue; CustomElementPart *cep; - if (qde.tagName() == "line") cep = new PartLine (0, this); - else if (qde.tagName() == "ellipse") cep = new PartEllipse (0, this); - else if (qde.tagName() == "circle") cep = new PartCircle (0, this); - else if (qde.tagName() == "polygon") cep = new PartPolygon (0, this); - else if (qde.tagName() == "terminal") cep = new PartTerminal (0, this); - else if (qde.tagName() == "text") cep = new PartText (0, this); - else if (qde.tagName() == "input") cep = new PartTextField(0, this); - else if (qde.tagName() == "arc") cep = new PartArc (0, this); + if (qde.tagName() == "line") cep = new PartLine (element_editor, 0, this); + else if (qde.tagName() == "ellipse") cep = new PartEllipse (element_editor, 0, this); + else if (qde.tagName() == "circle") cep = new PartCircle (element_editor, 0, this); + else if (qde.tagName() == "polygon") cep = new PartPolygon (element_editor, 0, this); + else if (qde.tagName() == "terminal") cep = new PartTerminal (element_editor, 0, this); + else if (qde.tagName() == "text") cep = new PartText (element_editor, 0, this); + else if (qde.tagName() == "input") cep = new PartTextField(element_editor, 0, this); + else if (qde.tagName() == "arc") cep = new PartArc (element_editor, 0, this); else continue; if (QGraphicsItem *qgi = dynamic_cast(cep)) qgi -> setZValue(z++); cep -> fromXml(qde); @@ -382,34 +384,34 @@ void EditorScene::fromXml(const QDomDocument &xml_document) { } } -QUndoStack &EditorScene::undoStack() { +QUndoStack &ElementScene::undoStack() { return(undo_stack); } -QGIManager &EditorScene::qgiManager() { +QGIManager &ElementScene::qgiManager() { return(qgi_manager); } -void EditorScene::slot_checkSelectionChanged() { +void ElementScene::slot_checkSelectionChanged() { static QList cache_selecteditems = QList(); QList selecteditems = selectedItems(); if (cache_selecteditems != selecteditems) emit(selectionChanged()); cache_selecteditems = selecteditems; } -void EditorScene::slot_selectAll() { +void ElementScene::slot_selectAll() { foreach(QGraphicsItem *qgi, items()) qgi -> setSelected(true); } -void EditorScene::slot_deselectAll() { +void ElementScene::slot_deselectAll() { clearSelection(); } -void EditorScene::slot_invertSelection() { +void ElementScene::slot_invertSelection() { foreach(QGraphicsItem *qgi, items()) qgi -> setSelected(!qgi -> isSelected()); } -void EditorScene::slot_delete() { +void ElementScene::slot_delete() { // verifie qu'il y a qqc de selectionne QList selected_items = selectedItems(); if (selected_items.isEmpty()) return; @@ -418,7 +420,7 @@ void EditorScene::slot_delete() { undo_stack.push(new DeletePartsCommand(this, selected_items)); } -void EditorScene::slot_editSizeHotSpot() { +void ElementScene::slot_editSizeHotSpot() { // cree un dialogue QDialog dialog_sh; dialog_sh.setModal(true); @@ -456,7 +458,7 @@ void EditorScene::slot_editSizeHotSpot() { } } -void EditorScene::slot_editOrientations() { +void ElementScene::slot_editOrientations() { // cree un dialogue QDialog dialog_ori; @@ -486,7 +488,7 @@ void EditorScene::slot_editOrientations() { if (dialog_ori.exec() == QDialog::Accepted) ori = ori_widget -> orientationSet(); } -void EditorScene::slot_editNames() { +void ElementScene::slot_editNames() { // cree un dialogue QDialog dialog; diff --git a/editor/editorscene.h b/editor/elementscene.h similarity index 76% rename from editor/editorscene.h rename to editor/elementscene.h index 5a0c4ce0a..2e2f9b042 100644 --- a/editor/editorscene.h +++ b/editor/elementscene.h @@ -1,16 +1,17 @@ -#ifndef EDITOR_SCNE_H -#define EDITOR_SCNE_H +#ifndef ELEMENT_SCENE_H +#define ELEMENT_SCENE_H #include #include #include "nameslistwidget.h" #include "orientationsetwidget.h" #include "qgimanager.h" +class QETElementEditor; class PartLine; class PartEllipse; class PartCircle; class PartPolygon; class PartArc; -class EditorScene : public QGraphicsScene { +class ElementScene : public QGraphicsScene { Q_OBJECT // enum @@ -18,11 +19,11 @@ class EditorScene : public QGraphicsScene { // constructeurs, destructeur public: - EditorScene(QObject * = 0); - virtual ~EditorScene(); + ElementScene(QETElementEditor *, QObject * = 0); + virtual ~ElementScene(); private: - EditorScene(const EditorScene &); + ElementScene(const ElementScene &); // attributs private: @@ -48,6 +49,7 @@ class EditorScene : public QGraphicsScene { PartCircle *current_circle; PartPolygon *current_polygon; PartArc *current_arc; + QETElementEditor *element_editor; // methodes public: @@ -97,47 +99,47 @@ class EditorScene : public QGraphicsScene { void needNormalMode(); }; -inline void EditorScene::setWidth(const uint &wid) { +inline void ElementScene::setWidth(const uint &wid) { _width = wid; while (_width % 10) ++ _width; _width /= 10; } -inline uint EditorScene::width() const { +inline uint ElementScene::width() const { return(_width * 10); } -inline void EditorScene::setHeight(const uint &hei) { +inline void ElementScene::setHeight(const uint &hei) { _height = hei; while (_height % 10) ++ _height; _height /= 10; } -inline uint EditorScene::height() const { +inline uint ElementScene::height() const { return(_height * 10); } -inline void EditorScene::setHotspot(const QPoint &hs) { +inline void ElementScene::setHotspot(const QPoint &hs) { _hotspot = hs; } -inline QPoint EditorScene::hotspot() const { +inline QPoint ElementScene::hotspot() const { return(_hotspot); } -inline void EditorScene::setNames(const NamesList nameslist) { +inline void ElementScene::setNames(const NamesList nameslist) { _names = nameslist; } -inline NamesList EditorScene::names() const { +inline NamesList ElementScene::names() const { return(_names); } -inline OrientationSet EditorScene::orientations() { +inline OrientationSet ElementScene::orientations() { return(ori); } -inline void EditorScene::setOrientations(const OrientationSet &orientation_set) { +inline void ElementScene::setOrientations(const OrientationSet &orientation_set) { ori = orientation_set; } diff --git a/editor/elementview.cpp b/editor/elementview.cpp new file mode 100644 index 000000000..5fc4637a5 --- /dev/null +++ b/editor/elementview.cpp @@ -0,0 +1,35 @@ +#include "elementview.h" +/** + Constructeur + @param scene ElementScene visualisee par cette ElementView + @param parent QWidget parent de cette ElementView +*/ +ElementView::ElementView(ElementScene *scene, QWidget *parent) : + QGraphicsView(scene, parent), + _scene(scene) +{ + setInteractive(true); + setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + //setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + setResizeAnchor(QGraphicsView::AnchorUnderMouse); + //setSceneRect(QRectF(0.0, 0.0, 50.0, 200.0)); + scale(4.0, 4.0); +} + +/// Destructeur +ElementView::~ElementView() { +} + +/// @return l'ElementScene visualisee par cette ElementView +ElementScene *ElementView::scene() const { + return(_scene); +} + +/** + Definit l'ElementScene visualisee par cette ElementView + @param s l'ElementScene visualisee par cette ElementView +*/ +void ElementView::setScene(ElementScene *s) { + QGraphicsView::setScene(s); + _scene = s; +} diff --git a/editor/elementview.h b/editor/elementview.h new file mode 100644 index 000000000..b0010eeb6 --- /dev/null +++ b/editor/elementview.h @@ -0,0 +1,24 @@ +#ifndef ELEMENT_VIEW_H +#define ELEMENT_VIEW_H +#include +#include "elementscene.h" +class ElementView : public QGraphicsView { + Q_OBJECT + // constructeurs, destructeur + public: + ElementView(ElementScene *, QWidget * = 0); + virtual ~ElementView(); + + private: + ElementView(const ElementView &); + + // methodes + public: + ElementScene *scene() const; + void setScene(ElementScene *); + + //attributs + private: + ElementScene *_scene; +}; +#endif diff --git a/editor/ellipseeditor.cpp b/editor/ellipseeditor.cpp index 454a11327..3d339df99 100644 --- a/editor/ellipseeditor.cpp +++ b/editor/ellipseeditor.cpp @@ -1,7 +1,7 @@ #include "ellipseeditor.h" #include "partellipse.h" -EllipseEditor::EllipseEditor(PartEllipse *ellipse, QWidget *parent) : QWidget(parent) { +EllipseEditor::EllipseEditor(QETElementEditor *editor, PartEllipse *ellipse, QWidget *parent) : ElementItemEditor(editor, parent) { part = ellipse; @@ -29,12 +29,8 @@ EllipseEditor::EllipseEditor(PartEllipse *ellipse, QWidget *parent) : QWidget(pa grid -> addWidget(new QLabel(tr("vertical :")), 4, 0); grid -> addWidget(v, 4, 1); + activeConnections(true); updateForm(); - - connect(x, SIGNAL(editingFinished()), this, SLOT(updateEllipse())); - connect(y, SIGNAL(editingFinished()), this, SLOT(updateEllipse())); - connect(h, SIGNAL(editingFinished()), this, SLOT(updateEllipse())); - connect(v, SIGNAL(editingFinished()), this, SLOT(updateEllipse())); } EllipseEditor::~EllipseEditor() { @@ -42,25 +38,36 @@ EllipseEditor::~EllipseEditor() { } void EllipseEditor::updateEllipse() { - qreal _x = x -> text().toDouble(); - qreal _y = y -> text().toDouble(); - qreal _h = h -> text().toDouble(); - qreal _v = v -> text().toDouble(); - _v = _v < 0 ? -_v : _v; - part -> setRect( - QRectF( - part -> mapFromScene(QPointF(_x - (_h / 2.0), _y - (_v / 2.0))), - QSizeF(_h, _v) - ) - ); + part -> setProperty("x", x -> text().toDouble()); + part -> setProperty("y", x -> text().toDouble()); + part -> setProperty("diameter_h", x -> text().toDouble()); + part -> setProperty("diameter_v", x -> text().toDouble()); } +void EllipseEditor::updateEllipseX() { addChangePartCommand(tr("abscisse"), part, "x", x -> text().toDouble()); } +void EllipseEditor::updateEllipseY() { addChangePartCommand(tr("ordonn\351e"), part, "y", y -> text().toDouble()); } +void EllipseEditor::updateEllipseH() { addChangePartCommand(tr("diam\350tre horizontal"), part, "diameter_h", h -> text().toDouble()); } +void EllipseEditor::updateEllipseV() { addChangePartCommand(tr("diam\350tre vertical"), part, "diameter_v", v -> text().toDouble()); } + void EllipseEditor::updateForm() { - qreal _h = part -> rect().width(); - qreal _v = part -> rect().height(); - QPointF top_left(part -> sceneTopLeft()); - x -> setText(QString("%1").arg(top_left.x() + (_h / 2.0))); - y -> setText(QString("%1").arg(top_left.y() + (_v / 2.0))); - h -> setText(QString("%1").arg(_h)); - v -> setText(QString("%1").arg(_v)); + activeConnections(false); + x -> setText(part -> property("x").toString()); + y -> setText(part -> property("y").toString()); + h -> setText(part -> property("diameter_h").toString()); + v -> setText(part -> property("diameter_v").toString()); + activeConnections(true); +} + +void EllipseEditor::activeConnections(bool active) { + if (active) { + connect(x, SIGNAL(editingFinished()), this, SLOT(updateEllipseX())); + connect(y, SIGNAL(editingFinished()), this, SLOT(updateEllipseY())); + connect(h, SIGNAL(editingFinished()), this, SLOT(updateEllipseH())); + connect(v, SIGNAL(editingFinished()), this, SLOT(updateEllipseV())); + } else { + disconnect(x, SIGNAL(editingFinished()), this, SLOT(updateEllipseX())); + disconnect(y, SIGNAL(editingFinished()), this, SLOT(updateEllipseY())); + disconnect(h, SIGNAL(editingFinished()), this, SLOT(updateEllipseH())); + disconnect(v, SIGNAL(editingFinished()), this, SLOT(updateEllipseV())); + } } diff --git a/editor/ellipseeditor.h b/editor/ellipseeditor.h index b713814a4..c2a173d76 100644 --- a/editor/ellipseeditor.h +++ b/editor/ellipseeditor.h @@ -1,12 +1,13 @@ #ifndef ELLIPSE_EDITOR_H #define ELLIPSE_EDITOR_H #include +#include "elementitemeditor.h" class PartEllipse; -class EllipseEditor : public QWidget { +class EllipseEditor : public ElementItemEditor { Q_OBJECT //constructeurs, destructeur public: - EllipseEditor(PartEllipse *, QWidget * = 0); + EllipseEditor(QETElementEditor *, PartEllipse *, QWidget * = 0); ~EllipseEditor(); private: EllipseEditor(const EllipseEditor &); @@ -19,6 +20,13 @@ class EllipseEditor : public QWidget { // methodes public slots: void updateEllipse(); + void updateEllipseX(); + void updateEllipseY(); + void updateEllipseH(); + void updateEllipseV(); void updateForm(); + + private: + void activeConnections(bool); }; #endif diff --git a/editor/lineeditor.cpp b/editor/lineeditor.cpp index 66c8ba35f..4c3cf607a 100644 --- a/editor/lineeditor.cpp +++ b/editor/lineeditor.cpp @@ -1,7 +1,7 @@ #include "lineeditor.h" #include "partline.h" -LineEditor::LineEditor(PartLine *line, QWidget *parent) : QWidget(parent) { +LineEditor::LineEditor(QETElementEditor *editor, PartLine *line, QWidget *parent) : ElementItemEditor(editor, parent) { part = line; @@ -21,11 +21,6 @@ LineEditor::LineEditor(PartLine *line, QWidget *parent) : QWidget(parent) { grid -> addWidget(y2, 1, 3); updateForm(); - - connect(x1, SIGNAL(editingFinished()), this, SLOT(updateLine())); - connect(y1, SIGNAL(editingFinished()), this, SLOT(updateLine())); - connect(x2, SIGNAL(editingFinished()), this, SLOT(updateLine())); - connect(y2, SIGNAL(editingFinished()), this, SLOT(updateLine())); } LineEditor::~LineEditor() { @@ -47,11 +42,32 @@ void LineEditor::updateLine() { ); } +void LineEditor::updateLineX1() { addChangePartCommand(tr("abscisse point 1"), part, "x1", x1 -> text().toDouble()); } +void LineEditor::updateLineY1() { addChangePartCommand(tr("ordonn\351e point 1"), part, "y1", y1 -> text().toDouble()); } +void LineEditor::updateLineX2() { addChangePartCommand(tr("abscisse point 2"), part, "x2", x2 -> text().toDouble()); } +void LineEditor::updateLineY2() { addChangePartCommand(tr("ordonn\351e point 2"), part, "y2", y2 -> text().toDouble()); } + void LineEditor::updateForm() { + activeConnections(false); QPointF p1(part -> sceneP1()); QPointF p2(part -> sceneP2()); x1 -> setText(QString("%1").arg(p1.x())); y1 -> setText(QString("%1").arg(p1.y())); x2 -> setText(QString("%1").arg(p2.x())); y2 -> setText(QString("%1").arg(p2.y())); + activeConnections(true); +} + +void LineEditor::activeConnections(bool active) { + if (active) { + connect(x1, SIGNAL(editingFinished()), this, SLOT(updateLineX1())); + connect(y1, SIGNAL(editingFinished()), this, SLOT(updateLineY1())); + connect(x2, SIGNAL(editingFinished()), this, SLOT(updateLineX2())); + connect(y2, SIGNAL(editingFinished()), this, SLOT(updateLineY2())); + } else { + connect(x1, SIGNAL(editingFinished()), this, SLOT(updateLineX1())); + connect(y1, SIGNAL(editingFinished()), this, SLOT(updateLineY1())); + connect(x2, SIGNAL(editingFinished()), this, SLOT(updateLineX2())); + connect(y2, SIGNAL(editingFinished()), this, SLOT(updateLineY2())); + } } diff --git a/editor/lineeditor.h b/editor/lineeditor.h index 4a7050dca..be238cec5 100644 --- a/editor/lineeditor.h +++ b/editor/lineeditor.h @@ -1,12 +1,13 @@ #ifndef LINE_EDITOR_H #define LINE_EDITOR_H #include +#include "elementitemeditor.h" class PartLine; -class LineEditor : public QWidget { +class LineEditor : public ElementItemEditor { Q_OBJECT //constructeurs, destructeur public: - LineEditor(PartLine *, QWidget * = 0); + LineEditor(QETElementEditor *, PartLine *, QWidget * = 0); ~LineEditor(); private: LineEditor(const LineEditor &); @@ -19,6 +20,13 @@ class LineEditor : public QWidget { // methodes public slots: void updateLine(); + void updateLineX1(); + void updateLineY1(); + void updateLineX2(); + void updateLineY2(); void updateForm(); + + private: + void activeConnections(bool); }; #endif diff --git a/editor/partarc.cpp b/editor/partarc.cpp index 6af4c130b..a5129cfa4 100644 --- a/editor/partarc.cpp +++ b/editor/partarc.cpp @@ -1,16 +1,18 @@ #include "partarc.h" #include "arceditor.h" -PartArc::PartArc(QGraphicsItem *parent, QGraphicsScene *scene) : +PartArc::PartArc(QETElementEditor *editor, QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsEllipseItem(parent, scene), - CustomElementGraphicPart(), + CustomElementGraphicPart(editor), _angle(-90), start_angle(0) { setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setAcceptedMouseButtons(Qt::LeftButton); - informations = new ArcEditor(this); + informations = new ArcEditor(elementEditor(), this); + informations -> setElementTypeName(QObject::tr("arc")); style_editor -> appendWidget(informations); + style_editor -> setElementTypeName(QObject::tr("arc")); } void PartArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { @@ -72,6 +74,57 @@ QPointF PartArc::sceneTopLeft() const { return(mapToScene(rect().topLeft())); } +void PartArc::setProperty(const QString &property, const QVariant &value) { + CustomElementGraphicPart::setProperty(property, value); + if (!value.canConvert(QVariant::Double)) return; + if (property == "x") { + QRectF current_rect = rect(); + QPointF current_pos = mapToScene(current_rect.center()); + setRect(current_rect.translated(value.toDouble() - current_pos.x(), 0.0)); + } else if (property == "y") { + QRectF current_rect = rect(); + QPointF current_pos = mapToScene(current_rect.center()); + setRect(current_rect.translated(0.0, value.toDouble() - current_pos.y())); + } else if (property == "diameter_h") { + qreal new_width = qAbs(value.toDouble()); + QRectF current_rect = rect(); + current_rect.translate((new_width - current_rect.width()) / -2.0, 0.0); + current_rect.setWidth(new_width); + setRect(current_rect); + } else if (property == "diameter_v") { + qreal new_height = qAbs(value.toDouble()); + QRectF current_rect = rect(); + current_rect.translate(0.0, (new_height - current_rect.height()) / -2.0); + current_rect.setHeight(new_height); + setRect(current_rect); + } else if (property == "start_angle") { + setStartAngle(value.toInt() ); + } else if (property == "angle") { + setAngle(value.toInt()); + } +} + +QVariant PartArc::property(const QString &property) { + // appelle la methode property de CustomElementGraphicpart pour les styles + QVariant style_property = CustomElementGraphicPart::property(property); + if (style_property != QVariant()) return(style_property); + + if (property == "x") { + return(mapToScene(rect().center()).x()); + } else if (property == "y") { + return(mapToScene(rect().center()).y()); + } else if (property == "diameter_h") { + return(rect().width()); + } else if (property == "diameter_v") { + return(rect().height()); + } else if (property == "start_angle") { + return(start_angle); + } else if (property == "angle") { + return(_angle); + } + return(QVariant()); +} + QVariant PartArc::itemChange(GraphicsItemChange change, const QVariant &value) { if (scene()) { if (change == QGraphicsItem::ItemPositionChange || change == QGraphicsItem::ItemSelectedChange) { diff --git a/editor/partarc.h b/editor/partarc.h index df1fb2aa3..fc1fa56ad 100644 --- a/editor/partarc.h +++ b/editor/partarc.h @@ -6,7 +6,7 @@ class ArcEditor; class PartArc : public QGraphicsEllipseItem, public CustomElementGraphicPart { // constructeurs, destructeur public: - PartArc(QGraphicsItem * = 0, QGraphicsScene * = 0); + PartArc(QETElementEditor *, QGraphicsItem * = 0, QGraphicsScene * = 0); virtual ~PartArc() { qDebug() << "~PartArc()"; } @@ -30,6 +30,8 @@ class PartArc : public QGraphicsEllipseItem, public CustomElementGraphicPart { virtual void setStartAngle(int); virtual int angle() const; virtual int startAngle() const; + virtual void setProperty(const QString &, const QVariant &); + virtual QVariant property(const QString &); protected: QVariant itemChange(GraphicsItemChange, const QVariant &); diff --git a/editor/partcircle.cpp b/editor/partcircle.cpp index e34c9a1a0..ae346dc2c 100644 --- a/editor/partcircle.cpp +++ b/editor/partcircle.cpp @@ -1,11 +1,13 @@ #include "partcircle.h" #include "circleeditor.h" -PartCircle::PartCircle(QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsEllipseItem(parent, scene), CustomElementGraphicPart() { +PartCircle::PartCircle(QETElementEditor *editor, QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsEllipseItem(parent, scene), CustomElementGraphicPart(editor) { setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setAcceptedMouseButtons(Qt::LeftButton); - informations = new CircleEditor(this); + informations = new CircleEditor(elementEditor(), this); + informations -> setElementTypeName(QObject::tr("cercle")); style_editor -> appendWidget(informations); + style_editor -> setElementTypeName(QObject::tr("cercle")); } void PartCircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { @@ -52,6 +54,44 @@ void PartCircle::fromXml(const QDomElement &qde) { ); } +void PartCircle::setProperty(const QString &property, const QVariant &value) { + CustomElementGraphicPart::setProperty(property, value); + if (!value.canConvert(QVariant::Double)) return; + if (property == "x") { + QRectF current_rect = rect(); + QPointF current_pos = mapToScene(current_rect.center()); + setRect(current_rect.translated(value.toDouble() - current_pos.x(), 0.0)); + } else if (property == "y") { + QRectF current_rect = rect(); + QPointF current_pos = mapToScene(current_rect.center()); + setRect(current_rect.translated(0.0, value.toDouble() - current_pos.y())); + } else if (property == "diameter") { + QRectF current_rect = rect(); + qreal new_diameter = qAbs(value.toDouble()); + current_rect.translate( + (new_diameter - current_rect.width()) / -2.0, + (new_diameter - current_rect.height()) / -2.0 + ); + current_rect.setSize(QSizeF(new_diameter, new_diameter)); + setRect(current_rect); + } +} + +QVariant PartCircle::property(const QString &property) { + // appelle la methode property de CustomElementGraphicpart pour les styles + QVariant style_property = CustomElementGraphicPart::property(property); + if (style_property != QVariant()) return(style_property); + + if (property == "x") { + return(mapToScene(rect().center()).x()); + } else if (property == "y") { + return(mapToScene(rect().center()).y()); + } else if (property == "diameter") { + return(rect().width()); + } + return(QVariant()); +} + QVariant PartCircle::itemChange(GraphicsItemChange change, const QVariant &value) { if (scene()) { if (change == QGraphicsItem::ItemPositionChange || change == QGraphicsItem::ItemSelectedChange) { diff --git a/editor/partcircle.h b/editor/partcircle.h index 2bbb55e3b..06d9398a3 100644 --- a/editor/partcircle.h +++ b/editor/partcircle.h @@ -6,7 +6,7 @@ class CircleEditor; class PartCircle : public QGraphicsEllipseItem, public CustomElementGraphicPart { // constructeurs, destructeur public: - PartCircle(QGraphicsItem * = 0, QGraphicsScene * = 0); + PartCircle(QETElementEditor *, QGraphicsItem * = 0, QGraphicsScene * = 0); virtual ~PartCircle() { qDebug() << "~PartCircle()"; } @@ -26,6 +26,8 @@ class PartCircle : public QGraphicsEllipseItem, public CustomElementGraphicPart virtual QPointF sceneTopLeft() const; virtual QRectF boundingRect() const; QPointF sceneCenter() const; + virtual void setProperty(const QString &, const QVariant &); + virtual QVariant property(const QString &); protected: QVariant itemChange(GraphicsItemChange, const QVariant &); diff --git a/editor/partellipse.cpp b/editor/partellipse.cpp index c2a6f5b14..1b8f9dd26 100644 --- a/editor/partellipse.cpp +++ b/editor/partellipse.cpp @@ -1,11 +1,13 @@ #include "partellipse.h" #include "ellipseeditor.h" -PartEllipse::PartEllipse(QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsEllipseItem(parent, scene), CustomElementGraphicPart() { +PartEllipse::PartEllipse(QETElementEditor *editor, QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsEllipseItem(parent, scene), CustomElementGraphicPart(editor) { setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setAcceptedMouseButtons(Qt::LeftButton); - informations = new EllipseEditor(this); + informations = new EllipseEditor(elementEditor(), this); + informations -> setElementTypeName(QObject::tr("ellipse")); style_editor -> appendWidget(informations); + style_editor -> setElementTypeName(QObject::tr("ellipse")); } void PartEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { @@ -52,6 +54,49 @@ void PartEllipse::fromXml(const QDomElement &qde) { ); } +void PartEllipse::setProperty(const QString &property, const QVariant &value) { + CustomElementGraphicPart::setProperty(property, value); + if (!value.canConvert(QVariant::Double)) return; + if (property == "x") { + QRectF current_rect = rect(); + QPointF current_pos = mapToScene(current_rect.center()); + setRect(current_rect.translated(value.toDouble() - current_pos.x(), 0.0)); + } else if (property == "y") { + QRectF current_rect = rect(); + QPointF current_pos = mapToScene(current_rect.center()); + setRect(current_rect.translated(0.0, value.toDouble() - current_pos.y())); + } else if (property == "diameter_h") { + qreal new_width = qAbs(value.toDouble()); + QRectF current_rect = rect(); + current_rect.translate((new_width - current_rect.width()) / -2.0, 0.0); + current_rect.setWidth(new_width); + setRect(current_rect); + } else if (property == "diameter_v") { + qreal new_height = qAbs(value.toDouble()); + QRectF current_rect = rect(); + current_rect.translate(0.0, (new_height - current_rect.height()) / -2.0); + current_rect.setHeight(new_height); + setRect(current_rect); + } +} + +QVariant PartEllipse::property(const QString &property) { + // appelle la methode property de CustomElementGraphicpart pour les styles + QVariant style_property = CustomElementGraphicPart::property(property); + if (style_property != QVariant()) return(style_property); + + if (property == "x") { + return(mapToScene(rect().center()).x()); + } else if (property == "y") { + return(mapToScene(rect().center()).y()); + } else if (property == "diameter_h") { + return(rect().width()); + } else if (property == "diameter_v") { + return(rect().height()); + } + return(QVariant()); +} + QVariant PartEllipse::itemChange(GraphicsItemChange change, const QVariant &value) { if (scene()) { if (change == QGraphicsItem::ItemPositionChange || change == QGraphicsItem::ItemSelectedChange) { diff --git a/editor/partellipse.h b/editor/partellipse.h index ae27183c2..916ea4f3c 100644 --- a/editor/partellipse.h +++ b/editor/partellipse.h @@ -6,7 +6,7 @@ class EllipseEditor; class PartEllipse : public QGraphicsEllipseItem, public CustomElementGraphicPart { // constructeurs, destructeur public: - PartEllipse(QGraphicsItem * = 0, QGraphicsScene * = 0); + PartEllipse(QETElementEditor *, QGraphicsItem * = 0, QGraphicsScene * = 0); virtual ~PartEllipse() { qDebug() << "~PartEllipse()"; } @@ -24,6 +24,8 @@ class PartEllipse : public QGraphicsEllipseItem, public CustomElementGraphicPart virtual const QDomElement toXml(QDomDocument &) const; virtual void fromXml(const QDomElement &); virtual QPointF sceneTopLeft() const; + virtual void setProperty(const QString &, const QVariant &); + virtual QVariant property(const QString &); protected: QVariant itemChange(GraphicsItemChange, const QVariant &); diff --git a/editor/partline.cpp b/editor/partline.cpp index 43fc55ba4..fe074adf7 100644 --- a/editor/partline.cpp +++ b/editor/partline.cpp @@ -2,11 +2,13 @@ #include "lineeditor.h" #include -PartLine::PartLine(QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsLineItem(parent, scene), CustomElementGraphicPart() { +PartLine::PartLine(QETElementEditor *editor, QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsLineItem(parent, scene), CustomElementGraphicPart(editor) { setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setAcceptedMouseButtons(Qt::LeftButton); - informations = new LineEditor(this); + informations = new LineEditor(elementEditor(), this); + informations -> setElementTypeName(QObject::tr("ligne")); style_editor -> appendWidget(informations); + style_editor -> setElementTypeName(QObject::tr("ligne")); } void PartLine::paint(QPainter *painter, const QStyleOptionGraphicsItem */*q*/, QWidget */*w*/) { @@ -56,6 +58,40 @@ void PartLine::fromXml(const QDomElement &qde) { ); } +void PartLine::setProperty(const QString &property, const QVariant &value) { + CustomElementGraphicPart::setProperty(property, value); + if (!value.canConvert(QVariant::Double)) return; + QPointF new_p1(sceneP1()), new_p2(sceneP2()); + bool setline = true; + if (property == "x1") { + new_p1.setX(value.toDouble()); + } else if (property == "y1") { + new_p1.setY(value.toDouble()); + } else if (property == "x2") { + new_p2.setX(value.toDouble()); + } else if (property == "y2") { + new_p2.setY(value.toDouble()); + } else setline = false; + setLine(QLineF(mapFromScene(new_p1), mapFromScene(new_p2))); +} + +QVariant PartLine::property(const QString &property) { + // appelle la methode property de CustomElementGraphicpart pour les styles + QVariant style_property = CustomElementGraphicPart::property(property); + if (style_property != QVariant()) return(style_property); + + if (property == "x1") { + return(sceneP1().x()); + } else if (property == "y1") { + return(sceneP1().y()); + } else if (property == "x2") { + return(sceneP2().x()); + } else if (property == "y2") { + return(sceneP2().y()); + } + return(QVariant()); +} + QVariant PartLine::itemChange(GraphicsItemChange change, const QVariant &value) { if (scene()) { if (change == QGraphicsItem::ItemPositionChange || change == QGraphicsItem::ItemSelectedChange) { @@ -73,13 +109,6 @@ QPointF PartLine::sceneP2() const { return(mapToScene(line().p2())); } -/* - - - - -*/ - QPainterPath PartLine::shape() const { QList points = fourShapePoints(); QPainterPath t; @@ -92,24 +121,6 @@ QPainterPath PartLine::shape() const { return(t); } -/* -QRectF PartLine::boundingRect() const { - QList points = fourShapePoints(); - qreal min_x = points.first().x(); - qreal max_x = points.first().x(); - qreal min_y = points.first().y(); - qreal max_y = points.first().y(); - foreach(QPointF p, points) { - if (p.x() > max_x) max_x = p.x(); - if (p.x() < min_x) min_x = p.x(); - if (p.y() > max_y) max_y = p.y(); - if (p.y() < min_y) min_y = p.y(); - } - QRectF r; - r.setCoords(min_x, min_y, max_x, max_y); - return(r); -} -*/ /** @return une liste contenant les deux points de la droite + les 4 points entourant ces deux points */ diff --git a/editor/partline.h b/editor/partline.h index 13b56aa6d..67e1146cc 100644 --- a/editor/partline.h +++ b/editor/partline.h @@ -6,7 +6,7 @@ class LineEditor; class PartLine : public QGraphicsLineItem, public CustomElementGraphicPart { // constructeurs, destructeur public: - PartLine(QGraphicsItem * = 0, QGraphicsScene * = 0); + PartLine(QETElementEditor *, QGraphicsItem * = 0, QGraphicsScene * = 0); virtual ~PartLine() { qDebug() << "~PartLine()"; } @@ -27,6 +27,8 @@ class PartLine : public QGraphicsLineItem, public CustomElementGraphicPart { virtual QPointF sceneP2() const; virtual QPainterPath shape() const; virtual QRectF boundingRect() const; + virtual void setProperty(const QString &, const QVariant &); + virtual QVariant property(const QString &); protected: QVariant itemChange(GraphicsItemChange, const QVariant &); diff --git a/editor/partpolygon.cpp b/editor/partpolygon.cpp index e8670ddda..72ea08277 100644 --- a/editor/partpolygon.cpp +++ b/editor/partpolygon.cpp @@ -1,15 +1,17 @@ #include "partpolygon.h" #include "qet.h" #include "polygoneditor.h" -PartPolygon::PartPolygon(QGraphicsItem *parent, QGraphicsScene *scene) : +PartPolygon::PartPolygon(QETElementEditor *editor, QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsPolygonItem(parent, scene), - CustomElementGraphicPart(), + CustomElementGraphicPart(editor), closed(false) { setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setAcceptedMouseButtons(Qt::LeftButton); - informations = new PolygonEditor(this); + informations = new PolygonEditor(elementEditor(), this); + informations -> setElementTypeName(QObject::tr("polygone")); style_editor -> appendWidget(informations); + style_editor -> setElementTypeName(QObject::tr("polygone")); } void PartPolygon::fromXml(const QDomElement &qde) { @@ -60,6 +62,20 @@ void PartPolygon::paint(QPainter *painter, const QStyleOptionGraphicsItem */*q*/ else painter -> drawPolyline(polygon()); } +void PartPolygon::setProperty(const QString &property, const QVariant &value) { + CustomElementGraphicPart::setProperty(property, value); + if (property == "closed") closed = value.toBool(); +} + +QVariant PartPolygon::property(const QString &property) { + // appelle la methode property de CustomElementGraphicpart pour les styles + QVariant style_property = CustomElementGraphicPart::property(property); + if (style_property != QVariant()) return(style_property); + + if (property == "closed") return(closed); + return(QVariant()); +} + QVariant PartPolygon::itemChange(GraphicsItemChange change, const QVariant &value) { if (scene()) { if (change == QGraphicsItem::ItemPositionChange || change == QGraphicsItem::ItemSelectedChange) { diff --git a/editor/partpolygon.h b/editor/partpolygon.h index edf0880af..4b314976f 100644 --- a/editor/partpolygon.h +++ b/editor/partpolygon.h @@ -6,7 +6,7 @@ class PolygonEditor; class PartPolygon : public QGraphicsPolygonItem, public CustomElementGraphicPart { // constructeurs, destructeur public: - PartPolygon(QGraphicsItem * = 0, QGraphicsScene * = 0); + PartPolygon(QETElementEditor *, QGraphicsItem * = 0, QGraphicsScene * = 0); virtual ~PartPolygon() { qDebug() << "~PartPolygon()"; } @@ -38,6 +38,8 @@ class PartPolygon : public QGraphicsPolygonItem, public CustomElementGraphicPart void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); void setClosed(bool c); bool isClosed() const; + void setProperty(const QString &, const QVariant &); + virtual QVariant property(const QString &); protected: QVariant itemChange(GraphicsItemChange, const QVariant &); diff --git a/editor/partterminal.cpp b/editor/partterminal.cpp index 507d089f1..7b4c92cf2 100644 --- a/editor/partterminal.cpp +++ b/editor/partterminal.cpp @@ -2,12 +2,13 @@ #include "terminal.h" #include "terminaleditor.h" -PartTerminal::PartTerminal(QGraphicsItem *parent, QGraphicsScene *scene) : - CustomElementPart(), +PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent, QGraphicsScene *scene) : + CustomElementPart(editor), QGraphicsItem(parent, scene), _orientation(QET::North) { - informations = new TerminalEditor(this); + informations = new TerminalEditor(elementEditor(), this); + informations -> setElementTypeName(QObject::tr("borne")); updateSecondPoint(); setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setZValue(100000); @@ -97,6 +98,30 @@ void PartTerminal::setOrientation(QET::Orientation ori) { informations -> updateForm(); } +void PartTerminal::setProperty(const QString &property, const QVariant &value) { + if (property == "x") { + if (!value.canConvert(QVariant::Double)) return; + setPos(value.toDouble(), pos().y()); + } else if (property == "y") { + if (!value.canConvert(QVariant::Double)) return; + setPos(pos().x(), value.toDouble()); + } else if (property == "orientation") { + if (!value.canConvert(QVariant::Int)) return; + setOrientation(static_cast(value.toInt())); + } +} + +QVariant PartTerminal::property(const QString &property) { + if (property == "x") { + return(scenePos().x()); + } else if (property == "y") { + return(scenePos().y()); + } else if (property == "orientation") { + return(_orientation); + } + return(QVariant()); +} + QVariant PartTerminal::itemChange(GraphicsItemChange change, const QVariant &value) { if (scene()) { if (change == QGraphicsItem::ItemPositionChange || change == QGraphicsItem::ItemSelectedChange) { diff --git a/editor/partterminal.h b/editor/partterminal.h index 00f49514d..7615939ed 100644 --- a/editor/partterminal.h +++ b/editor/partterminal.h @@ -4,10 +4,11 @@ #include "qet.h" #include class TerminalEditor; +class QETElementEditor; class PartTerminal : public CustomElementPart, public QGraphicsItem { public: // constructeurs, destructeur - PartTerminal(QGraphicsItem * = 0, QGraphicsScene * = 0); + PartTerminal(QETElementEditor *, QGraphicsItem * = 0, QGraphicsScene * = 0); virtual ~PartTerminal(); private: PartTerminal(const PartTerminal &); @@ -27,6 +28,8 @@ class PartTerminal : public CustomElementPart, public QGraphicsItem { virtual QRectF boundingRect() const; QET::Orientation orientation() const; void setOrientation(QET::Orientation); + virtual void setProperty(const QString &, const QVariant &); + virtual QVariant property(const QString &); protected: QVariant itemChange(GraphicsItemChange, const QVariant &); diff --git a/editor/parttext.cpp b/editor/parttext.cpp index e5641fc86..1a92cab89 100644 --- a/editor/parttext.cpp +++ b/editor/parttext.cpp @@ -1,10 +1,14 @@ #include "parttext.h" #include "texteditor.h" - -PartText::PartText(QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsTextItem(parent, scene), CustomElementPart(), can_check_changes(true) { +#include "elementscene.h" +PartText::PartText(QETElementEditor *editor, QGraphicsItem *parent, ElementScene *scene) : + QGraphicsTextItem(parent, scene), + CustomElementPart(editor) +{ setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setPlainText(tr("T")); - infos = new TextEditor(this); + infos = new TextEditor(elementEditor(), this); + infos -> setElementTypeName(QObject::tr("texte")); } PartText::~PartText() { @@ -88,8 +92,36 @@ void PartText::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) { setFocus(Qt::MouseFocusReason); } +void PartText::setProperty(const QString &property, const QVariant &value) { + if (property == "x") { + if (!value.canConvert(QVariant::Double)) return; + setPos(value.toDouble(), pos().y()); + } else if (property == "y") { + if (!value.canConvert(QVariant::Double)) return; + setPos(pos().x(), value.toDouble()); + } else if (property == "size") { + if (!value.canConvert(QVariant::Int)) return; + setFont(QFont(font().family(), value.toInt())); + } else if (property == "text") { + setPlainText(value.toString()); + } +} + +QVariant PartText::property(const QString &property) { + if (property == "x") { + return((scenePos() + margin()).x()); + } else if (property == "y") { + return((scenePos() + margin()).y()); + } else if (property == "size") { + return(font().pointSize()); + } else if (property == "text") { + return(toPlainText()); + } + return(QVariant()); +} + QVariant PartText::itemChange(GraphicsItemChange change, const QVariant &value) { - if (scene() && can_check_changes) { + if (scene()) { if (change == QGraphicsItem::ItemPositionChange || change == QGraphicsItem::ItemSelectedChange) { infos -> updateForm(); } diff --git a/editor/parttext.h b/editor/parttext.h index 82b58e6b9..7cd74c252 100644 --- a/editor/parttext.h +++ b/editor/parttext.h @@ -6,7 +6,7 @@ class TextEditor; class PartText : public QGraphicsTextItem, public CustomElementPart { // constructeurs, destructeur public: - PartText(QGraphicsItem * = 0, QGraphicsScene * = 0); + PartText(QETElementEditor *, QGraphicsItem * = 0, ElementScene * = 0); virtual ~PartText(); private: @@ -23,6 +23,8 @@ class PartText : public QGraphicsTextItem, public CustomElementPart { QPointF pos() const; void setPos(const QPointF &); void setPos(qreal, qreal); + virtual void setProperty(const QString &, const QVariant &); + virtual QVariant property(const QString &); protected: virtual void focusOutEvent(QFocusEvent *); @@ -30,9 +32,6 @@ class PartText : public QGraphicsTextItem, public CustomElementPart { virtual QVariant itemChange(GraphicsItemChange, const QVariant &); QRectF boundingRect() const; - public: - bool can_check_changes; - private: QPointF margin() const; }; diff --git a/editor/parttextfield.cpp b/editor/parttextfield.cpp index 3cb9b0ab9..ef8d672dd 100644 --- a/editor/parttextfield.cpp +++ b/editor/parttextfield.cpp @@ -2,10 +2,15 @@ #include "textfieldeditor.h" -PartTextField::PartTextField(QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsTextItem(parent, scene), CustomElementPart(), follow_parent_rotations(true), can_check_changes(true) { +PartTextField::PartTextField(QETElementEditor *editor, QGraphicsItem *parent, QGraphicsScene *scene) : + QGraphicsTextItem(parent, scene), + CustomElementPart(editor), + follow_parent_rotations(true) +{ setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setPlainText(tr("_")); - infos = new TextFieldEditor(this); + infos = new TextFieldEditor(elementEditor(), this); + infos -> setElementTypeName(QObject::tr("champ de texte")); } PartTextField::~PartTextField() { @@ -25,7 +30,7 @@ void PartTextField::fromXml(const QDomElement &xml_element) { xml_element.attribute("y").toDouble() ); - follow_parent_rotations = (xml_element.attribute("rotate") == "false"); + follow_parent_rotations = (xml_element.attribute("rotate") == "true"); } const QDomElement PartTextField::toXml(QDomDocument &xml_document) const { @@ -34,7 +39,7 @@ const QDomElement PartTextField::toXml(QDomDocument &xml_document) const { xml_element.setAttribute("y", QString("%1").arg((scenePos() + margin()).y())); xml_element.setAttribute("text", toPlainText()); xml_element.setAttribute("size", font().pointSize()); - if (follow_parent_rotations) xml_element.setAttribute("rotate", "false"); + if (follow_parent_rotations) xml_element.setAttribute("rotate", "true"); return(xml_element); } @@ -100,8 +105,40 @@ void PartTextField::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) { setFocus(Qt::MouseFocusReason); } +void PartTextField::setProperty(const QString &property, const QVariant &value) { + if (property == "x") { + if (!value.canConvert(QVariant::Double)) return; + setPos(value.toDouble(), pos().y()); + } else if (property == "y") { + if (!value.canConvert(QVariant::Double)) return; + setPos(pos().x(), value.toDouble()); + } else if (property == "size") { + if (!value.canConvert(QVariant::Int)) return; + setFont(QFont(font().family(), value.toInt())); + } else if (property == "text") { + setPlainText(value.toString()); + } else if (property == "rotate") { + follow_parent_rotations = value.toBool(); + } +} + +QVariant PartTextField::property(const QString &property) { + if (property == "x") { + return((scenePos() + margin()).x()); + } else if (property == "y") { + return((scenePos() + margin()).y()); + } else if (property == "size") { + return(font().pointSize()); + } else if (property == "text") { + return(toPlainText()); + } else if (property == "rotate") { + return(follow_parent_rotations); + } + return(QVariant()); +} + QVariant PartTextField::itemChange(GraphicsItemChange change, const QVariant &value) { - if (scene() && can_check_changes) { + if (scene()) { if (change == QGraphicsItem::ItemPositionChange || change == QGraphicsItem::ItemSelectedChange) { infos -> updateForm(); } diff --git a/editor/parttextfield.h b/editor/parttextfield.h index bed61e892..793b15d10 100644 --- a/editor/parttextfield.h +++ b/editor/parttextfield.h @@ -3,10 +3,11 @@ #include #include "customelementpart.h" class TextFieldEditor; +class QETElementEditor; class PartTextField : public QGraphicsTextItem, public CustomElementPart { // constructeurs, destructeur public: - PartTextField(QGraphicsItem * = 0, QGraphicsScene * = 0); + PartTextField(QETElementEditor *, QGraphicsItem * = 0, QGraphicsScene * = 0); virtual ~PartTextField(); private: @@ -26,6 +27,8 @@ class PartTextField : public QGraphicsTextItem, public CustomElementPart { void setPos(qreal, qreal); bool followParentRotations(); void setFollowParentRotations(bool); + virtual void setProperty(const QString &, const QVariant &); + virtual QVariant property(const QString &); protected: virtual void focusOutEvent(QFocusEvent *); @@ -33,9 +36,6 @@ class PartTextField : public QGraphicsTextItem, public CustomElementPart { virtual QVariant itemChange(GraphicsItemChange, const QVariant &); QRectF boundingRect() const; - public: - bool can_check_changes; - private: QPointF margin() const; }; diff --git a/editor/polygoneditor.cpp b/editor/polygoneditor.cpp index 4415befb5..614eaf1e5 100644 --- a/editor/polygoneditor.cpp +++ b/editor/polygoneditor.cpp @@ -1,13 +1,15 @@ #include "polygoneditor.h" #include "partpolygon.h" +#include "elementscene.h" +#include "editorcommands.h" /** Constructeur @param p Le polygone a editer @param parent le Widget parent */ -PolygonEditor::PolygonEditor(PartPolygon *p, QWidget *parent) : - QWidget(parent), +PolygonEditor::PolygonEditor(QETElementEditor *editor, PartPolygon *p, QWidget *parent) : + ElementItemEditor(editor, parent), points_list(this), close_polygon(tr("Polygone ferm\351"), this) { @@ -50,7 +52,16 @@ void PolygonEditor::updatePolygonPoints() { } void PolygonEditor::updatePolygonClosedState() { - part -> setClosed(close_polygon.isChecked()); + undoStack().push( + new ChangePartCommand( + tr("fermeture du polygone"), + part, + "closed", + QVariant(!close_polygon.isChecked()), + QVariant(close_polygon.isChecked()) + ) + ); +// part -> setClosed(close_polygon.isChecked()); } void PolygonEditor::updateForm() { diff --git a/editor/polygoneditor.h b/editor/polygoneditor.h index 0e0b8588b..29e98cb6d 100644 --- a/editor/polygoneditor.h +++ b/editor/polygoneditor.h @@ -1,14 +1,14 @@ #ifndef POLYGON_EDITOR_H #define POLYGON_EDITOR_H -#include +#include "elementitemeditor.h" class PartPolygon; -class PolygonEditor : public QWidget { +class PolygonEditor : public ElementItemEditor { Q_OBJECT // constructeurs, destructeur public: - PolygonEditor(PartPolygon *, QWidget * = 0); + PolygonEditor(QETElementEditor *, PartPolygon *, QWidget * = 0); ~PolygonEditor() { qDebug() << "~PolygonEditor()"; } diff --git a/editor/customelementeditor.cpp b/editor/qetelementeditor.cpp similarity index 90% rename from editor/customelementeditor.cpp rename to editor/qetelementeditor.cpp index 1a813385b..5bd4d4fc6 100644 --- a/editor/customelementeditor.cpp +++ b/editor/qetelementeditor.cpp @@ -1,10 +1,11 @@ -#include "customelementeditor.h" -#include "editorscene.h" +#include "qetelementeditor.h" +#include "elementscene.h" +#include "elementview.h" #include "customelementpart.h" #include "newelementwizard.h" #include "qetapp.h" -CustomElementEditor::CustomElementEditor(QWidget *parent) : +QETElementEditor::QETElementEditor(QWidget *parent) : QMainWindow(parent), read_only(false), min_title(tr("QElectroTech - \311diteur d'\351l\351ment")), @@ -20,11 +21,11 @@ CustomElementEditor::CustomElementEditor(QWidget *parent) : setupMenus(); } -CustomElementEditor::~CustomElementEditor() { - qDebug() << "~CustomElementEditor()"; +QETElementEditor::~QETElementEditor() { + qDebug() << "~QETElementEditor()"; } -void CustomElementEditor::setupActions() { +void QETElementEditor::setupActions() { new_element = new QAction(QIcon(":/ico/new.png"), tr("&Nouveau"), this); open = new QAction(QIcon(":/ico/open.png"), tr("&Ouvrir"), this); save = new QAction(QIcon(":/ico/save.png"), tr("&Enregistrer"), this); @@ -123,7 +124,7 @@ void CustomElementEditor::setupActions() { connect(ce_scene, SIGNAL(selectionChanged()), this, SLOT(slot_updateMenus())); } -void CustomElementEditor::setupMenus() { +void QETElementEditor::setupMenus() { file_menu = new QMenu(tr("Fichier")); edit_menu = new QMenu(tr("\311dition")); display_menu = new QMenu(tr("Affichage")); @@ -168,21 +169,15 @@ void CustomElementEditor::setupMenus() { menuBar() -> addMenu(help_menu); } -void CustomElementEditor::slot_updateMenus() { +void QETElementEditor::slot_updateMenus() { edit_delete -> setEnabled(!ce_scene -> selectedItems().isEmpty()); } -void CustomElementEditor::setupInterface() { +void QETElementEditor::setupInterface() { // editeur - ce_scene = new EditorScene(this); + ce_scene = new ElementScene(this, this); ce_scene -> slot_move(); - ce_view = new QGraphicsView(ce_scene, this); - ce_view -> setInteractive(true); - ce_view -> setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); - //ce_view -> setTransformationAnchor(QGraphicsView::AnchorUnderMouse); - ce_view -> setResizeAnchor(QGraphicsView::AnchorUnderMouse); - //ce_view -> setSceneRect(QRectF(0.0, 0.0, 50.0, 200.0)); - ce_view -> scale(4.0, 4.0); + ce_view = new ElementView(ce_scene, this); slot_setRubberBandToView(); setCentralWidget(ce_view); @@ -213,21 +208,21 @@ void CustomElementEditor::setupInterface() { statusBar() -> showMessage(tr("\311diteur d'\351l\351ments")); } -void CustomElementEditor::slot_setRubberBandToView() { +void QETElementEditor::slot_setRubberBandToView() { ce_view -> setDragMode(QGraphicsView::RubberBandDrag); } -void CustomElementEditor::slot_setNoDragToView() { +void QETElementEditor::slot_setNoDragToView() { ce_view -> setDragMode(QGraphicsView::NoDrag); } -void CustomElementEditor::slot_setNormalMode() { +void QETElementEditor::slot_setNormalMode() { if (!move -> isChecked()) move -> setChecked(true); ce_view -> setDragMode(QGraphicsView::RubberBandDrag); ce_scene -> slot_move(); } -void CustomElementEditor::slot_updateInformations() { +void QETElementEditor::slot_updateInformations() { QList selected_qgis = ce_scene -> selectedItems(); QList selected_parts; foreach(QGraphicsItem *qgi, selected_qgis) { @@ -260,7 +255,7 @@ void CustomElementEditor::slot_updateInformations() { } } -void CustomElementEditor::xmlPreview() { +void QETElementEditor::xmlPreview() { QMessageBox::information( this, "Export XML", @@ -268,7 +263,7 @@ void CustomElementEditor::xmlPreview() { ); } -void CustomElementEditor::fromFile(const QString &filepath) { +void QETElementEditor::fromFile(const QString &filepath) { bool state = true; QString error_message; @@ -325,7 +320,7 @@ void CustomElementEditor::fromFile(const QString &filepath) { setWindowTitle(new_title); } -bool CustomElementEditor::toFile(const QString &fn) { +bool QETElementEditor::toFile(const QString &fn) { QFile file(fn); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { QMessageBox::warning(this, tr("Erreur"), tr("Impossible d'ecrire dans ce fichier")); @@ -342,7 +337,7 @@ bool CustomElementEditor::toFile(const QString &fn) { specifie si l'editeur d'element doit etre en mode lecture seule @param ro true pour activer le mode lecture seule, false pour le desactiver */ -void CustomElementEditor::setReadOnly(bool ro) { +void QETElementEditor::setReadOnly(bool ro) { read_only = ro; // active / desactive les actions foreach (QAction *action, parts -> actions()) action -> setEnabled(!ro); @@ -359,16 +354,16 @@ void CustomElementEditor::setReadOnly(bool ro) { /** @return true si l'editeur d'element est en mode lecture seule */ -bool CustomElementEditor::isReadOnly() const { +bool QETElementEditor::isReadOnly() const { return(read_only); } -void CustomElementEditor::slot_new() { +void QETElementEditor::slot_new() { NewElementWizard new_element_wizard; new_element_wizard.exec(); } -void CustomElementEditor::slot_open() { +void QETElementEditor::slot_open() { // demande un nom de fichier a ouvrir a l'utilisateur QString user_filename = QFileDialog::getOpenFileName( this, @@ -377,19 +372,19 @@ void CustomElementEditor::slot_open() { tr("\311l\351ments QElectroTech (*.elmt);;Fichiers XML (*.xml);;Tous les fichiers (*)") ); if (user_filename == "") return; - CustomElementEditor *cee = new CustomElementEditor(); + QETElementEditor *cee = new QETElementEditor(); cee -> fromFile(user_filename); cee -> show(); } -bool CustomElementEditor::slot_save() { +bool QETElementEditor::slot_save() { // si on ne connait pas le nom du fichier en cours, enregistrer revient a enregistrer sous if (_filename == QString()) return(slot_saveAs()); // sinon on enregistre dans le nom de fichier connu return(toFile(_filename)); } -bool CustomElementEditor::slot_saveAs() { +bool QETElementEditor::slot_saveAs() { // demande un nom de fichier a l'utilisateur pour enregistrer l'element QString fn = QFileDialog::getSaveFileName( this, @@ -409,14 +404,14 @@ bool CustomElementEditor::slot_saveAs() { return(result_save); } -void CustomElementEditor::slot_quit(QCloseEvent *event) { +void QETElementEditor::slot_quit(QCloseEvent *event) { if (close()) { if (event != NULL) event -> accept(); delete(this); } else if (event != NULL) event -> ignore(); } -bool CustomElementEditor::close() { +bool QETElementEditor::close() { // demande d'abord a l'utilisateur s'il veut enregistrer l'element en cours QMessageBox::StandardButton answer = QMessageBox::question( this, @@ -438,6 +433,6 @@ bool CustomElementEditor::close() { Permet de quitter l'editeur lors de la fermeture de la fenetre principale @param qce Le QCloseEvent correspondant a l'evenement de fermeture */ -void CustomElementEditor::closeEvent(QCloseEvent *qce) { +void QETElementEditor::closeEvent(QCloseEvent *qce) { slot_quit(qce); } diff --git a/editor/customelementeditor.h b/editor/qetelementeditor.h similarity index 73% rename from editor/customelementeditor.h rename to editor/qetelementeditor.h index 8b69ecb02..2e5ab2d3e 100644 --- a/editor/customelementeditor.h +++ b/editor/qetelementeditor.h @@ -1,17 +1,18 @@ #ifndef CUSTOM_ELEMENT_EDITOR_H #define CUSTOM_ELEMENT_EDITOR_H #include -#include "editorscene.h" +#include "elementscene.h" #include "orientationset.h" -class CustomElementEditor : public QMainWindow { +class ElementView; +class QETElementEditor : public QMainWindow { Q_OBJECT // constructeur, destructeur public: - CustomElementEditor(QWidget * = 0); - virtual ~CustomElementEditor(); + QETElementEditor(QWidget * = 0); + virtual ~QETElementEditor(); private: - CustomElementEditor(const CustomElementEditor &); + QETElementEditor(const QETElementEditor &); // attributs private: @@ -20,9 +21,9 @@ class CustomElementEditor : public QMainWindow { /// menus QMenu *file_menu, *edit_menu, *display_menu, *tools_menu, *help_menu; /// vue sur la scene d'edition - QGraphicsView *ce_view; + ElementView *ce_view; /// scene d'edition - EditorScene *ce_scene; + ElementScene *ce_scene; /// container pour les widgets d'edition des parties QDockWidget *tools_dock; /// container pour la liste des annulations @@ -60,6 +61,7 @@ class CustomElementEditor : public QMainWindow { bool isReadOnly() const; void fromFile(const QString &); bool toFile(const QString &); + ElementScene *elementScene() const; protected: void closeEvent(QCloseEvent *); @@ -84,12 +86,12 @@ class CustomElementEditor : public QMainWindow { void xmlPreview(); }; -inline void CustomElementEditor::setSize(const QSize &siz) { +inline void QETElementEditor::setSize(const QSize &siz) { ce_scene -> setWidth(siz.width()); ce_scene -> setHeight(siz.height()); } -inline QSize CustomElementEditor::size() const { +inline QSize QETElementEditor::size() const { return( QSize( ce_scene -> width(), @@ -98,33 +100,37 @@ inline QSize CustomElementEditor::size() const { ); } -inline void CustomElementEditor::setHotspot(const QPoint &hs) { +inline void QETElementEditor::setHotspot(const QPoint &hs) { ce_scene -> setHotspot(hs); } -inline QPoint CustomElementEditor::hotspot() const { +inline QPoint QETElementEditor::hotspot() const { return(ce_scene -> hotspot()); } -inline void CustomElementEditor::setNames(const NamesList &nameslist) { +inline void QETElementEditor::setNames(const NamesList &nameslist) { ce_scene -> setNames(nameslist); } -inline void CustomElementEditor::setOrientations(const OrientationSet &orientation_set) { +inline void QETElementEditor::setOrientations(const OrientationSet &orientation_set) { ce_scene -> setOrientations(orientation_set); } -inline OrientationSet CustomElementEditor::orientations() const { +inline OrientationSet QETElementEditor::orientations() const { return(ce_scene -> orientations()); } -inline void CustomElementEditor::setFileName(const QString &fn) { +inline void QETElementEditor::setFileName(const QString &fn) { setWindowTitle(min_title + " - " + fn); _filename = fn; } -inline QString CustomElementEditor::fileName() const { +inline QString QETElementEditor::fileName() const { return(_filename); } +inline ElementScene *QETElementEditor::elementScene() const { + return(ce_scene); +} + #endif diff --git a/editor/styleeditor.cpp b/editor/styleeditor.cpp index 70724c91d..52fbc3d4b 100644 --- a/editor/styleeditor.cpp +++ b/editor/styleeditor.cpp @@ -1,37 +1,32 @@ #include "styleeditor.h" #include "customelementgraphicpart.h" -StyleEditor::StyleEditor(CustomElementGraphicPart *p, QWidget *parent) : QWidget(parent), part(p) { +StyleEditor::StyleEditor(QETElementEditor *editor, CustomElementGraphicPart *p, QWidget *parent) : ElementItemEditor(editor, parent), part(p) { // couleur color = new QButtonGroup(this); color -> addButton(black_color = new QRadioButton(tr("Noir")), CustomElementGraphicPart::BlackColor); color -> addButton(white_color = new QRadioButton(tr("Blanc")), CustomElementGraphicPart::WhiteColor); - connect(color, SIGNAL(buttonClicked(int)), this, SLOT(updatePart())); // style style = new QButtonGroup(this); style -> addButton(normal_style = new QRadioButton(tr("Normal")), CustomElementGraphicPart::NormalStyle); style -> addButton(dashed_style = new QRadioButton(tr("Pointill\351")), CustomElementGraphicPart::DashedStyle); style -> button(part -> lineStyle()) -> setChecked(true); - connect(style, SIGNAL(buttonClicked(int)), this, SLOT(updatePart())); // epaisseur weight = new QButtonGroup(this); weight -> addButton(none_weight = new QRadioButton(tr("Nulle")), CustomElementGraphicPart::NoneWeight); weight -> addButton(thin_weight = new QRadioButton(tr("Fine")), CustomElementGraphicPart::ThinWeight); weight -> addButton(normal_weight = new QRadioButton(tr("Normale")), CustomElementGraphicPart::NormalWeight); - connect(weight, SIGNAL(buttonClicked(int)), this, SLOT(updatePart())); // remplissage filling = new QButtonGroup(this); filling -> addButton(no_filling = new QRadioButton(tr("Aucun")), CustomElementGraphicPart::NoneFilling ); filling -> addButton(black_filling = new QRadioButton(tr("Noir")), CustomElementGraphicPart::BlackFilling); filling -> addButton(white_filling = new QRadioButton(tr("Blanc")), CustomElementGraphicPart::WhiteFilling); - connect(filling, SIGNAL(buttonClicked(int)), this, SLOT(updatePart())); // antialiasing antialiasing = new QCheckBox(tr("Antialiasing")); - connect(antialiasing, SIGNAL(stateChanged(int)), this, SLOT(updatePart())); updateForm(); @@ -97,11 +92,16 @@ void StyleEditor::updatePart() { part -> setFilling(static_cast(filling -> checkedId())); } +void StyleEditor::updatePartAntialiasing() { addChangePartCommand("style antialiasing", part, "antialias", antialiasing -> isChecked()); } +void StyleEditor::updatePartColor() { addChangePartCommand("style couleur", part, "color", color -> checkedId()); } +void StyleEditor::updatePartLineStyle() { addChangePartCommand("style ligne", part, "line-style", style -> checkedId()); } +void StyleEditor::updatePartLineWeight() { addChangePartCommand("style epaisseur", part, "line-weight", weight -> checkedId()); } +void StyleEditor::updatePartFilling() { addChangePartCommand("style remplissage", part, "filling", filling -> checkedId()); } + void StyleEditor::updateForm() { - // lit l'antialiasing : deconnexion du slot pour eviter l'appel a updatePart() - disconnect(antialiasing, SIGNAL(stateChanged(int)), this, SLOT(updatePart())); + activeConnections(false); + // lit l'antialiasing antialiasing -> setChecked(part -> antialiased()); - connect(antialiasing, SIGNAL(stateChanged(int)), this, SLOT(updatePart())); // lit la couleur color -> button(part -> color()) -> setChecked(true); @@ -114,8 +114,25 @@ void StyleEditor::updateForm() { // lit le remplissage filling -> button(part -> filling()) -> setChecked(true); + activeConnections(true); } void StyleEditor::appendWidget(QWidget *w) { main_layout -> insertWidget(7, w); } + +void StyleEditor::activeConnections(bool active) { + if (active) { + connect(color, SIGNAL(buttonClicked(int)), this, SLOT(updatePartColor())); + connect(style, SIGNAL(buttonClicked(int)), this, SLOT(updatePartLineStyle())); + connect(weight, SIGNAL(buttonClicked(int)), this, SLOT(updatePartLineWeight())); + connect(filling, SIGNAL(buttonClicked(int)), this, SLOT(updatePartFilling())); + connect(antialiasing, SIGNAL(stateChanged(int)), this, SLOT(updatePartAntialiasing())); + } else { + disconnect(color, SIGNAL(buttonClicked(int)), this, SLOT(updatePartColor())); + disconnect(style, SIGNAL(buttonClicked(int)), this, SLOT(updatePartLineStyle())); + disconnect(weight, SIGNAL(buttonClicked(int)), this, SLOT(updatePartLineWeight())); + disconnect(filling, SIGNAL(buttonClicked(int)), this, SLOT(updatePartFilling())); + disconnect(antialiasing, SIGNAL(stateChanged(int)), this, SLOT(updatePartAntialiasing())); + } +} diff --git a/editor/styleeditor.h b/editor/styleeditor.h index 0fc4e5773..45c26bda0 100644 --- a/editor/styleeditor.h +++ b/editor/styleeditor.h @@ -1,12 +1,13 @@ #ifndef STYLE_EDITOR_H #define STYLE_EDITOR_H #include +#include "elementitemeditor.h" class CustomElementGraphicPart; -class StyleEditor : public QWidget { +class StyleEditor : public ElementItemEditor { Q_OBJECT // constructeurs, destructeur public: - StyleEditor(CustomElementGraphicPart *, QWidget * = 0); + StyleEditor(QETElementEditor *, CustomElementGraphicPart *, QWidget * = 0); virtual ~StyleEditor(); private: @@ -29,5 +30,13 @@ class StyleEditor : public QWidget { public slots: void updatePart(); void updateForm(); + void updatePartAntialiasing(); + void updatePartColor(); + void updatePartLineStyle(); + void updatePartLineWeight(); + void updatePartFilling(); + + private: + void activeConnections(bool); }; #endif diff --git a/editor/terminaleditor.cpp b/editor/terminaleditor.cpp index 911daed95..6e51268bb 100644 --- a/editor/terminaleditor.cpp +++ b/editor/terminaleditor.cpp @@ -6,7 +6,7 @@ @param term Borne a editer @param parent QWidget parent de ce widget */ -TerminalEditor::TerminalEditor(PartTerminal *term, QWidget *parent) : QWidget(parent) { +TerminalEditor::TerminalEditor(QETElementEditor *editor, PartTerminal *term, QWidget *parent) : ElementItemEditor(editor, parent) { part = term; qle_x = new QLineEdit(); @@ -35,10 +35,7 @@ TerminalEditor::TerminalEditor(PartTerminal *term, QWidget *parent) : QWidget(pa main_layout -> addStretch(); setLayout(main_layout); - connect(qle_x, SIGNAL(textEdited(const QString &)), this, SLOT(updateTerminal())); - connect(qle_y, SIGNAL(textEdited(const QString &)), this, SLOT(updateTerminal())); - connect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminal())); - + activeConnections(true); updateForm(); } @@ -60,8 +57,27 @@ void TerminalEditor::updateTerminal() { ); } +void TerminalEditor::updateTerminalX() { addChangePartCommand(tr("abscisse"), part, "x", qle_x -> text().toDouble()); updateForm(); } +void TerminalEditor::updateTerminalY() { addChangePartCommand(tr("ordonn\351e"), part, "y", qle_y -> text().toDouble()); updateForm(); } +void TerminalEditor::updateTerminalO() { addChangePartCommand(tr("orientation"), part, "orientation", orientation -> itemData(orientation -> currentIndex()).toInt()); } + void TerminalEditor::updateForm() { - qle_x -> setText(QString("%1").arg(part -> pos().x())); - qle_y -> setText(QString("%1").arg(part -> pos().y())); + activeConnections(false); + qDebug() << part -> pos() << part -> scenePos(); + qle_x -> setText(part -> property("x").toString()); + qle_y -> setText(part -> property("y").toString()); orientation -> setCurrentIndex(static_cast(part -> orientation())); + activeConnections(true); +} + +void TerminalEditor::activeConnections(bool active) { + if (active) { + connect(qle_x, SIGNAL(editingFinished()), this, SLOT(updateTerminalX())); + connect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTerminalY())); + connect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO())); + } else { + disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updateTerminalX())); + disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTerminalY())); + disconnect(orientation, SIGNAL(activated(int)), this, SLOT(updateTerminalO())); + } } diff --git a/editor/terminaleditor.h b/editor/terminaleditor.h index ffc323da1..9f62f7a55 100644 --- a/editor/terminaleditor.h +++ b/editor/terminaleditor.h @@ -1,17 +1,18 @@ #ifndef TERMINAL_EDITOR_H #define TERMINAL_EDITOR_H #include +#include "elementitemeditor.h" class PartTerminal; /** Cette classe represente un editeur de borne. Elle permet d'editer a travers une interface graphique les proprietes d'une borne d'element. */ -class TerminalEditor : public QWidget { +class TerminalEditor : public ElementItemEditor { Q_OBJECT // Constructeurs, destructeur public: - TerminalEditor(PartTerminal *, QWidget * = 0); + TerminalEditor(QETElementEditor *, PartTerminal *, QWidget * = 0); virtual ~TerminalEditor(); private: TerminalEditor(const TerminalEditor &); @@ -25,6 +26,12 @@ class TerminalEditor : public QWidget { // methodes public slots: void updateTerminal(); + void updateTerminalX(); + void updateTerminalY(); + void updateTerminalO(); void updateForm(); + + private: + void activeConnections(bool); }; #endif diff --git a/editor/texteditor.cpp b/editor/texteditor.cpp index d2cee729b..376752d43 100644 --- a/editor/texteditor.cpp +++ b/editor/texteditor.cpp @@ -6,7 +6,7 @@ @param term Champ de texte a editer @param parent QWidget parent de ce widget */ -TextEditor::TextEditor(PartText *text, QWidget *parent) : QWidget(parent) { +TextEditor::TextEditor(QETElementEditor *editor, PartText *text, QWidget *parent) : ElementItemEditor(editor, parent) { part = text; qle_x = new QLineEdit(); @@ -37,12 +37,9 @@ TextEditor::TextEditor(PartText *text, QWidget *parent) : QWidget(parent) { main_layout -> addStretch(); setLayout(main_layout); - connect(qle_x, SIGNAL(textEdited(const QString &)), this, SLOT(updateText())); - connect(qle_y, SIGNAL(textEdited(const QString &)), this, SLOT(updateText())); - connect(qle_text, SIGNAL(textEdited(const QString &)), this, SLOT(updateText())); - connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(updateText())); - //updateForm(); + + updateForm(); } /** @@ -52,17 +49,42 @@ TextEditor::~TextEditor() { qDebug() << "~TextEditor()"; } +/** + Met a jour le champ de texte a partir des donnees du formulaire +*/ void TextEditor::updateText() { - part -> can_check_changes = false; - part -> setFont(QFont(part -> font().family(), font_size -> value())); + part -> setProperty("size", font_size -> value()); part -> setPlainText(qle_text -> text()); part -> setPos(qle_x -> text().toDouble(), qle_y -> text().toDouble()); - part -> can_check_changes = true; } +void TextEditor::updateTextX() { addChangePartCommand(tr("abscisse"), part, "x", qle_x -> text().toDouble()); updateForm(); } +void TextEditor::updateTextY() { addChangePartCommand(tr("ordonn\351e"), part, "y", qle_y -> text().toDouble()); updateForm(); } +void TextEditor::updateTextT() { addChangePartCommand(tr("texte"), part, "text", qle_text -> text()); } +void TextEditor::updateTextS() { addChangePartCommand(tr("taille"), part, "size", font_size -> value()); } + +/** + Met a jour le formulaire a partir du champ de texte +*/ void TextEditor::updateForm() { - qle_x -> setText(QString("%1").arg(part -> pos().x())); - qle_y -> setText(QString("%1").arg(part -> pos().y())); - qle_text -> setText(part -> toPlainText()); - font_size -> setValue(part -> font().pointSize()); + activeConnections(false); + qle_x -> setText(part -> property("x").toString()); + qle_y -> setText(part -> property("y").toString()); + qle_text -> setText(part -> property("text").toString()); + font_size -> setValue(part -> property("size").toInt()); + activeConnections(true); +} + +void TextEditor::activeConnections(bool active) { + if (active) { + connect(qle_x, SIGNAL(editingFinished()), this, SLOT(updateTextX())); + connect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTextY())); + connect(qle_text, SIGNAL(editingFinished()), this, SLOT(updateTextT())); + connect(font_size, SIGNAL(editingFinished()), this, SLOT(updateTextS())); + } else { + disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updateTextX())); + disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTextY())); + disconnect(qle_text, SIGNAL(editingFinished()), this, SLOT(updateTextT())); + disconnect(font_size, SIGNAL(editingFinished()), this, SLOT(updateTextS())); + } } diff --git a/editor/texteditor.h b/editor/texteditor.h index d312b6d53..d265b8c87 100644 --- a/editor/texteditor.h +++ b/editor/texteditor.h @@ -1,17 +1,18 @@ #ifndef TEXT_EDITOR_H #define TEXT_EDITOR_H #include +#include "elementitemeditor.h" class PartText; /** Cette classe represente un editeur de champ de texte non editable Elle permet d'editer a travers une interface graphique les proprietes d'un champ de texte non editable. */ -class TextEditor : public QWidget { +class TextEditor : public ElementItemEditor { Q_OBJECT // Constructeurs, destructeur public: - TextEditor(PartText *, QWidget * = 0); + TextEditor(QETElementEditor *, PartText *, QWidget * = 0); virtual ~TextEditor(); private: TextEditor(const TextEditor &); @@ -25,6 +26,13 @@ class TextEditor : public QWidget { // methodes public slots: void updateText(); + void updateTextX(); + void updateTextY(); + void updateTextT(); + void updateTextS(); void updateForm(); + + private: + void activeConnections(bool); }; #endif diff --git a/editor/textfieldeditor.cpp b/editor/textfieldeditor.cpp index 42bfe8921..bebf9bae7 100644 --- a/editor/textfieldeditor.cpp +++ b/editor/textfieldeditor.cpp @@ -6,7 +6,7 @@ @param part Champ de texte a editer @param parent QWidget parent */ -TextFieldEditor::TextFieldEditor(PartTextField *textfield, QWidget *parent) : QWidget(parent) { +TextFieldEditor::TextFieldEditor(QETElementEditor *editor, PartTextField *textfield, QWidget *parent) : ElementItemEditor(editor, parent) { part = textfield; qle_x = new QLineEdit(); @@ -43,12 +43,7 @@ TextFieldEditor::TextFieldEditor(PartTextField *textfield, QWidget *parent) : QW main_layout -> addStretch(); setLayout(main_layout); - - connect(qle_x, SIGNAL(textEdited(const QString &)), this, SLOT(updateTextField())); - connect(qle_y, SIGNAL(textEdited(const QString &)), this, SLOT(updateTextField())); - connect(qle_text, SIGNAL(textEdited(const QString &)), this, SLOT(updateTextField())); - connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(updateTextField())); - connect(rotate, SIGNAL(stateChanged(int)), this, SLOT(updateTextField())); + updateForm(); } /** @@ -62,21 +57,43 @@ TextFieldEditor::~TextFieldEditor() { Met a jour le champ de texte a partir des donnees du formulaire */ void TextFieldEditor::updateTextField() { - part -> can_check_changes = false; - part -> setFont(QFont(part -> font().family(), font_size -> value())); + part -> setProperty("size", font_size -> value()); part -> setPlainText(qle_text -> text()); part -> setPos(qle_x -> text().toDouble(), qle_y -> text().toDouble()); part -> setFollowParentRotations(!rotate -> isChecked()); - part -> can_check_changes = true; } +void TextFieldEditor::updateTextFieldX() { addChangePartCommand(tr("abscisse"), part, "x", qle_x -> text().toDouble()); updateForm(); } +void TextFieldEditor::updateTextFieldY() { addChangePartCommand(tr("ordonn\351e"), part, "y", qle_y -> text().toDouble()); updateForm(); } +void TextFieldEditor::updateTextFieldT() { addChangePartCommand(tr("texte"), part, "text", qle_text -> text()); } +void TextFieldEditor::updateTextFieldS() { addChangePartCommand(tr("taille"), part, "size", font_size -> value()); } +void TextFieldEditor::updateTextFieldR() { addChangePartCommand(tr("propri\351t\351"), part, "rotate", !rotate -> isChecked()); } + /** Met a jour le formulaire a partir du champ de texte */ void TextFieldEditor::updateForm() { - qle_x -> setText(QString("%1").arg(part -> pos().x())); - qle_y -> setText(QString("%1").arg(part -> pos().y())); - qle_text -> setText(part -> toPlainText()); - font_size -> setValue(part -> font().pointSize()); - rotate -> setChecked(!part -> followParentRotations()); + activeConnections(false); + qle_x -> setText(part -> property("x").toString()); + qle_y -> setText(part -> property("y").toString()); + qle_text -> setText(part -> property("text").toString()); + font_size -> setValue(part -> property("size").toInt()); + rotate -> setChecked(!part -> property("rotate").toBool()); + activeConnections(true); +} + +void TextFieldEditor::activeConnections(bool active) { + if (active) { + connect(qle_x, SIGNAL(editingFinished()), this, SLOT(updateTextFieldX())); + connect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTextFieldY())); + connect(qle_text, SIGNAL(editingFinished()), this, SLOT(updateTextFieldT())); + connect(font_size, SIGNAL(editingFinished()), this, SLOT(updateTextFieldS())); + connect(rotate, SIGNAL(stateChanged(int)), this, SLOT(updateTextFieldR())); + } else { + disconnect(qle_x, SIGNAL(editingFinished()), this, SLOT(updateTextFieldX())); + disconnect(qle_y, SIGNAL(editingFinished()), this, SLOT(updateTextFieldY())); + disconnect(qle_text, SIGNAL(editingFinished()), this, SLOT(updateTextFieldT())); + disconnect(font_size, SIGNAL(editingFinished()), this, SLOT(updateTextFieldS())); + disconnect(rotate, SIGNAL(stateChanged(int)), this, SLOT(updateTextFieldR())); + } } diff --git a/editor/textfieldeditor.h b/editor/textfieldeditor.h index c29b4ec75..d9f9eec82 100644 --- a/editor/textfieldeditor.h +++ b/editor/textfieldeditor.h @@ -1,6 +1,7 @@ #ifndef TEXTFIELD_EDITOR_H #define TEXTFIELD_EDITOR_H #include +#include "elementitemeditor.h" class PartTextField; /** Cette classe represente un editeur de champ de texte @@ -8,11 +9,11 @@ class PartTextField; proprietes d'un champ de texte : taille de la police, texte par defaut et position. */ -class TextFieldEditor : public QWidget { +class TextFieldEditor : public ElementItemEditor { Q_OBJECT // Constructeurs, destructeur public: - TextFieldEditor(PartTextField *, QWidget * = 0); + TextFieldEditor(QETElementEditor *, PartTextField *, QWidget * = 0); virtual ~TextFieldEditor(); private: TextFieldEditor(const TextFieldEditor &); @@ -27,6 +28,14 @@ class TextFieldEditor : public QWidget { // methodes public slots: void updateTextField(); + void updateTextFieldX(); + void updateTextFieldY(); + void updateTextFieldT(); + void updateTextFieldS(); + void updateTextFieldR(); void updateForm(); + + private: + void activeConnections(bool); }; #endif diff --git a/elementspanel.cpp b/elementspanel.cpp index b056d4ce7..7c9e4aa05 100644 --- a/elementspanel.cpp +++ b/elementspanel.cpp @@ -2,7 +2,7 @@ #include "elementscategory.h" #include "elementscategoryeditor.h" #include "customelement.h" -#include "customelementeditor.h" +#include "qetelementeditor.h" /** Constructeur @@ -178,9 +178,9 @@ void ElementsPanel::slot_doubleClick(QTreeWidgetItem *qtwi, int) { if (infos_file.isFile()) { // il s'agit d'un element - CustomElementEditor *cee = new CustomElementEditor(); - cee -> fromFile(filename); - cee -> show(); + QETElementEditor *editor = new QETElementEditor(); + editor -> fromFile(filename); + editor -> show(); } else if (infos_file.isDir()) { // il s'agit d'une categorie ElementsCategory c(filename); diff --git a/newelementwizard.cpp b/newelementwizard.cpp index d72ffecc4..328e8ba8c 100644 --- a/newelementwizard.cpp +++ b/newelementwizard.cpp @@ -5,7 +5,7 @@ #include "orientationsetwidget.h" #include "hotspoteditor.h" #include "element.h" -#include "customelementeditor.h" +#include "qetelementeditor.h" /** Constructeur @@ -308,7 +308,7 @@ bool NewElementWizard::validStep5() { Cree le nouvel element */ void NewElementWizard::createNewElement() { - CustomElementEditor *edit_new_element = new CustomElementEditor(parentWidget()); + QETElementEditor *edit_new_element = new QETElementEditor(parentWidget()); edit_new_element -> setSize(hotspot_editor -> elementSize()); edit_new_element -> setHotspot(hotspot_editor -> hotspot()); edit_new_element -> setNames(element_names -> names()); diff --git a/qelectrotech.pro b/qelectrotech.pro index 2df00aaa9..1f1269902 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -25,38 +25,40 @@ HEADERS += aboutqet.h \ elementtextitem.h \ exportdialog.h \ fixedelement.h \ + hotspoteditor.h \ nameslist.h \ nameslistwidget.h \ newelementwizard.h \ - qet.h \ - qetapp.h \ - terminal.h \ - editor/customelementeditor.h \ - editor/customelementgraphicpart.h \ - editor/customelementpart.h \ - editor/editorscene.h \ - editor/ellipseeditor.h \ - editor/lineeditor.h \ - editor/partellipse.h \ - editor/partline.h \ - editor/styleeditor.h \ - editor/partcircle.h \ - editor/circleeditor.h \ orientationset.h \ orientationsetwidget.h \ + qet.h \ + qetapp.h \ + qgimanager.h \ + terminal.h \ + editor/arceditor.h \ + editor/circleeditor.h \ + editor/customelementgraphicpart.h \ + editor/customelementpart.h \ + editor/editorcommands.h \ + editor/elementitemeditor.h \ + editor/elementscene.h \ + editor/elementview.h \ + editor/ellipseeditor.h \ + editor/lineeditor.h \ + editor/partarc.h \ + editor/partcircle.h \ + editor/partellipse.h \ + editor/partline.h \ editor/partpolygon.h \ - editor/polygoneditor.h \ editor/partterminal.h \ + editor/parttext.h \ + editor/parttextfield.h \ + editor/polygoneditor.h \ + editor/qetelementeditor.h \ + editor/styleeditor.h \ editor/terminaleditor.h \ - editor/parttext.h \ - editor/texteditor.h \ - editor/partarc.h \ - editor/arceditor.h \ - editor/parttextfield.h \ - editor/textfieldeditor.h \ - hotspoteditor.h \ - editor/editorcommands.h \ - qgimanager.h + editor/texteditor.h \ + editor/textfieldeditor.h SOURCES += aboutqet.cpp \ borderinset.cpp \ conducer.cpp \ @@ -74,39 +76,41 @@ SOURCES += aboutqet.cpp \ elementtextitem.cpp \ exportdialog.cpp \ fixedelement.cpp \ + hotspoteditor.cpp \ main.cpp \ nameslist.cpp \ nameslistwidget.cpp \ newelementwizard.cpp \ - qetapp.cpp \ - terminal.cpp \ - editor/customelementeditor.cpp \ - editor/customelementgraphicpart.cpp \ - editor/customelementpart.cpp \ - editor/editorscene.cpp \ - editor/ellipseeditor.cpp \ - editor/lineeditor.cpp \ - editor/partellipse.cpp \ - editor/partline.cpp \ - editor/styleeditor.cpp \ - editor/qet.cpp \ - editor/partcircle.cpp \ - editor/circleeditor.cpp \ orientationset.cpp \ orientationsetwidget.cpp \ + qetapp.cpp \ + qgimanager.cpp \ + terminal.cpp \ + editor/arceditor.cpp \ + editor/circleeditor.cpp \ + editor/customelementgraphicpart.cpp \ + editor/customelementpart.cpp \ + editor/editorcommands.cpp \ + editor/elementitemeditor.cpp \ + editor/elementscene.cpp \ + editor/elementview.cpp \ + editor/ellipseeditor.cpp \ + editor/lineeditor.cpp \ + editor/partarc.cpp \ + editor/partcircle.cpp \ + editor/partellipse.cpp \ + editor/partline.cpp \ editor/partpolygon.cpp \ - editor/polygoneditor.cpp \ editor/partterminal.cpp \ + editor/parttext.cpp \ + editor/parttextfield.cpp \ + editor/polygoneditor.cpp \ + editor/qet.cpp \ + editor/qetelementeditor.cpp \ + editor/styleeditor.cpp \ editor/terminaleditor.cpp \ - editor/parttext.cpp \ - editor/texteditor.cpp \ - editor/partarc.cpp \ - editor/arceditor.cpp \ - editor/parttextfield.cpp \ - editor/textfieldeditor.cpp \ - hotspoteditor.cpp \ - editor/editorcommands.cpp \ - qgimanager.cpp + editor/texteditor.cpp \ + editor/textfieldeditor.cpp RESOURCES += qelectrotech.qrc TRANSLATIONS += lang/qet_en.ts lang/qt_fr.ts QT += xml