//
// Created by iaom on 2025/9/12.
//

#ifndef REGION_H
#define REGION_H

#include <QObject>
#include <QQmlListProperty>
#include <QRegion>

namespace UkuiQuick {

class RectRegionPrivate;
class RectRegion : public QObject
{
    Q_OBJECT
    Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged)
    Q_PROPERTY(int y READ y WRITE setY NOTIFY yChanged)
    Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
    Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
    Q_PROPERTY(int radius READ radius WRITE setRadius NOTIFY radiusChanged)
public:
    explicit RectRegion(QObject *parent = nullptr);
    ~RectRegion();
    void setX(int x);
    int x() const;

    void setY(int y);
    int y() const;

    void setWidth(int width);
    int width() const;

    void setHeight(int height);
    int height() const;

    void setRadius(int radius);
    int radius() const;

Q_SIGNALS:
    void xChanged();
    void yChanged();
    void widthChanged();
    void heightChanged();
    void radiusChanged();

private:
    RectRegionPrivate *d = nullptr;
};

class RegionPrivate;
class Region : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QRegion region READ region NOTIFY regionChanged)

public:
    explicit Region(QObject *parent = nullptr);
    Q_INVOKABLE void appendRect(UkuiQuick::RectRegion *rect);
    Q_INVOKABLE void removeRect(UkuiQuick::RectRegion *rect);
    Q_INVOKABLE void clear();
    Q_INVOKABLE  QRegion region() const;

Q_SIGNALS:
    void regionChanged();
protected:
    bool event(QEvent *event) override;

private:
    RegionPrivate *d = nullptr;
};

}

#endif //REGION_H
