mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01:00
Primitive part : Change the cursor shape, according to the current available behavior
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4084 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -36,10 +36,7 @@ CustomElementGraphicPart::CustomElementGraphicPart(QETElementEditor *editor, QGr
|
|||||||
_color(BlackColor),
|
_color(BlackColor),
|
||||||
_antialiased(false)
|
_antialiased(false)
|
||||||
{
|
{
|
||||||
setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
|
setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemSendsGeometryChanges);
|
||||||
#if QT_VERSION >= 0x040600
|
|
||||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
|
||||||
#endif
|
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,6 +424,14 @@ void CustomElementGraphicPart::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|||||||
QGraphicsObject::hoverEnterEvent(event);
|
QGraphicsObject::hoverEnterEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CustomElementGraphicPart::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
|
{
|
||||||
|
if (isSelected())
|
||||||
|
setCursor(Qt::OpenHandCursor);
|
||||||
|
|
||||||
|
QGraphicsObject::hoverMoveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief CustomElementGraphicPart::hoverLeaveEvent
|
* @brief CustomElementGraphicPart::hoverLeaveEvent
|
||||||
* Reimplemented from QGraphicsObject.
|
* Reimplemented from QGraphicsObject.
|
||||||
@@ -436,6 +441,7 @@ void CustomElementGraphicPart::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|||||||
void CustomElementGraphicPart::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
void CustomElementGraphicPart::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
m_hovered = false;
|
m_hovered = false;
|
||||||
|
unsetCursor();
|
||||||
QGraphicsObject::hoverLeaveEvent(event);
|
QGraphicsObject::hoverLeaveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ class CustomElementGraphicPart : public QGraphicsObject, public CustomElementPar
|
|||||||
|
|
||||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||||
|
void hoverMoveEvent (QGraphicsSceneHoverEvent *event);
|
||||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
|
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|||||||
@@ -65,8 +65,14 @@ void PartArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *options,
|
|||||||
|
|
||||||
if (isSelected())
|
if (isSelected())
|
||||||
{
|
{
|
||||||
|
painter->save();
|
||||||
|
QPen pen(Qt::DotLine);
|
||||||
|
pen.setWidth(1);
|
||||||
|
pen.setCosmetic(true);
|
||||||
|
painter->setPen(pen);
|
||||||
//Draw the ellipse in black
|
//Draw the ellipse in black
|
||||||
painter -> drawEllipse(rect());
|
painter -> drawEllipse(rect());
|
||||||
|
painter->restore();
|
||||||
|
|
||||||
//Draw the arc in red
|
//Draw the arc in red
|
||||||
t.setColor(Qt::red);
|
t.setColor(Qt::red);
|
||||||
@@ -143,7 +149,7 @@ QPainterPath PartArc::shape() const
|
|||||||
shape.arcTo(m_rect, m_start_angle/16, m_span_angle/16);
|
shape.arcTo(m_rect, m_start_angle/16, m_span_angle/16);
|
||||||
|
|
||||||
QPainterPathStroker pps;
|
QPainterPathStroker pps;
|
||||||
pps.setWidth(penWeight());
|
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||||
shape = pps.createStroke(shape);
|
shape = pps.createStroke(shape);
|
||||||
|
|
||||||
if (isSelected())
|
if (isSelected())
|
||||||
@@ -165,6 +171,29 @@ QPainterPath PartArc::shadowShape() const
|
|||||||
return (pps.createStroke(shape));
|
return (pps.createStroke(shape));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PartArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
|
{
|
||||||
|
if (!isSelected())
|
||||||
|
{
|
||||||
|
CustomElementGraphicPart::hoverMoveEvent(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
CustomElementGraphicPart::hoverMoveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief PartArc::mousePressEvent
|
* @brief PartArc::mousePressEvent
|
||||||
* Handle mouse press event
|
* Handle mouse press event
|
||||||
@@ -172,21 +201,24 @@ QPainterPath PartArc::shadowShape() const
|
|||||||
*/
|
*/
|
||||||
void PartArc::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void PartArc::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (isSelected() && event->button() == Qt::LeftButton)
|
if (event->button() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
|
setCursor(Qt::ClosedHandCursor);
|
||||||
|
if (isSelected())
|
||||||
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_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
|
||||||
m_undo_command->setText(tr("Modifier un arc"));
|
|
||||||
m_undo_command->enableAnimation();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
CustomElementGraphicPart::mousePressEvent(event);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
CustomElementGraphicPart::mousePressEvent(event);
|
CustomElementGraphicPart::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -213,6 +245,9 @@ void PartArc::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
*/
|
*/
|
||||||
void PartArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void PartArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
if (event->button() == Qt::LeftButton)
|
||||||
|
setCursor(Qt::OpenHandCursor);
|
||||||
|
|
||||||
if (m_handler_index >= 0 && m_handler_index <= 7)
|
if (m_handler_index >= 0 && m_handler_index <= 7)
|
||||||
{
|
{
|
||||||
if (!m_rect.isValid())
|
if (!m_rect.isValid())
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ class PartArc : public AbstractPartEllipse
|
|||||||
virtual QPainterPath shadowShape() const;
|
virtual QPainterPath shadowShape() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ QPainterPath PartEllipse::shape() const
|
|||||||
shape.addEllipse(m_rect);
|
shape.addEllipse(m_rect);
|
||||||
|
|
||||||
QPainterPathStroker pps;
|
QPainterPathStroker pps;
|
||||||
pps.setWidth(penWeight());
|
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||||
shape = pps.createStroke(shape);
|
shape = pps.createStroke(shape);
|
||||||
|
|
||||||
if (isSelected())
|
if (isSelected())
|
||||||
@@ -166,6 +166,29 @@ QPainterPath PartEllipse::shadowShape() const
|
|||||||
return (pps.createStroke(shape));
|
return (pps.createStroke(shape));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PartEllipse::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
|
{
|
||||||
|
if (!isSelected())
|
||||||
|
{
|
||||||
|
CustomElementGraphicPart::hoverMoveEvent(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
CustomElementGraphicPart::hoverMoveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief PartEllipse::mousePressEvent
|
* @brief PartEllipse::mousePressEvent
|
||||||
* Handle mouse press event
|
* Handle mouse press event
|
||||||
@@ -173,21 +196,24 @@ QPainterPath PartEllipse::shadowShape() const
|
|||||||
*/
|
*/
|
||||||
void PartEllipse::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void PartEllipse::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (isSelected() && event->button() == Qt::LeftButton)
|
if (event->button() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
|
setCursor(Qt::ClosedHandCursor);
|
||||||
|
if (isSelected())
|
||||||
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_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
|
||||||
m_undo_command->setText(tr("Modifier une ellipse"));
|
|
||||||
m_undo_command->enableAnimation();
|
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 une ellipse"));
|
||||||
|
m_undo_command->enableAnimation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
CustomElementGraphicPart::mousePressEvent(event);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
CustomElementGraphicPart::mousePressEvent(event);
|
CustomElementGraphicPart::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -196,7 +222,7 @@ void PartEllipse::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
void PartEllipse::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
void PartEllipse::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if(m_handler_index >= 0 && m_handler_index <= 7)
|
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()));
|
||||||
@@ -214,6 +240,9 @@ void PartEllipse::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
*/
|
*/
|
||||||
void PartEllipse::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void PartEllipse::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
if (event->button() == Qt::LeftButton)
|
||||||
|
setCursor(Qt::OpenHandCursor);
|
||||||
|
|
||||||
if (m_handler_index >= 0 && m_handler_index <= 7)
|
if (m_handler_index >= 0 && m_handler_index <= 7)
|
||||||
{
|
{
|
||||||
if (!m_rect.isValid())
|
if (!m_rect.isValid())
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class PartEllipse : public AbstractPartEllipse
|
|||||||
virtual QPainterPath shadowShape() const;
|
virtual QPainterPath shadowShape() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|||||||
@@ -146,21 +146,25 @@ void PartLine::fromXml(const QDomElement &qde) {
|
|||||||
*/
|
*/
|
||||||
void PartLine::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void PartLine::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if(isSelected() && event->button() == Qt::LeftButton)
|
if(event->button() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForLine(m_line));
|
setCursor(Qt::ClosedHandCursor);
|
||||||
|
|
||||||
if(m_handler_index >= 0 && m_handler_index <= 1) //User click on an handler
|
if (isSelected())
|
||||||
{
|
{
|
||||||
m_undo_command = new QPropertyUndoCommand(this, "line", QVariant(m_line));
|
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForLine(m_line));
|
||||||
m_undo_command->setText(tr("Modifier une ligne"));
|
|
||||||
m_undo_command->enableAnimation();
|
if(m_handler_index >= 0 && m_handler_index <= 1) //User click on an handler
|
||||||
|
{
|
||||||
|
m_undo_command = new QPropertyUndoCommand(this, "line", QVariant(m_line));
|
||||||
|
m_undo_command->setText(tr("Modifier une ligne"));
|
||||||
|
m_undo_command->enableAnimation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
CustomElementGraphicPart::mousePressEvent(event);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
CustomElementGraphicPart::mousePressEvent(event);
|
CustomElementGraphicPart::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -187,6 +191,9 @@ void PartLine::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
*/
|
*/
|
||||||
void PartLine::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void PartLine::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
if (event->button() == Qt::LeftButton)
|
||||||
|
setCursor(Qt::OpenHandCursor);
|
||||||
|
|
||||||
if (m_handler_index >= 0 && m_handler_index <= 1)
|
if (m_handler_index >= 0 && m_handler_index <= 1)
|
||||||
{
|
{
|
||||||
m_undo_command->setNewValue(QVariant(m_line));
|
m_undo_command->setNewValue(QVariant(m_line));
|
||||||
@@ -233,7 +240,7 @@ QPainterPath PartLine::shape() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
QPainterPathStroker pps;
|
QPainterPathStroker pps;
|
||||||
pps.setWidth(penWeight());
|
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||||
shape = pps.createStroke(shape);
|
shape = pps.createStroke(shape);
|
||||||
|
|
||||||
if (isSelected())
|
if (isSelected())
|
||||||
@@ -526,6 +533,20 @@ void PartLine::setSecondEndLength(const qreal &l)
|
|||||||
emit secondEndLengthChanged();
|
emit secondEndLengthChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PartLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
|
{
|
||||||
|
if (!isSelected())
|
||||||
|
{
|
||||||
|
CustomElementGraphicPart::hoverMoveEvent(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForLine(m_line)) >= 0)
|
||||||
|
setCursor(Qt::SizeAllCursor);
|
||||||
|
else
|
||||||
|
CustomElementGraphicPart::hoverMoveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief PartLine::path
|
* @brief PartLine::path
|
||||||
* @return this line has a QPainterPath.
|
* @return this line has a QPainterPath.
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ class PartLine : public CustomElementGraphicPart
|
|||||||
void setSecondEndLength(const qreal &l);
|
void setSecondEndLength(const qreal &l);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|||||||
@@ -248,6 +248,20 @@ void PartPolygon::setClosed(bool close)
|
|||||||
emit closedChange();
|
emit closedChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PartPolygon::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
|
{
|
||||||
|
if (!isSelected())
|
||||||
|
{
|
||||||
|
CustomElementGraphicPart::hoverMoveEvent(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_handler.pointIsHoverHandler(event->pos(), m_polygon) >= 0)
|
||||||
|
setCursor(Qt::SizeAllCursor);
|
||||||
|
else
|
||||||
|
CustomElementGraphicPart::hoverMoveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief PartPolygon::mousePressEvent
|
* @brief PartPolygon::mousePressEvent
|
||||||
* Handle mouse press event
|
* Handle mouse press event
|
||||||
@@ -255,20 +269,23 @@ void PartPolygon::setClosed(bool close)
|
|||||||
*/
|
*/
|
||||||
void PartPolygon::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void PartPolygon::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (isSelected() && event->button() == Qt::LeftButton)
|
if (event->button() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_polygon);
|
setCursor(Qt::ClosedHandCursor);
|
||||||
|
if(isSelected())
|
||||||
if(m_handler_index >= 0) //User click on an handler
|
|
||||||
{
|
{
|
||||||
m_undo_command = new QPropertyUndoCommand(this, "polygon", QVariant(m_polygon));
|
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_polygon);
|
||||||
m_undo_command->setText(tr("Modifier un polygone"));
|
|
||||||
|
if(m_handler_index >= 0) //User click on an handler
|
||||||
|
{
|
||||||
|
m_undo_command = new QPropertyUndoCommand(this, "polygon", QVariant(m_polygon));
|
||||||
|
m_undo_command->setText(tr("Modifier un polygone"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
CustomElementGraphicPart::mousePressEvent(event);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
CustomElementGraphicPart::mousePressEvent(event);
|
CustomElementGraphicPart::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -296,6 +313,9 @@ void PartPolygon::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
*/
|
*/
|
||||||
void PartPolygon::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void PartPolygon::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
if (event->button() == Qt::LeftButton)
|
||||||
|
setCursor(Qt::OpenHandCursor);
|
||||||
|
|
||||||
if (m_handler_index >= 0)
|
if (m_handler_index >= 0)
|
||||||
{
|
{
|
||||||
m_undo_command->setNewValue(QVariant(m_polygon));
|
m_undo_command->setNewValue(QVariant(m_polygon));
|
||||||
@@ -320,7 +340,7 @@ QPainterPath PartPolygon::shape() const
|
|||||||
shape.lineTo(m_polygon.first());
|
shape.lineTo(m_polygon.first());
|
||||||
|
|
||||||
QPainterPathStroker pps;
|
QPainterPathStroker pps;
|
||||||
pps.setWidth(penWeight());
|
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||||
shape = pps.createStroke(shape);
|
shape = pps.createStroke(shape);
|
||||||
|
|
||||||
if (isSelected())
|
if (isSelected())
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ class PartPolygon : public CustomElementGraphicPart
|
|||||||
void setClosed (bool close);
|
void setClosed (bool close);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ QPainterPath PartRectangle::shape() const
|
|||||||
shape.addRect(m_rect);
|
shape.addRect(m_rect);
|
||||||
|
|
||||||
QPainterPathStroker pps;
|
QPainterPathStroker pps;
|
||||||
pps.setWidth(penWeight());
|
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||||
shape = pps.createStroke(shape);
|
shape = pps.createStroke(shape);
|
||||||
|
|
||||||
if (isSelected())
|
if (isSelected())
|
||||||
@@ -237,6 +237,29 @@ void PartRectangle::handleUserTransformation(const QRectF &initial_selection_rec
|
|||||||
setRect(QRectF(mapFromScene(mapped_points.at(0)), mapFromScene(mapped_points.at(1))));
|
setRect(QRectF(mapFromScene(mapped_points.at(0)), mapFromScene(mapped_points.at(1))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PartRectangle::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
|
{
|
||||||
|
if (!isSelected())
|
||||||
|
{
|
||||||
|
CustomElementGraphicPart::hoverMoveEvent(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
CustomElementGraphicPart::hoverMoveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief PartRectangle::mousePressEvent
|
* @brief PartRectangle::mousePressEvent
|
||||||
* Handle mouse press event
|
* Handle mouse press event
|
||||||
@@ -244,21 +267,24 @@ void PartRectangle::handleUserTransformation(const QRectF &initial_selection_rec
|
|||||||
*/
|
*/
|
||||||
void PartRectangle::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void PartRectangle::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (isSelected() && event->button() == Qt::LeftButton)
|
if (event->button() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
|
setCursor(Qt::ClosedHandCursor);
|
||||||
|
if(isSelected())
|
||||||
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_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
|
||||||
m_undo_command->setText(tr("Modifier un rectangle"));
|
|
||||||
m_undo_command->enableAnimation();
|
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 rectangle"));
|
||||||
|
m_undo_command->enableAnimation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
CustomElementGraphicPart::mousePressEvent(event);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
CustomElementGraphicPart::mousePressEvent(event);
|
CustomElementGraphicPart::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -285,6 +311,9 @@ void PartRectangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
*/
|
*/
|
||||||
void PartRectangle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
void PartRectangle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
if (event->button() == Qt::LeftButton)
|
||||||
|
setCursor(Qt::OpenHandCursor);
|
||||||
|
|
||||||
if (m_handler_index >= 0 && m_handler_index <= 7)
|
if (m_handler_index >= 0 && m_handler_index <= 7)
|
||||||
{
|
{
|
||||||
if (!m_rect.isValid())
|
if (!m_rect.isValid())
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ class PartRectangle : public CustomElementGraphicPart
|
|||||||
virtual void handleUserTransformation(const QRectF &, const QRectF &);
|
virtual void handleUserTransformation(const QRectF &, const QRectF &);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|||||||
Reference in New Issue
Block a user