diff --git a/editor/customelementpart.cpp b/editor/customelementpart.cpp index c316731d5..3b7cb4018 100644 --- a/editor/customelementpart.cpp +++ b/editor/customelementpart.cpp @@ -2,10 +2,6 @@ #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); diff --git a/editor/customelementpart.h b/editor/customelementpart.h index a67555b0f..0414ea595 100644 --- a/editor/customelementpart.h +++ b/editor/customelementpart.h @@ -32,16 +32,11 @@ class CustomElementPart { virtual void fromXml(const QDomElement &) = 0; virtual const QDomElement toXml(QDomDocument &) const = 0; virtual QWidget *elementInformations() = 0; - //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; + virtual QString name() const = 0; }; #endif diff --git a/editor/elementscene.cpp b/editor/elementscene.cpp index 07e4822dc..cdd5c8c06 100644 --- a/editor/elementscene.cpp +++ b/editor/elementscene.cpp @@ -168,33 +168,40 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { switch(behavior) { case Line: undo_stack.push(new AddPartCommand(tr("ligne"), this, current_line)); + emit(partsAdded()); break; case Ellipse: current_ellipse -> setRect(current_ellipse -> rect().normalized()); undo_stack.push(new AddPartCommand(tr("ellipse"), this, current_ellipse)); + emit(partsAdded()); break; case Arc: current_arc-> setRect(current_arc -> rect().normalized()); undo_stack.push(new AddPartCommand(tr("arc"), this, current_arc)); + emit(partsAdded()); break; case Circle: current_circle -> setRect(current_circle -> rect().normalized()); undo_stack.push(new AddPartCommand(tr("cercle"), this, current_circle)); + emit(partsAdded()); break; case Terminal: terminal = new PartTerminal(element_editor, 0, this); terminal -> setPos(e -> scenePos()); undo_stack.push(new AddPartCommand(tr("borne"), this, terminal)); + emit(partsAdded()); break; case Text: text = new PartText(element_editor, 0, this); text -> setPos(e -> scenePos()); undo_stack.push(new AddPartCommand(tr("texte"), this, text)); + emit(partsAdded()); break; case TextField: textfield = new PartTextField(element_editor, 0, this); textfield -> setPos(e -> scenePos()); undo_stack.push(new AddPartCommand(tr("champ de texte"), this, textfield)); + emit(partsAdded()); break; case Normal: default: @@ -212,6 +219,7 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { behavior = Normal; undo_stack.push(new AddPartCommand(tr("polygone"), this, current_polygon)); current_polygon = NULL; + emit(partsAdded()); emit(needNormalMode()); } else QGraphicsScene::mouseReleaseEvent(e); } else QGraphicsScene::mouseReleaseEvent(e); @@ -424,6 +432,7 @@ void ElementScene::slot_delete() { // efface tout ce qui est selectionne undo_stack.push(new DeletePartsCommand(this, selected_items)); + emit(partsRemoved()); } void ElementScene::slot_editSizeHotSpot() { @@ -536,6 +545,7 @@ void ElementScene::slot_editNames() { */ void ElementScene::slot_bringForward() { undoStack().push(new ChangeZValueCommand(this, ChangeZValueCommand::BringForward)); + emit(partsZValueChanged()); } /** @@ -543,6 +553,7 @@ void ElementScene::slot_bringForward() { */ void ElementScene::slot_raise() { undoStack().push(new ChangeZValueCommand(this, ChangeZValueCommand::Raise)); + emit(partsZValueChanged()); } /** @@ -550,6 +561,7 @@ void ElementScene::slot_raise() { */ void ElementScene::slot_lower() { undoStack().push(new ChangeZValueCommand(this, ChangeZValueCommand::Lower)); + emit(partsZValueChanged()); } /** @@ -557,6 +569,7 @@ void ElementScene::slot_lower() { */ void ElementScene::slot_sendBackward() { undoStack().push(new ChangeZValueCommand(this, ChangeZValueCommand::SendBackward)); + emit(partsZValueChanged()); } /** diff --git a/editor/elementscene.h b/editor/elementscene.h index 75cb86ffa..008a9890a 100644 --- a/editor/elementscene.h +++ b/editor/elementscene.h @@ -115,6 +115,9 @@ class ElementScene : public QGraphicsScene { signals: void selectionChanged(); void needNormalMode(); + void partsAdded(); + void partsRemoved(); + void partsZValueChanged(); }; inline void ElementScene::setWidth(const uint &wid) { diff --git a/editor/partarc.cpp b/editor/partarc.cpp index a5129cfa4..e262643bf 100644 --- a/editor/partarc.cpp +++ b/editor/partarc.cpp @@ -10,9 +10,9 @@ PartArc::PartArc(QETElementEditor *editor, QGraphicsItem *parent, QGraphicsScene setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setAcceptedMouseButtons(Qt::LeftButton); informations = new ArcEditor(elementEditor(), this); - informations -> setElementTypeName(QObject::tr("arc")); + informations -> setElementTypeName(name()); style_editor -> appendWidget(informations); - style_editor -> setElementTypeName(QObject::tr("arc")); + style_editor -> setElementTypeName(name()); } void PartArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { diff --git a/editor/partarc.h b/editor/partarc.h index fc56412a7..abe3d8466 100644 --- a/editor/partarc.h +++ b/editor/partarc.h @@ -27,6 +27,7 @@ class PartArc : public QGraphicsEllipseItem, public CustomElementGraphicPart { enum { Type = UserType + 1101 }; virtual int type() const { return Type; } virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0); + virtual QString name() const { return(QObject::tr("arc")); } virtual const QDomElement toXml(QDomDocument &) const; virtual void fromXml(const QDomElement &); virtual QPointF sceneTopLeft() const; diff --git a/editor/partcircle.cpp b/editor/partcircle.cpp index ae346dc2c..86af1d656 100644 --- a/editor/partcircle.cpp +++ b/editor/partcircle.cpp @@ -5,9 +5,9 @@ PartCircle::PartCircle(QETElementEditor *editor, QGraphicsItem *parent, QGraphic setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setAcceptedMouseButtons(Qt::LeftButton); informations = new CircleEditor(elementEditor(), this); - informations -> setElementTypeName(QObject::tr("cercle")); + informations -> setElementTypeName(name()); style_editor -> appendWidget(informations); - style_editor -> setElementTypeName(QObject::tr("cercle")); + style_editor -> setElementTypeName(name()); } void PartCircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { diff --git a/editor/partcircle.h b/editor/partcircle.h index e4f0a14da..0e8773bb1 100644 --- a/editor/partcircle.h +++ b/editor/partcircle.h @@ -25,6 +25,7 @@ class PartCircle : public QGraphicsEllipseItem, public CustomElementGraphicPart enum { Type = UserType + 1102 }; virtual int type() const { return Type; } virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0); + virtual QString name() const { return(QObject::tr("cercle")); } virtual const QDomElement toXml(QDomDocument &) const; virtual void fromXml(const QDomElement &); virtual QPointF sceneTopLeft() const; diff --git a/editor/partellipse.cpp b/editor/partellipse.cpp index 1b8f9dd26..1887fd932 100644 --- a/editor/partellipse.cpp +++ b/editor/partellipse.cpp @@ -5,9 +5,9 @@ PartEllipse::PartEllipse(QETElementEditor *editor, QGraphicsItem *parent, QGraph setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setAcceptedMouseButtons(Qt::LeftButton); informations = new EllipseEditor(elementEditor(), this); - informations -> setElementTypeName(QObject::tr("ellipse")); + informations -> setElementTypeName(name()); style_editor -> appendWidget(informations); - style_editor -> setElementTypeName(QObject::tr("ellipse")); + style_editor -> setElementTypeName(name()); } void PartEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { diff --git a/editor/partellipse.h b/editor/partellipse.h index ad824f975..66fc86b89 100644 --- a/editor/partellipse.h +++ b/editor/partellipse.h @@ -25,6 +25,7 @@ class PartEllipse : public QGraphicsEllipseItem, public CustomElementGraphicPart enum { Type = UserType + 1103 }; virtual int type() const { return Type; } virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0); + virtual QString name() const { return(QObject::tr("ellipse")); } virtual const QDomElement toXml(QDomDocument &) const; virtual void fromXml(const QDomElement &); virtual QPointF sceneTopLeft() const; diff --git a/editor/partline.cpp b/editor/partline.cpp index fe074adf7..7f17ce799 100644 --- a/editor/partline.cpp +++ b/editor/partline.cpp @@ -6,9 +6,9 @@ PartLine::PartLine(QETElementEditor *editor, QGraphicsItem *parent, QGraphicsSce setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setAcceptedMouseButtons(Qt::LeftButton); informations = new LineEditor(elementEditor(), this); - informations -> setElementTypeName(QObject::tr("ligne")); + informations -> setElementTypeName(name()); style_editor -> appendWidget(informations); - style_editor -> setElementTypeName(QObject::tr("ligne")); + style_editor -> setElementTypeName(name()); } void PartLine::paint(QPainter *painter, const QStyleOptionGraphicsItem */*q*/, QWidget */*w*/) { diff --git a/editor/partline.h b/editor/partline.h index 2d1600da0..d1084426a 100644 --- a/editor/partline.h +++ b/editor/partline.h @@ -25,6 +25,7 @@ class PartLine : public QGraphicsLineItem, public CustomElementGraphicPart { enum { Type = UserType + 1104 }; virtual int type() const { return Type; } virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0); + virtual QString name() const { return(QObject::tr("ligne")); } virtual const QDomElement toXml(QDomDocument &) const; virtual void fromXml(const QDomElement &); virtual QPointF sceneP1() const; diff --git a/editor/partpolygon.cpp b/editor/partpolygon.cpp index 72ea08277..f5443bff3 100644 --- a/editor/partpolygon.cpp +++ b/editor/partpolygon.cpp @@ -9,9 +9,9 @@ PartPolygon::PartPolygon(QETElementEditor *editor, QGraphicsItem *parent, QGraph setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setAcceptedMouseButtons(Qt::LeftButton); informations = new PolygonEditor(elementEditor(), this); - informations -> setElementTypeName(QObject::tr("polygone")); + informations -> setElementTypeName(name()); style_editor -> appendWidget(informations); - style_editor -> setElementTypeName(QObject::tr("polygone")); + style_editor -> setElementTypeName(name()); } void PartPolygon::fromXml(const QDomElement &qde) { diff --git a/editor/partpolygon.h b/editor/partpolygon.h index 88d47fc91..74fdc793e 100644 --- a/editor/partpolygon.h +++ b/editor/partpolygon.h @@ -37,6 +37,7 @@ class PartPolygon : public QGraphicsPolygonItem, public CustomElementGraphicPart public: enum { Type = UserType + 1105 }; virtual int type() const { return Type; } + virtual QString name() const { return(QObject::tr("polygone")); } void fromXml(const QDomElement &); const QDomElement toXml(QDomDocument &) const; void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); diff --git a/editor/partterminal.cpp b/editor/partterminal.cpp index 9c3ce0fc8..4ec3a9624 100644 --- a/editor/partterminal.cpp +++ b/editor/partterminal.cpp @@ -8,7 +8,7 @@ PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent, QGra _orientation(QET::North) { informations = new TerminalEditor(elementEditor(), this); - informations -> setElementTypeName(QObject::tr("borne")); + informations -> setElementTypeName(name()); updateSecondPoint(); setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setZValue(100000); @@ -59,12 +59,12 @@ void PartTerminal::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget t.setWidthF(1.0); // dessin de la borne en rouge - t.setColor(Qt::red); + t.setColor(isSelected() ? Terminal::couleur_neutre : Qt::red); p -> setPen(t); p -> drawLine(QPointF(0.0, 0.0), second_point); // dessin du point d'amarrage au conducteur en bleu - t.setColor(Terminal::couleur_neutre); + t.setColor(isSelected() ? Qt::red : Terminal::couleur_neutre); p -> setPen(t); p -> setBrush(Terminal::couleur_neutre); p -> drawPoint(QPointF(0.0, 0.0)); diff --git a/editor/partterminal.h b/editor/partterminal.h index dbba6b2c5..7626cb852 100644 --- a/editor/partterminal.h +++ b/editor/partterminal.h @@ -27,6 +27,7 @@ class PartTerminal : public CustomElementPart, public QGraphicsItem { public: enum { Type = UserType + 1106 }; virtual int type() const { return Type; } + virtual QString name() const { return(QObject::tr("borne")); } virtual void fromXml(const QDomElement &); virtual const QDomElement toXml(QDomDocument &) const; virtual QWidget *elementInformations(); diff --git a/editor/parttext.cpp b/editor/parttext.cpp index f33770dca..aba068180 100644 --- a/editor/parttext.cpp +++ b/editor/parttext.cpp @@ -9,7 +9,7 @@ PartText::PartText(QETElementEditor *editor, QGraphicsItem *parent, ElementScene setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setPlainText(QObject::tr("T")); infos = new TextEditor(elementEditor(), this); - infos -> setElementTypeName(QObject::tr("texte")); + infos -> setElementTypeName(name()); } PartText::~PartText() { diff --git a/editor/parttext.h b/editor/parttext.h index 1276649ce..6aebe1255 100644 --- a/editor/parttext.h +++ b/editor/parttext.h @@ -23,6 +23,7 @@ class PartText : public QGraphicsTextItem, public CustomElementPart { public: enum { Type = UserType + 1107 }; virtual int type() const { return Type; } + virtual QString name() const { return(QObject::tr("texte")); } void fromXml(const QDomElement &); const QDomElement toXml(QDomDocument &) const; QWidget *elementInformations(); diff --git a/editor/parttextfield.cpp b/editor/parttextfield.cpp index 918d38d85..3d6485fab 100644 --- a/editor/parttextfield.cpp +++ b/editor/parttextfield.cpp @@ -11,7 +11,7 @@ PartTextField::PartTextField(QETElementEditor *editor, QGraphicsItem *parent, QG setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setPlainText(QObject::tr("_")); infos = new TextFieldEditor(elementEditor(), this); - infos -> setElementTypeName(QObject::tr("champ de texte")); + infos -> setElementTypeName(name()); } PartTextField::~PartTextField() { diff --git a/editor/parttextfield.h b/editor/parttextfield.h index 9b9f13d97..eefbd3b9c 100644 --- a/editor/parttextfield.h +++ b/editor/parttextfield.h @@ -27,6 +27,7 @@ class PartTextField : public QGraphicsTextItem, public CustomElementPart { public: enum { Type = UserType + 1108 }; virtual int type() const { return Type; } + virtual QString name() const { return(QObject::tr("champ de texte")); } void fromXml(const QDomElement &); const QDomElement toXml(QDomDocument &) const; QWidget *elementInformations(); diff --git a/editor/qetelementeditor.cpp b/editor/qetelementeditor.cpp index 54ecdc491..275cb4939 100644 --- a/editor/qetelementeditor.cpp +++ b/editor/qetelementeditor.cpp @@ -4,6 +4,7 @@ #include "elementview.h" #include "customelementpart.h" #include "newelementwizard.h" +#include "elementitemeditor.h" QETElementEditor::QETElementEditor(QWidget *parent) : QMainWindow(parent), @@ -259,7 +260,24 @@ void QETElementEditor::setupInterface() { addDockWidget(Qt::RightDockWidgetArea, undo_dock); undo_dock -> setWidget(new QUndoView(&(ce_scene -> undoStack()), this)); + // panel sur le côté pour la liste des parties + parts_list = new QListWidget(this); + parts_list -> setSelectionMode(QAbstractItemView::ExtendedSelection); + connect(ce_scene, SIGNAL(partsAdded()), this, SLOT(slot_createPartsList())); + connect(ce_scene, SIGNAL(partsRemoved()), this, SLOT(slot_createPartsList())); + connect(ce_scene, SIGNAL(partsZValueChanged()), this, SLOT(slot_createPartsList())); + connect(ce_scene, SIGNAL(selectionChanged()), this, SLOT(slot_updatePartsList())); + connect(parts_list, SIGNAL(itemSelectionChanged()), this, SLOT(slot_updateSelectionFromPartsList())); + parts_dock = new QDockWidget(tr("Parties"), this); + parts_dock -> setObjectName("parts_list"); + parts_dock -> setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + parts_dock -> setFeatures(QDockWidget::AllDockWidgetFeatures); + parts_dock -> setMinimumWidth(290); + addDockWidget(Qt::RightDockWidgetArea, parts_dock); + parts_dock -> setWidget(parts_list); + slot_updateInformations(); + slot_createPartsList(); // barre d'etat statusBar() -> showMessage(tr("\311diteur d'\351l\351ments")); @@ -357,6 +375,7 @@ void QETElementEditor::fromFile(const QString &filepath) { // chargement de l'element ce_scene -> fromXml(document_xml); + slot_createPartsList(); // gestion de la lecture seule if (!infos_file.isWritable()) { @@ -496,3 +515,59 @@ void QETElementEditor::closeEvent(QCloseEvent *qce) { qce -> accept(); } else qce -> ignore(); } + +/** + Remplit la liste des parties +*/ +void QETElementEditor::slot_createPartsList() { + parts_list -> blockSignals(true); + parts_list -> clear(); + QList qgis = ce_scene -> zItems(true); + for (int j = qgis.count() - 1 ; j >= 0 ; -- j) { + QGraphicsItem *qgi = qgis[j]; + if (CustomElementPart *cep = dynamic_cast(qgi)) { + QString part_desc = cep -> name(); + QListWidgetItem *qlwi = new QListWidgetItem(part_desc); + QVariant v; + v.setValue(qgi); + qlwi -> setData(42, v); + parts_list -> addItem(qlwi); + qlwi -> setSelected(qgi -> isSelected()); + } + } + parts_list -> blockSignals(false); +} + +/** + Met a jour la selection dans la liste des parties +*/ +void QETElementEditor::slot_updatePartsList() { + parts_list -> blockSignals(true); + int i = 0; + QList items = ce_scene -> zItems(true); + for (int j = items.count() - 1 ; j >= 0 ; -- j) { + QGraphicsItem *qgi = items[j]; + QListWidgetItem *qlwi = parts_list -> item(i); + if (qlwi) qlwi -> setSelected(qgi -> isSelected()); + ++ i; + } + parts_list -> blockSignals(false); +} + +/** + Met a jour la selection des parties de l'element a partir de la liste des + parties +*/ +void QETElementEditor::slot_updateSelectionFromPartsList() { + ce_scene -> blockSignals(true); + parts_list -> blockSignals(true); + for (int i = 0 ; i < parts_list -> count() ; ++ i) { + QListWidgetItem *qlwi = parts_list -> item(i); + QGraphicsItem *qgi = qlwi -> data(42).value(); + if (qgi) { + qgi -> setSelected(qlwi -> isSelected()); + } + } + parts_list -> blockSignals(false); + ce_scene -> blockSignals(false); +} diff --git a/editor/qetelementeditor.h b/editor/qetelementeditor.h index 334861800..908dcef84 100644 --- a/editor/qetelementeditor.h +++ b/editor/qetelementeditor.h @@ -33,6 +33,10 @@ class QETElementEditor : public QMainWindow { QDockWidget *tools_dock; /// container pour la liste des annulations QDockWidget *undo_dock; + /// Container pour la liste des parties + QDockWidget *parts_dock; + /// Liste des parties + QListWidget *parts_list; /// actions du menu fichier QAction *new_element, *open, *save, *save_as, *quit; /// actions du menu edition @@ -90,6 +94,9 @@ class QETElementEditor : public QMainWindow { void slot_updateInformations(); void slot_updateMenus(); void slot_updateTitle(); + void slot_createPartsList(); + void slot_updatePartsList(); + void slot_updateSelectionFromPartsList(); void xmlPreview(); };