/*
   SPDX-FileCopyrightText: 2020-2026 Laurent Montel <montel@kde.org>

   SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include "textaddonswidgets_export.h"
#include <QLayout>
#include <QList>
namespace TextAddonsWidgets
{
/*!
 * \class TextAddonsWidgets::TextAddonsWidgetFlowLayout
 * \brief The TextAddonsWidgetFlowLayout class
 * \author Laurent Montel <montel@kde.org>
 * \inmodule TextAutoGenerateText
 * \inheaderfile TextAddonsWidgets/TextAddonsWidgetFlowLayout
 */
class TEXTADDONSWIDGETS_EXPORT TextAddonsWidgetFlowLayout : public QLayout
{
    Q_OBJECT

public:
    /*!
     */
    explicit TextAddonsWidgetFlowLayout(QWidget *parent = nullptr);
    /*!
     */
    ~TextAddonsWidgetFlowLayout() override;

    /*!
     */
    [[nodiscard]] int horizontalSpacing() const;
    /*!
     */
    void setHorizontalSpacing(int horizontalSpacing);

    /*!
     */
    [[nodiscard]] int verticalSpacing() const;
    /*!
     */
    void setVerticalSpacing(int verticalSpacing);

    /*!
     */
    [[nodiscard]] QSize sizeHint() const override;
    /*!
     */
    [[nodiscard]] QSize minimumSize() const override;

    /*!
     */
    void addItem(QLayoutItem *item) override;
    /*!
     */
    QLayoutItem *itemAt(int index) const override;
    /*!
     */
    QLayoutItem *takeAt(int index) override;
    /*!
     */
    [[nodiscard]] int count() const override;

    /*!
     */
    [[nodiscard]] Qt::Orientations expandingDirections() const override;
    /*!
     */
    [[nodiscard]] bool hasHeightForWidth() const override;
    /*!
     */
    [[nodiscard]] int heightForWidth(int width) const override;

    /*!
     */
    void setGeometry(const QRect &rect) override;

    /*!
     */
    void clearAndDeleteWidgets();

private:
    TEXTADDONSWIDGETS_NO_EXPORT void clear();
    TEXTADDONSWIDGETS_NO_EXPORT int doFlow(QRect rect, bool effective) const;
    QList<QLayoutItem *> mItems;
    int mHorizontalSpacing = -1;
    int mVerticalSpacing = -1;
};
}
