/*
    This file is part of Photoflare.

    Photoflare is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Photoflare is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Photoflare.  If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef TOOL_H
#define TOOL_H

#include <QObject>
#include <QPoint>
#include <QRect>
#include <QImage>
#include <QPainter>
#include <QCursor>
#include <QKeyEvent>
#include <QApplication>

class QPaintDevice;

/*!
 * This is the base class for all paint tools
 */
class Tool : public QObject
{
    Q_OBJECT
public:
    explicit Tool(QObject *parent = nullptr);
    ~Tool();

    void setPaintDevice(QPaintDevice *paintDevice);
    QPaintDevice* paintDevice() const;
    void setScale(float scale);
    /*!
     * Use methods below to paint using painter()
     */
    virtual void onMousePress(const QPoint &pos, Qt::MouseButton button);
    virtual void onMouseMove(const QPoint &pos);
    virtual void onMouseRelease(const QPoint &pos);
    virtual void onHover(const QPoint &pos) { Q_UNUSED(pos); }
    virtual void onKeyPressed(QKeyEvent *keyEvent);
    virtual void onKeyReleased(QKeyEvent *keyEvent);
    virtual void disconnect();
    virtual QCursor getCursor();
    virtual void onDeactivated() {}

signals:
    void cursorChanged(QCursor);
    void selectionChanged(QPolygon);
    /*!
     * This signal must be emitted after the tool completes any paint action.
     * When dirtyRect is provided, only that region of the canvas needs refreshing.
     * Pass a null QRect() to indicate the entire image was modified.
     */
    void painted(QPaintDevice *paintDevice, QRect dirtyRect = QRect());
    void overlaid(QPaintDevice *paintDevice, const QImage &overlayImage, QPainter::CompositionMode mode, QRect dirtyRect = QRect());

protected:
    QPaintDevice *m_paintDevice;
    float m_scale;
};

#endif // TOOL_H
