1 /*
2 	Copyright 2006-2019 The QElectroTech Team
3 	This file is part of QElectroTech.
4 
5 	QElectroTech is free software: you can redistribute it and/or modify
6 	it under the terms of the GNU General Public License as published by
7 	the Free Software Foundation, either version 2 of the License, or
8 	(at your option) any later version.
9 
10 	QElectroTech is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 	GNU General Public License for more details.
14 
15 	You should have received a copy of the GNU General Public License
16 	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include <QObject>
19 
20 #include "eseventaddtext.h"
21 #include "parttext.h"
22 #include "editorcommands.h"
23 #include "elementscene.h"
24 
25 /**
26  * @brief ESEventAddText::ESEventAddText
27  * @param scene
28  */
ESEventAddText(ElementScene * scene)29 ESEventAddText::ESEventAddText(ElementScene *scene) :
30 	ESEventInterface(scene)
31 {
32 	m_text = new PartText(m_editor);
33 	m_scene -> addItem(m_text);
34 	m_running = true;
35 }
36 
37 /**
38  * @brief ESEventAddText::~ESEventAddText
39  */
~ESEventAddText()40 ESEventAddText::~ESEventAddText() {
41 		delete m_text;
42 }
43 
44 /**
45  * @brief ESEventAddText::mouseMoveEvent
46  * @param event
47  * @return
48  */
mouseMoveEvent(QGraphicsSceneMouseEvent * event)49 bool ESEventAddText::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
50 	QPointF pos = m_scene -> snapToGrid(event -> scenePos());
51 	updateHelpCross(pos);
52 	m_text->setPos(pos);
53 	return true;
54 }
55 
56 /**
57  * @brief ESEventAddText::mouseReleaseEvent
58  * @param event
59  * @return
60  */
mouseReleaseEvent(QGraphicsSceneMouseEvent * event)61 bool ESEventAddText::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
62 	if (event->button() == Qt::LeftButton) {
63 		m_scene -> undoStack().push(new AddPartCommand(QObject::tr("Texte"), m_scene, m_text));
64 
65 		//Set new text
66 		m_text = new PartText(m_editor);
67 		m_scene -> addItem(m_text);
68 		m_text -> setPos(m_scene -> snapToGrid(event -> scenePos()));
69 
70 		return true;
71 	}
72 	else if (event->button() == Qt::RightButton) {
73 		m_running = false;
74 		return true;
75 	}
76 
77 	return false;
78 }
79