#ifndef MODALDIALOG_H
#define MODALDIALOG_H

#include <QDialog>
#include <QMutex>
#include <QPoint>

namespace Ui {
class ModalDialog;
}

class ModalDialog : public QDialog
{
    Q_OBJECT
public:
    enum Pages
    {
        Progress = 0,
        Tip,
        BusnessSetting,
        DataSetting,
        DiskCheck
    };

public:
    static ModalDialog *instance();
public:
    ModalDialog(const ModalDialog*)=delete;
    ModalDialog *operator =(const ModalDialog*)=delete;
public:
    void init(){}
    void destroy() { delete this; }
    bool isWayland() { return m_bIsWayland; }
public slots:
    QWidget *showPage(int);
    void cancelEnable(bool);
    void updatePosition(QPoint);
    void show();
    bool canBeClose() { return m_bCanClose; }
protected:
    void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
    void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
private:
    explicit ModalDialog(QWidget *parent = nullptr);
    ~ModalDialog();
private slots:
    void slotsTitle(QString);
    void slotsClose();
private:
    static ModalDialog *m_oInstance;
    static QMutex       m_oMutex;
private:
    bool                m_bCanClose;
    bool                m_bIsWayland;
    QPoint              m_oMainPos;
    QPushButton *m_oCancelBtn;
    QPushButton *m_oEnsureBtn;
private:
    Ui::ModalDialog    *ui;
signals:
    // log
    void info(QString); void warn(QString);
    void error(QString); void debug(QString);
    void cancel();
};

#define MODAL ModalDialog::instance()
#define PROGRESS MODAL->showPage(ModalDialog::Progress)
#define TIP MODAL->showPage(ModalDialog::Tip)
#define BUSNESSSETTING MODAL->showPage(ModalDialog::BusnessSetting)
#define DATASETTING MODAL->showPage(ModalDialog::DataSetting)
#define DISKCHECK MODAL->showPage(ModalDialog::DiskCheck)

#endif // MODALDIALOG_H
