mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01:00
Element editor : add handler for modifie primitives
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4058 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "partpolygon.h"
|
||||
#include "editorcommands.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief PartPolygon::PartPolygon
|
||||
@@ -25,7 +27,9 @@
|
||||
*/
|
||||
PartPolygon::PartPolygon(QETElementEditor *editor, QGraphicsItem *parent) :
|
||||
CustomElementGraphicPart(editor, parent),
|
||||
m_closed(false)
|
||||
m_closed(false),
|
||||
m_handler(10),
|
||||
m_handler_index(-1)
|
||||
{}
|
||||
|
||||
/**
|
||||
@@ -56,6 +60,9 @@ void PartPolygon::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
|
||||
|
||||
if (m_hovered)
|
||||
drawShadowShape(painter);
|
||||
|
||||
if (isSelected() && scene()->selectedItems().size() == 1)
|
||||
m_handler.drawHandler(painter, m_polygon);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,6 +235,61 @@ void PartPolygon::removeLastPoint()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PartPolygon::mousePressEvent
|
||||
* Handle mouse press event
|
||||
* @param event
|
||||
*/
|
||||
void PartPolygon::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (isSelected() && event->button() == Qt::LeftButton)
|
||||
{
|
||||
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_polygon);
|
||||
|
||||
if(m_handler_index >= 0) //User click on an handler
|
||||
m_undo_command = new ChangePartCommand(tr("Polygone"), this, "polygon", QVariant(m_polygon));
|
||||
else
|
||||
CustomElementGraphicPart::mousePressEvent(event);
|
||||
}
|
||||
else
|
||||
CustomElementGraphicPart::mousePressEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PartPolygon::mouseMoveEvent
|
||||
* Handle mouse move event
|
||||
* @param event
|
||||
*/
|
||||
void PartPolygon::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if(m_handler_index >= 0)
|
||||
{
|
||||
QPointF pos_ = event->modifiers() == Qt::ControlModifier ? event->pos() : mapFromScene(elementScene()->snapToGrid(event->scenePos()));
|
||||
prepareGeometryChange();
|
||||
m_polygon.replace(m_handler_index, pos_);
|
||||
}
|
||||
else
|
||||
CustomElementGraphicPart::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PartPolygon::mouseReleaseEvent
|
||||
* Handle mouse release event
|
||||
* @param event
|
||||
*/
|
||||
void PartPolygon::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (m_handler_index >= 0)
|
||||
{
|
||||
m_undo_command->setNewValue(QVariant(m_polygon));
|
||||
elementScene()->stackAction(m_undo_command);
|
||||
m_undo_command = nullptr;
|
||||
m_handler_index = -1;
|
||||
}
|
||||
else
|
||||
CustomElementGraphicPart::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PartPolygon::shape
|
||||
* @return the shape of this item
|
||||
|
||||
Reference in New Issue
Block a user