Commit 7bfa1ee4 authored by Frederik Christiani's avatar Frederik Christiani
Browse files

Merge branch 'alex.diev_small-issues' into 'master'

Dragged object does not follow mouse fix

Closes #56

See merge request esa/taste3!73
parents 64628b46 971a3102
Pipeline #1475 failed with stage
......@@ -243,48 +243,44 @@ void InteractiveObject::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void InteractiveObject::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (!m_clickPos.isNull())
onManualMoveProgress(GripPoint::Center, mapToParent(event->lastPos()), mapToParent(event->pos()));
onManualMoveProgress(GripPoint::Center, event->lastScenePos(), event->scenePos());
ClickNotifierItem::mouseMoveEvent(event);
}
void InteractiveObject::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
m_clickPos = mapToParent(event->pos());
onManualMoveStart(GripPoint::Center, m_clickPos);
onManualMoveStart(GripPoint::Center, event->scenePos());
ClickNotifierItem::mousePressEvent(event);
}
void InteractiveObject::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (!m_clickPos.isNull())
onManualMoveFinish(GripPoint::Center, m_clickPos, mapToParent(event->pos()));
m_clickPos = QPointF();
onManualMoveFinish(GripPoint::Center, event->buttonDownScenePos(event->button()), event->scenePos());
ClickNotifierItem::mouseReleaseEvent(event);
}
void InteractiveObject::onManualMoveStart(GripPoint::Location grip, const QPointF &at)
{
Q_UNUSED(grip);
Q_UNUSED(at);
if (grip == GripPoint::Center)
m_clickPos = mapFromScene(at);
}
void InteractiveObject::onManualMoveProgress(GripPoint::Location grip, const QPointF &from, const QPointF &to)
{
if (!scene())
return;
Q_UNUSED(from);
if (grip != GripPoint::Location::Center)
if (!scene() || grip != GripPoint::Location::Center || m_clickPos.isNull())
return;
const QPointF delta { to - from };
QPointF newPos = pos() + delta;
QPointF newPos = mapToParent(mapFromScene(to) - m_clickPos);
if (parentItem()) {
const QRectF contentRect = parentItem()->boundingRect();
if (newPos.x() < contentRect.left())
newPos.setX(contentRect.left());
else if ((newPos.x() + m_boundingRect.width()) > contentRect.right())
newPos.setX(contentRect.right() - m_boundingRect.width());
if (newPos.y() < contentRect.top())
newPos.setY(contentRect.top());
else if ((newPos.y() + m_boundingRect.height()) > contentRect.bottom())
......@@ -304,6 +300,8 @@ void InteractiveObject::onManualMoveFinish(GripPoint::Location grip, const QPoin
Q_UNUSED(grip);
Q_UNUSED(pressedAt);
Q_UNUSED(releasedAt);
m_clickPos = QPointF();
}
void InteractiveObject::onManualResizeStart(GripPoint::Location grip, const QPointF &at)
......
......@@ -115,6 +115,7 @@ protected:
HighlightRectItem *createHighlighter();
protected:
QPointer<GripPointsHandler> m_gripPoints;
QRectF m_boundingRect;
bool m_hovered = false;
......
......@@ -35,7 +35,6 @@ static const QList<Qt::Alignment> sides = { Qt::AlignLeft, Qt::AlignTop, Qt::Ali
namespace taste3 {
namespace aadl {
AADLInterfaceGraphicsItem::AADLInterfaceGraphicsItem(AADLObjectIface *entity, QGraphicsItem *parent)
: InteractiveObject(entity, parent)
, m_iface(new QGraphicsPathItem(this))
......@@ -259,5 +258,34 @@ void AADLInterfaceGraphicsItem::paint(QPainter *painter, const QStyleOptionGraph
Q_UNUSED(widget);
}
void AADLInterfaceGraphicsItem::onManualMoveProgress(GripPoint::Location grip, const QPointF &from, const QPointF &to)
{
Q_UNUSED(from);
if (!scene() || grip != GripPoint::Location::Center || m_clickPos.isNull())
return;
QPointF newPos = mapToParent(mapFromScene(to) - m_clickPos);
if (parentItem()) {
const QRectF contentRect = parentItem()->boundingRect();
if (newPos.x() < contentRect.left())
newPos.setX(contentRect.left());
else if ((newPos.x()) > contentRect.right())
newPos.setX(contentRect.right());
if (newPos.y() < contentRect.top())
newPos.setY(contentRect.top());
else if ((newPos.y()) > contentRect.bottom())
newPos.setY(contentRect.bottom());
}
setPos(newPos);
rebuildLayout();
updateGripPoints();
Q_EMIT needUpdateLayout();
}
} // namespace aadl
} // namespace taste3
......@@ -54,6 +54,7 @@ protected:
void onSelectionChanged(bool isSelected) override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
void onManualMoveProgress(GripPoint::Location grip, const QPointF &from, const QPointF &to) override;
private:
QGraphicsPathItem *m_iface = nullptr;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment