/*
    SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#ifndef BUTTON_H
#define BUTTON_H

#include <QIcon>
#include <QFont>
#include <QSize>
#include <QPointer>
#include <QWidget>
#include <QGraphicsItem>

#include "welcomescreen.h"
#include "animation.h"

class ButtonAnimation;

class Button : public QGraphicsObject
{
Q_OBJECT
    enum {
        BRIGHTNESS_NORMAL = 0,
        BRIGHTNESS_HOVER = 120,
        BRIGHTNESS_DOWN = 180
    };
    QIcon m_icon;
    QFont m_font;
    QString m_text;
    QSize m_size;
    int m_text_width;
    
    bool m_fixed_width;
    bool m_down;
    bool m_hover;
    double m_brightness;
    QPointer<ButtonAnimation> m_animation;
    
    QWidget* m_editor;
    
    void computeSize();
public:
    Button(QGraphicsItem* parent, const QIcon& icon, 
           const QFont& font, const QString& text);
    ~Button() override;
           
    void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
    QRectF boundingRect() const override;
    
    QSize size() const;
 
    void onMousePress();
    void onMouseRelease();
    void onMouseMove();
    void onMouseLeave();
    bool onClicked();
    
    void setText(const QString& text);
    void setBrightness(double value);
    double brightness() const;

    void setWidth(int width);
Q_SIGNALS:
    void clicked();
    void needsUpdate();
};

class ButtonAnimation : public Animation
{
Q_OBJECT
public:
    Button* m_button;
    int m_brightness;
    static double m_speed;
    int m_last;
public:
    ButtonAnimation(Button* button, int brightness);
    ~ButtonAnimation() override;
    void start(int t) override;
    bool step(int t) override;
    virtual void abort();
    
    void setBrightness(int value);
};

#endif // BUTTON_H
