mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-23 02:10:52 +01:00
Element editor : add new handler for arc to resize angle with mouse.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4722 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -27,10 +27,7 @@
|
||||
* @param parent : parent item
|
||||
*/
|
||||
PartArc::PartArc(QETElementEditor *editor, QGraphicsItem *parent) :
|
||||
AbstractPartEllipse(editor, parent),
|
||||
m_handler(10),
|
||||
m_handler_index(-1),
|
||||
m_undo_command(nullptr)
|
||||
AbstractPartEllipse(editor, parent)
|
||||
{
|
||||
m_start_angle = 0;
|
||||
m_span_angle = -1440;
|
||||
@@ -87,8 +84,12 @@ void PartArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *options,
|
||||
if (isSelected())
|
||||
{
|
||||
drawCross(m_rect.center(), painter);
|
||||
if (scene()->selectedItems().size() == 1)
|
||||
m_handler.drawHandler(painter, m_handler.pointsForRect(m_rect));
|
||||
if (scene()->selectedItems().size() == 1) {
|
||||
if (m_resize_mode == 3)
|
||||
m_handler.drawHandler(painter, m_handler.pointsForArc(m_rect, m_start_angle/16, m_span_angle/16));
|
||||
else
|
||||
m_handler.drawHandler(painter, m_handler.pointsForRect(m_rect));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,8 +125,8 @@ void PartArc::fromXml(const QDomElement &qde) {
|
||||
QSizeF(qde.attribute("width", "0").toDouble(),
|
||||
qde.attribute("height", "0").toDouble()) );
|
||||
|
||||
m_start_angle = qde.attribute("start", "0").toInt() * 16;
|
||||
m_span_angle = qde.attribute("angle", "-1440").toInt() * 16;
|
||||
m_start_angle = qde.attribute("start", "0").toDouble() * 16;
|
||||
m_span_angle = qde.attribute("angle", "-1440").toDouble() * 16;
|
||||
}
|
||||
|
||||
QRectF PartArc::boundingRect() const
|
||||
@@ -179,19 +180,28 @@ void PartArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
||||
return;
|
||||
}
|
||||
|
||||
int handler = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
|
||||
if (m_resize_mode == 1 || m_resize_mode == 2) {
|
||||
int handler = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
|
||||
|
||||
if (handler >= 0)
|
||||
{
|
||||
if (handler == 0 || handler == 2 || handler == 5 || handler == 7)
|
||||
setCursor(Qt::SizeAllCursor);
|
||||
else if (handler == 1 || handler == 6)
|
||||
setCursor(Qt::SizeVerCursor);
|
||||
else if (handler == 3 || handler == 4)
|
||||
setCursor(Qt::SizeHorCursor);
|
||||
if (handler >= 0)
|
||||
{
|
||||
if (handler == 0 || handler == 2 || handler == 5 || handler == 7)
|
||||
setCursor(Qt::SizeAllCursor);
|
||||
else if (handler == 1 || handler == 6)
|
||||
setCursor(Qt::SizeVerCursor);
|
||||
else if (handler == 3 || handler == 4)
|
||||
setCursor(Qt::SizeHorCursor);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
CustomElementGraphicPart::hoverMoveEvent(event);
|
||||
else if (m_resize_mode == 3) {
|
||||
if (m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForArc(m_rect, m_start_angle, m_span_angle)) >= 0)
|
||||
setCursor(Qt::SizeAllCursor);
|
||||
return;
|
||||
}
|
||||
|
||||
CustomElementGraphicPart::hoverMoveEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,15 +216,43 @@ void PartArc::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
if (isSelected())
|
||||
{
|
||||
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
|
||||
//resize rect
|
||||
if (m_resize_mode == 1 || m_resize_mode == 2) {
|
||||
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
|
||||
|
||||
if(m_handler_index >= 0 && m_handler_index <= 7) //User click on an handler
|
||||
{
|
||||
m_undo_command = new QPropertyUndoCommand(this, "rect", QVariant(m_rect));
|
||||
m_undo_command->setText(tr("Modifier un arc"));
|
||||
m_undo_command->enableAnimation();
|
||||
return;
|
||||
if(m_handler_index >= 0 && m_handler_index <= 7) //User click on an handler
|
||||
{
|
||||
m_undo_command = new QPropertyUndoCommand(this, "rect", QVariant(m_rect));
|
||||
m_undo_command->setText(tr("Modifier un arc"));
|
||||
m_undo_command->enableAnimation();
|
||||
return;
|
||||
}
|
||||
}
|
||||
//resize angle
|
||||
if (m_resize_mode == 3) {
|
||||
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForArc(m_rect, m_start_angle/16, m_span_angle/16));
|
||||
if (m_handler_index == 0) {
|
||||
m_span_point = m_handler.pointsForArc(m_rect, m_start_angle/16, m_span_angle/16).at(1);
|
||||
|
||||
m_undo_command = new QPropertyUndoCommand(this, "startAngle", QVariant(m_start_angle));
|
||||
m_undo_command->setText(tr("Modifier un arc"));
|
||||
m_undo_command->enableAnimation();
|
||||
|
||||
m_undo_command2 = new QPropertyUndoCommand(this, "spanAngle", QVariant(m_span_angle), m_undo_command);
|
||||
m_undo_command2->setText(tr("Modifier un arc"));
|
||||
m_undo_command2->enableAnimation();
|
||||
|
||||
return;
|
||||
}
|
||||
else if (m_handler_index == 1) {
|
||||
m_undo_command = new QPropertyUndoCommand(this, "spanAngle", QVariant(m_span_angle));
|
||||
m_undo_command->setText(tr("Modifier un arc"));
|
||||
m_undo_command->enableAnimation();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,18 +266,38 @@ void PartArc::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
*/
|
||||
void PartArc::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if(m_handler_index >= 0 && m_handler_index <= 7)
|
||||
{
|
||||
QPointF pos_ = event->modifiers() == Qt::ControlModifier ? event->pos() : mapFromScene(elementScene()->snapToGrid(event->scenePos()));
|
||||
prepareGeometryChange();
|
||||
if (m_resize_mode == 1 || m_resize_mode == 2) {
|
||||
if (m_handler_index >= 0 && m_handler_index <= 7) {
|
||||
QPointF pos_ = event->modifiers() == Qt::ControlModifier ? event->pos() : mapFromScene(elementScene()->snapToGrid(event->scenePos()));
|
||||
prepareGeometryChange();
|
||||
|
||||
if (m_resize_mode == 1)
|
||||
setRect(m_handler.rectForPosAtIndex(m_rect, pos_, m_handler_index));
|
||||
else
|
||||
setRect(m_handler.mirrorRectForPosAtIndex(m_rect, pos_, m_handler_index));
|
||||
if (m_resize_mode == 1)
|
||||
setRect(m_handler.rectForPosAtIndex(m_rect, pos_, m_handler_index));
|
||||
else
|
||||
setRect(m_handler.mirrorRectForPosAtIndex(m_rect, pos_, m_handler_index));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
CustomElementGraphicPart::mouseMoveEvent(event);
|
||||
else if (m_resize_mode == 3) {
|
||||
if (m_handler_index == 0 || m_handler_index == 1) {
|
||||
QLineF line(m_rect.center(), event->pos());
|
||||
prepareGeometryChange();
|
||||
|
||||
if (m_handler_index == 0) {
|
||||
setStartAngle(line.angle()*16);
|
||||
setSpanAngle(line.angleTo(QLineF(m_rect.center(), m_span_point))*16);
|
||||
}
|
||||
else if (m_handler_index == 1) {
|
||||
QLineF line2(m_rect.center(), m_handler.pointsForArc(m_rect, m_start_angle/16, m_span_angle/16).at(0));
|
||||
setSpanAngle (line2.angleTo(line)*16);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CustomElementGraphicPart::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -255,18 +313,38 @@ void PartArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
switchResizeMode();
|
||||
}
|
||||
|
||||
if (m_handler_index >= 0 && m_handler_index <= 7)
|
||||
{
|
||||
if (!m_rect.isValid())
|
||||
m_rect = m_rect.normalized();
|
||||
if (m_resize_mode == 1 || m_resize_mode == 2) {
|
||||
if (m_handler_index >= 0 && m_handler_index <= 7) {
|
||||
if (!m_rect.isValid())
|
||||
m_rect = m_rect.normalized();
|
||||
|
||||
m_undo_command->setNewValue(QVariant(m_rect));
|
||||
elementScene()->undoStack().push(m_undo_command);
|
||||
m_undo_command = nullptr;
|
||||
m_handler_index = -1;
|
||||
m_undo_command->setNewValue(QVariant(m_rect));
|
||||
elementScene()->undoStack().push(m_undo_command);
|
||||
m_undo_command = nullptr;
|
||||
m_handler_index = -1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
CustomElementGraphicPart::mouseReleaseEvent(event);
|
||||
else if (m_resize_mode == 3) {
|
||||
if (m_handler_index == 0) {
|
||||
m_undo_command->setNewValue(QVariant(m_start_angle));
|
||||
m_undo_command2->setNewValue(QVariant(m_span_angle));
|
||||
elementScene()->undoStack().push(m_undo_command);
|
||||
m_undo_command = nullptr;
|
||||
m_undo_command2 = nullptr;
|
||||
m_handler_index = -1;
|
||||
return;
|
||||
}
|
||||
else if (m_handler_index == 1) {
|
||||
m_undo_command->setNewValue(QVariant(m_span_angle));
|
||||
elementScene()->undoStack().push(m_undo_command);
|
||||
m_undo_command = nullptr;
|
||||
m_handler_index = -1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CustomElementGraphicPart::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void PartArc::switchResizeMode()
|
||||
@@ -275,6 +353,10 @@ void PartArc::switchResizeMode()
|
||||
m_resize_mode = 2;
|
||||
m_handler.setOuterColor(Qt::darkGreen);
|
||||
}
|
||||
else if (m_resize_mode == 2 ) {
|
||||
m_resize_mode = 3;
|
||||
m_handler.setOuterColor(Qt::magenta);
|
||||
}
|
||||
else {
|
||||
m_resize_mode = 1;
|
||||
m_handler.setOuterColor(Qt::blue);
|
||||
|
||||
Reference in New Issue
Block a user