mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +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:
@@ -169,6 +169,28 @@ QVector<QPointF> QetGraphicsHandlerUtility::pointsForLine(const QLineF &line) {
|
|||||||
return (QVector<QPointF> {line.p1(), line.p2()});
|
return (QVector<QPointF> {line.p1(), line.p2()});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
/**
|
||||||
|
* @brief QetGraphicsHandlerUtility::pointsForArc
|
||||||
|
* Return the points for the given arc.
|
||||||
|
* The first value in the vector is the start point, the second the end point.
|
||||||
|
* @param rect
|
||||||
|
* @param start_angle : start angle in degree
|
||||||
|
* @param span_angle : span angle in degree;
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
QVector<QPointF> QetGraphicsHandlerUtility::pointsForArc(const QRectF &rect, qreal start_angle, qreal span_angle)
|
||||||
|
{
|
||||||
|
QVector<QPointF> vector;
|
||||||
|
QPainterPath path;
|
||||||
|
path.arcTo(rect, start_angle, 0);
|
||||||
|
vector.append(path.currentPosition());
|
||||||
|
path.arcTo(rect, start_angle, span_angle);
|
||||||
|
vector.append(path.currentPosition());
|
||||||
|
return vector;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief QetGraphicsHandlerUtility::rectForPosAtIndex
|
* @brief QetGraphicsHandlerUtility::rectForPosAtIndex
|
||||||
* Return a rectangle after modification of the point '@pos' at index '@index' of original rectangle '@old_rect'.
|
* Return a rectangle after modification of the point '@pos' at index '@index' of original rectangle '@old_rect'.
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ class QetGraphicsHandlerUtility
|
|||||||
public:
|
public:
|
||||||
static QVector <QPointF> pointsForRect (const QRectF &rect);
|
static QVector <QPointF> pointsForRect (const QRectF &rect);
|
||||||
static QVector <QPointF> pointsForLine (const QLineF &line);
|
static QVector <QPointF> pointsForLine (const QLineF &line);
|
||||||
|
static QVector <QPointF> pointsForArc (const QRectF &rect, qreal start_angle, qreal span_angle);
|
||||||
static QRectF rectForPosAtIndex (const QRectF &old_rect, const QPointF &pos, int index);
|
static QRectF rectForPosAtIndex (const QRectF &old_rect, const QPointF &pos, int index);
|
||||||
static QRectF mirrorRectForPosAtIndex (const QRectF &old_rect, const QPointF &pos, int index);
|
static QRectF mirrorRectForPosAtIndex (const QRectF &old_rect, const QPointF &pos, int index);
|
||||||
static QLineF lineForPosAtIndex (const QLineF &old_line, const QPointF &pos, int index);
|
static QLineF lineForPosAtIndex (const QLineF &old_line, const QPointF &pos, int index);
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ void ArcEditor::updateArcS()
|
|||||||
{
|
{
|
||||||
if (m_locked) return;
|
if (m_locked) return;
|
||||||
m_locked = true;
|
m_locked = true;
|
||||||
double value = ((start_angle -> value() * -1) + 90) * 16;
|
double value = start_angle->value() * 16;
|
||||||
|
|
||||||
if (value != part->property("startAngle"))
|
if (value != part->property("startAngle"))
|
||||||
{
|
{
|
||||||
@@ -156,7 +156,7 @@ void ArcEditor::updateArcA()
|
|||||||
{
|
{
|
||||||
if (m_locked) return;
|
if (m_locked) return;
|
||||||
m_locked = true;
|
m_locked = true;
|
||||||
double value = angle -> value() * -16;
|
double value = angle->value() * 16;
|
||||||
|
|
||||||
if (value != part->property("spanAngle"))
|
if (value != part->property("spanAngle"))
|
||||||
{
|
{
|
||||||
@@ -204,8 +204,8 @@ void ArcEditor::updateForm()
|
|||||||
y->setValue(part->mapToScene(rect.topLeft()).y() + (rect.height()/2));
|
y->setValue(part->mapToScene(rect.topLeft()).y() + (rect.height()/2));
|
||||||
h->setValue(rect.width());
|
h->setValue(rect.width());
|
||||||
v->setValue(rect.height());
|
v->setValue(rect.height());
|
||||||
start_angle -> setValue(((part->property("startAngle").toInt() / 16) - 90) * -1);
|
start_angle->setValue(part->property("startAngle").toInt()/16);
|
||||||
angle -> setValue(part->property("spanAngle").toInt() / -16);
|
angle->setValue(part->property("spanAngle").toInt()/16);
|
||||||
activeConnections(true);
|
activeConnections(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,8 +73,8 @@ class AbstractPartEllipse : public CustomElementGraphicPart
|
|||||||
protected:
|
protected:
|
||||||
QList<QPointF> saved_points_;
|
QList<QPointF> saved_points_;
|
||||||
QRectF m_rect;
|
QRectF m_rect;
|
||||||
int m_start_angle;
|
qreal m_start_angle;
|
||||||
int m_span_angle;
|
qreal m_span_angle;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ABSTRACTPARTELLIPSE_H
|
#endif // ABSTRACTPARTELLIPSE_H
|
||||||
|
|||||||
@@ -27,10 +27,7 @@
|
|||||||
* @param parent : parent item
|
* @param parent : parent item
|
||||||
*/
|
*/
|
||||||
PartArc::PartArc(QETElementEditor *editor, QGraphicsItem *parent) :
|
PartArc::PartArc(QETElementEditor *editor, QGraphicsItem *parent) :
|
||||||
AbstractPartEllipse(editor, parent),
|
AbstractPartEllipse(editor, parent)
|
||||||
m_handler(10),
|
|
||||||
m_handler_index(-1),
|
|
||||||
m_undo_command(nullptr)
|
|
||||||
{
|
{
|
||||||
m_start_angle = 0;
|
m_start_angle = 0;
|
||||||
m_span_angle = -1440;
|
m_span_angle = -1440;
|
||||||
@@ -87,10 +84,14 @@ void PartArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *options,
|
|||||||
if (isSelected())
|
if (isSelected())
|
||||||
{
|
{
|
||||||
drawCross(m_rect.center(), painter);
|
drawCross(m_rect.center(), painter);
|
||||||
if (scene()->selectedItems().size() == 1)
|
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));
|
m_handler.drawHandler(painter, m_handler.pointsForRect(m_rect));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief PartArc::toXml
|
* @brief PartArc::toXml
|
||||||
@@ -124,8 +125,8 @@ void PartArc::fromXml(const QDomElement &qde) {
|
|||||||
QSizeF(qde.attribute("width", "0").toDouble(),
|
QSizeF(qde.attribute("width", "0").toDouble(),
|
||||||
qde.attribute("height", "0").toDouble()) );
|
qde.attribute("height", "0").toDouble()) );
|
||||||
|
|
||||||
m_start_angle = qde.attribute("start", "0").toInt() * 16;
|
m_start_angle = qde.attribute("start", "0").toDouble() * 16;
|
||||||
m_span_angle = qde.attribute("angle", "-1440").toInt() * 16;
|
m_span_angle = qde.attribute("angle", "-1440").toDouble() * 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF PartArc::boundingRect() const
|
QRectF PartArc::boundingRect() const
|
||||||
@@ -179,6 +180,7 @@ void PartArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_resize_mode == 1 || m_resize_mode == 2) {
|
||||||
int handler = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
|
int handler = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
|
||||||
|
|
||||||
if (handler >= 0)
|
if (handler >= 0)
|
||||||
@@ -189,8 +191,16 @@ void PartArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
|||||||
setCursor(Qt::SizeVerCursor);
|
setCursor(Qt::SizeVerCursor);
|
||||||
else if (handler == 3 || handler == 4)
|
else if (handler == 3 || handler == 4)
|
||||||
setCursor(Qt::SizeHorCursor);
|
setCursor(Qt::SizeHorCursor);
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
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);
|
CustomElementGraphicPart::hoverMoveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,6 +216,8 @@ void PartArc::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
setCursor(Qt::ClosedHandCursor);
|
setCursor(Qt::ClosedHandCursor);
|
||||||
if (isSelected())
|
if (isSelected())
|
||||||
{
|
{
|
||||||
|
//resize rect
|
||||||
|
if (m_resize_mode == 1 || m_resize_mode == 2) {
|
||||||
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
|
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
|
if(m_handler_index >= 0 && m_handler_index <= 7) //User click on an handler
|
||||||
@@ -215,6 +227,32 @@ void PartArc::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
m_undo_command->enableAnimation();
|
m_undo_command->enableAnimation();
|
||||||
return;
|
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,8 +266,8 @@ void PartArc::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
*/
|
*/
|
||||||
void PartArc::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
void PartArc::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if(m_handler_index >= 0 && m_handler_index <= 7)
|
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()));
|
QPointF pos_ = event->modifiers() == Qt::ControlModifier ? event->pos() : mapFromScene(elementScene()->snapToGrid(event->scenePos()));
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
|
|
||||||
@@ -237,8 +275,28 @@ void PartArc::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
setRect(m_handler.rectForPosAtIndex(m_rect, pos_, m_handler_index));
|
setRect(m_handler.rectForPosAtIndex(m_rect, pos_, m_handler_index));
|
||||||
else
|
else
|
||||||
setRect(m_handler.mirrorRectForPosAtIndex(m_rect, pos_, m_handler_index));
|
setRect(m_handler.mirrorRectForPosAtIndex(m_rect, pos_, m_handler_index));
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
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);
|
CustomElementGraphicPart::mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,8 +313,8 @@ void PartArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
switchResizeMode();
|
switchResizeMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_handler_index >= 0 && m_handler_index <= 7)
|
if (m_resize_mode == 1 || m_resize_mode == 2) {
|
||||||
{
|
if (m_handler_index >= 0 && m_handler_index <= 7) {
|
||||||
if (!m_rect.isValid())
|
if (!m_rect.isValid())
|
||||||
m_rect = m_rect.normalized();
|
m_rect = m_rect.normalized();
|
||||||
|
|
||||||
@@ -264,8 +322,28 @@ void PartArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
elementScene()->undoStack().push(m_undo_command);
|
elementScene()->undoStack().push(m_undo_command);
|
||||||
m_undo_command = nullptr;
|
m_undo_command = nullptr;
|
||||||
m_handler_index = -1;
|
m_handler_index = -1;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
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);
|
CustomElementGraphicPart::mouseReleaseEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,6 +353,10 @@ void PartArc::switchResizeMode()
|
|||||||
m_resize_mode = 2;
|
m_resize_mode = 2;
|
||||||
m_handler.setOuterColor(Qt::darkGreen);
|
m_handler.setOuterColor(Qt::darkGreen);
|
||||||
}
|
}
|
||||||
|
else if (m_resize_mode == 2 ) {
|
||||||
|
m_resize_mode = 3;
|
||||||
|
m_handler.setOuterColor(Qt::magenta);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
m_resize_mode = 1;
|
m_resize_mode = 1;
|
||||||
m_handler.setOuterColor(Qt::blue);
|
m_handler.setOuterColor(Qt::blue);
|
||||||
|
|||||||
@@ -68,9 +68,11 @@ class PartArc : public AbstractPartEllipse
|
|||||||
void switchResizeMode();
|
void switchResizeMode();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QetGraphicsHandlerUtility m_handler;
|
QetGraphicsHandlerUtility m_handler = 10;
|
||||||
int m_handler_index;
|
int m_handler_index = -1;
|
||||||
QPropertyUndoCommand *m_undo_command;
|
QPropertyUndoCommand *m_undo_command = nullptr;
|
||||||
|
QPropertyUndoCommand *m_undo_command2 = nullptr;
|
||||||
int m_resize_mode = 1;
|
int m_resize_mode = 1;
|
||||||
|
QPointF m_span_point;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user