/******************************************************************************
 * QSkinny - Copyright (C) The authors
 *           SPDX-License-Identifier: BSD-3-Clause
 *****************************************************************************/

#ifndef QSK_GRID_LAYOUT_ENGINE_H
#define QSK_GRID_LAYOUT_ENGINE_H

#include "QskGlobal.h"
#include "QskLayoutEngine2D.h"

#include <qnamespace.h>
#include <memory>

class QQuickItem;
class QSizeF;
class QRectF;

class QSK_EXPORT QskGridLayoutEngine : public QskLayoutEngine2D
{
  public:
    QskGridLayoutEngine();
    ~QskGridLayoutEngine() override;

    int count() const override final;

    bool setStretchFactor( int pos, int stretch, Qt::Orientation );
    int stretchFactor( int pos, Qt::Orientation ) const;

    bool setRowSizeHint( int row, Qt::SizeHint, qreal height );
    qreal rowSizeHint( int row, Qt::SizeHint ) const;

    bool setColumnSizeHint( int column, Qt::SizeHint, qreal width );
    qreal columnSizeHint( int column, Qt::SizeHint ) const;

    int insertItem( QQuickItem*, const QRect& grid );
    int insertSpacer( const QSizeF&, const QRect& grid );

    bool removeAt( int index );
    bool clear();

    QQuickItem* itemAt( int index ) const;
    QSizeF spacerAt( int index ) const;

    QQuickItem* itemAt( int row, int column ) const;
    int indexAt( int row, int column ) const;

    int indexOf( const QQuickItem* ) const;

    bool setGridAt( int index, const QRect& );
    QRect gridAt( int index ) const;

    QRect effectiveGridAt( int index ) const;

    void transpose();

  private:
    QskSizePolicy sizePolicyAt( int index ) const override final;
    void layoutItems() override;
    int effectiveCount( Qt::Orientation ) const override;

    void invalidateElementCache() override;

    void setupChain( Qt::Orientation, const QskLayoutChain::Segments&,
        QskLayoutChain& ) const override final;

    class PrivateData;
    std::unique_ptr< PrivateData > m_data;
};

#endif
