diff --git a/qelectrotech.pro b/qelectrotech.pro index f433d25b3..fdd512dc1 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -73,7 +73,8 @@ INCLUDEPATH += sources \ sources/editor \ sources/editor/esevent \ sources/editor/graphicspart \ - sources/undocommand + sources/undocommand \ + sources/diagramevent # Fichiers sources @@ -83,7 +84,8 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) $$files(sources/editor/* $$files(sources/editor/esevent/*.h) \ $$files(sources/editor/graphicspart/*.h) \ $$files(sources/dvevent/*.h) \ - $$files(sources/undocommand/*.h) + $$files(sources/undocommand/*.h) \ + $$files(sources/diagramevent/*.h) SOURCES += $$files(sources/*.cpp) $$files(sources/editor/*.cpp) $$files(sources/titleblock/*.cpp) $$files(sources/richtext/*.cpp) $$files(sources/ui/*.cpp) $$files(sources/qetgraphicsitem/*.cpp) $$files(sources/factory/*.cpp) \ $$files(sources/properties/*.cpp) \ @@ -91,7 +93,8 @@ SOURCES += $$files(sources/*.cpp) $$files(sources/editor/*.cpp) $$files(sources/ $$files(sources/editor/esevent/*.cpp) \ $$files(sources/editor/graphicspart/*.cpp) \ $$files(sources/dvevent/*.cpp) \ - $$files(sources/undocommand/*.cpp) + $$files(sources/undocommand/*.cpp) \ + $$files(sources/diagramevent/*.cpp) # Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt RESOURCES += qelectrotech.qrc diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 37695fa7a..516bd2659 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -34,6 +34,7 @@ #include "qetgraphicsitem/qetshapeitem.h" #include "terminal.h" #include "elementtextsmover.h" +#include "diagrameventinterface.h" const int Diagram::xGrid = 10; const int Diagram::yGrid = 10; @@ -54,17 +55,15 @@ Diagram::Diagram(QETProject *project) : draw_grid_ (true), use_border_ (true), draw_terminals_ (true), - draw_colored_conductors_ (true) + draw_colored_conductors_ (true), + m_event_interface (nullptr) { setProject(project); qgi_manager_ = new QGIManager(this); setBackgroundBrush(Qt::white); conductor_setter_ = new QGraphicsLineItem(0); conductor_setter_ -> setZValue(1000000); -// QPen t; -// t.setColor(Qt::black); -// t.setWidthF(1.5); -// t.setStyle(Qt::DashLine); + QPen pen(Qt::NoBrush, 1.5, Qt::DashLine); pen.setColor(Qt::black); conductor_setter_ -> setPen(pen); @@ -93,6 +92,8 @@ Diagram::~Diagram() { // delete of object for manage movement delete elements_mover_; delete element_texts_mover_; + + if (m_event_interface) delete m_event_interface; // list removable items QList deletable_items; @@ -155,10 +156,115 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) { } /** - Gere les enfoncements de touches du clavier - @param e QKeyEvent decrivant l'evenement clavier -*/ -void Diagram::keyPressEvent(QKeyEvent *e) { + * @brief Diagram::mouseDoubleClickEvent + * This event is managed by diagram event interface if any. + * @param event : + */ +void Diagram::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + if (m_event_interface) { + if (m_event_interface -> mouseDoubleClickEvent(event)) { + if (m_event_interface->isFinish()) { + delete m_event_interface; m_event_interface = nullptr; + } + return; + } + } + + QGraphicsScene::mouseDoubleClickEvent(event); +} + +/** + * @brief Diagram::mousePressEvent + * This event is managed by diagram event interface if any. + * @param event + */ +void Diagram::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + if (m_event_interface) { + if (m_event_interface -> mousePressEvent(event)) { + if (m_event_interface->isFinish()) { + delete m_event_interface; m_event_interface = nullptr; + } + return; + } + } + + QGraphicsScene::mousePressEvent(event); +} + +/** + * @brief Diagram::mouseMoveEvent + * This event is managed by diagram event interface if any. + * @param event + */ +void Diagram::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + if (m_event_interface) { + if (m_event_interface -> mouseMoveEvent(event)) { + if (m_event_interface->isFinish()) { + delete m_event_interface; m_event_interface = nullptr; + } + return; + } + } + + QGraphicsScene::mouseMoveEvent(event); +} + +/** + * @brief Diagram::mouseReleaseEvent + * This event is managed by diagram event interface if any. + * @param event + */ +void Diagram::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (m_event_interface) { + if (m_event_interface -> mouseReleaseEvent(event)) { + if (m_event_interface->isFinish()) { + delete m_event_interface; m_event_interface = nullptr; + } + return; + } + } + + QGraphicsScene::mouseReleaseEvent(event); +} + +/** + * @brief Diagram::wheelEvent + * This event is managed by diagram event interface if any. + * @param event + */ +void Diagram::wheelEvent(QGraphicsSceneWheelEvent *event) +{ + if (m_event_interface) { + if (m_event_interface -> wheelEvent(event)) { + if (m_event_interface->isFinish()) { + delete m_event_interface; m_event_interface = nullptr; + } + return; + } + } +} + +/** + * @brief Diagram::keyPressEvent + * This event is managed by diagram event interface if any. + * Else move selected elements + * @param e + */ +void Diagram::keyPressEvent(QKeyEvent *e) +{ + if (m_event_interface) { + if (m_event_interface -> keyPressEvent(e)) { + if (m_event_interface->isFinish()) { + delete m_event_interface; m_event_interface = nullptr; + } + return; + } + } + bool transmit_event = true; if (!isReadOnly()) { QPointF movement; @@ -181,10 +287,22 @@ void Diagram::keyPressEvent(QKeyEvent *e) { } /** - Gere les relachements de touches du clavier - @param e QKeyEvent decrivant l'evenement clavier -*/ -void Diagram::keyReleaseEvent(QKeyEvent *e) { + * @brief Diagram::keyReleaseEvent + * This event is managed by diagram event interface if any. + * Else move selected element + * @param e + */ +void Diagram::keyReleaseEvent(QKeyEvent *e) +{ + if (m_event_interface) { + if (m_event_interface -> KeyReleaseEvent(e)) { + if (m_event_interface->isFinish()) { + delete m_event_interface; m_event_interface = nullptr; + } + return; + } + } + bool transmit_event = true; if (!isReadOnly()) { // detecte le relachement d'une touche de direction ( = deplacement d'elements) @@ -203,6 +321,24 @@ void Diagram::keyReleaseEvent(QKeyEvent *e) { } } +/** + * @brief Diagram::setEventInterface + * Set event_interface has current interface. + * Diagram become the ownership of event_interface + * If there is a previous interface, they will be delete before + * and call init() to the new interface. + * @param event_interface + */ +void Diagram::setEventInterface(DiagramEventInterface *event_interface) +{ + if (m_event_interface) + { + delete m_event_interface; + event_interface -> init(); + } + m_event_interface = event_interface; +} + /** * @brief Diagram::conductorsAutonumName * @return the name of autonum to use. diff --git a/sources/diagram.h b/sources/diagram.h index 5cfbedadf..a00de321c 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -43,6 +43,8 @@ class Terminal; class ConductorTextItem; class DiagramImageItem; class ElementTextsMover; +class DiagramEventInterface; + /** This class represents an electric diagram. It manages its various child elements, conductors and texts and handles their graphic rendering. @@ -99,14 +101,23 @@ class Diagram : public QGraphicsScene bool draw_colored_conductors_; QString m_conductors_autonum_name; + DiagramEventInterface *m_event_interface; // METHODS protected: virtual void drawBackground(QPainter *, const QRectF &); - virtual void keyPressEvent(QKeyEvent *); - virtual void keyReleaseEvent(QKeyEvent *); + + virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event); + virtual void mousePressEvent (QGraphicsSceneMouseEvent *event); + virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event); + virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event); + virtual void wheelEvent (QGraphicsSceneWheelEvent *event); + virtual void keyPressEvent (QKeyEvent *); + virtual void keyReleaseEvent (QKeyEvent *); public: + void setEventInterface (DiagramEventInterface *event_interface); + //methods related to xref properties QString defaultReportProperties () const {return project_ -> defaultReportProperties();} XRefProperties defaultXRefProperties (const QString &str) const {return project_ -> defaultXRefProperties(str);} diff --git a/sources/diagramevent/diagrameventaddelement.cpp b/sources/diagramevent/diagrameventaddelement.cpp new file mode 100644 index 000000000..534d22b3f --- /dev/null +++ b/sources/diagramevent/diagrameventaddelement.cpp @@ -0,0 +1,237 @@ +/* + Copyright 2006-2015 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 "diagrameventaddelement.h" +#include "elementscollectionitem.h" +#include "qetapp.h" +#include "integrationmoveelementshandler.h" +#include "elementfactory.h" +#include "diagram.h" +#include "element.h" +#include "diagramcommands.h" +#include "conductorautonumerotation.h" + + +/** + * @brief DiagramEventAddElement::DiagramEventAddElement + * Defaut constructor + * @param location :location of diagram + * @param diagram : diagram owner of this event + * @param pos : first pos of item ( optional, by defaut QPointF(0,0) ) + */ +DiagramEventAddElement::DiagramEventAddElement(ElementsLocation &location, Diagram *diagram, QPointF pos) : + DiagramEventInterface(diagram), + m_location(location), + m_element(nullptr) +{ + //Check if there is an element at this location + ElementsCollectionItem *item = QETApp::collectionItem(location); + if (item) + { + //location is an element, we build it, if build fail, + //m_running stay to false (by default), so this interface will be deleted at next event + if (buildElement()) + { + init(); + m_element -> setPos(pos); + m_element -> displayHelpLine(true); + m_diagram -> addItem(m_element); + m_running = true; + } + } +} + +/** + * @brief DiagramEventAddElement::~DiagramEventAddElement + * Destructor + * Enable context menu for each view of diagram + */ +DiagramEventAddElement::~DiagramEventAddElement() +{ + if (m_element) delete m_element; + foreach(QGraphicsView *view, m_diagram->views()) + view -> setContextMenuPolicy(Qt::DefaultContextMenu); +} + +/** + * @brief DiagramEventAddElement::mouseMoveEvent + * Move the element to new pos of mouse + * @param event + * @return always true + */ +bool DiagramEventAddElement::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + if (m_element) + m_element -> setPos(Diagram::snapToGrid(event->scenePos())); + + return true; +} + +/** + * @brief DiagramEventAddElement::mousePressEvent + * Do nothing, but return true for not transit the event to other thing in diagram. + * @param event + * @return always true + */ +bool DiagramEventAddElement::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_UNUSED(event); + return true; +} + +/** + * @brief DiagramEventAddElement::mouseReleaseEvent + * Right button finish this event (isRunning = false) + * Left button add an element to diagram + * @param event + * @return always true + */ +bool DiagramEventAddElement::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (m_element) + { + if (event->button() == Qt::RightButton) + { + delete m_element; + m_element = nullptr; + m_running = false; + } + else if (event->button() == Qt::LeftButton) + { + addElement(); + } + } + + return true; +} + +/** + * @brief DiagramEventAddElement::mouseDoubleClickEvent + * If mouse left double clic, finish this event (isRunning = false) + * @param event + * @return always true + */ +bool DiagramEventAddElement::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + if (m_element && (event -> button() == Qt::LeftButton)) + { + delete m_element; + m_element = nullptr; + m_running = false; + } + + return true; +} + +/** + * @brief DiagramEventAddElement::keyPressEvent + * Press space key rotate the element to 90° (return true) + * else call DiagramEventInterface::keyPressEvent(event), and return the value. + * @param event + * @return + */ +bool DiagramEventAddElement::keyPressEvent(QKeyEvent *event) +{ + if (m_element && event->key() == Qt::Key_Space) + { + m_element->rotateBy(90); + return true; + } + + return DiagramEventInterface::keyPressEvent(event); +} + +/** + * @brief DiagramEventAddElement::init + * Init this event. + */ +void DiagramEventAddElement::init() +{ + foreach(QGraphicsView *view, m_diagram->views()) + view->setContextMenuPolicy(Qt::NoContextMenu); +} + +/** + * @brief DiagramEventAddElement::buildElement + * Build the element, if the element is build successfully, we return true, otherwise false + */ +bool DiagramEventAddElement::buildElement() +{ + if (QETProject::integrateElementToProject(m_location, m_diagram -> project())) + { + QString error_msg; + IntegrationMoveElementsHandler *integ_handler = new IntegrationMoveElementsHandler(); + QString integ_path = m_diagram -> project() -> integrateElement(m_location.toString(), integ_handler, error_msg); + delete integ_handler; + if (integ_path.isEmpty()) + { + qDebug() << "DiagramView::addDroppedElement : Impossible d'ajouter l'element. Motif : " << qPrintable(error_msg); + return false; + } + } + + int state; + m_element = ElementFactory::Instance() -> createElement(m_location, 0, &state); + //The creation of element failed, we delete it + if (state) + { + delete m_element; + return(false); + } + //Everything is good + return true; +} + +/** + * @brief DiagramEventAddElement::addElement + * Add an element at the current pos en current rotation, + * if project autoconductor option is enable, and the element can be wired, we do it. + */ +void DiagramEventAddElement::addElement() +{ + int state; + Element *element = ElementFactory::Instance() -> createElement(m_location, 0, &state); + //Build failed + if (state) + { + delete element; + return; + } + + //We must add item to scene (even if addItemCommand do this) + //for create the autoconnection below + element -> setPos(m_element->pos()); + element -> setRotation(m_element -> rotation()); + m_diagram -> addItem(element); + + QUndoCommand *undo_object = new AddItemCommand(element, m_diagram, m_element -> pos()); + + while (!element -> AlignedFreeTerminals().isEmpty() && m_diagram -> project() -> autoConductor()) + { + QPair pair = element -> AlignedFreeTerminals().takeFirst(); + + Conductor *conductor = new Conductor(pair.first, pair.second); + conductor -> setProperties(m_diagram -> defaultConductorProperties); + + new AddItemCommand(conductor, m_diagram, QPointF(), undo_object); + + //Autonum the new conductor, the undo command associated for this, have for parent undo_object + ConductorAutoNumerotation can (conductor, m_diagram, undo_object); + can.numerate(); + }; + m_diagram -> undoStack().push(undo_object); +} diff --git a/sources/diagramevent/diagrameventaddelement.h b/sources/diagramevent/diagrameventaddelement.h new file mode 100644 index 000000000..c7f2f37d8 --- /dev/null +++ b/sources/diagramevent/diagrameventaddelement.h @@ -0,0 +1,53 @@ +/* + Copyright 2006-2015 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 DIAGRAMEVENTADDELEMENT_H +#define DIAGRAMEVENTADDELEMENT_H + +#include "diagrameventinterface.h" +#include "elementslocation.h" + +class Element; + +/** + * @brief The DiagramEventAddElement class + * This diagram event add a new element, for each left click button at the position of click. + * Space key rotate current element by 90°, right click button finish this event. + */ +class DiagramEventAddElement : public DiagramEventInterface +{ + public: + DiagramEventAddElement(ElementsLocation &location, Diagram *diagram, QPointF pos = QPointF(0,0)); + virtual ~DiagramEventAddElement(); + + virtual bool mouseMoveEvent (QGraphicsSceneMouseEvent *event); + virtual bool mousePressEvent (QGraphicsSceneMouseEvent *event); + virtual bool mouseReleaseEvent (QGraphicsSceneMouseEvent *event); + virtual bool mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event); + virtual bool keyPressEvent (QKeyEvent *event); + virtual void init(); + + private: + bool buildElement(); + void addElement(); + + private: + ElementsLocation m_location; + Element *m_element; +}; + +#endif // DIAGRAMEVENTADDELEMENT_H diff --git a/sources/diagramevent/diagrameventinterface.cpp b/sources/diagramevent/diagrameventinterface.cpp new file mode 100644 index 000000000..6dc0d7f4f --- /dev/null +++ b/sources/diagramevent/diagrameventinterface.cpp @@ -0,0 +1,86 @@ +/* + Copyright 2006-2015 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 "diagrameventinterface.h" +#include +#include + + +DiagramEventInterface::DiagramEventInterface(Diagram *diagram) : + m_diagram(diagram), + m_running(false), + m_abort(false) +{ +} + +DiagramEventInterface::~DiagramEventInterface() {}; + +bool DiagramEventInterface::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { + Q_UNUSED (event); + return false; +} + +bool DiagramEventInterface::mousePressEvent(QGraphicsSceneMouseEvent *event) { + Q_UNUSED (event); + return false; +} + +bool DiagramEventInterface::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { + Q_UNUSED (event); + return false; +} + +bool DiagramEventInterface::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + Q_UNUSED (event); + return false; +} + +bool DiagramEventInterface::wheelEvent(QGraphicsSceneWheelEvent *event) { + Q_UNUSED (event); + return false; +} + +/** + * @brief DiagramEventInterface::keyPressEvent + * By default, press escape key abort the curent action + * @param event + * @return + */ +bool DiagramEventInterface::keyPressEvent(QKeyEvent *event) { + if (event->key() == Qt::Key_Escape) { + m_running = false; + m_abort = true; + return true; + } + return false; +} + +bool DiagramEventInterface::KeyReleaseEvent(QKeyEvent *event) { + Q_UNUSED (event); + return false; +} + +bool DiagramEventInterface::isRunning() const { + return m_running; +} + +bool DiagramEventInterface::isFinish() const { + return !m_running; +} + +void DiagramEventInterface::init() +{} diff --git a/sources/diagramevent/diagrameventinterface.h b/sources/diagramevent/diagrameventinterface.h new file mode 100644 index 000000000..aef5e3831 --- /dev/null +++ b/sources/diagramevent/diagrameventinterface.h @@ -0,0 +1,70 @@ +/* + Copyright 2006-2015 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 DIAGRAMEVENTINTERFACE_H +#define DIAGRAMEVENTINTERFACE_H + +class QGraphicsSceneMouseEvent; +class QGraphicsSceneWheelEvent; +class QKeyEvent; +class Diagram; + +/** + * @brief The DiagramEventInterface class + * Each method return a bool: True if the methode do something else return false. + * Each method of DVEventInterface return false; + * isRunning() return true if action is started but not finish. By default return false. + * isFinish() return true when the action is finish, or not started. By default return true. + * + * ##USE DiagramEventInterface## + * This class is the basic interface for manage event on a diagram. + * To create a behavior for event diagram, we need to herite this class. + * This interface work like this : + * You need to create an interface and call diagram::setEventInterface(*your_interface). + * When a diagram get an event (mouse or key) if they have an event interface, + * they send the event to the interface (for exemple mousePressEvent). + * If the interface do something with this event, you need to return true to signal the diagram you work with this event. + * (if you do nothing by defaut the interface return false, so diagram do nothing) + * after that, the diagram call interface::isRunning(), if true diagram do nothing, else if false, + * that mean interface has finish is action (interface::isFinish return true) so the diagram will delete this interface. + * Be carreful with the destructor, diagram can at any time (even if interface is still running) delete the interface, + * the bool m_abort is here for that at destruction time. + * + */ +class DiagramEventInterface +{ + public: + DiagramEventInterface(Diagram *diagram); + virtual ~DiagramEventInterface() = 0; + virtual bool mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event); + virtual bool mousePressEvent (QGraphicsSceneMouseEvent *event); + virtual bool mouseMoveEvent (QGraphicsSceneMouseEvent *event); + virtual bool mouseReleaseEvent (QGraphicsSceneMouseEvent *event); + virtual bool wheelEvent (QGraphicsSceneWheelEvent *event); + virtual bool keyPressEvent (QKeyEvent *event); + virtual bool KeyReleaseEvent (QKeyEvent *event); + virtual bool isRunning () const; + virtual bool isFinish () const; + virtual void init(); + + protected: + Diagram *m_diagram; + bool m_running; + bool m_abort; +}; + +#endif // DIAGRAMEVENTINTERFACE_H diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 15927db5e..2c8f50ed0 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -42,6 +42,7 @@ #include "factory/elementfactory.h" #include "diagrampropertiesdialog.h" #include "dveventinterface.h" +#include "diagrameventaddelement.h" /** Constructeur @@ -287,11 +288,15 @@ void DiagramView::handleElementDrop(QDropEvent *e) { // verifie qu'il existe un element correspondant a cet emplacement ElementsCollectionItem *dropped_item = QETApp::collectionItem(location); if (!dropped_item) return; + + diagram()->setEventInterface(new DiagramEventAddElement(location, diagram(), mapToScene(e->pos()))); + //Set focus to the view to get event + this->setFocus(); - next_location_ = location; - next_position_ = e-> pos(); +// next_location_ = location; +// next_position_ = e-> pos(); - emit(aboutToAddElement()); +// emit(aboutToAddElement()); } /** diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 859395e03..85c2093c0 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -75,6 +75,17 @@ void Element::setHighlighted(bool hl) { update(); } +/** + * @brief Element::displayHelpLine + * Display the help line of each terminal if b is true + * @param b + */ +void Element::displayHelpLine(bool b) +{ + foreach (Terminal *t, terminals()) + t->drawHelpLine(b); +} + /** Methode principale de dessin de l'element @param painter Le QPainter utilise pour dessiner l'elment diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index 3dc636c81..064d8b6b5 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -139,19 +139,20 @@ class Element : public QetGraphicsItem { Draw this element */ public: - virtual void paint(QPainter *, const QStyleOptionGraphicsItem *) = 0; - /// @return This element type ID - virtual QString typeId() const = 0; - /// @return the human name for this element - virtual QString name() const = 0; + virtual void paint(QPainter *, const QStyleOptionGraphicsItem *) = 0; + /// @return This element type ID + virtual QString typeId() const = 0; + /// @return the human name for this element + virtual QString name() const = 0; - virtual bool isHighlighted() const; - virtual void setHighlighted(bool); - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - QRectF boundingRect() const; - QSize setSize(int, int); - QSize size() const; - QPixmap pixmap(); + virtual bool isHighlighted() const; + virtual void setHighlighted(bool); + void displayHelpLine(bool b = true); + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + QRectF boundingRect() const; + QSize setSize(int, int); + QSize size() const; + QPixmap pixmap(); // methods related to the hotspot QPoint setHotspot(QPoint); diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index a0d64487c..41baf46ca 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -168,6 +168,27 @@ QETProject::~QETProject() { delete undo_stack_; } +/** + * @brief QETProject::integrateElementToProject + * Return true if we must to integarte the element to the project otherwise false + * @param location : element location + * @param project : project to test + * @return + */ +bool QETProject::integrateElementToProject(const ElementsLocation &location, const QETProject *project) +{ + //Integration element must be enable + bool auto_integration_enabled = QETApp::settings().value("diagrameditor/integrate-elements", true).toBool(); + + //the element belongs there a project and if so, is this another project of the project given by parameter? + bool elmt_from_project = location.project(); + bool elmt_from_another_project = elmt_from_project && location.project() != project; + + bool must_integrate_element = (elmt_from_another_project || (auto_integration_enabled && !elmt_from_project)); + + return(must_integrate_element); +} + /** Cette methode peut etre utilisee pour tester la bonne ouverture d'un projet @return l'etat du projet diff --git a/sources/qetproject.h b/sources/qetproject.h index 5a2e0bad7..81f707dbd 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -75,6 +75,8 @@ class QETProject : public QObject ProjectParsingFailed = 4, /// the parsing of the XML content failed FileOpenDiscard = 5 /// the user cancelled the file opening }; + + static bool integrateElementToProject (const ElementsLocation &location, const QETProject *project); // methods public: