@ -45,9 +45,9 @@ EventsSink::~EventsSink()
{
}
QQuickItem * EventsSink : : origin Item( ) const
QQuickItem * EventsSink : : origin Parent Item( ) const
{
return m_origin Item;
return m_origin Parent Item;
}
QQuickItem * EventsSink : : destinationItem ( ) const
@ -55,22 +55,21 @@ QQuickItem *EventsSink::destinationItem() const
return m_destinationItem ;
}
void EventsSink : : setSink ( QQuickItem * origin , QQuickItem * destination )
void EventsSink : : setSink ( QQuickItem * origin Parent , QQuickItem * destination )
{
if ( ( m_origin Item = = origin ) & & ( m_destinationItem = = destination ) ) {
if ( ( m_origin Parent Item = = origin Parent ) & & ( m_destinationItem = = destination ) ) {
return ;
}
m_origin Item = origin ;
m_origin Parent Item = origin Parent ;
m_destinationItem = destination ;
emit itemsChanged ( ) ;
}
bool EventsSink : : isActive ( )
{
return ( ( m_origin Item ! = nullptr ) & & ( m_destinationItem ! = nullptr ) ) ;
return ( ( m_origin Parent Item ! = nullptr ) & & ( m_destinationItem ! = nullptr ) ) ;
}
void EventsSink : : release ( )
@ -97,16 +96,14 @@ QEvent *EventsSink::onEvent(QEvent *e)
case QEvent : : DragEnter :
if ( auto de = static_cast < QDragEnterEvent * > ( e ) ) {
QPointF point = de - > posF ( ) ;
QPointF originInternal = m_originItem - > mapFromScene ( point ) ;
if ( m_originItem - > contains ( originInternal ) ) {
if ( originSinksContain ( point ) ) {
auto de2 = new QDragEnterEvent ( positionAdjustedForDestination ( point ) . toPoint ( ) ,
de - > possibleActions ( ) ,
de - > mimeData ( ) ,
de - > mouseButtons ( ) ,
de - > keyboardModifiers ( ) ) ;
sunkevent = de2 ;
} else {
} else if ( ! destinationContains ( point ) ) {
release ( ) ;
}
}
@ -115,9 +112,7 @@ QEvent *EventsSink::onEvent(QEvent *e)
case QEvent : : DragMove :
if ( auto de = static_cast < QDragMoveEvent * > ( e ) ) {
QPointF point = de - > posF ( ) ;
QPointF originInternal = m_originItem - > mapFromScene ( point ) ;
if ( m_originItem - > contains ( originInternal ) ) {
if ( originSinksContain ( point ) ) {
auto de2 = new QDragMoveEvent ( positionAdjustedForDestination ( point ) . toPoint ( ) ,
de - > possibleActions ( ) ,
de - > mimeData ( ) ,
@ -125,7 +120,7 @@ QEvent *EventsSink::onEvent(QEvent *e)
de - > keyboardModifiers ( ) ) ;
sunkevent = de2 ;
} else {
} else if ( ! destinationContains ( point ) ) {
release ( ) ;
}
}
@ -134,9 +129,7 @@ QEvent *EventsSink::onEvent(QEvent *e)
case QEvent : : Drop :
if ( auto de = static_cast < QDropEvent * > ( e ) ) {
QPointF point = de - > posF ( ) ;
QPointF originInternal = m_originItem - > mapFromScene ( point ) ;
if ( m_originItem - > contains ( originInternal ) ) {
if ( originSinksContain ( point ) ) {
auto de2 = new QDropEvent ( positionAdjustedForDestination ( point ) . toPoint ( ) ,
de - > possibleActions ( ) ,
de - > mimeData ( ) ,
@ -144,7 +137,7 @@ QEvent *EventsSink::onEvent(QEvent *e)
de - > keyboardModifiers ( ) ) ;
sunkevent = de2 ;
} else {
} else if ( ! destinationContains ( point ) ) {
release ( ) ;
}
}
@ -153,9 +146,7 @@ QEvent *EventsSink::onEvent(QEvent *e)
case QEvent : : MouseMove :
if ( auto me = dynamic_cast < QMouseEvent * > ( e ) ) {
QPointF originInternal = m_originItem - > mapFromScene ( me - > windowPos ( ) ) ;
if ( m_view - > positioner ( ) & & m_view - > positioner ( ) - > isCursorInsideView ( ) & & m_originItem - > contains ( originInternal ) ) {
if ( m_view - > positioner ( ) & & m_view - > positioner ( ) - > isCursorInsideView ( ) & & originSinksContain ( me - > windowPos ( ) ) ) {
auto positionadjusted = positionAdjustedForDestination ( me - > windowPos ( ) ) ;
auto me2 = new QMouseEvent ( me - > type ( ) ,
positionadjusted ,
@ -164,7 +155,7 @@ QEvent *EventsSink::onEvent(QEvent *e)
me - > button ( ) , me - > buttons ( ) , me - > modifiers ( ) ) ;
sunkevent = me2 ;
} else {
} else if ( ! destinationContains ( me - > windowPos ( ) ) ) {
release ( ) ;
}
}
@ -172,9 +163,7 @@ QEvent *EventsSink::onEvent(QEvent *e)
case QEvent : : MouseButtonPress :
if ( auto me = dynamic_cast < QMouseEvent * > ( e ) ) {
QPointF originInternal = m_originItem - > mapFromScene ( me - > windowPos ( ) ) ;
if ( m_originItem - > contains ( originInternal ) ) {
if ( originSinksContain ( me - > windowPos ( ) ) ) {
auto positionadjusted = positionAdjustedForDestination ( me - > windowPos ( ) ) ;
auto me2 = new QMouseEvent ( me - > type ( ) ,
positionadjusted ,
@ -184,7 +173,7 @@ QEvent *EventsSink::onEvent(QEvent *e)
qDebug ( ) < < " Sunk Event:: sunk event pressed... " ;
sunkevent = me2 ;
} else {
} else if ( ! destinationContains ( me - > windowPos ( ) ) ) {
release ( ) ;
}
}
@ -192,9 +181,7 @@ QEvent *EventsSink::onEvent(QEvent *e)
case QEvent : : MouseButtonRelease :
if ( auto me = dynamic_cast < QMouseEvent * > ( e ) ) {
QPointF originInternal = m_originItem - > mapFromScene ( me - > windowPos ( ) ) ;
if ( m_originItem - > contains ( originInternal ) ) {
if ( originSinksContain ( me - > windowPos ( ) ) ) {
auto positionadjusted = positionAdjustedForDestination ( me - > windowPos ( ) ) ;
auto me2 = new QMouseEvent ( me - > type ( ) ,
positionadjusted ,
@ -203,7 +190,7 @@ QEvent *EventsSink::onEvent(QEvent *e)
me - > button ( ) , me - > buttons ( ) , me - > modifiers ( ) ) ;
sunkevent = me2 ;
} else {
} else if ( ! destinationContains ( me - > windowPos ( ) ) ) {
release ( ) ;
}
}
@ -216,9 +203,8 @@ QEvent *EventsSink::onEvent(QEvent *e)
# else
QPoint pos = we - > position ( ) . toPoint ( ) ;
# endif
QPointF originInternal = m_originItem - > mapFromScene ( pos ) ;
if ( m_originItem- > contains ( originInternal ) ) {
if ( originSinksContain( pos ) ) {
auto positionadjusted = positionAdjustedForDestination ( pos ) ;
auto we2 = new QWheelEvent ( positionadjusted ,
positionadjusted + m_view - > position ( ) ,
@ -226,7 +212,7 @@ QEvent *EventsSink::onEvent(QEvent *e)
we - > orientation ( ) , we - > buttons ( ) , we - > modifiers ( ) , we - > phase ( ) ) ;
sunkevent = we2 ;
} else {
} else if ( ! destinationContains ( pos ) ) {
release ( ) ;
}
}
@ -246,6 +232,25 @@ QPointF EventsSink::positionAdjustedForDestination(const QPointF &point) const
qBound ( destinationRectToScene . top ( ) , point . y ( ) , destinationRectToScene . bottom ( ) ) ) ;
}
bool EventsSink : : destinationContains ( const QPointF & point ) const
{
QRectF destinationRectToScene = m_destinationItem - > mapRectToScene ( QRectF ( 0 , 0 , m_destinationItem - > width ( ) - 1 , m_destinationItem - > height ( ) - 1 ) ) ;
return destinationRectToScene . contains ( point ) ;
}
bool EventsSink : : originSinksContain ( const QPointF & point ) const
{
QRegion originsRegion ;
for ( const auto currentOrigin : m_originParentItem - > childItems ( ) ) {
QRectF currentOriginGeometry = currentOrigin - > mapRectToScene ( QRectF ( 0 , 0 , currentOrigin - > width ( ) , currentOrigin - > height ( ) ) ) ;
originsRegion = originsRegion . united ( currentOriginGeometry . toRect ( ) ) ;
}
return originsRegion . contains ( point . toPoint ( ) ) ;
}
}
}