Graphics item handler is bigger when overred

This commit is contained in:
joshua
2022-01-04 18:41:46 +01:00
parent ae9faa2192
commit 1a75eb19d0
2 changed files with 53 additions and 6 deletions

View File

@@ -19,6 +19,7 @@
#include <QPainter>
#include <QDebug>
#include <utility>
#include <QPropertyAnimation>
/**
@brief QetGraphicsHandlerItem::QetGraphicsHandlerItem
@@ -26,6 +27,7 @@
*/
QetGraphicsHandlerItem::QetGraphicsHandlerItem(qreal size)
{
setAcceptHoverEvents(true);
setFlag(QGraphicsItem::ItemIgnoresTransformations);
setSize(size);
}
@@ -33,9 +35,9 @@ QetGraphicsHandlerItem::QetGraphicsHandlerItem(qreal size)
void QetGraphicsHandlerItem::setSize(qreal size)
{
prepareGeometryChange();
m_size = size;
m_handler_rect.setRect(0-m_size/2, 0-m_size/2, m_size, m_size);
m_br.setRect(-1-m_size/2, -1-m_size/2, m_size+2, m_size+2);
m_current_size = m_original_size = size;
m_handler_rect.setRect(0-m_current_size/2, 0-m_current_size/2, m_current_size, m_current_size);
m_br.setRect(-1-m_current_size/2, -1-m_current_size/2, m_current_size+2, m_current_size+2);
}
/**
@@ -84,6 +86,38 @@ void QetGraphicsHandlerItem::paint(QPainter *painter,
painter->restore();
}
void QetGraphicsHandlerItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
auto animation_ = new QPropertyAnimation(this, "currentSize");
animation_->setStartValue(m_original_size);
animation_->setEndValue(m_original_size*1.5);
animation_->setDuration(200);
animation_->setEasingCurve(QEasingCurve::OutBack);
animation_->start(QAbstractAnimation::DeleteWhenStopped);
}
void QetGraphicsHandlerItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
auto animation_ = new QPropertyAnimation(this, "currentSize");
animation_->setStartValue(m_current_size);
animation_->setEndValue(m_original_size);
animation_->setDuration(200);
animation_->setEasingCurve(QEasingCurve::OutBack);
animation_->start(QAbstractAnimation::DeleteWhenStopped);
}
void QetGraphicsHandlerItem::setCurrentSize(qreal size)
{
prepareGeometryChange();
m_current_size = size;
m_handler_rect.setRect(0-m_current_size/2, 0-m_current_size/2, m_current_size, m_current_size);
m_br.setRect(-1-m_current_size/2, -1-m_current_size/2, m_current_size+2, m_current_size+2);
}
/**
@brief QetGraphicsHandlerItem::handlerForPoint
@param points