/*
 * Copyright (C) 2022, KylinSoft Co., Ltd.
 *
 * This program 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.
 *
 * This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * Authors: Xin Li <lixin@kylinos.cn>
 */
#ifndef CUSTOMBUTTON_H
#define CUSTOMBUTTON_H

#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QPainter>
#include <QDebug>
#include <QString>

class CustomButton : public QPushButton
{
    Q_OBJECT
public:
    explicit CustomButton(QString normalPicPath, QString hoverPicPath, QString selectedPicPath,
                          QWidget *parent = nullptr);
    ~CustomButton();

    enum BUTTONSTATE {
        NORMAL = 0X01,   //正常状态
        HOVER = 0X02,    //悬浮状态
        SELECTED = 0X04, //选中状态
        GRAY = 0x06
    };

public:
    /**/
    void setImagePath(QString normalImgPath, QString hoverImgPath, QString selectedImgPath);
    void setButtonEnabled(bool isAvailable, bool isMini);

protected:
    void paintEvent(QPaintEvent *);

    void enterEvent(QEvent *) override;
    void leaveEvent(QEvent *) override;
    void mousePressEvent(QMouseEvent *e) override;
    void mouseReleaseEvent(QMouseEvent *e) override;

private:
    QPixmap normalPix;              //正常状态的pix
    QPixmap hoverPix;               //悬浮状态的pix
    QPixmap selectedPix;            //选中状态的pix
    QPixmap grayPix;                //不可点击置灰的pix
    QString m_NormalPicPath = "";   //正常状态的图片资源路径
    QString m_HoverPicPath = "";    //悬浮状态的图片资源路径
    QString m_SelectedPicPath = ""; //选中状态的图片资源路径
    QString m_grayPicPath = "";     //按钮置灰的图片资源路径
    QString m_miniGrayPicPath = ""; // mini按钮置灰的图片资源路径
    BUTTONSTATE m_curState;         //当前状态

    void setNormalPixmap(QString strImagePath);
    void setEnterPixmap(QString strImagePath);
    void setLeavePixmap(QString strImagePath);
    void setPressPixmap(QString strImagePath);
    void setReleasePixmap(QString strImagePath);

    void SetBtnState(BUTTONSTATE state); //设置按钮状态


signals:
};

#endif // CUSTOMBUTTON_H
