Msgbox.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "Msgbox.h"
  2. #include "QDebug"
  3. MsgBox::MsgBox(QObject * parent )
  4. :QObject(parent), m_btnres(QMessageBox::NoButton) {
  5. //qRegisterMetaType<QMessageBox::StandardButtons>("QMessageBox::StandardButtons");
  6. //qRegisterMetaType<QMessageBox::StandardButton>("QMessageBox::StandardButton");
  7. connect(this, SIGNAL(msgbox_sig(MSGBOXTYPE, QWidget *, const QString, const QString, QMessageBox::StandardButtons, QMessageBox::StandardButton)), SLOT(on_msgbox(MSGBOXTYPE, QWidget *, const QString , const QString, QMessageBox::StandardButtons , QMessageBox::StandardButton )), Qt::BlockingQueuedConnection);
  8. }
  9. void MsgBox::about(QWidget * parent, const QString &title, const QString &text) {
  10. emit msgbox_sig(mbt_about, parent, title, text, QMessageBox::NoButton, QMessageBox::NoButton);
  11. }
  12. void MsgBox::aboutQt(QWidget *parent, const QString &title) {
  13. emit msgbox_sig(mbt_aboutqt, parent, title, tr(""), QMessageBox::NoButton, QMessageBox::NoButton);
  14. }
  15. int MsgBox::critical(QWidget * parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons , QMessageBox::StandardButton defaultButton ) {
  16. emit msgbox_sig(mbt_critical, parent, title, text, buttons, defaultButton);
  17. return m_btnres;
  18. }
  19. int MsgBox::information(QWidget * parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons , QMessageBox::StandardButton defaultButton )
  20. {
  21. emit msgbox_sig(mbt_information, parent, title, text, buttons, defaultButton);
  22. return m_btnres;
  23. }
  24. int MsgBox::question(QWidget * parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons , QMessageBox::StandardButton defaultButton) {
  25. emit msgbox_sig(mbt_question, parent, title, text, buttons, defaultButton);
  26. return m_btnres;
  27. }
  28. int MsgBox::warning(QWidget * parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons , QMessageBox::StandardButton defaultButton) {
  29. emit msgbox_sig(mbt_warning, parent, title, text, buttons, defaultButton);
  30. return m_btnres;
  31. }
  32. void MsgBox::on_msgbox(MSGBOXTYPE type, QWidget * parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton) {
  33. switch(type) {
  34. case mbt_about:
  35. QMessageBox::about(parent,title,text);
  36. break;
  37. case mbt_aboutqt:
  38. QMessageBox::aboutQt(parent, title);
  39. break;
  40. case mbt_critical:
  41. m_btnres = QMessageBox::critical(parent, title, text, buttons, defaultButton);
  42. break;
  43. case mbt_information:
  44. m_btnres = QMessageBox::information(parent, title, text, buttons, defaultButton);
  45. break;
  46. case mbt_question:
  47. m_btnres = QMessageBox::question(parent, title, text, buttons, defaultButton);
  48. break;
  49. case mbt_warning:
  50. m_btnres = QMessageBox::warning(parent, title, text, buttons, defaultButton);
  51. break;
  52. default:
  53. Q_ASSERT_X(false,"QMessageBox in thread","invalid box type specified.");
  54. }
  55. }