12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- // Description : Utility for dismissing every modal windows
- #include "EditorDefs.h"
- #include "ModalWindowDismisser.h"
- // Qt
- #include <QDialog>
- ModalWindowDismisser::ModalWindowDismisser()
- {
- qApp->installEventFilter(this);
- }
- ModalWindowDismisser::~ModalWindowDismisser()
- {
- if (qApp)
- {
- qApp->removeEventFilter(this);
- }
- }
- bool ModalWindowDismisser::eventFilter(QObject* object, QEvent* event)
- {
- if (QDialog* dialog = qobject_cast<QDialog*>(object))
- {
- if (dialog->isModal())
- {
- if (event->type() == QEvent::Paint || event->type() == QEvent::PolishRequest)
- {
- auto it = AZStd::find(m_windows.begin(), m_windows.end(), dialog);
- if (it == m_windows.end())
- {
- m_windows.push_back(dialog);
- }
- dialog->close();
- }
- else if (event->type() == QEvent::Close)
- {
- auto it = AZStd::find(m_windows.begin(), m_windows.end(), dialog);
- if (it != m_windows.end())
- {
- m_windows.erase(it);
- }
- }
- }
- }
- return false;
- }
|