#ifndef PQMESSAGEBOX
#define PQMESSAGEBOX

#include <QMessageBox>
#include "classes/pqwidget.h"

class PQMessageBox;
class PQMessageBox : public QMessageBox {
    Q_OBJECT
    PQ_WIDGET_EX(QMessageBox)

    Q_PROPERTY( QString text READ text WRITE setText )
    Q_PROPERTY( QString detailedText READ detailedText WRITE setDetailedText )
    Q_PROPERTY( QString informativeText READ informativeText WRITE setInformativeText )
    Q_PROPERTY( bool modal READ isModal WRITE setModal )
    Q_PROPERTY( int icon READ icon WRITE setIcon )
    Q_PROPERTY( int standardButtons WRITE setStandardButtons )
    Q_PROPERTY( int defaultButton WRITE setDefaultButton )

public:
    Q_INVOKABLE explicit PQMessageBox(QWidget *parent = 0);
    Q_INVOKABLE PQMessageBox(int icon, const QString &title, const QString &text,
                int buttons = NoButton, QWidget *parent = 0,
                int flags = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
    virtual ~PQMessageBox();

    Q_INVOKABLE QString text();

    Q_INVOKABLE QString detailedText();
    Q_INVOKABLE QString informativeText();
    Q_INVOKABLE bool isModal();
    Q_INVOKABLE int icon();
    Q_INVOKABLE void setStandardButtons(int buttons);
    Q_INVOKABLE void setDefaultButton(int button);
    Q_INVOKABLE void addButton(const QString &text, int role);
    Q_INVOKABLE void addButton(int button);

    Q_INVOKABLE int question(QWidget *parent, const QString &title,
                             const QString &text,
                             int buttons = QMessageBox::Yes|QMessageBox::No, int defaultButton = QMessageBox::NoButton);

    Q_INVOKABLE int question(QWidget *parent, const QString &title,
                             const QString &text,
                             const QString &button0Text,
                             const QString &button1Text = QString(),
                             const QString &button2Text = QString(),
                             int defaultButtonNumber = 0);


    Q_INVOKABLE int information(QWidget *parent, const QString &title,
                                const QString &text, int buttons = QMessageBox::Ok,
                                int defaultButton = QMessageBox::NoButton);

    Q_INVOKABLE int information(QWidget *parent, const QString &title,
                             const QString& text,
                             const QString& button0Text,
                             const QString& button1Text = QString(),
                             const QString& button2Text = QString(),
                             int defaultButtonNumber = 0);


    Q_INVOKABLE int warning(QWidget *parent, const QString &title,
                            const QString &text, int buttons = QMessageBox::Ok,
                            int defaultButton = QMessageBox::NoButton);
    Q_INVOKABLE int warning(const QString &title,
                            const QString &text, int buttons = QMessageBox::Ok,
                            int defaultButton = QMessageBox::NoButton) {
        return warning(0, title, text, buttons, defaultButton);
    }

    Q_INVOKABLE int warning(QWidget *parent, const QString &title,
                             const QString &text,
                             const QString &button0Text,
                             const QString &button1Text = QString(),
                             const QString &button2Text = QString(),
                             int defaultButtonNumber = 0);


    Q_INVOKABLE int critical(QWidget *parent, const QString &title,
                             const QString &text, int buttons = QMessageBox::Ok,
                             int defaultButton = QMessageBox::NoButton);

    Q_INVOKABLE int critical(QWidget *parent, const QString &title,
                             const QString &text,
                             const QString &button0Text,
                             const QString &button1Text = QString(),
                             const QString &button2Text = QString(),
                             int defaultButtonNumber = 0);


    Q_INVOKABLE void about(QWidget *parent, const QString &title, const QString &text);
    Q_INVOKABLE void aboutQt(QWidget *parent, const QString &title = QString());

public Q_SLOTS:
    Q_INVOKABLE int exec();
    Q_INVOKABLE void setText(const QString &text);
    Q_INVOKABLE void setDetailedText(const QString &text);
    Q_INVOKABLE void setInformativeText(const QString &text);
    Q_INVOKABLE void setModal(bool modal);
    Q_INVOKABLE void setIcon(int icon);
    Q_INVOKABLE void forceFinish();

    void accepted_pslot();
    void finished_pslot(int result);
    void rejected_pslot();

    PQ_ON_SIGNAL_DECL_START {
        PQ_ON_SIGNAL(accepted());
        PQ_ON_SIGNAL(finished(int));
        PQ_ON_SIGNAL(rejected());
        PQWIDGET_ON_SIGNALS();
    } PQ_ON_SIGNAL_DECL_END
private:
    void new_thread();
};

Q_DECLARE_METATYPE(PQMessageBox*)

#endif // PQMESSAGEBOX

