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),
|
||||
_antialiased(false)
|
||||
{
|
||||
setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
|
||||
#if QT_VERSION >= 0x040600
|
||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||
#endif
|
||||
setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemSendsGeometryChanges);
|
||||
setAcceptHoverEvents(true);
|
||||
}
|
||||
|
||||
@@ -427,6 +424,14 @@ void CustomElementGraphicPart::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
QGraphicsObject::hoverEnterEvent(event);
|
||||
}
|
||||
|
||||
void CustomElementGraphicPart::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
if (isSelected())
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
|
||||
QGraphicsObject::hoverMoveEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CustomElementGraphicPart::hoverLeaveEvent
|
||||
* Reimplemented from QGraphicsObject.
|
||||
@@ -436,6 +441,7 @@ void CustomElementGraphicPart::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
void CustomElementGraphicPart::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
m_hovered = false;
|
||||
unsetCursor();
|
||||
QGraphicsObject::hoverLeaveEvent(event);
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ class CustomElementGraphicPart : public QGraphicsObject, public CustomElementPar
|
||||
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||
void hoverMoveEvent (QGraphicsSceneHoverEvent *event);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
@@ -65,8 +65,14 @@ void PartArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *options,
|
||||
|
||||
if (isSelected())
|
||||
{
|
||||
painter->save();
|
||||
QPen pen(Qt::DotLine);
|
||||
pen.setWidth(1);
|
||||
pen.setCosmetic(true);
|
||||
painter->setPen(pen);
|
||||
//Draw the ellipse in black
|
||||
painter -> drawEllipse(rect());
|
||||
painter->restore();
|
||||
|
||||
//Draw the arc in 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);
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(penWeight());
|
||||
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||
shape = pps.createStroke(shape);
|
||||
|
||||
if (isSelected())
|
||||
@@ -165,6 +171,29 @@ QPainterPath PartArc::shadowShape() const
|
||||
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
|
||||
* Handle mouse press event
|
||||
@@ -172,7 +201,10 @@ QPainterPath PartArc::shadowShape() const
|
||||
*/
|
||||
void PartArc::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (isSelected() && event->button() == Qt::LeftButton)
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
if (isSelected())
|
||||
{
|
||||
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
|
||||
|
||||
@@ -181,11 +213,11 @@ void PartArc::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -213,6 +245,9 @@ void PartArc::mouseMoveEvent(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_rect.isValid())
|
||||
|
||||
@@ -59,6 +59,7 @@ class PartArc : public AbstractPartEllipse
|
||||
virtual QPainterPath shadowShape() const;
|
||||
|
||||
protected:
|
||||
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
@@ -145,7 +145,7 @@ QPainterPath PartEllipse::shape() const
|
||||
shape.addEllipse(m_rect);
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(penWeight());
|
||||
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||
shape = pps.createStroke(shape);
|
||||
|
||||
if (isSelected())
|
||||
@@ -166,6 +166,29 @@ QPainterPath PartEllipse::shadowShape() const
|
||||
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
|
||||
* Handle mouse press event
|
||||
@@ -173,7 +196,10 @@ QPainterPath PartEllipse::shadowShape() const
|
||||
*/
|
||||
void PartEllipse::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (isSelected() && event->button() == Qt::LeftButton)
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
if (isSelected())
|
||||
{
|
||||
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
|
||||
|
||||
@@ -182,11 +208,11 @@ void PartEllipse::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -214,6 +240,9 @@ void PartEllipse::mouseMoveEvent(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_rect.isValid())
|
||||
|
||||
@@ -61,6 +61,7 @@ class PartEllipse : public AbstractPartEllipse
|
||||
virtual QPainterPath shadowShape() const;
|
||||
|
||||
protected:
|
||||
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
@@ -146,7 +146,11 @@ void PartLine::fromXml(const QDomElement &qde) {
|
||||
*/
|
||||
void PartLine::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if(isSelected() && event->button() == Qt::LeftButton)
|
||||
if(event->button() == Qt::LeftButton)
|
||||
{
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
|
||||
if (isSelected())
|
||||
{
|
||||
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForLine(m_line));
|
||||
|
||||
@@ -155,11 +159,11 @@ void PartLine::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -187,6 +191,9 @@ void PartLine::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
*/
|
||||
void PartLine::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton)
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
|
||||
if (m_handler_index >= 0 && m_handler_index <= 1)
|
||||
{
|
||||
m_undo_command->setNewValue(QVariant(m_line));
|
||||
@@ -233,7 +240,7 @@ QPainterPath PartLine::shape() const
|
||||
}
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(penWeight());
|
||||
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||
shape = pps.createStroke(shape);
|
||||
|
||||
if (isSelected())
|
||||
@@ -526,6 +533,20 @@ void PartLine::setSecondEndLength(const qreal &l)
|
||||
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
|
||||
* @return this line has a QPainterPath.
|
||||
|
||||
@@ -96,6 +96,7 @@ class PartLine : public CustomElementGraphicPart
|
||||
void setSecondEndLength(const qreal &l);
|
||||
|
||||
protected:
|
||||
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
@@ -248,6 +248,20 @@ void PartPolygon::setClosed(bool close)
|
||||
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
|
||||
* Handle mouse press event
|
||||
@@ -255,7 +269,10 @@ void PartPolygon::setClosed(bool close)
|
||||
*/
|
||||
void PartPolygon::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (isSelected() && event->button() == Qt::LeftButton)
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
if(isSelected())
|
||||
{
|
||||
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_polygon);
|
||||
|
||||
@@ -263,11 +280,11 @@ void PartPolygon::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -296,6 +313,9 @@ void PartPolygon::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
*/
|
||||
void PartPolygon::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton)
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
|
||||
if (m_handler_index >= 0)
|
||||
{
|
||||
m_undo_command->setNewValue(QVariant(m_polygon));
|
||||
@@ -320,7 +340,7 @@ QPainterPath PartPolygon::shape() const
|
||||
shape.lineTo(m_polygon.first());
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(penWeight());
|
||||
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||
shape = pps.createStroke(shape);
|
||||
|
||||
if (isSelected())
|
||||
|
||||
@@ -85,6 +85,7 @@ class PartPolygon : public CustomElementGraphicPart
|
||||
void setClosed (bool close);
|
||||
|
||||
protected:
|
||||
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
@@ -161,7 +161,7 @@ QPainterPath PartRectangle::shape() const
|
||||
shape.addRect(m_rect);
|
||||
|
||||
QPainterPathStroker pps;
|
||||
pps.setWidth(penWeight());
|
||||
pps.setWidth(m_hovered? penWeight()+SHADOWS_HEIGHT : penWeight());
|
||||
shape = pps.createStroke(shape);
|
||||
|
||||
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))));
|
||||
}
|
||||
|
||||
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
|
||||
* Handle mouse press event
|
||||
@@ -244,7 +267,10 @@ void PartRectangle::handleUserTransformation(const QRectF &initial_selection_rec
|
||||
*/
|
||||
void PartRectangle::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (isSelected() && event->button() == Qt::LeftButton)
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
if(isSelected())
|
||||
{
|
||||
m_handler_index = m_handler.pointIsHoverHandler(event->pos(), m_handler.pointsForRect(m_rect));
|
||||
|
||||
@@ -253,11 +279,11 @@ void PartRectangle::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -285,6 +311,9 @@ void PartRectangle::mouseMoveEvent(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_rect.isValid())
|
||||
|
||||
@@ -75,6 +75,7 @@ class PartRectangle : public CustomElementGraphicPart
|
||||
virtual void handleUserTransformation(const QRectF &, const QRectF &);
|
||||
|
||||
protected:
|
||||
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
Reference in New Issue
Block a user