// SPDX-FileCopyrightText: 2023 Claudio Cambra <claudio.cambra@kde.org>
// SPDX-License-Identifier: LGPL-2.1-or-later

#pragma once

#include <QObject>
#include <QPointF>
#include <QtQmlIntegration>

class QQmlEngine;
class QJSEngine;

class MouseTracker : public QObject
{
    Q_OBJECT
    QML_ELEMENT
    QML_SINGLETON
    Q_PROPERTY(QPointF mousePosition READ mousePosition NOTIFY mousePositionChanged)

public:
    static MouseTracker *instance();
    static MouseTracker *create(QQmlEngine *, QJSEngine *)
    {
        return instance();
    }
    [[nodiscard]] QPointF mousePosition() const;

Q_SIGNALS:
    void mousePositionChanged(QPointF position);
    void mouseButtonReleased(Qt::MouseButton button);

protected:
    [[nodiscard]] bool eventFilter(QObject *watched, QEvent *event) override;

private:
    explicit MouseTracker(QObject *parent = nullptr);

    QPointF m_lastMousePos;
};
