[qet] [3476] Element editor : clean some code

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


Revision: 3476
Author:   blacksun
Date:     2014-11-10 23:57:32 +0100 (Mon, 10 Nov 2014)
Log Message:
-----------
Element editor : clean some code

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

Modified: trunk/sources/editor/elementscene.cpp
===================================================================
--- trunk/sources/editor/elementscene.cpp	2014-11-10 21:47:28 UTC (rev 3475)
+++ trunk/sources/editor/elementscene.cpp	2014-11-10 22:57:32 UTC (rev 3476)
@@ -80,7 +80,6 @@
 		if (m_event_interface -> mouseMoveEvent(e)) {
 			if (m_event_interface->isFinish()) {
 				emit(partsAdded());
-				emit(needNormalMode());
 				delete m_event_interface; m_event_interface = nullptr;
 			}
 			return;
@@ -109,7 +108,6 @@
 		if (m_event_interface -> mousePressEvent(e)) {
 			if (m_event_interface->isFinish()) {
 				emit(partsAdded());
-				emit(needNormalMode());
 				delete m_event_interface; m_event_interface = nullptr;
 			}
 			return;
@@ -128,7 +126,6 @@
 		if (m_event_interface -> mouseReleaseEvent(e)) {
 			if (m_event_interface->isFinish()) {
 				emit(partsAdded());
-				emit(needNormalMode());
 				delete m_event_interface; m_event_interface = nullptr;
 			}
 			return;
@@ -155,7 +152,6 @@
 		if (m_event_interface -> mouseDoubleClickEvent(event)) {
 			if (m_event_interface->isFinish()) {
 				emit(partsAdded());
-				emit(needNormalMode());
 				delete m_event_interface; m_event_interface = nullptr;
 			}
 			return;
@@ -175,7 +171,6 @@
 		if (m_event_interface -> keyPressEvent(event)) {
 			if (m_event_interface->isFinish()) {
 				emit(partsAdded());
-				emit(needNormalMode());
 				delete m_event_interface; m_event_interface = nullptr;
 			}
 			return;
@@ -211,7 +206,12 @@
  * @param interface
  */
 void ElementScene::setEventInterface(ESEventInterface *interface) {
-	if (m_event_interface) delete m_event_interface;
+	if (m_event_interface) {
+		delete m_event_interface;
+		//We must to re-init because previous interface
+		//Reset his own init when deleted
+		interface->init();
+	}
 	m_event_interface = interface;
 }
 

Modified: trunk/sources/editor/elementscene.h
===================================================================
--- trunk/sources/editor/elementscene.h	2014-11-10 21:47:28 UTC (rev 3475)
+++ trunk/sources/editor/elementscene.h	2014-11-10 22:57:32 UTC (rev 3476)
@@ -174,11 +174,6 @@
 	void stackAction(ElementEditionCommand *);
 	
 	signals:
-	/**
-		Signal emitted when the scene requires the element editor to switch back to
-		normal mode.
-	*/
-	void needNormalMode();
 	/// Signal emitted after one or several parts were added
 	void partsAdded();
 	/// Signal emitted after one or several parts were removed

Modified: trunk/sources/editor/esevent/eseventaddellipse.cpp
===================================================================
--- trunk/sources/editor/esevent/eseventaddellipse.cpp	2014-11-10 21:47:28 UTC (rev 3475)
+++ trunk/sources/editor/esevent/eseventaddellipse.cpp	2014-11-10 22:57:32 UTC (rev 3476)
@@ -60,7 +60,7 @@
 
 		//Add ellipse to scene
 		m_ellipse  -> setRect(m_ellipse -> rect().normalized());
-		m_scene -> undoStack().push(new AddPartCommand(QObject::tr("Rectangle"), m_scene, m_ellipse));
+		m_scene -> undoStack().push(new AddPartCommand(QObject::tr("Ellipse"), m_scene, m_ellipse));
 
 		//Set m_ellipse to nullptr for create new ellipse at next mouse press
 		m_ellipse = nullptr;

Modified: trunk/sources/editor/esevent/eseventinterface.cpp
===================================================================
--- trunk/sources/editor/esevent/eseventinterface.cpp	2014-11-10 21:47:28 UTC (rev 3475)
+++ trunk/sources/editor/esevent/eseventinterface.cpp	2014-11-10 22:57:32 UTC (rev 3476)
@@ -28,8 +28,14 @@
 	m_running    (false),
 	m_abort      (false)
 {
+	init();
+}
+
+void ESEventInterface::init() {
 	foreach (QGraphicsView *qgv, m_scene->views())
 		qgv->setContextMenuPolicy(Qt::NoContextMenu);
+
+	m_editor->slot_setNoDragToView();
 }
 
 ESEventInterface::~ESEventInterface() {
@@ -38,6 +44,8 @@
 
 	foreach (QGraphicsView *qgv, m_scene->views())
 		qgv->setContextMenuPolicy(Qt::DefaultContextMenu);
+
+	m_editor->slot_setRubberBandToView();
 }
 
 bool ESEventInterface::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {

Modified: trunk/sources/editor/esevent/eseventinterface.h
===================================================================
--- trunk/sources/editor/esevent/eseventinterface.h	2014-11-10 21:47:28 UTC (rev 3475)
+++ trunk/sources/editor/esevent/eseventinterface.h	2014-11-10 22:57:32 UTC (rev 3476)
@@ -32,6 +32,8 @@
 		ESEventInterface(ElementScene *scene);
 		virtual ~ESEventInterface();
 
+		void init();
+
 		virtual bool mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event);
 		virtual bool mousePressEvent       (QGraphicsSceneMouseEvent *event);
 		virtual bool mouseMoveEvent        (QGraphicsSceneMouseEvent *event);

Modified: trunk/sources/editor/qetelementeditor.cpp
===================================================================
--- trunk/sources/editor/qetelementeditor.cpp	2014-11-10 21:47:28 UTC (rev 3475)
+++ trunk/sources/editor/qetelementeditor.cpp	2014-11-10 22:57:32 UTC (rev 3476)
@@ -162,7 +162,6 @@
 	edit_lower        = new QAction(QET::Icons::Lower,                tr("\311loigner"),                               this);
 	edit_backward     = new QAction(QET::Icons::SendBackward,         tr("Envoyer au fond"),                           this);
 	edit_forward      = new QAction(QET::Icons::BringForward,         tr("Amener au premier plan"),                    this);
-	move              = new QAction(QET::Icons::PartSelect,           tr("D\351placer un objet"),                      this);
 	add_line          = new QAction(QET::Icons::PartLine,             tr("Ajouter une ligne"),                         this);
 	add_rectangle     = new QAction(QET::Icons::PartRectangle,        tr("Ajouter un rectangle"),                      this);
 	add_ellipse       = new QAction(QET::Icons::PartEllipse,          tr("Ajouter une ellipse"),                       this);
@@ -172,16 +171,6 @@
 	add_terminal      = new QAction(QET::Icons::Terminal,             tr("Ajouter une borne"),                         this);
 	add_textfield     = new QAction(QET::Icons::PartTextField,        tr("Ajouter un champ de texte"),                 this);
 	
-	QString add_status_tip = tr("Maintenez la touche Shift enfonc\351e pour effectuer plusieurs ajouts d'affil\351e");
-	add_line      -> setStatusTip(add_status_tip);
-	add_rectangle -> setStatusTip(add_status_tip);
-	add_ellipse   -> setStatusTip(add_status_tip);
-	add_text      -> setStatusTip(add_status_tip);
-	add_arc       -> setStatusTip(add_status_tip);
-	add_terminal  -> setStatusTip(add_status_tip);
-	add_textfield -> setStatusTip(add_status_tip);
-	add_polygon   -> setStatusTip(tr("Utilisez le bouton droit de la souris pour poser le dernier point du polygone"));
-	
 	undo = ce_scene -> undoStack().createUndoAction(this, tr("Annuler"));
 	redo = ce_scene -> undoStack().createRedoAction(this, tr("Refaire"));
 	undo -> setIcon(QET::Icons::EditUndo);
@@ -251,7 +240,6 @@
 	connect(edit_raise,      SIGNAL(triggered()), ce_scene, SLOT(slot_raise()));
 	connect(edit_lower,      SIGNAL(triggered()), ce_scene, SLOT(slot_lower()));
 	connect(edit_backward,   SIGNAL(triggered()), ce_scene, SLOT(slot_sendBackward()));
-	connect(move,            SIGNAL(triggered()), ce_scene, SLOT(slot_move()));
 
 	connect(add_line,        SIGNAL(triggered()), this, SLOT(addLine()));
 	connect(add_rectangle,   SIGNAL(triggered()), this, SLOT(addRect()));
@@ -261,20 +249,7 @@
 	connect(add_arc,         SIGNAL(triggered()), this, SLOT(addArc()));
 	connect(add_terminal,    SIGNAL(triggered()), this, SLOT(addTerminal()));
 	connect(add_textfield,   SIGNAL(triggered()), this, SLOT(addTextField()));
-
-	connect(move,            SIGNAL(triggered()), this,     SLOT(slot_setRubberBandToView()));
-	connect(add_line,        SIGNAL(triggered()), this,     SLOT(slot_setNoDragToView()));
-	connect(add_rectangle,   SIGNAL(triggered()), this,     SLOT(slot_setNoDragToView()));
-	connect(add_ellipse,     SIGNAL(triggered()), this,     SLOT(slot_setNoDragToView()));
-	connect(add_polygon,     SIGNAL(triggered()), this,     SLOT(slot_setNoDragToView()));
-	connect(add_text,        SIGNAL(triggered()), this,     SLOT(slot_setNoDragToView()));
-	connect(add_arc,         SIGNAL(triggered()), this,     SLOT(slot_setNoDragToView()));
-	connect(add_terminal,    SIGNAL(triggered()), this,     SLOT(slot_setNoDragToView()));
-	connect(add_textfield,   SIGNAL(triggered()), this,     SLOT(slot_setNoDragToView()));
 	
-	connect(ce_scene,        SIGNAL(needNormalMode()), this, SLOT(slot_setNormalMode()));
-	
-	move          -> setCheckable(true);
 	add_line      -> setCheckable(true);
 	add_rectangle -> setCheckable(true);
 	add_ellipse   -> setCheckable(true);
@@ -285,7 +260,6 @@
 	add_textfield -> setCheckable(true);
 	
 	parts = new QActionGroup(this);
-	parts -> addAction(move);
 	parts -> addAction(add_line);
 	parts -> addAction(add_rectangle);
 	parts -> addAction(add_ellipse);
@@ -295,11 +269,12 @@
 	parts -> addAction(add_textfield);
 	parts -> addAction(add_terminal);
 	parts -> setExclusive(true);
+
+	connect (ce_scene, SIGNAL(partsAdded()), this, SLOT(UncheckAddPrimitive()));
 	
 	parts_toolbar = new QToolBar(tr("Parties", "toolbar title"), this);
 	parts_toolbar -> setObjectName("parts");
 	foreach (QAction *action, parts -> actions()) parts_toolbar -> addAction(action);
-	move -> setChecked(true);
 	parts_toolbar -> setAllowedAreas(Qt::AllToolBarAreas);
 	
 	/*
@@ -598,15 +573,6 @@
 }
 
 /**
-	Passe l'editeur en mode normal
-*/
-void QETElementEditor::slot_setNormalMode() {
-	if (!move -> isChecked()) move -> setChecked(true);
-	ce_view -> setDragMode(QGraphicsView::RubberBandDrag);
-	ce_scene -> slot_move();
-}
-
-/**
 	Met a jour la zone d'information et d'edition des primitives.
 	Si plusieurs primitives sont selectionnees, seule leur quantite est
 	affichee. Sinon, un widget d'edition approprie est mis en place.
@@ -994,6 +960,14 @@
 }
 
 /**
+ * @brief QETElementEditor::UncheckAddPrimitive
+ * Uncheck all action related to primitive
+ */
+void QETElementEditor::UncheckAddPrimitive() {
+	foreach(QAction *action, parts->actions()) action -> setChecked(false);
+}
+
+/**
 	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 21:47:28 UTC (rev 3475)
+++ trunk/sources/editor/qetelementeditor.h	2014-11-10 22:57:32 UTC (rev 3476)
@@ -81,7 +81,7 @@
 	QToolBar *parts_toolbar, *main_toolbar, *view_toolbar, *depth_toolbar, *element_toolbar;
 	/// toolbars actions
 	QActionGroup *parts;
-	QAction *move, *add_line, *add_rectangle, *add_ellipse, *add_polygon, *add_text;
+	QAction *add_line, *add_rectangle, *add_ellipse, *add_polygon, *add_text;
 	QAction *add_arc, *add_terminal, *add_textfield;
 	/// minimum window title
 	QString min_title;
@@ -136,6 +136,7 @@
 		void addText();
 		void addTextField();
 		void addTerminal();
+		void UncheckAddPrimitive();
 
 	void slot_new();
 	void slot_open();
@@ -148,7 +149,6 @@
 	bool slot_saveAsFile();
 	void slot_setRubberBandToView();
 	void slot_setNoDragToView();
-	void slot_setNormalMode();
 	void slot_updateInformations();
 	void slot_updateMenus();
 	void slot_updateTitle();


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