diff --git a/sources/editor/elementscene.cpp b/sources/editor/elementscene.cpp index 29a57493b..b72a29b22 100644 --- a/sources/editor/elementscene.cpp +++ b/sources/editor/elementscene.cpp @@ -72,17 +72,9 @@ void ElementScene::slot_move() { } /** - Passe la scene en mode "ajout de borne" -*/ -void ElementScene::slot_addTerminal() { - behavior = Terminal; - if (m_event_interface) delete m_event_interface; m_event_interface = nullptr; -} - -/** - Gere les mouvements de la souris - @param e objet decrivant l'evenement -*/ + * @brief ElementScene::mouseMoveEvent + * @param e + */ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { if (m_event_interface) { if (m_event_interface -> mouseMoveEvent(e)) { @@ -109,9 +101,9 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { } /** - Gere les appuis sur les boutons de la souris - @param e objet decrivant l'evenement -*/ + * @brief ElementScene::mousePressEvent + * @param e + */ void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e) { if (m_event_interface) { if (m_event_interface -> mousePressEvent(e)) { @@ -128,9 +120,9 @@ void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e) { } /** - Gere les relachements de boutons de la souris - @param e objet decrivant l'evenement -*/ + * @brief ElementScene::mouseReleaseEvent + * @param e + */ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { if (m_event_interface) { if (m_event_interface -> mouseReleaseEvent(e)) { @@ -142,11 +134,6 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { return; } } - - QPointF event_pos = e -> scenePos(); - if (mustSnapToGrid(e)) event_pos = snapToGrid(event_pos); - - PartTerminal *terminal; if (behavior == PasteArea) { defined_paste_area_ = paste_area_ -> rect(); @@ -155,26 +142,14 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { behavior = Normal; return; } - - if (e -> button() & Qt::LeftButton) { - switch(behavior) { - case Terminal: - terminal = new PartTerminal(element_editor, 0, this); - terminal -> setPos(event_pos); - undo_stack.push(new AddPartCommand(tr("borne"), this, terminal)); - emit(partsAdded()); - endCurrentBehavior(e); - break; - case Normal: - default: - // detecte les deplacements de parties - QGraphicsScene::mouseReleaseEvent(e); - moving_parts_ = false; - } - } - else QGraphicsScene::mouseReleaseEvent(e); + + QGraphicsScene::mouseReleaseEvent(e); } +/** + * @brief ElementScene::mouseDoubleClickEvent + * @param event + */ void ElementScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { if (m_event_interface) { if (m_event_interface -> mouseDoubleClickEvent(event)) { @@ -230,20 +205,6 @@ void ElementScene::drawForeground(QPainter *p, const QRectF &rect) { p -> restore(); } -/** - A partir d'un evenement souris, cette methode regarde si la touche shift est - enfoncee ou non. Si oui, elle laisse le comportement en cours (cercle, - texte, polygone, ...). Si non, elle repasse en mode normal / selection. - @param event objet decrivant l'evenement souris -*/ -void ElementScene::endCurrentBehavior(const QGraphicsSceneMouseEvent *event) { - if (!(event -> modifiers() & Qt::ShiftModifier)) { - // la touche Shift n'est pas enfoncee : on demande le mode normal - behavior = Normal; - emit(needNormalMode()); - } -} - /** * @brief ElementScene::setEventInterface * Set a new event interface @@ -504,14 +465,6 @@ void ElementScene::copy() { last_copied_ = clipboard_content; } -/** - Gere le fait de coller le contenu du presse-papier = l'importer dans le - presse-papier a une position donnee. -*/ -void ElementScene::paste() { - -} - void ElementScene::contextMenu(QContextMenuEvent *event) { if (behavior == ElementScene::Normal) element_editor -> contextMenu(event); diff --git a/sources/editor/elementscene.h b/sources/editor/elementscene.h index 95f7ee27a..2de517ff3 100644 --- a/sources/editor/elementscene.h +++ b/sources/editor/elementscene.h @@ -41,7 +41,7 @@ class ElementScene : public QGraphicsScene { // enum public: - enum Behavior { Normal, Terminal, PasteArea }; + enum Behavior { Normal, PasteArea }; enum ItemOption { SortByZValue = 1, IncludeTerminals = 2, @@ -81,7 +81,6 @@ class ElementScene : public QGraphicsScene { */ QPointF fsi_pos; QPointF moving_press_pos; - bool moving_parts_; /// Variables related to drawing ESEventInterface *m_event_interface; @@ -132,7 +131,6 @@ class ElementScene : public QGraphicsScene { bool wasCopiedFromThisElement(const QString &); void cut(); void copy(); - void paste(); void contextMenu (QContextMenuEvent *event); QETElementEditor* editor() const; @@ -144,7 +142,6 @@ class ElementScene : public QGraphicsScene { virtual void keyPressEvent (QKeyEvent *event); virtual void drawForeground(QPainter *, const QRectF &); - virtual void endCurrentBehavior(const QGraphicsSceneMouseEvent *); private: QRectF elementContentBoundingRect(const ElementContent &) const; @@ -161,7 +158,6 @@ class ElementScene : public QGraphicsScene { public slots: void slot_move(); - void slot_addTerminal(); void slot_select(const ElementContent &); void slot_selectAll(); void slot_deselectAll(); diff --git a/sources/editor/esevent/eseventaddterminal.cpp b/sources/editor/esevent/eseventaddterminal.cpp new file mode 100644 index 000000000..bbf4284bf --- /dev/null +++ b/sources/editor/esevent/eseventaddterminal.cpp @@ -0,0 +1,91 @@ +/* + Copyright 2006-2014 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 + +#include "partterminal.h" +#include "editorcommands.h" +#include "elementscene.h" +#include "eseventaddterminal.h" + +/** + * @brief ESEventAddTerminal::ESEventAddTerminal + * @param scene + */ +ESEventAddTerminal::ESEventAddTerminal(ElementScene *scene) : + ESEventInterface(scene) +{ + m_terminal = new PartTerminal(m_editor, 0, m_scene); + m_running = true; +} + +/** + * @brief ESEventAddTerminal::~ESEventAddTerminal + */ +ESEventAddTerminal::~ESEventAddTerminal() { + delete m_terminal; +} + +/** + * @brief ESEventAddTerminal::mouseMoveEvent + * @param event + * @return + */ +bool ESEventAddTerminal::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { + QPointF pos = m_scene -> snapToGrid(event -> scenePos()); + updateHelpCross(pos); + m_terminal -> setPos(pos); + return true; +} + +/** + * @brief ESEventAddTerminal::mouseReleaseEvent + * @param event + * @return + */ +bool ESEventAddTerminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + if (event -> button() == Qt::LeftButton) { + m_scene -> undoStack().push(new AddPartCommand(QObject::tr("Borne"), m_scene, m_terminal)); + + //Set new terminal with same rotation + qreal rotation = m_terminal -> rotation(); + m_terminal = new PartTerminal(m_editor, 0, m_scene); + m_terminal -> setRotation(rotation); + m_terminal -> setPos(m_scene -> snapToGrid(event -> scenePos())); + + return true; + } + else if (event -> button() == Qt::RightButton) { + m_running = false; + return true; + } + + return false; +} + +/** + * @brief ESEventAddTerminal::keyPressEvent + * @param event + * @return + */ +bool ESEventAddTerminal::keyPressEvent(QKeyEvent *event) { + if (event -> key() == Qt::Key_Space) { + m_terminal -> setRotation(m_terminal -> rotation() + 90); + return true; + } + return false; +} diff --git a/sources/editor/esevent/eseventaddterminal.h b/sources/editor/esevent/eseventaddterminal.h new file mode 100644 index 000000000..e87553e3a --- /dev/null +++ b/sources/editor/esevent/eseventaddterminal.h @@ -0,0 +1,45 @@ +/* + Copyright 2006-2014 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 ESEVENTADDTERMINAL_H +#define ESEVENTADDTERMINAL_H + +#include "eseventinterface.h" + +class ElementScene; +class PartTerminal; +class QGraphicsSceneMouseEvent; + +/** + * @brief The ESEventAddTerminal class + * This ESEvent manage creation of terminal in an ElementScene + */ +class ESEventAddTerminal : public ESEventInterface +{ + public: + ESEventAddTerminal(ElementScene *scene); + virtual ~ESEventAddTerminal(); + + virtual bool mouseMoveEvent (QGraphicsSceneMouseEvent *event); + virtual bool mouseReleaseEvent (QGraphicsSceneMouseEvent *event); + virtual bool keyPressEvent (QKeyEvent *event); + + private: + PartTerminal *m_terminal; +}; + +#endif // ESEVENTADDTERMINAL_H diff --git a/sources/editor/qetelementeditor.cpp b/sources/editor/qetelementeditor.cpp index dc4e593c7..51f67e1a8 100644 --- a/sources/editor/qetelementeditor.cpp +++ b/sources/editor/qetelementeditor.cpp @@ -48,6 +48,7 @@ #include "eseventaddarc.h" #include "eseventaddtext.h" #include "eseventaddtextfield.h" +#include "eseventaddterminal.h" #include /* @@ -258,7 +259,7 @@ void QETElementEditor::setupActions() { connect(add_polygon, SIGNAL(triggered()), this, SLOT(addPolygon())); connect(add_text, SIGNAL(triggered()), this, SLOT(addText())); connect(add_arc, SIGNAL(triggered()), this, SLOT(addArc())); - connect(add_terminal, SIGNAL(triggered()), ce_scene, SLOT(slot_addTerminal())); + connect(add_terminal, SIGNAL(triggered()), this, SLOT(addTerminal())); connect(add_textfield, SIGNAL(triggered()), this, SLOT(addTextField())); connect(move, SIGNAL(triggered()), this, SLOT(slot_setRubberBandToView())); @@ -978,12 +979,20 @@ void QETElementEditor::addText() { /** * @brief QETElementEditor::addTextField - * Set text field interface to scene + * Set text field creation interface to scene */ void QETElementEditor::addTextField() { ce_scene -> setEventInterface(new ESEventAddTextField(ce_scene)); } +/** + * @brief QETElementEditor::addTerminal + * Set terminal creation interface to scene + */ +void QETElementEditor::addTerminal() { + ce_scene -> setEventInterface(new ESEventAddTerminal(ce_scene)); +} + /** Lance l'assistant de creation d'un nouvel element. */ diff --git a/sources/editor/qetelementeditor.h b/sources/editor/qetelementeditor.h index 75ffa992e..eef4c9105 100644 --- a/sources/editor/qetelementeditor.h +++ b/sources/editor/qetelementeditor.h @@ -135,6 +135,7 @@ class QETElementEditor : public QETMainWindow { void addArc(); void addText(); void addTextField(); + void addTerminal(); void slot_new(); void slot_open();