qskinny/src/layouts/QskIndexedLayoutBox.cpp

113 lines
2.6 KiB
C++
Raw Normal View History

2017-07-21 18:21:34 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
2023-04-06 09:23:37 +02:00
* SPDX-License-Identifier: BSD-3-Clause
2017-07-21 18:21:34 +02:00
*****************************************************************************/
#include "QskIndexedLayoutBox.h"
2018-08-03 08:15:28 +02:00
#include "QskQuick.h"
2018-05-01 12:41:20 +02:00
2017-07-21 18:21:34 +02:00
class QskIndexedLayoutBox::PrivateData
{
2018-08-03 08:15:28 +02:00
public:
PrivateData()
: autoAddChildren( true )
2019-12-03 17:21:56 +01:00
, blockChildAddedRemoved( false )
2017-07-21 18:21:34 +02:00
{
}
bool autoAddChildren : 1;
2019-12-03 17:21:56 +01:00
bool blockChildAddedRemoved : 1;
2017-07-21 18:21:34 +02:00
};
2018-08-03 08:15:28 +02:00
QskIndexedLayoutBox::QskIndexedLayoutBox( QQuickItem* parent )
: QskBox( false, parent )
2018-08-03 08:15:28 +02:00
, m_data( new PrivateData() )
2017-07-21 18:21:34 +02:00
{
// classBegin/componentComplete -> setActive( false/true ) ?
}
QskIndexedLayoutBox::~QskIndexedLayoutBox()
{
}
void QskIndexedLayoutBox::setAutoAddChildren( bool on )
{
if ( on != m_data->autoAddChildren )
{
m_data->autoAddChildren = on;
Q_EMIT autoAddChildrenChanged();
}
}
bool QskIndexedLayoutBox::autoAddChildren() const
{
return m_data->autoAddChildren;
}
void QskIndexedLayoutBox::itemChange(
QQuickItem::ItemChange change, const QQuickItem::ItemChangeData& value )
{
2018-08-03 08:15:28 +02:00
switch ( change )
2017-07-21 18:21:34 +02:00
{
case QQuickItem::ItemChildAddedChange:
{
2019-12-03 17:21:56 +01:00
if ( m_data->autoAddChildren && !m_data->blockChildAddedRemoved )
2017-07-21 18:21:34 +02:00
{
2022-04-08 16:46:20 +02:00
if ( qskPlacementPolicy( value.item ).isEffective() )
autoAddItem( value.item );
2017-07-21 18:21:34 +02:00
}
break;
}
case QQuickItem::ItemChildRemovedChange:
{
2019-12-03 17:21:56 +01:00
if ( !m_data->blockChildAddedRemoved )
autoRemoveItem( value.item );
2017-07-21 18:21:34 +02:00
break;
}
#if 1
case QQuickItem::ItemSceneChange:
{
// when changing the window we should run into polish anyway
if ( value.window )
polish();
break;
}
#endif
2017-07-21 18:21:34 +02:00
default:
{
break;
}
}
2022-03-24 07:59:28 +01:00
Inherited::itemChange( change, value );
2017-07-21 18:21:34 +02:00
}
void QskIndexedLayoutBox::reparentItem( QQuickItem* item )
{
if ( item->parent() == nullptr )
item->setParent( this );
if ( item->parentItem() != this )
{
2019-12-03 17:21:56 +01:00
m_data->blockChildAddedRemoved = true;
item->setParentItem( this );
2019-12-03 17:21:56 +01:00
m_data->blockChildAddedRemoved = false;
}
}
void QskIndexedLayoutBox::unparentItem( QQuickItem* item )
{
if ( item->parentItem() == this )
{
m_data->blockChildAddedRemoved = true;
item->setParentItem( nullptr );
m_data->blockChildAddedRemoved = false;
}
}
2017-07-21 18:21:34 +02:00
#include "moc_QskIndexedLayoutBox.cpp"