auto reparenting the focus indicator to be always below the most inner
clip
This commit is contained in:
parent
b80aed9c92
commit
ebe332c14e
|
@ -22,7 +22,7 @@ static void qskSetupGeometryConnections(
|
||||||
}
|
}
|
||||||
|
|
||||||
QskFocusIndicator::QskFocusIndicator( QQuickItem* parent ):
|
QskFocusIndicator::QskFocusIndicator( QQuickItem* parent ):
|
||||||
Inherited( parent )
|
Inherited( parent ) // parentItem() might change, but parent() stays
|
||||||
{
|
{
|
||||||
setTransparentForPositioner( true );
|
setTransparentForPositioner( true );
|
||||||
resetConnections();
|
resetConnections();
|
||||||
|
@ -43,30 +43,58 @@ void QskFocusIndicator::onFocusItemChanged()
|
||||||
{
|
{
|
||||||
disconnect( this, SLOT( onFocusItemGeometryChanged() ) );
|
disconnect( this, SLOT( onFocusItemGeometryChanged() ) );
|
||||||
|
|
||||||
const QQuickItem* focusItem = window() ? window()->activeFocusItem() : nullptr;
|
if ( window() == nullptr )
|
||||||
|
return;
|
||||||
|
|
||||||
if ( focusItem )
|
const QQuickItem* focusItem = window()->activeFocusItem();
|
||||||
|
if ( ( focusItem == nullptr ) || ( focusItem == window()->contentItem() ) )
|
||||||
{
|
{
|
||||||
qskSetupGeometryConnections( focusItem,
|
/*
|
||||||
this, SLOT(onFocusItemGeometryChanged()) );
|
We might get here, when the previously focused item was destroyed.
|
||||||
|
Might happen in common situations, like when a subwindow
|
||||||
|
was closed. We put ourself below the root item then.
|
||||||
|
*/
|
||||||
|
|
||||||
// we might have to raise on top, but the code below
|
if ( parentItem() != window()->contentItem() )
|
||||||
// might not be good enough to cover all corner cases ??
|
{
|
||||||
|
setParentItem( window()->contentItem() );
|
||||||
|
updateFocusFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qskSetupGeometryConnections( focusItem,
|
||||||
|
this, SLOT( onFocusItemGeometryChanged() ) );
|
||||||
|
|
||||||
const QQuickItem* item = focusItem;
|
const QQuickItem* item = focusItem;
|
||||||
while ( item->parentItem() )
|
while ( item->parentItem() )
|
||||||
{
|
{
|
||||||
if ( item->parentItem() == parentItem() )
|
auto itemParent = item->parentItem();
|
||||||
|
|
||||||
|
if ( itemParent == window()->contentItem() || itemParent->clip() )
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
When the focus item is clipped - maybe because of being at the
|
||||||
|
border of a scrollarea - the focus indicator needs to be
|
||||||
|
clipped as well. The easiest way to have this is to put us
|
||||||
|
below the item having the clip.
|
||||||
|
*/
|
||||||
|
setParentItem( itemParent );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( itemParent == parentItem() )
|
||||||
|
{
|
||||||
|
// We want to be on top, but do we cover all corner cases ???
|
||||||
|
|
||||||
setZ( item->z() + 10e-6 );
|
setZ( item->z() + 10e-6 );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
item = item->parentItem();
|
item = itemParent;
|
||||||
|
|
||||||
qskSetupGeometryConnections( item,
|
qskSetupGeometryConnections( item,
|
||||||
this, SLOT(onFocusItemGeometryChanged()) );
|
this, SLOT( onFocusItemGeometryChanged() ) );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFocusFrame();
|
updateFocusFrame();
|
||||||
|
@ -91,7 +119,7 @@ QRectF QskFocusIndicator::focusRect() const
|
||||||
if ( window() && parentItem() )
|
if ( window() && parentItem() )
|
||||||
{
|
{
|
||||||
const QQuickItem* focusItem = window()->activeFocusItem();
|
const QQuickItem* focusItem = window()->activeFocusItem();
|
||||||
if ( focusItem )
|
if ( focusItem && ( focusItem != window()->contentItem() ) )
|
||||||
return parentItem()->mapRectFromItem( focusItem, focusItem->boundingRect() );
|
return parentItem()->mapRectFromItem( focusItem, focusItem->boundingRect() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue