qskinny/src/layouts/QskIndexedLayoutBox.cpp

101 lines
2.3 KiB
C++
Raw Normal View History

2017-07-21 18:21:34 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#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 )
, blockChildAdded( false )
2017-07-21 18:21:34 +02:00
{
}
bool autoAddChildren : 1;
bool blockChildAdded : 1;
};
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:
{
if ( m_data->autoAddChildren && !m_data->blockChildAdded )
{
if ( !qskIsTransparentForPositioner( value.item ) )
autoAddItem( value.item );
2017-07-21 18:21:34 +02:00
}
break;
}
case QQuickItem::ItemChildRemovedChange:
{
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;
}
}
return Inherited::itemChange( change, value );
}
void QskIndexedLayoutBox::reparentItem( QQuickItem* item )
{
if ( item->parent() == nullptr )
item->setParent( this );
if ( item->parentItem() != this )
{
m_data->blockChildAdded = true;
item->setParentItem( this );
m_data->blockChildAdded = false;
}
}
2017-07-21 18:21:34 +02:00
#include "moc_QskIndexedLayoutBox.cpp"