QElectroTech  0.70
eseventaddtext.cpp
Go to the documentation of this file.
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 
30  ESEventInterface(scene)
31 {
32  m_text = new PartText(m_editor);
33  m_scene -> addItem(m_text);
34  m_running = true;
35 }
36 
41  delete m_text;
42 }
43 
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 
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 }
bool mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
ESEventAddText::mouseReleaseEvent.
ElementScene * m_scene
QETElementEditor * m_editor
QIcon PartText
Definition: qeticons.cpp:134
void updateHelpCross(const QPointF &p)
QIcon tr
Definition: qeticons.cpp:204
bool mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
ESEventAddText::mouseMoveEvent.
~ESEventAddText() override
ESEventAddText::~ESEventAddText.
PartText * m_text
ESEventAddText(ElementScene *scene)
ESEventAddText::ESEventAddText.