QElectroTech  0.70
eseventadddynamictextfield.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 */
19 #include "elementscene.h"
20 #include "editorcommands.h"
21 #include "partdynamictextfield.h"
22 
23 #include <QUndoStack>
24 
30  ESEventInterface(scene)
31 {
33  m_scene->addItem(m_text);
34  m_running = true;
35 }
36 
41  delete m_text;
42 }
43 
49 bool ESEventAddDynamicTextField::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
50 {
51  QPointF pos = m_scene->snapToGrid(event->scenePos());
52  updateHelpCross(pos);
53  m_text->setPos(pos);
54  return true;
55 }
56 
62 bool ESEventAddDynamicTextField::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
63 {
64  if (event->button() == Qt::LeftButton)
65  {
66  m_scene->undoStack().push(new AddPartCommand(QObject::tr("Champ texte dynamique"), m_scene, m_text));
67 
68  //Set new text
70  m_scene->addItem(m_text);
71  m_text->setPos(m_scene->snapToGrid(event->scenePos()));
72 
73  return true;
74  }
75  else if (event->button() == Qt::RightButton)
76  {
77  m_running = false;
78  return true;
79  }
80 
81  return false;
82 }
bool mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
ESEventAddDynamicTextField::mouseReleaseEvent.
~ESEventAddDynamicTextField() override
ESEventAddDynamicTextField::~ESEventAddDynamicTextField.
ElementScene * m_scene
QETElementEditor * m_editor
The PartDynamicTextField class This class represents an editable dynamic text field which may be used...
void updateHelpCross(const QPointF &p)
QUndoStack & undoStack()
bool mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
ESEventAddDynamicTextField::mouseMoveEvent.
QIcon tr
Definition: qeticons.cpp:204
ESEventAddDynamicTextField(ElementScene *scene)
ESEventAddDynamicTextField::ESEventAddDynamicTextField.
QPointF snapToGrid(QPointF point)