2017-07-21 16:21:34 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "QskGridBox.h"
|
2019-06-19 12:08:45 +00:00
|
|
|
#include "QskGridLayoutEngine.h"
|
|
|
|
#include "QskLayoutConstraint.h"
|
|
|
|
#include "QskEvent.h"
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
static void qskSetItemActive( QObject* receiver, const QQuickItem* item, bool on )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
if ( ( item == nullptr ) || ( qskControlCast( item ) != nullptr ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
For QQuickItems not being derived from QskControl we manually
|
|
|
|
send QEvent::LayoutRequest events.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( on )
|
|
|
|
{
|
|
|
|
auto sendLayoutRequest =
|
|
|
|
[receiver]()
|
|
|
|
{
|
|
|
|
QEvent event( QEvent::LayoutRequest );
|
|
|
|
QCoreApplication::sendEvent( receiver, &event );
|
|
|
|
};
|
|
|
|
|
|
|
|
QObject::connect( item, &QQuickItem::implicitWidthChanged,
|
|
|
|
receiver, sendLayoutRequest );
|
|
|
|
|
|
|
|
QObject::connect( item, &QQuickItem::implicitHeightChanged,
|
|
|
|
receiver, sendLayoutRequest );
|
|
|
|
|
|
|
|
QObject::connect( item, &QQuickItem::visibleChanged,
|
|
|
|
receiver, sendLayoutRequest );
|
|
|
|
}
|
|
|
|
else
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
QObject::disconnect( item, &QQuickItem::implicitWidthChanged, receiver, nullptr );
|
|
|
|
QObject::disconnect( item, &QQuickItem::implicitHeightChanged, receiver, nullptr );
|
|
|
|
QObject::disconnect( item, &QQuickItem::visibleChanged, receiver, nullptr );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
2019-06-19 12:08:45 +00:00
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
class QskGridBox::PrivateData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QskGridLayoutEngine engine;
|
2017-07-21 16:21:34 +00:00
|
|
|
};
|
|
|
|
|
2018-08-03 06:15:28 +00:00
|
|
|
QskGridBox::QskGridBox( QQuickItem* parent )
|
2019-06-19 12:08:45 +00:00
|
|
|
: QskBox( false, parent )
|
2018-08-03 06:15:28 +00:00
|
|
|
, m_data( new PrivateData() )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QskGridBox::~QskGridBox()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void QskGridBox::addItem( QQuickItem* item,
|
|
|
|
int row, int column, int rowSpan, int columnSpan,
|
|
|
|
Qt::Alignment alignment )
|
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
if ( item == nullptr )
|
|
|
|
return;
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
if ( item->parent() == nullptr )
|
|
|
|
item->setParent( this );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
if ( item->parentItem() != this )
|
|
|
|
item->setParentItem( this );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
qskSetItemActive( this, item, true );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
// What about the focus tab chain - TODO ... ????
|
|
|
|
// check if item is already inserted ???
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
m_data->engine.insertItem(
|
|
|
|
item, row, column, rowSpan, columnSpan, alignment );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
resetImplicitSize();
|
|
|
|
polish();
|
2017-07-21 16:21:34 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::removeAt( int index )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
auto& engine = m_data->engine;
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
if ( auto item = engine.itemAt( index ) )
|
|
|
|
qskSetItemActive( this, item, false );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
engine.removeAt( index );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
resetImplicitSize();
|
|
|
|
polish();
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::removeItem( const QQuickItem* item )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
removeAt( indexOf( item ) );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::clear( bool autoDelete )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-07-17 15:54:16 +00:00
|
|
|
for ( int i = count() - 1; i >= 0; i-- )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
auto item = itemAtIndex( i );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
removeAt( i );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
if( item )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
if( autoDelete && ( item->parent() == this ) )
|
|
|
|
delete item;
|
|
|
|
else
|
|
|
|
item->setParentItem( nullptr );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-17 15:54:16 +00:00
|
|
|
int QskGridBox::count() const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
return m_data->engine.itemCount();
|
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
int QskGridBox::rowCount() const
|
|
|
|
{
|
|
|
|
return m_data->engine.rowCount();
|
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
int QskGridBox::columnCount() const
|
|
|
|
{
|
|
|
|
return m_data->engine.columnCount();
|
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
QQuickItem* QskGridBox::itemAtIndex( int index ) const
|
|
|
|
{
|
|
|
|
return m_data->engine.itemAt( index );
|
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
int QskGridBox::indexOf( const QQuickItem* item ) const
|
|
|
|
{
|
|
|
|
return m_data->engine.indexOf( item );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
QQuickItem* QskGridBox::itemAt( int row, int column ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
return m_data->engine.itemAt( row, column );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
int QskGridBox::indexAt( int row, int column ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
return m_data->engine.indexAt( row, column );
|
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
int QskGridBox::rowOfIndex( int index ) const
|
|
|
|
{
|
|
|
|
return m_data->engine.rowOfIndex( index );
|
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
int QskGridBox::rowSpanOfIndex( int index ) const
|
|
|
|
{
|
|
|
|
return m_data->engine.rowSpanOfIndex( index );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
int QskGridBox::columnOfIndex( int index ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
return m_data->engine.columnOfIndex( index );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
int QskGridBox::columnSpanOfIndex( int index ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
return m_data->engine.columnSpanOfIndex( index );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::setSpacing( Qt::Orientations orientations, qreal spacing )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
|
|
|
spacing = qMax( spacing, 0.0 );
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
bool doUpdate = false;
|
|
|
|
|
|
|
|
auto& engine = m_data->engine;
|
|
|
|
|
|
|
|
for ( const auto o : { Qt::Horizontal, Qt::Vertical } )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
if ( orientations & o )
|
|
|
|
{
|
|
|
|
if ( spacing != engine.spacing( o ) )
|
|
|
|
{
|
|
|
|
engine.setSpacing( o, spacing );
|
|
|
|
doUpdate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
if ( doUpdate )
|
|
|
|
{
|
|
|
|
resetImplicitSize();
|
|
|
|
polish();
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::resetSpacing( Qt::Orientations orientations )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
for ( const auto o : { Qt::Horizontal, Qt::Vertical } )
|
|
|
|
{
|
|
|
|
if ( orientations & o )
|
|
|
|
setSpacing( o, QskGridLayoutEngine::defaultSpacing( o ) );
|
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
qreal QskGridBox::spacing( Qt::Orientation orientation ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
return m_data->engine.spacing( orientation );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QskGridBox::setRowSpacing( int row, qreal spacing )
|
|
|
|
{
|
|
|
|
spacing = qMax( spacing, 0.0 );
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
auto& engine = m_data->engine;
|
|
|
|
|
|
|
|
if ( spacing != engine.spacingAt( Qt::Vertical, row ) )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
engine.setSpacingAt( Qt::Vertical, row, spacing );
|
|
|
|
polish();
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal QskGridBox::rowSpacing( int row ) const
|
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
return m_data->engine.spacingAt( Qt::Vertical, row );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QskGridBox::setColumnSpacing( int column, qreal spacing )
|
|
|
|
{
|
|
|
|
spacing = qMax( spacing, 0.0 );
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
auto& engine = m_data->engine;
|
|
|
|
|
|
|
|
if ( spacing != engine.spacingAt( Qt::Horizontal, column ) )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
engine.setSpacingAt( Qt::Horizontal, column, spacing );
|
|
|
|
polish();
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal QskGridBox::columnSpacing( int column ) const
|
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
return m_data->engine.spacingAt( Qt::Horizontal, column );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QskGridBox::setRowStretchFactor( int row, int stretch )
|
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
auto& engine = m_data->engine;
|
|
|
|
|
|
|
|
if ( stretch != engine.stretchFactorAt( Qt::Vertical, row ) )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
engine.setStretchFactorAt( Qt::Vertical, row, stretch );
|
|
|
|
polish();
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int QskGridBox::rowStretchFactor( int row ) const
|
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
return m_data->engine.stretchFactorAt( Qt::Vertical, row );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QskGridBox::setColumnStretchFactor( int column, int stretch )
|
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
auto& engine = m_data->engine;
|
|
|
|
|
|
|
|
if ( stretch != engine.stretchFactorAt( Qt::Horizontal, column ) )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
engine.setStretchFactorAt( Qt::Horizontal, column, stretch );
|
|
|
|
polish();
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int QskGridBox::columnStretchFactor( int column ) const
|
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
return m_data->engine.stretchFactorAt( Qt::Horizontal, column );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::setRowFixedHeight( int row, qreal height )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
setRowSizeHint( row, Qt::MinimumSize, height );
|
|
|
|
setRowSizeHint( row, Qt::MaximumSize, height );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::setColumnFixedWidth( int column, qreal width )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
setColumnSizeHint( column, Qt::MinimumSize, width );
|
|
|
|
setColumnSizeHint( column, Qt::MaximumSize, width );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::setRowAlignment( int row, Qt::Alignment alignment )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
auto& engine = m_data->engine;
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
if ( engine.alignmentAt( Qt::Vertical, row ) != alignment )
|
|
|
|
{
|
|
|
|
engine.setAlignmentAt( Qt::Vertical, row, alignment );
|
|
|
|
polish();
|
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
Qt::Alignment QskGridBox::rowAlignment( int row ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
return m_data->engine.alignmentAt( Qt::Vertical, row );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::setColumnAlignment( int column, Qt::Alignment alignment )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
auto& engine = m_data->engine;
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
if ( engine.alignmentAt( Qt::Horizontal, column ) != alignment )
|
|
|
|
{
|
|
|
|
engine.setAlignmentAt( Qt::Horizontal, column, alignment );
|
|
|
|
polish();
|
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
Qt::Alignment QskGridBox::columnAlignment( int column ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
return m_data->engine.alignmentAt( Qt::Horizontal, column );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::setAlignment( const QQuickItem* item, Qt::Alignment alignment )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
auto& engine = m_data->engine;
|
|
|
|
|
|
|
|
if ( engine.alignmentOf( item ) != alignment )
|
|
|
|
{
|
|
|
|
engine.setAlignmentOf( item, alignment );
|
|
|
|
polish();
|
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
Qt::Alignment QskGridBox::alignment( const QQuickItem* item ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
return m_data->engine.alignmentOf( item );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::setRetainSizeWhenHidden( const QQuickItem* item, bool on )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
auto& engine = m_data->engine;
|
|
|
|
|
|
|
|
if ( engine.retainSizeWhenHiddenOf( item ) != on )
|
|
|
|
{
|
|
|
|
engine.setRetainSizeWhenHiddenOf( item, on );
|
|
|
|
invalidate();
|
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
bool QskGridBox::retainSizeWhenHidden( const QQuickItem* item ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
return m_data->engine.retainSizeWhenHiddenOf( item );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::setRowSizeHint( int row, Qt::SizeHint which, qreal height )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
auto& engine = m_data->engine;
|
|
|
|
|
|
|
|
if ( height != engine.rowSizeHint( row, which ) )
|
|
|
|
{
|
|
|
|
engine.setRowSizeHint( row, which, height );
|
|
|
|
polish();
|
|
|
|
}
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
qreal QskGridBox::rowSizeHint( int row, Qt::SizeHint which ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
return m_data->engine.rowSizeHint( row, which );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::setColumnSizeHint( int column, Qt::SizeHint which, qreal width )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
auto& engine = m_data->engine;
|
|
|
|
|
|
|
|
if ( width != engine.columnSizeHint( column, which ) )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
engine.setColumnSizeHint( column, which, width );
|
|
|
|
polish();
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
qreal QskGridBox::columnSizeHint( int column, Qt::SizeHint which ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
return m_data->engine.columnSizeHint( column, which );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::invalidate()
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
m_data->engine.invalidate();
|
|
|
|
|
|
|
|
resetImplicitSize();
|
|
|
|
polish();
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::updateLayout()
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-23 10:53:38 +00:00
|
|
|
if ( !maybeUnresized() )
|
|
|
|
m_data->engine.setGeometries( layoutRect() );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
QSizeF QskGridBox::contentsSizeHint() const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-07-17 15:54:16 +00:00
|
|
|
if ( count() == 0 )
|
2019-06-19 12:08:45 +00:00
|
|
|
return QSizeF( 0, 0 );
|
|
|
|
|
|
|
|
return m_data->engine.sizeHint( Qt::PreferredSize, QSizeF() );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
qreal QskGridBox::heightForWidth( qreal width ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
auto constrainedHeight =
|
|
|
|
[this]( QskLayoutConstraint::Type, const QskControl*, qreal width )
|
|
|
|
{
|
|
|
|
return m_data->engine.heightForWidth( width );
|
|
|
|
};
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
return QskLayoutConstraint::constrainedMetric(
|
|
|
|
QskLayoutConstraint::HeightForWidth, this, width, constrainedHeight );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
qreal QskGridBox::widthForHeight( qreal height ) const
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
auto constrainedWidth =
|
|
|
|
[this]( QskLayoutConstraint::Type, const QskControl*, qreal height )
|
|
|
|
{
|
|
|
|
return m_data->engine.widthForHeight( height );
|
|
|
|
};
|
|
|
|
|
|
|
|
return QskLayoutConstraint::constrainedMetric(
|
|
|
|
QskLayoutConstraint::WidthForHeight, this, height, constrainedWidth );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::geometryChangeEvent( QskGeometryChangeEvent* event )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
Inherited::geometryChangeEvent( event );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
if ( event->isResized() )
|
|
|
|
polish();
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void QskGridBox::itemChange( ItemChange change, const ItemChangeData& value )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
Inherited::itemChange( change, value );
|
|
|
|
|
|
|
|
switch ( change )
|
|
|
|
{
|
|
|
|
case ItemChildRemovedChange:
|
|
|
|
{
|
|
|
|
removeItem( value.item );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QQuickItem::ItemVisibleHasChanged:
|
|
|
|
{
|
|
|
|
if ( value.boolValue )
|
|
|
|
polish();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QQuickItem::ItemSceneChange:
|
|
|
|
{
|
|
|
|
if ( value.window )
|
|
|
|
polish();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QskGridBox::event( QEvent* event )
|
|
|
|
{
|
|
|
|
switch ( event->type() )
|
2017-07-21 16:21:34 +00:00
|
|
|
{
|
2019-06-19 12:08:45 +00:00
|
|
|
case QEvent::LayoutRequest:
|
|
|
|
{
|
|
|
|
invalidate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QEvent::LayoutDirectionChange:
|
|
|
|
{
|
|
|
|
m_data->engine.setVisualDirection(
|
|
|
|
layoutMirroring() ? Qt::RightToLeft : Qt::LeftToRight );
|
|
|
|
|
|
|
|
polish();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QEvent::ContentsRectChange:
|
|
|
|
{
|
|
|
|
polish();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
2019-06-19 12:08:45 +00:00
|
|
|
|
|
|
|
return Inherited::event( event );
|
2017-07-21 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_QskGridBox.cpp"
|