diff options
Diffstat (limited to 'src/plugins/qmldesigner/components/curveeditor/detail/handleitem.cpp')
-rw-r--r-- | src/plugins/qmldesigner/components/curveeditor/detail/handleitem.cpp | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/handleitem.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/handleitem.cpp index e96ebd0d39..33f35e52ac 100644 --- a/src/plugins/qmldesigner/components/curveeditor/detail/handleitem.cpp +++ b/src/plugins/qmldesigner/components/curveeditor/detail/handleitem.cpp @@ -24,6 +24,7 @@ ****************************************************************************/ #include "handleitem.h" +#include "graphicsscene.h" #include "keyframeitem.h" #include "utils.h" @@ -48,8 +49,9 @@ struct HandleGeometry double angle; }; -HandleItem::HandleItem(QGraphicsItem *parent) +HandleItem::HandleItem(QGraphicsItem *parent, HandleItem::Slot slot) : SelectableItem(parent) + , m_slot(slot) , m_style() { setFlag(QGraphicsItem::ItemStacksBehindParent, true); @@ -62,16 +64,31 @@ int HandleItem::type() const return Type; } +HandleItem::Slot HandleItem::slot() const +{ + return m_slot; +} + QRectF HandleItem::boundingRect() const { HandleGeometry geom(pos(), m_style); + return geom.handle; +} - QTransform transform; - transform.rotate(geom.angle); +bool HandleItem::contains(const QPointF &point) const +{ + if (KeyframeItem *parent = qgraphicsitem_cast<KeyframeItem *>(parentItem())) { + HandleGeometry geom(pos(), m_style); + geom.handle.moveCenter(parent->pos() + pos()); + return geom.handle.contains(point); + } + return false; +} - QRectF bounds = bbox(geom.handle, transform); - grow(bounds, -pos()); - return bounds; +void HandleItem::underMouseCallback() +{ + if (auto *gscene = qobject_cast<GraphicsScene *>(scene())) + gscene->handleUnderMouse(this); } void HandleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) @@ -82,7 +99,12 @@ void HandleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option Q_UNUSED(option) Q_UNUSED(widget) - QColor handleColor(isSelected() ? m_style.selectionColor : m_style.color); + QColor handleColor(selected() ? m_style.selectionColor : m_style.color); + + if (activated()) + handleColor = m_style.activeColor; + if (isUnderMouse()) + handleColor = m_style.hoverColor; HandleGeometry geom(pos(), m_style); @@ -109,13 +131,12 @@ QVariant HandleItem::itemChange(QGraphicsItem::GraphicsItemChange change, const { if (change == ItemPositionChange) { if (KeyframeItem *parent = qgraphicsitem_cast<KeyframeItem *>(parentItem())) { - HandleSlot slot = parent->handleSlot(this); QPointF pos = value.toPointF(); - if (slot == HandleSlot::Left) { + if (m_slot == HandleItem::Slot::Left) { if (pos.x() > 0.0) pos.rx() = 0.0; - } else if (slot == HandleSlot::Right) { + } else if (m_slot == HandleItem::Slot::Right) { if (pos.x() < 0.0) pos.rx() = 0.0; } |