ModalWindowDismisser.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. // Description : Utility for dismissing every modal windows
  9. #include "EditorDefs.h"
  10. #include "ModalWindowDismisser.h"
  11. // Qt
  12. #include <QDialog>
  13. ModalWindowDismisser::ModalWindowDismisser()
  14. {
  15. qApp->installEventFilter(this);
  16. }
  17. ModalWindowDismisser::~ModalWindowDismisser()
  18. {
  19. if (qApp)
  20. {
  21. qApp->removeEventFilter(this);
  22. }
  23. }
  24. bool ModalWindowDismisser::eventFilter(QObject* object, QEvent* event)
  25. {
  26. if (QDialog* dialog = qobject_cast<QDialog*>(object))
  27. {
  28. if (dialog->isModal())
  29. {
  30. if (event->type() == QEvent::Paint || event->type() == QEvent::PolishRequest)
  31. {
  32. auto it = AZStd::find(m_windows.begin(), m_windows.end(), dialog);
  33. if (it == m_windows.end())
  34. {
  35. m_windows.push_back(dialog);
  36. }
  37. dialog->close();
  38. }
  39. else if (event->type() == QEvent::Close)
  40. {
  41. auto it = AZStd::find(m_windows.begin(), m_windows.end(), dialog);
  42. if (it != m_windows.end())
  43. {
  44. m_windows.erase(it);
  45. }
  46. }
  47. }
  48. }
  49. return false;
  50. }