MessageBox.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * MessageBox.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "vcmiqt.h"
  12. #include <QMessageBox>
  13. #include <QTimer>
  14. namespace MessageBoxCustom
  15. {
  16. #ifdef VCMI_IOS
  17. // iOS can't display modal dialogs when called directly on button press
  18. // https://bugreports.qt.io/browse/QTBUG-98651
  19. template<typename Functor>
  20. inline void showDialog(QWidget *parent, const Functor & f)
  21. {
  22. QTimer::singleShot(0, parent, f);
  23. }
  24. inline void information(QWidget *parent, const QString &title, const QString& text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton)
  25. {
  26. QTimer::singleShot(0, parent, [=](){
  27. QMessageBox::information(parent, title, text, buttons, defaultButton);
  28. });
  29. }
  30. #else
  31. template<typename Functor>
  32. inline void showDialog(QWidget *parent, const Functor & f)
  33. {
  34. f();
  35. }
  36. inline void information(QWidget *parent, const QString &title, const QString& text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton)
  37. {
  38. QMessageBox::information(parent, title, text, buttons, defaultButton);
  39. }
  40. #endif
  41. }