#ifndef KQUICKGRIDVIEW_H
#define KQUICKGRIDVIEW_H

#include <QtQuick/private/qtquickglobal_p.h>

#include "kquickitemview.h"

QT_BEGIN_NAMESPACE

class KQuickGridViewAttached;
class KQuickGridViewPrivate;
class KQuickGridView : public KQuickItemView
{
    Q_OBJECT
    Q_DECLARE_PRIVATE(KQuickGridView)

    Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
    Q_PROPERTY(qreal cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged)
    Q_PROPERTY(qreal cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged)

    Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)

    Q_CLASSINFO("DefaultProperty", "data")

public:
    enum Flow {
        FlowLeftToRight = LeftToRight,
        FlowTopToBottom = TopToBottom
    };
    Q_ENUM(Flow)

    KQuickGridView(QQuickItem *parent=nullptr);
    ~KQuickGridView();

    void setHighlightFollowsCurrentItem(bool) override;
    void setHighlightMoveDuration(int) override;

    Flow flow() const;
    void setFlow(Flow);

    qreal cellWidth() const;
    void setCellWidth(qreal);

    qreal cellHeight() const;
    void setCellHeight(qreal);

    enum SnapMode { NoSnap, SnapToRow, SnapOneRow };
    Q_ENUM(SnapMode)
    SnapMode snapMode() const;
    void setSnapMode(SnapMode mode);

    static KQuickGridViewAttached *qmlAttachedProperties(QObject *);

public Q_SLOTS:
    void moveCurrentIndexUp();
    void moveCurrentIndexDown();
    void moveCurrentIndexLeft();
    void moveCurrentIndexRight();

Q_SIGNALS:
    void cellWidthChanged();
    void cellHeightChanged();
    void highlightMoveDurationChanged();
    void flowChanged();
    void snapModeChanged();

protected:
    void viewportMoved(Qt::Orientations) override;
    void keyPressEvent(QKeyEvent *) override;
    void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
    void initItem(int index, QObject *item) override;
};

class KQuickGridViewAttached : public KQuickItemViewAttached
{
    Q_OBJECT
public:
    KQuickGridViewAttached(QObject *parent)
        : KQuickItemViewAttached(parent) {}
    ~KQuickGridViewAttached() {}
};


QT_END_NAMESPACE

QML_DECLARE_TYPE(KQuickGridView)
QML_DECLARE_TYPEINFO(KQuickGridView, QML_HAS_ATTACHED_PROPERTIES)


#endif // KQUICKGRIDVIEW_H
