diff --git a/qelectrotech.pro b/qelectrotech.pro index 487533aee..afd00787d 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -64,8 +64,8 @@ DEPENDPATH += . INCLUDEPATH += sources sources/editor sources/titleblock # Fichiers sources -HEADERS += sources/*.h sources/ui/*.h sources/editor/*.h sources/titleblock/*.h sources/richtext/*.h -SOURCES += sources/*.cpp sources/editor/*.cpp sources/titleblock/*.cpp sources/richtext/*.cpp sources/ui/*.cpp +HEADERS += sources/*.h sources/ui/*.h sources/editor/*.h sources/titleblock/*.h sources/richtext/*.h sources/qetgraphicsitem/*.h +SOURCES += sources/*.cpp sources/editor/*.cpp sources/titleblock/*.cpp sources/richtext/*.cpp sources/ui/*.cpp sources/qetgraphicsitem/*.cpp # Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt RESOURCES += qelectrotech.qrc diff --git a/sources/conductorautonumerotation.h b/sources/conductorautonumerotation.h index fcc44f075..387b10884 100644 --- a/sources/conductorautonumerotation.h +++ b/sources/conductorautonumerotation.h @@ -18,7 +18,7 @@ #ifndef CONDUCTORAUTONUMEROTATION_H #define CONDUCTORAUTONUMEROTATION_H -#include "conductor.h" +#include "qetgraphicsitem/conductor.h" #include "numerotationcontext.h" #include "autonumerotation.h" diff --git a/sources/conductorautonumerotationwidget.h b/sources/conductorautonumerotationwidget.h index 79d48b47a..675dee5ca 100644 --- a/sources/conductorautonumerotationwidget.h +++ b/sources/conductorautonumerotationwidget.h @@ -6,7 +6,7 @@ #include #include #include -#include "conductor.h" +#include "qetgraphicsitem/conductor.h" #include "diagram.h" class ConductorAutoNumerotationWidget : public QDialog diff --git a/sources/conductorprofile.cpp b/sources/conductorprofile.cpp index 40d27aef0..bfc6f89d9 100644 --- a/sources/conductorprofile.cpp +++ b/sources/conductorprofile.cpp @@ -16,7 +16,7 @@ along with QElectroTech. If not, see . */ #include "conductorprofile.h" -#include "conductor.h" +#include "qetgraphicsitem/conductor.h" #include "conductorsegmentprofile.h" /// Constructeur diff --git a/sources/conductorpropertieswidget.cpp b/sources/conductorpropertieswidget.cpp index 274f65ef2..7a15f132a 100644 --- a/sources/conductorpropertieswidget.cpp +++ b/sources/conductorpropertieswidget.cpp @@ -17,7 +17,7 @@ */ #include "conductorpropertieswidget.h" #include -#include "conductor.h" +#include "qetgraphicsitem/conductor.h" #include "qeticons.h" #include "qetapp.h" diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 0c907a507..acaad2d6c 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -16,21 +16,21 @@ along with QElectroTech. If not, see . */ #include -#include "conductor.h" -#include "conductortextitem.h" -#include "customelement.h" +#include "qetgraphicsitem/conductor.h" +#include "qetgraphicsitem/conductortextitem.h" +#include "qetgraphicsitem/customelement.h" #include "diagram.h" #include "diagramcommands.h" #include "diagramcontent.h" #include "diagramposition.h" -#include "elementtextitem.h" +#include "qetgraphicsitem/elementtextitem.h" #include "elementsmover.h" #include "elementtextsmover.h" #include "exportdialog.h" -#include "ghostelement.h" -#include "independenttextitem.h" +#include "qetgraphicsitem/ghostelement.h" +#include "qetgraphicsitem/independenttextitem.h" #include "qetapp.h" -#include "diagramimageitem.h" +#include "qetgraphicsitem/diagramimageitem.h" const int Diagram::xGrid = 10; const int Diagram::yGrid = 10; @@ -547,7 +547,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf // chargement de tous les textes du fichiers XML QList added_texts; foreach (QDomElement text_xml, QET::findInDomElement(root, "inputs", "input")) { - IndependentTextItem *iti = new IndependentTextItem(this); + IndependentTextItem *iti = new IndependentTextItem(this); iti -> fromXml(text_xml); addIndependentTextItem(iti); added_texts << iti; @@ -555,7 +555,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf QList added_images; foreach (QDomElement image_xml, QET::findInDomElement(root, "images", "image")) { - DiagramImageItem *dii = new DiagramImageItem (this); + DiagramImageItem *dii = new DiagramImageItem (); dii -> fromXml(image_xml); addItem(dii); added_images << dii; @@ -1256,20 +1256,11 @@ DiagramContent Diagram::selectedContent() { */ bool Diagram::canRotateSelection() const { foreach(QGraphicsItem * qgi, selectedItems()) { - if (qgraphicsitem_cast(qgi)) { - return(true); - } else if (qgraphicsitem_cast(qgi)) { - return(true); - } else if (qgraphicsitem_cast(qgi)) { - return(true); - } else if (Element *e = qgraphicsitem_cast(qgi)) { - // l'element est-il pivotable ? - if (e -> orientation().current() != e -> orientation().next()) { - return(true); - } - } else if (qgraphicsitem_cast(qgi)) { - return (true); - } + if (qgraphicsitem_cast(qgi) || + qgraphicsitem_cast(qgi) || + qgraphicsitem_cast(qgi) || + qgraphicsitem_cast(qgi) || + qgraphicsitem_cast(qgi)) return (true); } return(false); } diff --git a/sources/diagramcommands.cpp b/sources/diagramcommands.cpp index 43401dae0..b1e684a10 100644 --- a/sources/diagramcommands.cpp +++ b/sources/diagramcommands.cpp @@ -16,16 +16,16 @@ along with QElectroTech. If not, see . */ #include "diagramcommands.h" -#include "element.h" -#include "conductor.h" -#include "conductortextitem.h" +#include "qetgraphicsitem/element.h" +#include "qetgraphicsitem/conductor.h" +#include "qetgraphicsitem/conductortextitem.h" #include "diagram.h" -#include "elementtextitem.h" -#include "independenttextitem.h" +#include "qetgraphicsitem/elementtextitem.h" +#include "qetgraphicsitem/independenttextitem.h" #include "qgimanager.h" #include "diagram.h" -#include "diagramtextitem.h" -#include "diagramimageitem.h" +#include "qetgraphicsitem/diagramtextitem.h" +#include "qetgraphicsitem/diagramimageitem.h" /** Constructeur @@ -630,12 +630,12 @@ void ChangeDiagramTextCommand::redo() { @param texts Textes a pivoter @param parent QUndoCommand parent */ -RotateElementsCommand::RotateElementsCommand(const QHash &elements, const QList &texts, const QList &images, QUndoCommand *parent) : +RotateElementsCommand::RotateElementsCommand(const QList &elements, const QList &texts, const QList &images, QUndoCommand *parent) : QUndoCommand(parent), elements_to_rotate(elements), texts_to_rotate(texts), images_to_rotate(images), - applied_rotation_angle_(-90.0) + applied_rotation_angle_(90.0) { setText( QString( @@ -653,14 +653,14 @@ RotateElementsCommand::~RotateElementsCommand() { /// defait le pivotement void RotateElementsCommand::undo() { - foreach(Element *e, elements_to_rotate.keys()) { - rotateElement(e, elements_to_rotate[e]); + foreach(Element *e, elements_to_rotate) { + e -> rotateBy(-applied_rotation_angle_); } foreach(DiagramTextItem *dti, texts_to_rotate) { //ConductorTextItem have a default rotation angle, we apply a specific treatment if (ConductorTextItem *cti = qgraphicsitem_cast(dti)) { cti -> forceRotateByUser(previous_rotate_by_user_[cti]); - (cti -> wasRotateByUser()) ? cti -> rotateBy(-appliedRotationAngle()) : + (cti -> wasRotateByUser()) ? cti -> rotateBy(-applied_rotation_angle_) : cti -> parentConductor() -> adjustTextItemPosition(); } else {dti -> rotateBy(-applied_rotation_angle_);} @@ -670,8 +670,8 @@ void RotateElementsCommand::undo() { /// refait le pivotement void RotateElementsCommand::redo() { - foreach(Element *e, elements_to_rotate.keys()) { - rotateElement(e, e -> orientation().next()); + foreach(Element *e, elements_to_rotate) { + e -> rotateBy(applied_rotation_angle_); } foreach(DiagramTextItem *dti, texts_to_rotate) { //we grab the previous rotation by user of each ConductorTextItem @@ -684,50 +684,6 @@ void RotateElementsCommand::redo() { foreach(DiagramImageItem *dii, images_to_rotate) dii -> rotateBy(applied_rotation_angle_); } -/** - @return l'angle de rotation applique aux textes -*/ -qreal RotateElementsCommand::appliedRotationAngle() const { - return(applied_rotation_angle_); -} - -/** - @param angle l'angle de rotation a appliquer aux textes -*/ -void RotateElementsCommand::setAppliedRotationAngle(const qreal &angle) { - applied_rotation_angle_ = QET::correctAngle(angle); -} - -/** - Passe un element a une orientation donnee, en prenant soin de gerer ses textes enfants - @param element Element a orienter soigneusement - @param orientation Nouvelle orientation de l'element -*/ -void RotateElementsCommand::rotateElement(Element *element, QET::Orientation orientation) { - qreal rotation_value = 90.0 * (orientation - element -> orientation().current()); - element -> setOrientation(orientation); - element -> update(); - if (rotation_value) { - // repositionne les textes de l'element qui ne comportent pas l'option "FollowParentRotations" - foreach(ElementTextItem *eti, element -> texts()) { - if (!eti -> followParentRotations()) { - // on souhaite pivoter le champ de texte par rapport a son centre - QPointF eti_center = eti -> boundingRect().center(); - // pour ce faire, on repere la position de son centre par rapport a son parent - QPointF parent_eti_center_before = eti -> mapToParent(eti_center); - // on applique ensuite une simple rotation contraire, qui sera donc appliquee sur le milieu du cote gauche du champ de texte - eti -> rotateBy(-rotation_value); - // on regarde ensuite la nouvelle position du centre du champ de texte par rapport a son parent - QPointF parent_eti_center_after = eti -> mapToParent(eti_center); - // on determine la translation a appliquer - QPointF eti_translation = parent_eti_center_before - parent_eti_center_after; - // on applique cette translation - eti -> setPos(eti -> pos() + eti_translation); - } - } - } -} - /** Constructeur @param previous_state Hash associant les textes impactes par l'action et leur angle de rotation avant l'action diff --git a/sources/diagramcommands.h b/sources/diagramcommands.h index 688ec7cbd..a95beb6a5 100644 --- a/sources/diagramcommands.h +++ b/sources/diagramcommands.h @@ -19,7 +19,7 @@ #define DIAGRAM_COMMANDS_H #include #include "borderproperties.h" -#include "conductor.h" +#include "qetgraphicsitem/conductor.h" #include "conductorproperties.h" #include "diagramcontent.h" #include "titleblockproperties.h" @@ -330,7 +330,7 @@ class ChangeDiagramTextCommand : public QUndoCommand { class RotateElementsCommand : public QUndoCommand { // constructors, destructor public: - RotateElementsCommand(const QHash &elements, const QList &, const QList &, QUndoCommand * = 0); + RotateElementsCommand(const QList &elements, const QList &, const QList &, QUndoCommand * = 0); virtual ~RotateElementsCommand(); private: RotateElementsCommand(const RotateElementsCommand &); @@ -339,14 +339,11 @@ class RotateElementsCommand : public QUndoCommand { public: virtual void undo(); virtual void redo(); - qreal appliedRotationAngle() const; - void setAppliedRotationAngle(const qreal &); - static void rotateElement(Element *, QET::Orientation); // attributes private: /// hold rotated elements along with their former orientation - QHash elements_to_rotate; + QList elements_to_rotate; /// text items to be rotated QList texts_to_rotate; /// images item to be rotated diff --git a/sources/diagramcontent.cpp b/sources/diagramcontent.cpp index bf99ecf6f..89b0050c1 100644 --- a/sources/diagramcontent.cpp +++ b/sources/diagramcontent.cpp @@ -17,10 +17,10 @@ */ #include "diagramcontent.h" #include -#include "element.h" -#include "independenttextitem.h" -#include "conductor.h" -#include "diagramimageitem.h" +#include "qetgraphicsitem/element.h" +#include "qetgraphicsitem/independenttextitem.h" +#include "qetgraphicsitem/conductor.h" +#include "qetgraphicsitem/diagramimageitem.h" /** Constructeur par defaut. Ne contient rien. diff --git a/sources/diagramimageitem.cpp b/sources/diagramimageitem.cpp deleted file mode 100644 index ca6456c4c..000000000 --- a/sources/diagramimageitem.cpp +++ /dev/null @@ -1,323 +0,0 @@ -/* - Copyright 2006-2013 QElectroTech Team - This file is part of QElectroTech. - - QElectroTech is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - QElectroTech is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with QElectroTech. If not, see . -*/ -#include "diagramimageitem.h" -#include "diagramcommands.h" -#include "qet.h" -#include "qetapp.h" - -DiagramImageItem::DiagramImageItem(Diagram *parent_diagram) : - QGraphicsPixmapItem(0, parent_diagram), - first_move_(false) -{ - setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable); -#if QT_VERSION >= 0x040600 - setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); -#endif -} - -/** - * @brief DiagramImageItem::DiagramImageItem - * @param parent - * @param parent_diagram - */ -DiagramImageItem::DiagramImageItem(const QPixmap &pixmap, Diagram *parent_diagram) : - QGraphicsPixmapItem(pixmap, 0, parent_diagram), - first_move_(false) -{ - setTransformOriginPoint(boundingRect().center()); - setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable); -#if QT_VERSION >= 0x040600 - setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); -#endif -} - -/// Destructeur -DiagramImageItem::~DiagramImageItem() { -} - -/** - @return le Diagram auquel ce image appartient, ou 0 si ce image n'est - rattache a aucun schema -*/ -Diagram *DiagramImageItem::diagram() const { - return(qobject_cast(scene())); -} - -/** - Permet de tourner le image a un angle donne de maniere absolue. - Un angle de 0 degres correspond a un image horizontal non retourne. - @param rotation Nouvel angle de rotation de ce image - @see applyRotation -*/ -void DiagramImageItem::setRotationAngle(const qreal &rotation_angle) { - qreal applied_rotation = QET::correctAngle(rotation_angle); - applyRotation(applied_rotation - rotation()); -} - -/** - Permet de tourner le image de maniere relative. - L'angle added_rotation est ajoute a l'orientation actuelle du image. - @param added_rotation Angle a ajouter a la rotation actuelle - @see applyRotation -*/ -void DiagramImageItem::rotateBy(const qreal &added_rotation) { - qreal applied_added_rotation = QET::correctAngle(added_rotation); - applyRotation(applied_added_rotation); -} - -/** - Dessine le champ de image. - Cette methode delegue simplement le travail a QGraphicsPixmapItem::paint apres - avoir desactive l'antialiasing. - @param painter Le QPainter a utiliser pour dessiner le champ de image - @param option Les options de style pour le champ de image - @param widget Le QWidget sur lequel on dessine -*/ -void DiagramImageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - painter -> setRenderHint(QPainter::Antialiasing, false); - QGraphicsPixmapItem::paint(painter, option, widget); -} - -/** - Gere le clic sur le champ de texte - @param e Objet decrivant l'evenement souris -*/ -void DiagramImageItem::mousePressEvent(QGraphicsSceneMouseEvent *e) { - first_move_ = true; - if (e -> modifiers() & Qt::ControlModifier) { - setSelected(!isSelected()); - } - QGraphicsItem::mousePressEvent(e); -} - -/** - Gere les double-clics sur ce champ de image. - @param event un QGraphicsSceneMouseEvent decrivant le double-clic -*/ -void DiagramImageItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { - Q_UNUSED (event); - edit(); -} - -/** - * @brief DiagramImageItem::mouseMoveEvent - * Gere les mouvements de souris lies a l'image - * @param e Objet decrivant l'evenement souris - */ -void DiagramImageItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { - if (isSelected() && e -> buttons() & Qt::LeftButton) { - //Image is moving - if(diagram()) { - if (first_move_) { - //It's the first movement, we signal it to parent diagram - diagram() -> beginMoveElements(this); - } - } - - //we apply the mouse movement - QPointF old_pos = pos(); - if (first_move_) { - mouse_to_origin_movement_ = old_pos - e -> buttonDownScenePos(Qt::LeftButton); - } - QPointF expected_pos = e-> scenePos() + mouse_to_origin_movement_; - setPos(expected_pos); // setPos() will snap the expected position to the grid - - //we calcul the real movement apply by setPos() - QPointF effective_movement = pos() - old_pos; - if (diagram()) { - //we signal the real movement apply to diagram, - //who he apply to other selected item - diagram() -> continueMoveElements(effective_movement); - } - } else e -> ignore(); - - if (first_move_) first_move_ = false; -} - -/** - * @brief DiagramImageItem::mouseReleaseEvent - * Gere le relachement de souris - * Cette methode a ete reimplementee pour tenir a jour la liste - * des images à deplacer au niveau du schema. - * @param e Objet decrivant l'evenement souris - */ -void DiagramImageItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { - if (diagram()) { - diagram() -> endMoveElements(); - } - if (!(e -> modifiers() & Qt::ControlModifier)) { - QGraphicsItem::mouseReleaseEvent(e); - } -} - -/** - Effectue la rotation du image en elle-meme - Pour les DiagramImageItem, la rotation s'effectue autour du point (0, 0). - Cette methode peut toutefois etre redefinie dans des classes filles - @param angle Angle de la rotation a effectuer -*/ -void DiagramImageItem::applyRotation(const qreal &angle) { - setRotation(QET::correctAngle(rotation()+angle)); -} - -/** - Change la position du champ de image en veillant a ce qu'il - reste sur la grille du schema auquel il appartient. - @param p Nouvelles coordonnees de l'element -*/ -void DiagramImageItem::setPos(const QPointF &p) { - if (p == pos()) return; - // pas la peine de positionner sur la grille si l'element n'est pas sur un Diagram - if (scene()) { - // arrondit l'abscisse a 10 px pres - int p_x = qRound(p.x() / (Diagram::xGrid * 1.0)) * Diagram::xGrid; - // arrondit l'ordonnee a 10 px pres - int p_y = qRound(p.y() / (Diagram::yGrid * 1.0)) * Diagram::yGrid; - QGraphicsPixmapItem::setPos(p_x, p_y); - } else QGraphicsPixmapItem::setPos(p); -} - -/** - Change la position du champ de image en veillant a ce que l'il - reste sur la grille du schema auquel il appartient. - @param x Nouvelle abscisse de l'element - @param y Nouvelle ordonnee de l'element -*/ -void DiagramImageItem::setPos(qreal x, qreal y) { - setPos(QPointF(x, y)); -} - -/** - * @brief DiagramImageItem::setScale - * @param scale the value of @scale must be betwen 1 and 200 - */ -void DiagramImageItem::PreviewScale(int scale) { - if (scale >= 1 && scale <= 200) { - qreal new_scale = scale; - new_scale /= 100; - setScale(new_scale); - } -} - -/** - * @brief Edit the image with .... - */ -void DiagramImageItem::edit() { - if (diagram() -> isReadOnly()) return; - //the range for scale image and divisor factor - int min_range = 1; - int max_range = 200; - int factor_range = 100; - - //the dialog - QDialog property_dialog; - property_dialog.setWindowTitle(tr("\311diter les propri\351t\351s d'une image", "window title")); - //the main layout - QVBoxLayout *dialog_layout = new QVBoxLayout(&property_dialog); - - //GroupBox for resizer image - QGroupBox *resize_groupe = new QGroupBox(tr("Dimension de l'image", "image size")); - dialog_layout -> addWidget(resize_groupe); - QHBoxLayout *resize_layout = new QHBoxLayout(resize_groupe); - - //slider - QSlider *slider = new QSlider(Qt::Horizontal, &property_dialog); - slider->setRange(min_range, max_range); - qreal scale_= scale(); - slider -> setValue(scale_*factor_range); - //spinbox - QSpinBox *spin_box = new QSpinBox(&property_dialog); - spin_box -> setRange(min_range, max_range); - spin_box -> setValue(scale_*factor_range); - spin_box -> setSuffix(" %"); - //synchro slider with spinbox - connect(slider, SIGNAL(valueChanged(int)), spin_box, SLOT(setValue(int))); - connect(slider, SIGNAL(valueChanged(int)), this, SLOT(PreviewScale(int))); - connect(spin_box, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int))); - //add slider and spinbox to layout - resize_layout -> addWidget(slider); - resize_layout -> addWidget(spin_box); - - //dialog button, box - QDialogButtonBox *dbb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - dialog_layout -> addWidget(dbb); - connect(dbb, SIGNAL(accepted()), &property_dialog, SLOT(accept())); - connect(dbb, SIGNAL(rejected()), &property_dialog, SLOT(reject())); - //dialog is accepted... - if (property_dialog.exec() == QDialog::Accepted) { - qreal new_scale = slider -> value(); - new_scale /= factor_range; - if (scale_ != new_scale) diagram()->undoStack().push(new ImageResizerCommand(this, scale_, new_scale)); - } - //...or not - else setScale(scale_); - return; -} - -void DiagramImageItem::setPixmap(const QPixmap &pixmap) { - QGraphicsPixmapItem::setPixmap(pixmap); - setTransformOriginPoint(boundingRect().center()); -} - -/** - Load the image from this xml element - @param e xml element that define an image -*/ -bool DiagramImageItem::fromXml(const QDomElement &e) { - if (e.tagName() != "image") return (false); - QDomNode image_node = e.firstChild(); - if (!image_node.isText()) return (false); - - //load xml text image to QByteArray - QByteArray array; - array = QByteArray::fromBase64(e.text().toAscii()); - - //Set QPixmap from the @array - QPixmap pixmap; - pixmap.loadFromData(array); - setPixmap(pixmap); - - setScale(e.attribute("size").toDouble()); - setRotationAngle(e.attribute("rotation").toDouble()); - setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble()); - - return (true); -} - -/** - @param document Le document XML a utiliser - @return L'element XML representant ce champ de texte -*/ -QDomElement DiagramImageItem::toXml(QDomDocument &document) const { - QDomElement result = document.createElement("image"); - //write some attribute - result.setAttribute("x", QString("%1").arg(pos().x())); - result.setAttribute("y", QString("%1").arg(pos().y())); - result.setAttribute("rotation", QString("%1").arg(rotation())); - result.setAttribute("size", QString("%1").arg(scale())); - - //write the pixmap in the xml element after he was been transformed to base64 - QByteArray array; - QBuffer buffer(&array); - buffer.open(QIODevice::ReadWrite); - pixmap().save(&buffer, "PNG"); - QDomText base64 = document.createTextNode(array.toBase64()); - result.appendChild(base64); - - return(result); -} diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 268b3f190..1dc1a9b73 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -17,16 +17,16 @@ */ #include "diagramview.h" #include "diagram.h" -#include "customelement.h" -#include "ghostelement.h" -#include "conductor.h" +#include "qetgraphicsitem/customelement.h" +#include "qetgraphicsitem/ghostelement.h" +#include "qetgraphicsitem/conductor.h" #include "diagramcommands.h" #include "diagramposition.h" #include "conductorpropertieswidget.h" -#include "conductortextitem.h" -#include "elementtextitem.h" -#include "independenttextitem.h" -#include "diagramimageitem.h" +#include "qetgraphicsitem/conductortextitem.h" +#include "qetgraphicsitem/elementtextitem.h" +#include "qetgraphicsitem/independenttextitem.h" +#include "qetgraphicsitem/diagramimageitem.h" #include "titleblockpropertieswidget.h" #include "templatelocation.h" #include "qetapp.h" @@ -144,12 +144,12 @@ void DiagramView::rotateSelection() { if (scene -> isReadOnly()) return; // recupere les elements et les champs de texte a pivoter - QHash elements_to_rotate; + QList elements_to_rotate; QList texts_to_rotate; QList images_to_rotate; foreach (QGraphicsItem *item, scene -> selectedItems()) { if (Element *e = qgraphicsitem_cast(item)) { - elements_to_rotate.insert(e, e -> orientation().current()); + elements_to_rotate << e; } else if (ConductorTextItem *cti = qgraphicsitem_cast(item)) { texts_to_rotate << cti; } else if (IndependentTextItem *iti = qgraphicsitem_cast(item)) { @@ -1294,7 +1294,7 @@ void DiagramView::editImage() { if (images.count() != 1) return; DiagramImageItem *image; if ((image = qgraphicsitem_cast (images.first()))) { - image -> edit(); + image -> editProperty(); } } diff --git a/sources/editor/customelementpart.cpp b/sources/editor/customelementpart.cpp index 2cb534be0..fc811731d 100644 --- a/sources/editor/customelementpart.cpp +++ b/sources/editor/customelementpart.cpp @@ -16,7 +16,7 @@ along with QElectroTech. If not, see . */ #include "customelementpart.h" -#include "customelement.h" +#include "qetgraphicsitem/customelement.h" #include "qetelementeditor.h" /// @return le QETElementEditor auquel cet editeur appartient diff --git a/sources/editor/editorcommands.cpp b/sources/editor/editorcommands.cpp index 8f3a5c68e..4286f7689 100644 --- a/sources/editor/editorcommands.cpp +++ b/sources/editor/editorcommands.cpp @@ -409,39 +409,6 @@ void ChangeNamesCommand::redo() { editor_scene_ -> setNames(names_after); } -/** - Constructeur - @param element_scene Element edite - @param before Orientations avant changement - @param after Orientations apres changement - @param parent QUndoCommand parent -*/ -ChangeOrientationsCommand::ChangeOrientationsCommand( - ElementScene *element_scene, - const OrientationSet &before, - const OrientationSet &after, - QUndoCommand *parent -) : - ElementEditionCommand(QObject::tr("modification orientations", "undo caption"), element_scene, 0, parent), - ori_before(before), - ori_after(after) -{ -} - -/// Destructeur -ChangeOrientationsCommand::~ChangeOrientationsCommand() { -} - -/// Annule le changement -void ChangeOrientationsCommand::undo() { - editor_scene_ -> setOrientations(ori_before); -} - -/// Refait le changement -void ChangeOrientationsCommand::redo() { - editor_scene_ -> setOrientations(ori_after); -} - /** Constructeur @param elmt ElementScene concernee @@ -565,32 +532,6 @@ void ChangeZValueCommand::applySendBackward(const QList &items_ foreach(QGraphicsItem *qgi, non_selected_items) redo_hash.insert(qgi, z ++); } -/** - Constructeur - @param elmt ElementScene concernee - @param allow true pour que les connexions internes soient acceptees, false sinon - @param parent QUndoCommand parent -*/ -AllowInternalConnectionsCommand::AllowInternalConnectionsCommand(ElementScene *elmt, bool allow, QUndoCommand *parent) : - ElementEditionCommand(QObject::tr("modification connexions internes", "undo caption"), elmt, 0, parent), - ic(allow) -{ -} - -/// Destructeur -AllowInternalConnectionsCommand::~AllowInternalConnectionsCommand() { -} - -/// Annule le changement d'autorisation pour les connexions internes -void AllowInternalConnectionsCommand::undo() { - editor_scene_ -> setInternalConnections(!ic); -} - -/// Refait le changement d'autorisation pour les connexions internes -void AllowInternalConnectionsCommand::redo() { - editor_scene_ -> setInternalConnections(ic); -} - /** Constructeur @param elmt ElementScene concernee diff --git a/sources/editor/editorcommands.h b/sources/editor/editorcommands.h index a4573a2a8..1cf8b0374 100644 --- a/sources/editor/editorcommands.h +++ b/sources/editor/editorcommands.h @@ -248,30 +248,6 @@ class ChangeNamesCommand : public ElementEditionCommand { NamesList names_after; }; -/** - This command changes the allowed orientations of an electrical element. -*/ -class ChangeOrientationsCommand : public ElementEditionCommand { - // constructors, destructor - public: - ChangeOrientationsCommand(ElementScene *, const OrientationSet &, const OrientationSet &, QUndoCommand * = 0); - virtual ~ChangeOrientationsCommand(); - private: - ChangeOrientationsCommand(const ChangeOrientationsCommand &); - - // methods - public: - virtual void undo(); - virtual void redo(); - - // attributes - private: - /// Former orientations - OrientationSet ori_before; - /// New orientations - OrientationSet ori_after; -}; - /** This command changes the zValue of a set of primitives when editing an electrical element. @@ -312,29 +288,6 @@ class ChangeZValueCommand : public ElementEditionCommand { Option option; }; -/** - This command enables or disables internal connections for an electrical - element. -*/ -class AllowInternalConnectionsCommand : public ElementEditionCommand { - // constructors, destructor - public: - AllowInternalConnectionsCommand(ElementScene *, bool, QUndoCommand * = 0); - virtual ~AllowInternalConnectionsCommand(); - private: - AllowInternalConnectionsCommand(const AllowInternalConnectionsCommand &); - - // methods - public: - virtual void undo(); - virtual void redo(); - - // attributes - private: - /// whether internal connections are allowed afterward - bool ic; -}; - /** This command changes extra information carried by an electrical element. */ diff --git a/sources/editor/elementscene.cpp b/sources/editor/elementscene.cpp index 858ab9b56..1973c1f8f 100644 --- a/sources/editor/elementscene.cpp +++ b/sources/editor/elementscene.cpp @@ -38,7 +38,6 @@ */ ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) : QGraphicsScene(parent), - internal_connections(false), qgi_manager(this), element_editor(editor), decorator_(0) @@ -415,9 +414,9 @@ const QDomDocument ElementScene::toXml(bool all_parts) { root.setAttribute("height", QString("%1").arg(upheight)); root.setAttribute("hotspot_x", QString("%1").arg(-(qRound(size.x() - (xmargin/2))))); root.setAttribute("hotspot_y", QString("%1").arg(-(qRound(size.y() - (ymargin/2))))); - root.setAttribute("orientation", ori.toString()); + root.setAttribute("orientation", "dyyy"); //we keep the orientation for compatibility with previous version of qet root.setAttribute("version", QET::version); - if (internal_connections) root.setAttribute("ic", "true"); + root.setAttribute("ic", "true"); //we keep the internal connection for compatibility with previous version of qet // noms de l'element root.appendChild(_names.toXml(xml_document)); @@ -663,58 +662,6 @@ void ElementScene::slot_delete() { emit(selectionChanged()); } -/** - Lance un dialogue pour editer les noms de cete element -*/ -void ElementScene::slot_editOrientations() { - bool is_read_only = element_editor && element_editor -> isReadOnly(); - - // cree un dialogue - QDialog dialog_ori(element_editor); - dialog_ori.setModal(true); -#ifdef Q_WS_MAC - dialog_ori.setWindowFlags(Qt::Sheet); -#endif - dialog_ori.setMinimumSize(400, 260); - dialog_ori.setWindowTitle(tr("\311diter les orientations", "window title")); - QVBoxLayout *dialog_layout = new QVBoxLayout(&dialog_ori); - - // ajoute un champ explicatif au dialogue - QLabel *information_label = new QLabel(tr("L'orientation par d\351faut est l'orientation dans laquelle s'effectue la cr\351ation de l'\351l\351ment.")); - information_label -> setAlignment(Qt::AlignJustify | Qt::AlignVCenter); - information_label -> setWordWrap(true); - dialog_layout -> addWidget(information_label); - - // ajoute un OrientationSetWidget au dialogue - OrientationSetWidget *ori_widget = new OrientationSetWidget(); - ori_widget -> setOrientationSet(ori); - ori_widget -> setReadOnly(is_read_only); - dialog_layout -> addWidget(ori_widget); - - // ajoute une case a cocher pour les connexions internes - QCheckBox *ic_checkbox = new QCheckBox(tr("Autoriser les connexions internes")); - ic_checkbox -> setChecked(internal_connections); - ic_checkbox -> setDisabled(is_read_only); - dialog_layout -> addWidget(ic_checkbox); - dialog_layout -> addStretch(); - // ajoute deux boutons au dialogue - QDialogButtonBox *dialog_buttons = new QDialogButtonBox(is_read_only ? QDialogButtonBox::Ok : QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - dialog_layout -> addWidget(dialog_buttons); - connect(dialog_buttons, SIGNAL(accepted()), &dialog_ori, SLOT(accept())); - connect(dialog_buttons, SIGNAL(rejected()), &dialog_ori, SLOT(reject())); - - // lance le dialogue - if (dialog_ori.exec() == QDialog::Accepted && !is_read_only) { - OrientationSet new_ori = ori_widget -> orientationSet(); - if (new_ori != ori) { - undoStack().push(new ChangeOrientationsCommand(this, ori, new_ori)); - } - if (ic_checkbox -> isChecked() != internal_connections) { - undoStack().push(new AllowInternalConnectionsCommand(this, ic_checkbox -> isChecked())); - } - } -} - /** Lance un dialogue pour editer les informations complementaires de cet element. Concretement, ce champ libre est destine a accueillir des informations @@ -979,18 +926,7 @@ bool ElementScene::applyInformations(const QDomDocument &xml_document, QString * } return(false); } - - // orientations - internal_connections = (root.attribute("ic") == "true"); - - // connexions internes - if (!ori.fromString(root.attribute("orientation"))) { - if (error_message) { - *error_message = tr("Les orientations ne sont pas valides.", "error message"); - } - return(false); - } - + // extrait les noms de la definition XML _names.fromXml(root); diff --git a/sources/editor/elementscene.h b/sources/editor/elementscene.h index 23e7255d4..c344eaa42 100644 --- a/sources/editor/elementscene.h +++ b/sources/editor/elementscene.h @@ -20,7 +20,6 @@ #include #include #include "nameslistwidget.h" -#include "orientationsetwidget.h" #include "qgimanager.h" #include "elementcontent.h" class CustomElementPart; @@ -65,10 +64,6 @@ class ElementScene : public QGraphicsScene { private: /// List of localized names NamesList _names; - /// Set of orientations - OrientationSet ori; - /// whether internal connections (i.e. connections between terminals of a same element) are accepted - bool internal_connections; /// Extra informations QString informations_; /// QGraphicsItem manager @@ -112,8 +107,6 @@ class ElementScene : public QGraphicsScene { public: void setNames(const NamesList &); NamesList names() const; - OrientationSet orientations(); - void setOrientations(const OrientationSet &); bool internalConnections(); void setInternalConnections(bool); QString informations() const; @@ -178,7 +171,6 @@ class ElementScene : public QGraphicsScene { void slot_invertSelection(); void slot_delete(); void slot_editNames(); - void slot_editOrientations(); void slot_editAuthorInformations(); void slot_bringForward(); void slot_raise(); @@ -222,34 +214,6 @@ inline NamesList ElementScene::names() const { return(_names); } -/** - @return the orientation set of the currently edited element -*/ -inline OrientationSet ElementScene::orientations() { - return(ori); -} - -/** - @param orientation_set the new orientation set for the currently edited element -*/ -inline void ElementScene::setOrientations(const OrientationSet &orientation_set) { - ori = orientation_set; -} - -/** - @return whether internal connections are accepted -*/ -inline bool ElementScene::internalConnections() { - return(internal_connections); -} - -/** - @param ic true for internal connections to be accepted, false otherwise -*/ -inline void ElementScene::setInternalConnections(bool ic) { - internal_connections = ic; -} - /** @return extra informations of the currently edited element */ diff --git a/sources/editor/elementview.cpp b/sources/editor/elementview.cpp index e68cd3c89..7e1303e71 100644 --- a/sources/editor/elementview.cpp +++ b/sources/editor/elementview.cpp @@ -322,7 +322,6 @@ ElementContent ElementView::pasteWithOffset(const QDomDocument &xml_document) { // on applique le decalage qui convient final_pasted_content_bounding_rect = applyMovement( pasted_content_bounding_rect, - QETElementEditor::pasteMovement(), QETElementEditor::pasteOffset() ); } @@ -483,21 +482,11 @@ void ElementView::drawBackground(QPainter *p, const QRectF &r) { @param movement Orientation du decalage a appliquer @param offset Decalage a appliquer */ -QRectF ElementView::applyMovement(const QRectF &start, const QET::OrientedMovement &movement, const QPointF &offset) { - // calcule le decalage a appliquer a partir de l'offset indique et du mouvement +QRectF ElementView::applyMovement(const QRectF &start, const QPointF &offset) { + // calcule le decalage a appliquer a partir de l'offset QPointF final_offset; - if (movement == QET::ToNorthEast || movement == QET::ToEast || movement == QET::ToSouthEast) { - final_offset.rx() = start.width() + offset.x(); - } else if (movement == QET::ToNorthWest || movement == QET::ToWest || movement == QET::ToSouthWest) { - final_offset.rx() = -start.width() - offset.x(); - } - - if (movement == QET::ToNorthWest || movement == QET::ToNorth || movement == QET::ToNorthEast) { - final_offset.ry() = -start.height() - offset.y(); - } else if (movement == QET::ToSouthWest || movement == QET::ToSouth || movement == QET::ToSouthEast) { - final_offset.ry() = start.height() + offset.y(); - } - + final_offset.rx() = start.width() + offset.x(); + // applique le decalage ainsi calcule return(start.translated(final_offset)); } diff --git a/sources/editor/elementview.h b/sources/editor/elementview.h index a9b81e99e..e3bbe7479 100644 --- a/sources/editor/elementview.h +++ b/sources/editor/elementview.h @@ -19,6 +19,7 @@ #define ELEMENT_VIEW_H #include #include "elementscene.h" + /** This class provides a widget to render an ElementScene instance, i.e. the edition class for electrical elements. @@ -50,7 +51,7 @@ class ElementView : public QGraphicsView { virtual void drawBackground(QPainter *, const QRectF &); private: - QRectF applyMovement(const QRectF &, const QET::OrientedMovement &, const QPointF &); + QRectF applyMovement(const QRectF &, const QPointF &); public slots: void setVisualisationMode(); diff --git a/sources/editor/qetelementeditor.cpp b/sources/editor/qetelementeditor.cpp index e09e42248..04666306b 100644 --- a/sources/editor/qetelementeditor.cpp +++ b/sources/editor/qetelementeditor.cpp @@ -145,7 +145,6 @@ void QETElementEditor::setupActions() { zoom_fit = new QAction(QET::Icons::ZoomFitBest, tr("Zoom adapt\351"), this); zoom_reset = new QAction(QET::Icons::ZoomOriginal, tr("Pas de zoom"), this); edit_names = new QAction(QET::Icons::Names, tr("\311diter les noms"), this); - edit_ori = new QAction(QET::Icons::Orientations, tr("\311diter les orientations"), this); edit_author = new QAction(QET::Icons::UserInformations, tr("\311diter les informations sur l'auteur"), this); edit_raise = new QAction(QET::Icons::Raise, tr("Rapprocher"), this); edit_lower = new QAction(QET::Icons::Lower, tr("\311loigner"), this); @@ -204,7 +203,6 @@ void QETElementEditor::setupActions() { zoom_reset -> setShortcut(QKeySequence(tr("Ctrl+0"))); edit_names -> setShortcut(QKeySequence(tr("Ctrl+E"))); - edit_ori -> setShortcut(QKeySequence(tr("Ctrl+T"))); edit_author -> setShortcut(tr("Ctrl+Y")); edit_raise -> setShortcut(QKeySequence(tr("Ctrl+Shift+Up"))); @@ -235,7 +233,6 @@ void QETElementEditor::setupActions() { connect(zoom_reset, SIGNAL(triggered()), ce_view, SLOT(zoomReset())); connect(edit_delete, SIGNAL(triggered()), ce_scene, SLOT(slot_delete())); connect(edit_names, SIGNAL(triggered()), ce_scene, SLOT(slot_editNames())); - connect(edit_ori, SIGNAL(triggered()), ce_scene, SLOT(slot_editOrientations())); connect(edit_author, SIGNAL(triggered()), ce_scene, SLOT(slot_editAuthorInformations())); connect(edit_forward, SIGNAL(triggered()), ce_scene, SLOT(slot_bringForward())); connect(edit_raise, SIGNAL(triggered()), ce_scene, SLOT(slot_raise())); @@ -318,7 +315,6 @@ void QETElementEditor::setupActions() { view_toolbar -> addAction(zoom_fit); view_toolbar -> addAction(zoom_reset); element_toolbar -> addAction(edit_names); - element_toolbar -> addAction(edit_ori); depth_toolbar -> addAction(edit_forward); depth_toolbar -> addAction(edit_raise); depth_toolbar -> addAction(edit_lower); @@ -393,7 +389,6 @@ void QETElementEditor::setupMenus() { edit_menu -> addAction(edit_delete); edit_menu -> addSeparator(); edit_menu -> addAction(edit_names); - edit_menu -> addAction(edit_ori); edit_menu -> addAction(edit_author); edit_menu -> addSeparator(); edit_menu -> addAction(edit_forward); @@ -1238,14 +1233,6 @@ QPointF QETElementEditor::pasteOffset() { return(paste_offset); } -/** - @return Le type de mouvement a effectuer lors d'un copier/coller avec - decalage. -*/ -QET::OrientedMovement QETElementEditor::pasteMovement() { - return(QET::ToEast); -} - /** Demande a l'utilisateur d'ouvrir un fichier sense etre un element. @param parent QWidget parent du dialogue d'ouverture de fichier diff --git a/sources/editor/qetelementeditor.h b/sources/editor/qetelementeditor.h index 7ba676df9..787148b7f 100644 --- a/sources/editor/qetelementeditor.h +++ b/sources/editor/qetelementeditor.h @@ -71,7 +71,7 @@ class QETElementEditor : public QETMainWindow { QAction *selectall, *deselectall, *inv_select; QAction *cut, *copy, *paste, *paste_in_area, *paste_from_file, *paste_from_elmt; QAction *undo, *redo; - QAction *edit_delete, *edit_size_hs, *edit_names, *edit_ori, *edit_author; + QAction *edit_delete, *edit_size_hs, *edit_names, *edit_author; QAction *edit_raise, *edit_lower, *edit_backward, *edit_forward; /// actions for the "display" menu QAction *zoom_in, *zoom_out, *zoom_fit, *zoom_reset; @@ -93,7 +93,6 @@ class QETElementEditor : public QETMainWindow { // methods public: void setNames(const NamesList &); - void setOrientations(const OrientationSet &orientation_set); OrientationSet orientations() const; void setLocation(const ElementsLocation &); ElementsLocation location() const; @@ -111,7 +110,6 @@ class QETElementEditor : public QETMainWindow { void readSettings(); void writeSettings(); static QPointF pasteOffset(); - static QET::OrientedMovement pasteMovement(); static QString getOpenElementFileName(QWidget * = 0, const QString & = QString()); void contextMenu(QContextMenuEvent *event); @@ -160,20 +158,6 @@ inline void QETElementEditor::setNames(const NamesList &nameslist) { ce_scene -> setNames(nameslist); } -/** - @param orientation_set the new set of orientations for the currently edited element -*/ -inline void QETElementEditor::setOrientations(const OrientationSet &orientation_set) { - ce_scene -> setOrientations(orientation_set); -} - -/** - @param the set of orientations for the currently edited element -*/ -inline OrientationSet QETElementEditor::orientations() const { - return(ce_scene -> orientations()); -} - /** @return the location of the currently edited element */ diff --git a/sources/elementscategorieslist.cpp b/sources/elementscategorieslist.cpp index 0157474a1..ef8baad0e 100644 --- a/sources/elementscategorieslist.cpp +++ b/sources/elementscategorieslist.cpp @@ -17,7 +17,7 @@ */ #include "elementscategorieslist.h" #include "qetapp.h" -#include "customelement.h" +#include "qetgraphicsitem/customelement.h" #include "elementscollection.h" #include "elementscategory.h" #include "elementdefinition.h" diff --git a/sources/elementscollectioncache.cpp b/sources/elementscollectioncache.cpp index 7302f39d7..fb169c317 100644 --- a/sources/elementscollectioncache.cpp +++ b/sources/elementscollectioncache.cpp @@ -2,7 +2,7 @@ #include "elementscollection.h" #include "elementscategory.h" #include "elementdefinition.h" -#include "customelement.h" +#include "qetgraphicsitem/customelement.h" /** Construct a cache for elements collections. diff --git a/sources/elementsmover.cpp b/sources/elementsmover.cpp index c5e1b1e64..504435d96 100644 --- a/sources/elementsmover.cpp +++ b/sources/elementsmover.cpp @@ -16,13 +16,13 @@ along with QElectroTech. If not, see . */ #include "elementsmover.h" -#include "conductor.h" -#include "conductortextitem.h" +#include "qetgraphicsitem/conductor.h" +#include "qetgraphicsitem/conductortextitem.h" #include "diagram.h" #include "diagramcommands.h" -#include "element.h" -#include "independenttextitem.h" -#include "diagramimageitem.h" +#include "qetgraphicsitem/element.h" +#include "qetgraphicsitem/independenttextitem.h" +#include "qetgraphicsitem/diagramimageitem.h" /** Constructeur diff --git a/sources/elementspanel.cpp b/sources/elementspanel.cpp index 69023f665..516234505 100644 --- a/sources/elementspanel.cpp +++ b/sources/elementspanel.cpp @@ -21,7 +21,7 @@ #include "diagram.h" #include "elementscategory.h" #include "elementscollectioncache.h" -#include "customelement.h" +#include "qetgraphicsitem/customelement.h" #include "fileelementscollection.h" #include "fileelementdefinition.h" #include "qeticons.h" diff --git a/sources/elementtextsmover.cpp b/sources/elementtextsmover.cpp index bed7f4a4c..7dee51161 100644 --- a/sources/elementtextsmover.cpp +++ b/sources/elementtextsmover.cpp @@ -16,12 +16,12 @@ along with QElectroTech. If not, see . */ #include "elementtextsmover.h" -#include "conductor.h" -#include "elementtextitem.h" +#include "qetgraphicsitem/conductor.h" +#include "qetgraphicsitem/elementtextitem.h" #include "diagram.h" #include "diagramcommands.h" -#include "element.h" -#include "independenttextitem.h" +#include "qetgraphicsitem/element.h" +#include "qetgraphicsitem/independenttextitem.h" /** Constructeur diff --git a/sources/newelementwizard.cpp b/sources/newelementwizard.cpp index b8acfef5a..a7e37efa5 100644 --- a/sources/newelementwizard.cpp +++ b/sources/newelementwizard.cpp @@ -20,8 +20,7 @@ #include "elementscategorieswidget.h" #include "elementscategorieslist.h" #include "nameslistwidget.h" -#include "orientationsetwidget.h" -#include "element.h" +#include "qetgraphicsitem/element.h" #include "qetelementeditor.h" #include "qet.h" #include "qetapp.h" @@ -52,7 +51,6 @@ NewElementWizard::NewElementWizard(QWidget *parent, Qt::WindowFlags f) : addPage(buildStep1()); addPage(buildStep2()); addPage(buildStep3()); - addPage(buildStep4()); setFixedSize(705, 325); } @@ -96,7 +94,7 @@ bool NewElementWizard::preselectCategory(ElementsCategory *category) { QWizardPage *NewElementWizard::buildStep1() { QWizardPage *page = new QWizardPage(); page -> setProperty("WizardState", Category); - page -> setTitle(tr("\311tape 1/4 : Cat\351gorie parente", "wizard page title")); + page -> setTitle(tr("\311tape 1/3 : Cat\351gorie parente", "wizard page title")); page -> setSubTitle(tr("S\351lectionnez une cat\351gorie dans laquelle enregistrer le nouvel \351l\351ment.", "wizard page subtitle")); QVBoxLayout *layout = new QVBoxLayout(); @@ -113,7 +111,7 @@ QWizardPage *NewElementWizard::buildStep1() { QWizardPage *NewElementWizard::buildStep2() { QWizardPage *page = new QWizardPage(); page -> setProperty("WizardState", Filename); - page -> setTitle(tr("\311tape 2/4 : Nom du fichier", "wizard page title")); + page -> setTitle(tr("\311tape 2/3 : Nom du fichier", "wizard page title")); page -> setSubTitle(tr("Indiquez le nom du fichier dans lequel enregistrer le nouvel \351l\351ment.", "wizard page subtitle")); QVBoxLayout *layout = new QVBoxLayout(); @@ -136,7 +134,7 @@ QWizardPage *NewElementWizard::buildStep2() { QWizardPage *NewElementWizard::buildStep3() { QWizardPage *page = new QWizardPage(); page -> setProperty("WizardState", Names); - page -> setTitle(tr("\311tape 3/4 : Noms de l'\351l\351ment", "wizard page title")); + page -> setTitle(tr("\311tape 3/3 : Noms de l'\351l\351ment", "wizard page title")); page -> setSubTitle(tr("Indiquez le ou les noms de l'\351l\351ment.", "wizard page subtitle")); QVBoxLayout *layout = new QVBoxLayout(); @@ -150,33 +148,17 @@ QWizardPage *NewElementWizard::buildStep3() { return(page); } -/** - Met en place l'etape 4 : orientations possibles pour le nouvel element -*/ -QWizardPage *NewElementWizard::buildStep4() { - QWizardPage *page = new QWizardPage(); - page -> setProperty("WizardState", Orientations); - page -> setTitle(tr("\311tape 4/4 : Orientations", "wizard page title")); - page -> setSubTitle(tr("Indiquez les orientations possibles pour le nouvel \351l\351ment.", "wizard page subtitle")); - QVBoxLayout *layout = new QVBoxLayout(); - - orientation_set = new OrientationSetWidget(); - layout -> addWidget(orientation_set); - layout -> addSpacing(25); - - page -> setLayout(layout); - return(page); -} - /// @return true si l'etape en cours est validee, false sinon bool NewElementWizard::validateCurrentPage() { WizardState wizard_state = static_cast(currentPage() -> property("WizardState").toInt()); if (wizard_state == Category) return(validStep1()); else if (wizard_state == Filename) return(validStep2()); - else if (wizard_state == Names) return(element_names -> checkOneName()); // il doit y avoir au moins un nom - else if (wizard_state == Orientations) { - createNewElement(); - return(true); + else if (wizard_state == Names) { + // must have one name minimum + if (element_names -> checkOneName()) + createNewElement(); + return true; + } else return(true); } @@ -259,7 +241,6 @@ bool NewElementWizard::validStep2() { void NewElementWizard::createNewElement() { QETElementEditor *edit_new_element = new QETElementEditor(parentWidget()); edit_new_element -> setNames(element_names -> names()); - edit_new_element -> setOrientations(orientation_set -> orientationSet()); ElementsLocation new_element_location = chosen_category -> location(); new_element_location.addToPath(chosen_file); diff --git a/sources/newelementwizard.h b/sources/newelementwizard.h index a63600b14..5b42df5c0 100644 --- a/sources/newelementwizard.h +++ b/sources/newelementwizard.h @@ -21,7 +21,6 @@ class ElementsCategoriesWidget; class ElementsCategory; class NamesListWidget; -class OrientationSetWidget; class QFileNameEdit; /** This class provides a wizard dialog enabling users to to specify the basic @@ -31,9 +30,6 @@ class QFileNameEdit; - the category the element should be saved to - the filename the element should be saved to - localized names - - dimensions - - hotspot position - - allowed and default orientations */ class NewElementWizard : public QWizard { Q_OBJECT @@ -53,11 +49,10 @@ class NewElementWizard : public QWizard { // attributes private: - enum WizardState { Category, Filename, Names, Dimensions, Orientations }; + enum WizardState { Category, Filename, Names }; ElementsCategoriesWidget *categories_list; QFileNameEdit *qle_filename; NamesListWidget *element_names; - OrientationSetWidget *orientation_set; WizardState current_state; QString chosen_file; ElementsCategory *chosen_category; @@ -67,7 +62,6 @@ class NewElementWizard : public QWizard { QWizardPage *buildStep1(); QWizardPage *buildStep2(); QWizardPage *buildStep3(); - QWizardPage *buildStep4(); bool validStep1(); bool validStep2(); bool validateCurrentPage(); diff --git a/sources/nomenclature.h b/sources/nomenclature.h index dcc9931d9..685e41cb6 100644 --- a/sources/nomenclature.h +++ b/sources/nomenclature.h @@ -22,9 +22,9 @@ #include "qetproject.h" #include "diagram.h" -#include "element.h" +#include "qetgraphicsitem/element.h" #include "diagramcontent.h" -#include "customelement.h" +#include "qetgraphicsitem/customelement.h" class QETProject; class Diagram; diff --git a/sources/orientationsetwidget.cpp b/sources/orientationsetwidget.cpp deleted file mode 100644 index f82b175bc..000000000 --- a/sources/orientationsetwidget.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* - Copyright 2006-2012 Xavier Guerrin - This file is part of QElectroTech. - - QElectroTech is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - QElectroTech is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with QElectroTech. If not, see . -*/ -#include "orientationsetwidget.h" -#include "qeticons.h" - -/** - Constructeur - @param parent QWidget parent -*/ -OrientationSetWidget::OrientationSetWidget(QWidget *parent) : QWidget(parent) { - - default_radios = new QButtonGroup(this); - - #define MK_COMBO_BOX(a) a##_orientation = new QComboBox();\ - a##_orientation -> addItem(QET::Icons::Allowed, tr("Possible"), "y");\ - a##_orientation -> addItem(QET::Icons::Forbidden,tr("Impossible"), "n");\ - connect(a##_orientation, SIGNAL(activated(int)), this, SLOT(updateOrientationSet()));\ - a##_default = new QRadioButton(); - - // 4 combo box, 4 boutons radios - MK_COMBO_BOX(north) - MK_COMBO_BOX(east) - MK_COMBO_BOX(south) - MK_COMBO_BOX(west) - - #undef MK_COMBO_BOX - - default_radios -> addButton(north_default, QET::North); - default_radios -> addButton(east_default, QET::East); - default_radios -> addButton(south_default, QET::South); - default_radios -> addButton(west_default, QET::West); - connect(default_radios, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(slot_defaultChanged(QAbstractButton *))); - - // petites icones symbolisant les orientations - QLabel *north_pixmap = new QLabel(tr("Nord :")); - north_pixmap -> setPixmap(QET::Icons::North.pixmap(16, 16)); - QLabel *east_pixmap = new QLabel(tr("Est :")); - east_pixmap -> setPixmap(QET::Icons::East.pixmap(16, 16)); - QLabel *south_pixmap = new QLabel(tr("Sud :")); - south_pixmap -> setPixmap(QET::Icons::South.pixmap(16, 16)); - QLabel *west_pixmap = new QLabel(tr("Ouest :")); - west_pixmap -> setPixmap(QET::Icons::West.pixmap(16, 16)); - - QGridLayout *qgl = new QGridLayout(this); - qgl -> addWidget(new QLabel(tr("Par d\351faut")), 0, 3); - qgl -> addWidget(north_pixmap, 1, 0); - qgl -> addWidget(new QLabel(tr("Nord :")), 1, 1); - qgl -> addWidget(north_orientation, 1, 2); - qgl -> addWidget(north_default, 1, 3, Qt::AlignHCenter); - qgl -> addWidget(east_pixmap, 2, 0); - qgl -> addWidget(new QLabel(tr("Est :")), 2, 1); - qgl -> addWidget(east_orientation, 2, 2); - qgl -> addWidget(east_default, 2, 3, Qt::AlignHCenter); - qgl -> addWidget(south_pixmap, 3, 0); - qgl -> addWidget(new QLabel(tr("Sud :")), 3, 1); - qgl -> addWidget(south_orientation, 3, 2); - qgl -> addWidget(south_default, 3, 3, Qt::AlignHCenter); - qgl -> addWidget(west_pixmap, 4, 0); - qgl -> addWidget(new QLabel(tr("Ouest :")), 4, 1); - qgl -> addWidget(west_orientation, 4, 2); - qgl -> addWidget(west_default, 4, 3, Qt::AlignHCenter); - - // les combobox s'etendent autant que possible - qgl -> setColumnStretch(2, 1); - - // l'orientation par defaut par defaut est le Nord - north_default -> setChecked(true); - slot_defaultChanged(north_default); -} - -/** - @return l'OrientationSet -*/ -OrientationSet OrientationSetWidget::orientationSet() const { - return(ori); -} - -/** - @param os l'OrientationSet a editer -*/ -void OrientationSetWidget::setOrientationSet(const OrientationSet &os) { - ori = os; - updateForm(); -} - -/** - @return true si ce widget est en lecture seule, false sinon -*/ -bool OrientationSetWidget::isReadOnly() const { - return(!north_orientation -> isEnabled()); -} - -/** - @param ro true pour passer ce widget en lecture seule, false sinon -*/ -void OrientationSetWidget::setReadOnly(bool ro) { - north_orientation -> setDisabled(ro); - east_orientation -> setDisabled(ro); - south_orientation -> setDisabled(ro); - west_orientation -> setDisabled(ro); - north_default -> setDisabled(ro); - east_default -> setDisabled(ro); - south_default -> setDisabled(ro); - west_default -> setDisabled(ro); -} - -/** - Slot gerant le changement d'orientation par defaut. - L'orientation concernee affiche alors "Possible" et ce statut devient - impossible a modifier. -*/ -void OrientationSetWidget::slot_defaultChanged(QAbstractButton *button) { - if (button == north_default) north_orientation -> setCurrentIndex(0); - else if (button == east_default) east_orientation -> setCurrentIndex(0); - else if (button == south_default) south_orientation -> setCurrentIndex(0); - else if (button == west_default) west_orientation -> setCurrentIndex(0); - - north_orientation -> setEnabled(button != north_default); - east_orientation -> setEnabled(button != east_default); - south_orientation -> setEnabled(button != south_default); - west_orientation -> setEnabled(button != west_default); - - updateOrientationSet(); -} - -/** - Met a jour les donnees de la classe a partir du dialogue -*/ -void OrientationSetWidget::updateOrientationSet() { - ori.setNorth(!north_orientation -> currentIndex()); - ori.setEast (!east_orientation -> currentIndex()); - ori.setSouth(!south_orientation -> currentIndex()); - ori.setWest (!west_orientation -> currentIndex()); - ori.setDefaultOrientation(static_cast(default_radios -> checkedId())); -} - -/** - Met a jour le dialogue a partir des donnees de la classe -*/ -void OrientationSetWidget::updateForm() { - north_orientation -> setCurrentIndex(ori.north() ? 0 : 1); - east_orientation -> setCurrentIndex(ori.east() ? 0 : 1); - south_orientation -> setCurrentIndex(ori.south() ? 0 : 1); - west_orientation -> setCurrentIndex(ori.west() ? 0 : 1); - QRadioButton *default_button = NULL; - switch(ori.defaultOrientation()) { - case QET::North: default_button = north_default; break; - case QET::East : default_button = east_default ; break; - case QET::South: default_button = south_default; break; - case QET::West : default_button = west_default ; break; - } - if (default_button != NULL) { - default_button -> setChecked(true); - slot_defaultChanged(default_button); - } -} diff --git a/sources/orientationsetwidget.h b/sources/orientationsetwidget.h deleted file mode 100644 index be77a0eb3..000000000 --- a/sources/orientationsetwidget.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - Copyright 2006-2012 Xavier Guerrin - This file is part of QElectroTech. - - QElectroTech is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - QElectroTech is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with QElectroTech. If not, see . -*/ -#ifndef ORIENTATION_SET_WIDGET_H -#define ORIENTATION_SET_WIDGET_H -#include -#include "orientationset.h" -/** - Widget to edit an OrientationSet. - @see OrientationSet -*/ -class OrientationSetWidget : public QWidget { - Q_OBJECT - // constructors, destructor - public: - OrientationSetWidget(QWidget * = 0); - virtual ~OrientationSetWidget() {}; - - private: - OrientationSetWidget(const OrientationSetWidget &); - - // attributes - private: - OrientationSet ori; - QComboBox *north_orientation; - QComboBox *east_orientation; - QComboBox *south_orientation; - QComboBox *west_orientation; - QRadioButton *north_default; - QRadioButton *east_default; - QRadioButton *south_default; - QRadioButton *west_default; - QButtonGroup *default_radios; - - // methods - public: - OrientationSet orientationSet() const; - void setOrientationSet(const OrientationSet &); - bool isReadOnly() const; - void setReadOnly(bool); - - private: - void updateForm(); - - public slots: - void slot_defaultChanged(QAbstractButton *); - void updateOrientationSet(); -}; -#endif diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 1d08580e2..f9f883c2b 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -20,10 +20,10 @@ #include "diagramcontent.h" #include "diagramview.h" #include "diagram.h" -#include "element.h" +#include "qetgraphicsitem/element.h" #include "elementspanelwidget.h" #include "conductorpropertieswidget.h" -#include "customelement.h" +#include "qetgraphicsitem/customelement.h" #include "qetproject.h" #include "projectview.h" #include "recentfiles.h" diff --git a/sources/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp similarity index 100% rename from sources/conductor.cpp rename to sources/qetgraphicsitem/conductor.cpp diff --git a/sources/conductor.h b/sources/qetgraphicsitem/conductor.h similarity index 100% rename from sources/conductor.h rename to sources/qetgraphicsitem/conductor.h diff --git a/sources/conductortextitem.cpp b/sources/qetgraphicsitem/conductortextitem.cpp similarity index 100% rename from sources/conductortextitem.cpp rename to sources/qetgraphicsitem/conductortextitem.cpp diff --git a/sources/conductortextitem.h b/sources/qetgraphicsitem/conductortextitem.h similarity index 100% rename from sources/conductortextitem.h rename to sources/qetgraphicsitem/conductortextitem.h diff --git a/sources/customelement.cpp b/sources/qetgraphicsitem/customelement.cpp similarity index 99% rename from sources/customelement.cpp rename to sources/qetgraphicsitem/customelement.cpp index bb4b27185..4b3e97968 100644 --- a/sources/customelement.cpp +++ b/sources/qetgraphicsitem/customelement.cpp @@ -702,7 +702,9 @@ void CustomElement::setQPainterAntiAliasing(QPainter &qp, bool aa) { @return true si l'attribut "orientation" est valide, false sinon */ bool CustomElement::validOrientationAttribute(const QDomElement &e) { - return(ori.fromString(e.attribute("orientation"))); + int ori = e.attribute("orientation").toInt(); + if(ori >= 0 && ori <=3) return true; + return false; } /** diff --git a/sources/customelement.h b/sources/qetgraphicsitem/customelement.h similarity index 100% rename from sources/customelement.h rename to sources/qetgraphicsitem/customelement.h diff --git a/sources/qetgraphicsitem/diagramimageitem.cpp b/sources/qetgraphicsitem/diagramimageitem.cpp new file mode 100644 index 000000000..474eed176 --- /dev/null +++ b/sources/qetgraphicsitem/diagramimageitem.cpp @@ -0,0 +1,222 @@ +/* + Copyright 2006-2013 QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "diagramimageitem.h" +#include "diagramcommands.h" + +/** + * @brief DiagramImageItem::DiagramImageItem + * Constructor without pixmap + * @param parent_item the parent graphics item + */ +DiagramImageItem::DiagramImageItem(QetGraphicsItem *parent_item): + QetGraphicsItem(parent_item) +{ + setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable); +#if QT_VERSION >= 0x040600 + setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); +#endif +} + +/** + * @brief DiagramImageItem::DiagramImageItem + * Constructor with pixmap + * @param pixmap the pixmap to be draw + * @param parent_item the parent graphic item + */ +DiagramImageItem::DiagramImageItem(const QPixmap &pixmap, QetGraphicsItem *parent_item): + QetGraphicsItem(parent_item), + pixmap_(pixmap) +{ + setTransformOriginPoint(boundingRect().center()); + setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable); +#if QT_VERSION >= 0x040600 + setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); +#endif +} + +/** + * @brief DiagramImageItem::~DiagramImageItem + * Destructor + */ +DiagramImageItem::~DiagramImageItem() { +} + +/** + * @brief DiagramImageItem::paint + * Draw the pixmap. + * @param painter the Qpainter to use for draw the pixmap + * @param option the style option + * @param widget the QWidget where we draw the pixmap + */ +void DiagramImageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + painter -> drawPixmap(pixmap_.rect(),pixmap_); + + if (isSelected()) { + painter -> save(); + // Annulation des renderhints + painter -> setRenderHint(QPainter::Antialiasing, false); + painter -> setRenderHint(QPainter::TextAntialiasing, false); + painter -> setRenderHint(QPainter::SmoothPixmapTransform, false); + // Dessin du cadre de selection en noir a partir du boundingrect + QPen t(Qt::black); + t.setStyle(Qt::DashLine); + painter -> setPen(t); + painter -> drawRect(boundingRect()); + painter -> restore(); + } +} + +/** + * @brief DiagramImageItem::setScale + * @param scale the value of @scale must be betwen 1 and 200 + */ +void DiagramImageItem::PreviewScale(int scale) { + if (scale >= 1 && scale <= 200) { + qreal new_scale = scale; + new_scale /= 100; + setScale(new_scale); + } +} + +/** + * @brief Edit the image with .... + */ +void DiagramImageItem::editProperty() { + if (diagram() -> isReadOnly()) return; + //the range for scale image and divisor factor + int min_range = 1; + int max_range = 200; + int factor_range = 100; + + //the dialog + QDialog property_dialog; + property_dialog.setWindowTitle(tr("\311diter les propri\351t\351s d'une image", "window title")); + //the main layout + QVBoxLayout *dialog_layout = new QVBoxLayout(&property_dialog); + + //GroupBox for resizer image + QGroupBox *resize_groupe = new QGroupBox(tr("Dimension de l'image", "image size")); + dialog_layout -> addWidget(resize_groupe); + QHBoxLayout *resize_layout = new QHBoxLayout(resize_groupe); + + //slider + QSlider *slider = new QSlider(Qt::Horizontal, &property_dialog); + slider->setRange(min_range, max_range); + qreal scale_= scale(); + slider -> setValue(scale_*factor_range); + //spinbox + QSpinBox *spin_box = new QSpinBox(&property_dialog); + spin_box -> setRange(min_range, max_range); + spin_box -> setValue(scale_*factor_range); + spin_box -> setSuffix(" %"); + //synchro slider with spinbox + connect(slider, SIGNAL(valueChanged(int)), spin_box, SLOT(setValue(int))); + connect(slider, SIGNAL(valueChanged(int)), this, SLOT(PreviewScale(int))); + connect(spin_box, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int))); + //add slider and spinbox to layout + resize_layout -> addWidget(slider); + resize_layout -> addWidget(spin_box); + + //dialog button, box + QDialogButtonBox *dbb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + dialog_layout -> addWidget(dbb); + connect(dbb, SIGNAL(accepted()), &property_dialog, SLOT(accept())); + connect(dbb, SIGNAL(rejected()), &property_dialog, SLOT(reject())); + //dialog is accepted... + if (property_dialog.exec() == QDialog::Accepted) { + qreal new_scale = slider -> value(); + new_scale /= factor_range; + if (scale_ != new_scale) diagram()->undoStack().push(new ImageResizerCommand(this, scale_, new_scale)); + } + //...or not + else setScale(scale_); + return; +} + +/** + * @brief DiagramImageItem::setPixmap + * Set the new pixmap to be draw + * @param pixmap the new pixmap + */ +void DiagramImageItem::setPixmap(const QPixmap &pixmap) { + pixmap_ = pixmap; + setTransformOriginPoint(boundingRect().center()); +} + +/** + * @brief DiagramImageItem::boundingRect + * the outer bounds of the item as a rectangle, + * if no pixmap are set, return a default QRectF + * @return a QRectF represent the bounding rectangle + */ +QRectF DiagramImageItem::boundingRect() const { + if (!pixmap_.isNull()) { + return (QRectF(pixmap_.rect())); + } else { + QRectF bound; + return (bound); + } +} + +/** + Load the image from this xml element + @param e xml element that define an image +*/ +bool DiagramImageItem::fromXml(const QDomElement &e) { + if (e.tagName() != "image") return (false); + QDomNode image_node = e.firstChild(); + if (!image_node.isText()) return (false); + + //load xml image to QByteArray + QByteArray array; + array = QByteArray::fromBase64(e.text().toAscii()); + + //Set QPixmap from the @array + QPixmap pixmap; + pixmap.loadFromData(array); + setPixmap(pixmap); + + setScale(e.attribute("size").toDouble()); + applyRotation(e.attribute("rotation").toDouble()); + setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble()); + + return (true); +} + +/** + @param document Le document XML a utiliser + @return L'element XML representant l'image +*/ +QDomElement DiagramImageItem::toXml(QDomDocument &document) const { + QDomElement result = document.createElement("image"); + //write some attribute + result.setAttribute("x", QString("%1").arg(pos().x())); + result.setAttribute("y", QString("%1").arg(pos().y())); + result.setAttribute("rotation", QString("%1").arg(rotation())); + result.setAttribute("size", QString("%1").arg(scale())); + + //write the pixmap in the xml element after he was been transformed to base64 + QByteArray array; + QBuffer buffer(&array); + buffer.open(QIODevice::ReadWrite); + pixmap_.save(&buffer, "PNG"); + QDomText base64 = document.createTextNode(array.toBase64()); + result.appendChild(base64); + + return(result); +} diff --git a/sources/diagramimageitem.h b/sources/qetgraphicsitem/diagramimageitem.h similarity index 62% rename from sources/diagramimageitem.h rename to sources/qetgraphicsitem/diagramimageitem.h index 5752f7652..59de61642 100644 --- a/sources/diagramimageitem.h +++ b/sources/qetgraphicsitem/diagramimageitem.h @@ -18,18 +18,20 @@ #ifndef DIAGRAM_IMAGE_ITEM_H #define DIAGRAM_IMAGE_ITEM_H #include -#include "diagram.h" +#include "qetgraphicsitem.h" + /** This class represents a selectable, movable and editable image on a diagram. @see QGraphicsItem::GraphicsItemFlags */ -class DiagramImageItem : public QObject, public QGraphicsPixmapItem { +class DiagramImageItem : public QetGraphicsItem { Q_OBJECT + // constructors, destructor public: - DiagramImageItem(Diagram * = 0); - DiagramImageItem(const QPixmap &, Diagram * = 0); + DiagramImageItem(QetGraphicsItem * = 0); + DiagramImageItem(const QPixmap &pixmap, QetGraphicsItem * = 0); virtual ~DiagramImageItem(); // attributes @@ -44,35 +46,22 @@ class DiagramImageItem : public QObject, public QGraphicsPixmapItem { @return the QGraphicsItem type */ virtual int type() const { return Type; } - Diagram *diagram() const; virtual bool fromXml(const QDomElement &); virtual QDomElement toXml(QDomDocument &) const; - - virtual void setPos(const QPointF &); - virtual void setPos(qreal, qreal); - void setRotationAngle(const qreal &); - void rotateBy(const qreal &); - void edit(); + virtual void editProperty(); void setPixmap(const QPixmap &pixmap); + virtual QRectF boundingRect() const; protected: - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - void mousePressEvent(QGraphicsSceneMouseEvent *e); - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *); - void mouseMoveEvent(QGraphicsSceneMouseEvent *); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *); - void applyRotation(const qreal &); + virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); signals: - /// signal emitted after image was changed - void diagramImageChanged(DiagramImageItem *, const QString &, const QString &); - + private slots: void PreviewScale(int); - private: - bool first_move_; - QPointF mouse_to_origin_movement_; + protected: + QPixmap pixmap_; }; #endif diff --git a/sources/diagramtextitem.cpp b/sources/qetgraphicsitem/diagramtextitem.cpp similarity index 100% rename from sources/diagramtextitem.cpp rename to sources/qetgraphicsitem/diagramtextitem.cpp diff --git a/sources/diagramtextitem.h b/sources/qetgraphicsitem/diagramtextitem.h similarity index 100% rename from sources/diagramtextitem.h rename to sources/qetgraphicsitem/diagramtextitem.h diff --git a/sources/element.cpp b/sources/qetgraphicsitem/element.cpp similarity index 76% rename from sources/element.cpp rename to sources/qetgraphicsitem/element.cpp index 90fd9f58c..eedcefbfe 100644 --- a/sources/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -27,11 +27,9 @@ Constructeur pour un element sans scene ni parent */ Element::Element(QGraphicsItem *parent, Diagram *scene) : - QObject(), - QGraphicsItem(parent, scene), + QetGraphicsItem(parent), internal_connections_(false), - must_highlight_(false), - first_move_(true) + must_highlight_(false) { setZValue(10); } @@ -72,9 +70,7 @@ void Element::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, Diagram *dia = diagram(); if (dia && options -> levelOfDetail == 1.0 && widget) { // calcule la rotation qu'a subi l'element - qreal applied_rotation = 90.0 * (ori.current() - ori.defaultOrientation()); - while (applied_rotation < 360.0) applied_rotation += 360.0; - while (applied_rotation > 360.0) applied_rotation -= 360.0; + qreal applied_rotation = 90.0 * orientation(); if (applied_rotation == 90.0) painter -> translate(1.0, -1.0); else if (applied_rotation == 180.0) painter -> translate(-1.0, -1.0); else if (applied_rotation == 270.0) painter -> translate(-1.0, 1.0); @@ -169,25 +165,38 @@ QPixmap Element::pixmap() { } /** - Permet de specifier l'orientation de l'element - @param o la nouvelle orientation de l'objet - @return true si l'orientation a pu etre appliquee, false sinon -*/ -bool Element::setOrientation(QET::Orientation o) { - // verifie que l'orientation demandee est acceptee - if (!ori.accept(o)) return(false); - prepareGeometryChange(); - // rotation en consequence et rafraichissement de l'element graphique - qreal rotation_value = 90.0 * (o - ori.current()); - rotate(rotation_value); - ori.setCurrent(o); - update(); + * @brief Element::rotateBy + * this methode is redefined for handle child item + * @param angle + */ +void Element::rotateBy(const qreal &angle) { + qreal applied_angle = QET::correctAngle(angle); + applyRotation(applied_angle + rotation()); + + //update the path of conductor foreach(QGraphicsItem *qgi, childItems()) { if (Terminal *p = qgraphicsitem_cast(qgi)) { p -> updateConductor(); } } - return(true); + + // repositionne les textes de l'element qui ne comportent pas l'option "FollowParentRotations" + foreach(ElementTextItem *eti, texts()) { + if (!eti -> followParentRotations()) { + // on souhaite pivoter le champ de texte par rapport a son centre + QPointF eti_center = eti -> boundingRect().center(); + // pour ce faire, on repere la position de son centre par rapport a son parent + QPointF parent_eti_center_before = eti -> mapToParent(eti_center); + // on applique ensuite une simple rotation contraire, qui sera donc appliquee sur le milieu du cote gauche du champ de texte + eti -> rotateBy(-applied_angle); + // on regarde ensuite la nouvelle position du centre du champ de texte par rapport a son parent + QPointF parent_eti_center_after = eti -> mapToParent(eti_center); + // on determine la translation a appliquer + QPointF eti_translation = parent_eti_center_before - parent_eti_center_after; + // on applique cette translation + eti -> setPos(eti -> pos() + eti_translation); + } + } } /*** Methodes protegees ***/ @@ -276,95 +285,6 @@ void Element::updatePixmap() { paint(&p, 0); } -/** - Change la position de l'element en veillant a ce que l'element - reste sur la grille du Diagram auquel il appartient. - @param p Nouvelles coordonnees de l'element -*/ -void Element::setPos(const QPointF &p) { - if (p == pos()) return; - // pas la peine de positionner sur la grille si l'element n'est pas sur un Diagram - if (scene()) { - // arrondit l'abscisse a 10 px pres - int p_x = qRound(p.x() / (Diagram::xGrid * 1.0)) * Diagram::xGrid; - // arrondit l'ordonnee a 10 px pres - int p_y = qRound(p.y() / (Diagram::yGrid * 1.0)) * Diagram::yGrid; - QGraphicsItem::setPos(p_x, p_y); - } else QGraphicsItem::setPos(p); -} - -/** - Change la position de l'element en veillant a ce que l'element - reste sur la grille du Diagram auquel il appartient. - @param x Nouvelle abscisse de l'element - @param y Nouvelle ordonnee de l'element -*/ -void Element::setPos(qreal x, qreal y) { - setPos(QPointF(x, y)); -} - -/** - Gere le clic sur l'element - @param e Objet decrivant l'evenement souris -*/ -void Element::mousePressEvent(QGraphicsSceneMouseEvent *e) { - first_move_ = true; - if (e -> modifiers() & Qt::ControlModifier) { - setSelected(!isSelected()); - } - QGraphicsItem::mousePressEvent(e); -} - -/** - Gere les mouvements de souris lies a l'element - @param e Objet decrivant l'evenement souris -*/ -void Element::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { - if (isSelected() && e -> buttons() & Qt::LeftButton) { - // l'element est en train d'etre deplace - Diagram *diagram_ptr = diagram(); - if (diagram_ptr) { - if (first_move_) { - // il s'agit du premier mouvement du deplacement, on le signale - // au schema parent - diagram_ptr -> beginMoveElements(this); - } - } - - // on applique le mouvement impose par la souris - QPointF old_pos = pos(); - setPos(mapToParent(e -> pos()) - matrix().map(e -> buttonDownPos(Qt::LeftButton))); - - // on calcule le mouvement reellement applique par setPos() - QPointF effective_movement = pos() - old_pos; - - if (diagram_ptr) { - // on signale le mouvement ainsi applique au schema parent, qui - // l'appliquera aux autres items selectionnes selon son bon vouloir - diagram_ptr -> continueMoveElements(effective_movement); - } - } else e -> ignore(); - - if (first_move_) { - first_move_ = false; - } -} - -/** - Gere le relachement de souris - Cette methode a ete reimplementee pour tenir a jour la liste des elements - et conducteurs a deplacer au niveau du schema. -*/ -void Element::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { - if (Diagram *diagram_ptr = diagram()) { - diagram_ptr -> endMoveElements(); - } - - if (!(e -> modifiers() & Qt::ControlModifier)) { - QGraphicsItem::mouseReleaseEvent(e); - } -} - /** Permet de savoir si un element XML (QDomElement) represente bien un element @param e Le QDomElement a valide @@ -462,11 +382,11 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool // orientation bool conv_ok; int read_ori = e.attribute("orientation").toInt(&conv_ok); - if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = ori.defaultOrientation(); + if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = 0; if (handle_inputs_rotation) { - RotateElementsCommand::rotateElement(this, (QET::Orientation)read_ori); + rotateBy(90*read_ori); } else { - setOrientation((QET::Orientation)read_ori); + applyRotation(90*read_ori); } return(true); } @@ -488,7 +408,7 @@ QDomElement Element::toXml(QDomDocument &document, QHash &table // position, selection et orientation element.setAttribute("x", QString("%1").arg(pos().x())); element.setAttribute("y", QString("%1").arg(pos().y())); - element.setAttribute("orientation", QString("%1").arg(ori.current())); + element.setAttribute("orientation", QString("%1").arg(orientation())); /* recupere le premier id a utiliser pour les bornes de cet element */ int id_terminal = 0; @@ -522,8 +442,3 @@ QDomElement Element::toXml(QDomDocument &document, QHash &table return(element); } - -/// @return le Diagram auquel cet element appartient, ou 0 si cet element est independant -Diagram *Element::diagram() const { - return(qobject_cast(scene())); -} diff --git a/sources/element.h b/sources/qetgraphicsitem/element.h similarity index 84% rename from sources/element.h rename to sources/qetgraphicsitem/element.h index 66d1b0c52..9a40917ae 100644 --- a/sources/element.h +++ b/sources/qetgraphicsitem/element.h @@ -19,16 +19,15 @@ #define ELEMENT_H #include #include "terminal.h" -#include "orientationset.h" +#include "qetgraphicsitem.h" class Diagram; class ElementTextItem; /** This is the base class for electrical elements. */ -class Element : public QObject, public QGraphicsItem { +class Element : public QetGraphicsItem { Q_OBJECT - Q_INTERFACES(QGraphicsItem) // constructors, destructor public: @@ -43,14 +42,6 @@ class Element : public QObject, public QGraphicsItem { enum { Type = UserType + 1000 }; protected: - /** - Hold orientations for the element : - * allowed orientations - * current orientation - * default orientation - @see OrientationSet - */ - OrientationSet ori; private: QSize dimensions; @@ -87,7 +78,6 @@ class Element : public QObject, public QGraphicsItem { virtual QString typeId() const = 0; /// @return the human name for this element virtual QString name() const = 0; - Diagram *diagram() const; virtual bool isHighlighted() const; virtual void setHighlighted(bool); @@ -103,15 +93,12 @@ class Element : public QObject, public QGraphicsItem { // selection-related methods void select(); - void deselect(); - - // position-related methods - void setPos(const QPointF &); - void setPos(qreal, qreal); + void deselect(); // methods related to internal connections bool internalConnections(); void setInternalConnections(bool); + virtual void rotateBy(const qreal &); // methods related to XML import/export static bool valideXml(QDomElement &); @@ -119,19 +106,14 @@ class Element : public QObject, public QGraphicsItem { virtual QDomElement toXml(QDomDocument &, QHash &) const; // orientation-related methods - bool setOrientation(QET::Orientation o); - const OrientationSet &orientation() const; + int orientation() const; protected: void drawAxes(QPainter *, const QStyleOptionGraphicsItem *); - void mousePressEvent(QGraphicsSceneMouseEvent *); - void mouseMoveEvent(QGraphicsSceneMouseEvent *); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *); private: bool internal_connections_; bool must_highlight_; - bool first_move_; void drawSelection(QPainter *, const QStyleOptionGraphicsItem *); void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *); void updatePixmap(); @@ -157,10 +139,14 @@ inline void Element::setInternalConnections(bool ic) { /** Indicate the current orientation of this element + O = 0° + 1 = 90° + 2 = 180° + 3 = 270° @return the current orientation of this element */ -inline const OrientationSet & Element::orientation() const { - return(ori); +inline int Element::orientation() const { + return(QET::correctAngle(rotation())/90); } #endif diff --git a/sources/elementtextitem.cpp b/sources/qetgraphicsitem/elementtextitem.cpp similarity index 100% rename from sources/elementtextitem.cpp rename to sources/qetgraphicsitem/elementtextitem.cpp diff --git a/sources/elementtextitem.h b/sources/qetgraphicsitem/elementtextitem.h similarity index 100% rename from sources/elementtextitem.h rename to sources/qetgraphicsitem/elementtextitem.h diff --git a/sources/fixedelement.cpp b/sources/qetgraphicsitem/fixedelement.cpp similarity index 100% rename from sources/fixedelement.cpp rename to sources/qetgraphicsitem/fixedelement.cpp diff --git a/sources/fixedelement.h b/sources/qetgraphicsitem/fixedelement.h similarity index 100% rename from sources/fixedelement.h rename to sources/qetgraphicsitem/fixedelement.h diff --git a/sources/ghostelement.cpp b/sources/qetgraphicsitem/ghostelement.cpp similarity index 96% rename from sources/ghostelement.cpp rename to sources/qetgraphicsitem/ghostelement.cpp index 7ead6f030..791593a63 100644 --- a/sources/ghostelement.cpp +++ b/sources/qetgraphicsitem/ghostelement.cpp @@ -86,11 +86,11 @@ bool GhostElement::fromXml(QDomElement &e, QHash &table_id_adr, // orientation bool conv_ok; int read_ori = e.attribute("orientation").toInt(&conv_ok); - if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = ori.defaultOrientation(); + if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = 0; if (handle_inputs_rotation) { - RotateElementsCommand::rotateElement(this, (QET::Orientation)read_ori); + rotateBy(90*read_ori); } else { - setOrientation((QET::Orientation)read_ori); + applyRotation(90*read_ori); } return(true); } diff --git a/sources/ghostelement.h b/sources/qetgraphicsitem/ghostelement.h similarity index 100% rename from sources/ghostelement.h rename to sources/qetgraphicsitem/ghostelement.h diff --git a/sources/independenttextitem.cpp b/sources/qetgraphicsitem/independenttextitem.cpp similarity index 100% rename from sources/independenttextitem.cpp rename to sources/qetgraphicsitem/independenttextitem.cpp diff --git a/sources/independenttextitem.h b/sources/qetgraphicsitem/independenttextitem.h similarity index 100% rename from sources/independenttextitem.h rename to sources/qetgraphicsitem/independenttextitem.h diff --git a/sources/qetgraphicsitem/qetgraphicsitem.cpp b/sources/qetgraphicsitem/qetgraphicsitem.cpp new file mode 100644 index 000000000..e1d9804c7 --- /dev/null +++ b/sources/qetgraphicsitem/qetgraphicsitem.cpp @@ -0,0 +1,155 @@ +/* + Copyright 2006-2013 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "qetgraphicsitem.h" + +/** + * @brief QetGraphicsItem::QetGraphicsItem Default constructor + * @param uuid, uuid of the item + * @param diagram, diagram aka QGraphicsScene of the item + * @param parent, Parent Item + */ +QetGraphicsItem::QetGraphicsItem(QGraphicsItem *parent): + QGraphicsObject(parent), + first_move_(true) +{ +} + +QetGraphicsItem::~QetGraphicsItem() +{} + +void QetGraphicsItem::editProperty(){} + +/** + * @brief QetGraphicsItem::diagram + *return the diagram of this item + */ +Diagram* QetGraphicsItem::diagram() const{ + return(qobject_cast(scene())); +} + +/** + * @brief QetGraphicsItem::setPos + *set the position of the item to p + * @param p the new position of item + */ +void QetGraphicsItem::setPos(const QPointF &p) { + if (p == pos()) return; + if (scene()) { + // arrondit l'abscisse a 10 px pres + int p_x = qRound(p.x() / (Diagram::xGrid * 1.0)) * Diagram::xGrid; + // arrondit l'ordonnee a 10 px pres + int p_y = qRound(p.y() / (Diagram::yGrid * 1.0)) * Diagram::yGrid; + QGraphicsItem::setPos(p_x, p_y); + } else QGraphicsItem::setPos(p); +} + +/** + * @brief QetGraphicsItem::setPos + *set the position of the item + * @param x new abscisse of item + * @param y new ordonne of item + */ +void QetGraphicsItem::setPos(qreal x, qreal y) { + setPos(QPointF(x, y)); +} + +/** + Permet de tourner l'item de maniere relative. + L'angle added_rotation est ajoute a l'orientation actuelle du image. + @param added_rotation Angle a ajouter a la rotation actuelle + @see applyRotation +*/ +void QetGraphicsItem::rotateBy(const qreal &added_rotation) { + qreal applied_added_rotation = QET::correctAngle(added_rotation + rotation()); + applyRotation(applied_added_rotation); +} + +/** + Effectue la rotation de l'item en lui même + Cette methode peut toutefois etre redefinie dans des classes filles + @param angle Angle de la rotation a effectuer +*/ +void QetGraphicsItem::applyRotation(const qreal &angle) { + setRotation(QET::correctAngle(angle)); +} + +/** + * @brief QetGraphicsItem::mousePressEvent + *handle the mouse click + * @param e + */ +void QetGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *e) { + first_move_ = true; + if (e -> modifiers() & Qt::ControlModifier) { + setSelected(!isSelected()); + } + QGraphicsItem::mousePressEvent(e); +} + +/** + * @brief QetGraphicsItem::mouseDoubleClickEvent + *handle the mouse double click + * @param e + */ +void QetGraphicsItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) { + Q_UNUSED (e); + editProperty(); +} + +/** + * @brief QetGraphicsItem::mouseMoveEvent + *handle mouse movement + * @param e + */ +void QetGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { + if (isSelected() && e -> buttons() & Qt::LeftButton) { + //Item is moving + if(diagram() && first_move_) { + //It's the first movement, we signal it to parent diagram + diagram() -> beginMoveElements(this); + } + + //we apply the mouse movement + QPointF old_pos = pos(); + if (first_move_) { + mouse_to_origin_movement_ = old_pos - e -> buttonDownScenePos(Qt::LeftButton); + } + QPointF expected_pos = e -> scenePos() + mouse_to_origin_movement_; + setPos(expected_pos); // setPos() will snap the expected position to the grid + + //we calcul the real movement apply by setPos() + QPointF effective_movement = pos() - old_pos; + if (diagram()) { + //we signal the real movement apply to diagram, + //who he apply to other selected item + diagram() -> continueMoveElements(effective_movement); + } + } else e -> ignore(); + + if (first_move_) first_move_ = false; +} + +/** + * @brief QetGraphicsItem::mouseReleaseEvent + *handle mouse release click + * @param e + */ +void QetGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { + if (diagram()) diagram() -> endMoveElements(); + if (!(e -> modifiers() & Qt::ControlModifier)) QGraphicsItem::mouseReleaseEvent(e); +} diff --git a/sources/qetgraphicsitem/qetgraphicsitem.h b/sources/qetgraphicsitem/qetgraphicsitem.h new file mode 100644 index 000000000..d29213253 --- /dev/null +++ b/sources/qetgraphicsitem/qetgraphicsitem.h @@ -0,0 +1,58 @@ +/* + Copyright 2006-2013 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef QETGRAPHICSITEM_H +#define QETGRAPHICSITEM_H + +#include "diagram.h" + +class QetGraphicsItem : public QGraphicsObject { + Q_OBJECT + + public: + //constructor destructor + QetGraphicsItem(QGraphicsItem *parent = 0); + virtual ~QetGraphicsItem() = 0; + + //abstarct methode + virtual void editProperty (); + + //public methode + Diagram* diagram() const; + virtual void setPos(const QPointF &p); + virtual void setPos(qreal x, qreal y); + virtual void rotateBy(const qreal &); + virtual void applyRotation(const qreal &); + + signals: + + public slots: + + //protected method + protected: + virtual void mousePressEvent(QGraphicsSceneMouseEvent *e); + virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e); + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *e); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *e); + + protected: + bool first_move_; + QPointF mouse_to_origin_movement_; + +}; + +#endif // QETGRAPHICSITEM_H diff --git a/sources/terminal.cpp b/sources/terminal.cpp index 7ed117ef6..a64881180 100644 --- a/sources/terminal.cpp +++ b/sources/terminal.cpp @@ -17,8 +17,8 @@ */ #include "terminal.h" #include "diagram.h" -#include "element.h" -#include "conductor.h" +#include "qetgraphicsitem/element.h" +#include "qetgraphicsitem/conductor.h" #include "diagramcommands.h" #include "qetapp.h" @@ -131,13 +131,12 @@ Terminal::~Terminal() { QET::Orientation Terminal::orientation() const { if (Element *elt = qgraphicsitem_cast(parentItem())) { // orientations actuelle et par defaut de l'element - QET::Orientation ori_cur = elt -> orientation().current(); - QET::Orientation ori_def = elt -> orientation().defaultOrientation(); - if (ori_cur == ori_def) return(ori_); + int ori_cur = elt -> orientation(); + if (ori_cur == 0) return(ori_); else { // calcul l'angle de rotation implique par l'orientation de l'element parent // angle de rotation de la borne sur la scene, divise par 90 - int angle = ori_cur - ori_def + ori_; + int angle = ori_cur + ori_; while (angle >= 4) angle -= 4; return((QET::Orientation)angle); } @@ -213,9 +212,8 @@ void Terminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, QWidg qreal applied_rotation = 0.0; if (Element *elt = qgraphicsitem_cast(parentItem())) { // orientations actuelle et par defaut de l'element - QET::Orientation ori_cur = elt -> orientation().current(); - QET::Orientation ori_def = elt -> orientation().defaultOrientation(); - applied_rotation = QET::correctAngle(90.0 * (ori_cur - ori_def)); + int ori_cur = elt -> orientation(); + applied_rotation = QET::correctAngle(90.0 * ori_cur); } if (applied_rotation == 90.0) p -> translate(1.0, -1.0); else if (applied_rotation == 180.0) p -> translate(-1.0, -1.0);