QElectroTech  0.70
eseventaddterminal.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 "partterminal.h"
21 #include "editorcommands.h"
22 #include "elementscene.h"
23 #include "eseventaddterminal.h"
24 
30  ESEventInterface(scene)
31 {
33  m_scene -> addItem(m_terminal);
34  m_running = true;
35 }
36 
41  delete m_terminal;
42 }
43 
49 bool ESEventAddTerminal::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
50  QPointF pos = m_scene -> snapToGrid(event -> scenePos());
51  updateHelpCross(pos);
52  m_terminal -> setPos(pos);
53  return true;
54 }
55 
61 bool ESEventAddTerminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
62  if (event -> button() == Qt::LeftButton) {
63  m_scene -> undoStack().push(new AddPartCommand(QObject::tr("Borne"), m_scene, m_terminal));
64 
65  //Set new terminal with same rotation
66  Qet::Orientation ori = m_terminal -> orientation();
68  m_scene -> addItem(m_terminal);
69  m_terminal -> setOrientation(ori);
70  m_terminal -> setPos(m_scene -> snapToGrid(event -> scenePos()));
71 
72  return true;
73  }
74  else if (event -> button() == Qt::RightButton) {
75  m_running = false;
76  return true;
77  }
78 
79  return false;
80 }
81 
87 bool ESEventAddTerminal::keyPressEvent(QKeyEvent *event) {
88  if (event -> key() == Qt::Key_Space) {
89  switch (m_terminal->orientation()) {
90  case Qet::North :
91  m_terminal -> setOrientation(Qet::East);
92  break;
93  case Qet::East :
94  m_terminal -> setOrientation(Qet::South);
95  break;
96  case Qet::South :
97  m_terminal -> setOrientation(Qet::West);
98  break;
99  case Qet::West :
100  m_terminal -> setOrientation(Qet::North);
101  break;
102  default :
103  m_terminal -> setOrientation(Qet::North);
104  break;
105  }
106  return true;
107  }
108  return (ESEventInterface::keyPressEvent(event));
109 }
bool mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
ESEventAddTerminal::mouseMoveEvent.
ElementScene * m_scene
QETElementEditor * m_editor
bool mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
ESEventAddTerminal::mouseReleaseEvent.
Definition: qet.h:207
void updateHelpCross(const QPointF &p)
~ESEventAddTerminal() override
ESEventAddTerminal::~ESEventAddTerminal.
bool keyPressEvent(QKeyEvent *event) override
ESEventAddTerminal::keyPressEvent.
QIcon tr
Definition: qeticons.cpp:204
ESEventAddTerminal(ElementScene *scene)
ESEventAddTerminal::ESEventAddTerminal.
virtual bool keyPressEvent(QKeyEvent *event)
ESEventInterface::keyPressEvent By default, press escape key abort the curent action.
PartTerminal * m_terminal
Definition: qet.h:205
Qet::Orientation orientation
Definition: partterminal.h:33
Orientation
Orientation (used for electrical elements and their terminals)
Definition: qet.h:204