QElectroTech  0.70
eseventinterface.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 "eseventinterface.h"
19 #include "elementscene.h"
20 #include "qetelementeditor.h"
21 #include <QGraphicsSceneMouseEvent>
22 
24  m_scene (scene),
25  m_editor (scene->editor()),
26  m_help_horiz (nullptr),
27  m_help_verti (nullptr),
28  m_running (false),
29  m_abort (false)
30 {
31  init();
32 }
33 
39 {
40  m_scene->setBehavior(ElementScene::Behavior::AddPart);
42 }
43 
49 {
50  delete m_help_horiz;
51  delete m_help_verti;
52 
53  m_scene->setBehavior(ElementScene::Behavior::Normal);
55 }
56 
57 bool ESEventInterface::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
58  Q_UNUSED (event);
59  return false;
60 }
61 
62 bool ESEventInterface::mousePressEvent(QGraphicsSceneMouseEvent *event) {
63  Q_UNUSED (event);
64  return false;
65 }
66 
67 bool ESEventInterface::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
68  Q_UNUSED (event);
69  return false;
70 }
71 
72 bool ESEventInterface::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
73  Q_UNUSED (event);
74  return false;
75 }
76 
77 bool ESEventInterface::wheelEvent(QGraphicsSceneWheelEvent *event) {
78  Q_UNUSED (event);
79  return false;
80 }
81 
88 bool ESEventInterface::keyPressEvent(QKeyEvent *event) {
89  if (event->key() == Qt::Key_Escape) {
90  m_running = false;
91  m_abort = true;
92  return true;
93  }
94  return false;
95 }
96 
97 bool ESEventInterface::KeyReleaseEvent(QKeyEvent *event) {
98  Q_UNUSED (event);
99  return false;
100 }
101 
103  return m_running;
104 }
105 
107  return !m_running;
108 }
109 
110 void ESEventInterface::updateHelpCross(const QPointF &p) {
111  //If line isn't created yet, we create it.
112  if (!m_help_horiz || !m_help_verti) {
113  QPen pen;
114  pen.setWidthF(0.4);
115  pen.setCosmetic(true);
116  pen.setColor(Qt::darkGray);
117  if (!m_help_horiz) {
118  m_help_horiz = new QGraphicsLineItem(-10000, 0, 10000, 0);
119  m_help_horiz -> setPen(pen);
120  m_scene -> addItem(m_help_horiz);
121  }
122  if (!m_help_verti) {
123  m_help_verti = new QGraphicsLineItem(0, -10000, 0, 10000);
124  m_help_verti -> setPen(pen);
125  m_scene -> addItem(m_help_verti);
126  }
127  }
128 
129  //Update the position of the cross
130  QPointF point = m_scene -> snapToGrid(p);
131 
132  m_help_horiz -> setY(point.y());
133  m_help_verti -> setX(point.x());
134 
135 }
ElementScene * m_scene
QETElementEditor * m_editor
virtual ~ESEventInterface()
ESEventInterface::~ESEventInterface Destructor.
void setBehavior(ElementScene::Behavior)
ElementScene::setBehavior Modifie the current behavior of this scene.
virtual bool wheelEvent(QGraphicsSceneWheelEvent *event)
void init()
ESEventInterface::init Init this event interface.
QGraphicsLineItem * m_help_horiz
virtual bool mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void updateHelpCross(const QPointF &p)
virtual bool KeyReleaseEvent(QKeyEvent *event)
virtual bool mousePressEvent(QGraphicsSceneMouseEvent *event)
QGraphicsLineItem * m_help_verti
virtual bool keyPressEvent(QKeyEvent *event)
ESEventInterface::keyPressEvent By default, press escape key abort the curent action.
ESEventInterface(ElementScene *scene)
virtual bool isFinish() const
virtual bool isRunning() const
virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent *event)
virtual bool mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)