2014-11-10 21:47:28 +00:00
|
|
|
/*
|
2020-06-15 17:42:37 +02:00
|
|
|
Copyright 2006-2020 The QElectroTech Team
|
2014-11-10 21:47:28 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
#include "partterminal.h"
|
|
|
|
#include "editorcommands.h"
|
|
|
|
#include "elementscene.h"
|
|
|
|
#include "eseventaddterminal.h"
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ESEventAddTerminal::ESEventAddTerminal
|
|
|
|
@param scene
|
|
|
|
*/
|
2014-11-10 21:47:28 +00:00
|
|
|
ESEventAddTerminal::ESEventAddTerminal(ElementScene *scene) :
|
|
|
|
ESEventInterface(scene)
|
|
|
|
{
|
2015-02-09 08:57:40 +00:00
|
|
|
m_terminal = new PartTerminal(m_editor);
|
|
|
|
m_scene -> addItem(m_terminal);
|
2014-11-10 21:47:28 +00:00
|
|
|
m_running = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ESEventAddTerminal::~ESEventAddTerminal
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
ESEventAddTerminal::~ESEventAddTerminal()
|
|
|
|
{
|
2014-11-10 21:47:28 +00:00
|
|
|
delete m_terminal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ESEventAddTerminal::mouseMoveEvent
|
|
|
|
@param event
|
|
|
|
@return
|
|
|
|
*/
|
2014-11-10 21:47:28 +00:00
|
|
|
bool ESEventAddTerminal::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
|
|
|
QPointF pos = m_scene -> snapToGrid(event -> scenePos());
|
|
|
|
updateHelpCross(pos);
|
|
|
|
m_terminal -> setPos(pos);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ESEventAddTerminal::mouseReleaseEvent
|
|
|
|
@param event
|
|
|
|
@return
|
|
|
|
*/
|
2014-11-10 21:47:28 +00:00
|
|
|
bool ESEventAddTerminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
|
|
|
if (event -> button() == Qt::LeftButton) {
|
|
|
|
m_scene -> undoStack().push(new AddPartCommand(QObject::tr("Borne"), m_scene, m_terminal));
|
|
|
|
|
|
|
|
//Set new terminal with same rotation
|
2014-11-25 05:45:50 +00:00
|
|
|
Qet::Orientation ori = m_terminal -> orientation();
|
2015-02-09 08:57:40 +00:00
|
|
|
m_terminal = new PartTerminal(m_editor);
|
|
|
|
m_scene -> addItem(m_terminal);
|
2014-11-25 05:45:50 +00:00
|
|
|
m_terminal -> setOrientation(ori);
|
2014-11-10 21:47:28 +00:00
|
|
|
m_terminal -> setPos(m_scene -> snapToGrid(event -> scenePos()));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (event -> button() == Qt::RightButton) {
|
|
|
|
m_running = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief ESEventAddTerminal::keyPressEvent
|
|
|
|
@param event
|
|
|
|
@return
|
|
|
|
*/
|
2014-11-10 21:47:28 +00:00
|
|
|
bool ESEventAddTerminal::keyPressEvent(QKeyEvent *event) {
|
|
|
|
if (event -> key() == Qt::Key_Space) {
|
2014-11-25 05:45:50 +00:00
|
|
|
switch (m_terminal->orientation()) {
|
|
|
|
case Qet::North :
|
|
|
|
m_terminal -> setOrientation(Qet::East);
|
|
|
|
break;
|
|
|
|
case Qet::East :
|
|
|
|
m_terminal -> setOrientation(Qet::South);
|
|
|
|
break;
|
|
|
|
case Qet::South :
|
|
|
|
m_terminal -> setOrientation(Qet::West);
|
|
|
|
break;
|
|
|
|
case Qet::West :
|
|
|
|
m_terminal -> setOrientation(Qet::North);
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
m_terminal -> setOrientation(Qet::North);
|
|
|
|
break;
|
|
|
|
}
|
2014-11-10 21:47:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-11-25 05:45:50 +00:00
|
|
|
return (ESEventInterface::keyPressEvent(event));
|
2014-11-10 21:47:28 +00:00
|
|
|
}
|