mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-21 08:40:53 +01:00
Element editor: add polygon is managed by an esevent
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3466 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
117
sources/editor/esevent/eseventaddpolygon.cpp
Normal file
117
sources/editor/esevent/eseventaddpolygon.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
Copyright 2006-2014 The QElectroTech Team
|
||||
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 "eseventaddpolygon.h"
|
||||
#include "elementscene.h"
|
||||
#include "partpolygon.h"
|
||||
#include "editorcommands.h"
|
||||
|
||||
/**
|
||||
* @brief ESEventAddPolygon::ESEventAddPolygon
|
||||
* @param scene
|
||||
*/
|
||||
ESEventAddPolygon::ESEventAddPolygon(ElementScene *scene) :
|
||||
ESEventInterface(scene),
|
||||
m_polygon(nullptr)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddPolygon::~ESEventAddPolygon
|
||||
*/
|
||||
ESEventAddPolygon::~ESEventAddPolygon() {
|
||||
if (m_running || m_abort)
|
||||
delete m_polygon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddPolygon::mousePressEvent
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddPolygon::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if (event -> button() == Qt::LeftButton) {
|
||||
if(!m_running) m_running = true;
|
||||
QPointF pos = m_scene->snapToGrid(event -> scenePos());
|
||||
|
||||
//create new polygon
|
||||
if (!m_polygon) {
|
||||
m_polygon = new PartPolygon(m_editor, 0, m_scene);
|
||||
m_polygon -> addPoint(pos);
|
||||
}
|
||||
|
||||
m_polygon -> addPoint(pos);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddPolygon::mouseMoveEvent
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddPolygon::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
updateHelpCross(event -> scenePos());
|
||||
if (!m_polygon) return false;
|
||||
|
||||
m_polygon -> setLastPoint(m_scene -> snapToGrid(event -> scenePos()));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddPolygon::mouseReleaseEvent
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddPolygon::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if (event -> button() == Qt::RightButton) {
|
||||
if (m_polygon) {
|
||||
m_polygon -> removeLastPoint();
|
||||
|
||||
if (m_polygon -> polygon().size() > 1)
|
||||
{ m_polygon -> setLastPoint(m_scene -> snapToGrid(event -> scenePos())); }
|
||||
else
|
||||
{ delete m_polygon; m_polygon = nullptr; }
|
||||
}
|
||||
else
|
||||
{ m_running = false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ESEventAddPolygon::mouseDoubleClickEvent
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool ESEventAddPolygon::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if (event -> button() == Qt::LeftButton) {
|
||||
if (m_polygon) {
|
||||
m_polygon -> addPoint(m_scene -> snapToGrid(event -> scenePos()));
|
||||
m_scene -> undoStack().push(new AddPartCommand(QObject::tr("Polygone"), m_scene, m_polygon));
|
||||
|
||||
//Set m_polygon to nullptr for create new polygon at next mouse press
|
||||
m_polygon = nullptr;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user