#ifndef CUSTOMMESSAGEBOX_H
#define CUSTOMMESSAGEBOX_H

#include <QDialog>
#include <QPoint>
#include <QMouseEvent>

#include <thread>
#include <unistd.h>
#include "utils/utilsInclude.h"
#include "frame/MaskWidget.h"

namespace Ui {
class CustomMessageBox;
}

// 设在按钮个数
enum MSG_TYPE
{
    SA_OK           = 0,    // 只有一个“确定”按钮，且两秒钟后自动关闭消息窗口
    SA_OKCANCEL     = 1,    // 一个“是”按钮，一个“否”按钮
    SA_OKS          = 2     // 只有一个“确定”按钮，不会自动关闭消息窗口
};

// 设在提示的类型
enum MSG_TIP_TYPE
{
    SA_SUCCESS      = 0,    // 完成
    SA_FAILED       = 1,    // 错误
    SA_WARNING      = 2,    // 警告
    SA_TIPS         = 3,    // 提示
    SA_QUESTION     = 4     // 未知
};


class CustomMessageBox : public QDialog
{
    Q_OBJECT

public:
    explicit CustomMessageBox(QWidget *parent = nullptr,MSG_TYPE nType = SA_OKCANCEL,MSG_TIP_TYPE nTipType = SA_TIPS);
    ~CustomMessageBox();

    static int success(QWidget *parent = nullptr, const QString subTitle = "", const QString text = "");
    static int failure(QWidget *parent = nullptr, const QString subTitle = "", const QString text = "");
    static int warning(QWidget *parent = nullptr, const QString subTitle = "", const QString text = "");
    static int tips(QWidget *parent = nullptr, const QString subTitle = "", const QString text = "");
    static int confirm(QWidget *parent = nullptr, const QString subTitle = "", const QString text = "");

    // 设置提示语
    void setTips(const QString strTips);
    void setSubTitle(const QString subTitle);

private:
    // 设在sec秒后关闭窗体
    void _startTimerClose(int sec = 2);
    // 线程执行的函数，用于计时关闭窗体
    void ticktack(int sec = 2);

private slots:
    void on_btnClose_clicked();    // “叉”按钮槽函数
    void on_btnConfirm_clicked();  // “是”按钮槽函数
    void on_btnCancel_clicked();   // “否”按钮槽函数

protected:
    void mouseMoveEvent(QMouseEvent *event) override;       // 鼠标移动
    void mousePressEvent(QMouseEvent *event) override;      // 鼠标按下
    void mouseReleaseEvent(QMouseEvent *event) override;    // 鼠标释放

    // 窗体show前的事件操作
    void showEvent(QShowEvent *) override;

private:
    Ui::CustomMessageBox *ui;
    int m_nType;
    int m_nTipType;
    QList<QPixmap> iconList;
    QPoint m_pMousePoint;
    bool m_bMousePressed;
    std::thread *t1;

    void initForm();
    void initButtons();
    void initIcons();
};

#endif // CUSTOMMESSAGEBOX_H
