#include "custom_message_box.h"
#include "common_ui.h"

QPushButton *CustomMessageBox::addButton(const QString &text, ButtonRole role)
{
    QPushButton *button = QMessageBox::addButton(text, role);
    switch (role)
    {
    case QMessageBox::YesRole:
        m_yesButton = button;
        break;
    case QMessageBox::NoRole:
        m_noButton = button;
        break;
    default:
        break;
    }
    return button;
}

QPushButton *CustomMessageBox::clickedButton()
{
    if(m_ret == 0 && m_yesButton != nullptr) {
        return m_yesButton;
    }
    
    if (m_ret == 1 && m_noButton != nullptr) {
        return m_noButton;
    }

    return dynamic_cast<QPushButton *>(QMessageBox::clickedButton());
}

int CustomMessageBox::exec()
{
    m_ret = QMessageBox::exec();
    return m_ret;
}

void CustomMessageBox::setParent(QWidget *parent)
{
    QMessageBox::setParent(parent);
    centerTheWindow(this, parent);
}