[qet] [3475] Element editor: add terminal is managed by esevent

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 3475
Author:   blacksun
Date:     2014-11-10 22:47:28 +0100 (Mon, 10 Nov 2014)
Log Message:
-----------
Element editor: add terminal is managed by esevent

Modified Paths:
--------------
    trunk/sources/editor/elementscene.cpp
    trunk/sources/editor/elementscene.h
    trunk/sources/editor/qetelementeditor.cpp
    trunk/sources/editor/qetelementeditor.h

Added Paths:
-----------
    trunk/sources/editor/esevent/eseventaddterminal.cpp
    trunk/sources/editor/esevent/eseventaddterminal.h

Modified: trunk/sources/editor/elementscene.cpp
===================================================================
--- trunk/sources/editor/elementscene.cpp	2014-11-10 16:23:41 UTC (rev 3474)
+++ trunk/sources/editor/elementscene.cpp	2014-11-10 21:47:28 UTC (rev 3475)
@@ -72,17 +72,9 @@
 }
 
 /**
-	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 @@
 }
 
 /**
-	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 @@
 }
 
 /**
-	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,12 +134,7 @@
 			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();
 		removeItem(paste_area_);
@@ -155,26 +142,14 @@
 		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)) {
@@ -231,20 +206,6 @@
 }
 
 /**
-	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
  * @param interface
@@ -504,14 +465,6 @@
 	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);

Modified: trunk/sources/editor/elementscene.h
===================================================================
--- trunk/sources/editor/elementscene.h	2014-11-10 16:23:41 UTC (rev 3474)
+++ trunk/sources/editor/elementscene.h	2014-11-10 21:47:28 UTC (rev 3475)
@@ -41,7 +41,7 @@
 	
 	// enum
 	public:
-	enum Behavior { Normal, Terminal, PasteArea };
+	enum Behavior { Normal, PasteArea };
 	enum ItemOption {
 		SortByZValue = 1,
 		IncludeTerminals = 2,
@@ -81,7 +81,6 @@
 		*/
 		QPointF fsi_pos;
 		QPointF moving_press_pos;
-		bool moving_parts_;
 	
 		/// Variables related to drawing
 		ESEventInterface *m_event_interface;
@@ -132,7 +131,6 @@
 	bool wasCopiedFromThisElement(const QString &);
 	void cut();
 	void copy();
-	void paste();
 	void contextMenu (QContextMenuEvent *event);
 	QETElementEditor* editor() const;
 	
@@ -144,7 +142,6 @@
 		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 @@
 	
 	public slots:
 	void slot_move();
-	void slot_addTerminal();
 	void slot_select(const ElementContent &);
 	void slot_selectAll();
 	void slot_deselectAll();

Added: trunk/sources/editor/esevent/eseventaddterminal.cpp
===================================================================
--- trunk/sources/editor/esevent/eseventaddterminal.cpp	                        (rev 0)
+++ trunk/sources/editor/esevent/eseventaddterminal.cpp	2014-11-10 21:47:28 UTC (rev 3475)
@@ -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 <http://www.gnu.org/licenses/>.
+*/
+#include <QObject>
+
+#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;
+}

Added: trunk/sources/editor/esevent/eseventaddterminal.h
===================================================================
--- trunk/sources/editor/esevent/eseventaddterminal.h	                        (rev 0)
+++ trunk/sources/editor/esevent/eseventaddterminal.h	2014-11-10 21:47:28 UTC (rev 3475)
@@ -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 <http://www.gnu.org/licenses/>.
+*/
+#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

Modified: trunk/sources/editor/qetelementeditor.cpp
===================================================================
--- trunk/sources/editor/qetelementeditor.cpp	2014-11-10 16:23:41 UTC (rev 3474)
+++ trunk/sources/editor/qetelementeditor.cpp	2014-11-10 21:47:28 UTC (rev 3475)
@@ -48,6 +48,7 @@
 #include "eseventaddarc.h"
 #include "eseventaddtext.h"
 #include "eseventaddtextfield.h"
+#include "eseventaddterminal.h"
 
 #include <QMessageBox>
 /*
@@ -258,7 +259,7 @@
 	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,13 +979,21 @@
 
 /**
  * @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.
 */
 void QETElementEditor::slot_new() {

Modified: trunk/sources/editor/qetelementeditor.h
===================================================================
--- trunk/sources/editor/qetelementeditor.h	2014-11-10 16:23:41 UTC (rev 3474)
+++ trunk/sources/editor/qetelementeditor.h	2014-11-10 21:47:28 UTC (rev 3475)
@@ -135,6 +135,7 @@
 		void addArc();
 		void addText();
 		void addTextField();
+		void addTerminal();
 
 	void slot_new();
 	void slot_open();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/