+void SdiWindow::Internal::MainWindow::closeEvent(QCloseEvent * e)
+{
+ // Try to close all the managed panels; ignore the event if one of the managed panels refuses to close
+ foreach (QWeakPointer<Gui::Panel> p, mPanels) {
+ if (p) {
+ if (!p.data()->close()) {
+ e->ignore();
+ return;
+ }
+ }
+ }
+
+ QWidget::closeEvent(e);
+}
+
+void SdiWindow::Internal::MainWindow::changeEvent(QEvent * e)
+{
+ if (e->type() == QEvent::WindowStateChange) {
+ QWindowStateChangeEvent * wse = static_cast<QWindowStateChangeEvent *>(e);
+
+ if (windowState() == Qt::WindowNoState && wse->oldState() == Qt::WindowMinimized) {
+
+ // Restore all the managed panels that were previously minimized
+ foreach (QWeakPointer<Gui::Panel> p, mMinimizedPanels) {
+ if (p && p.data()->isVisible())
+ p.data()->showNormal();
+ }
+ mMinimizedPanels.clear();
+ }
+
+ else if (windowState() == Qt::WindowMinimized && wse->oldState() != Qt::WindowMinimized) {
+
+ // Minimize all the managed panels that are not minimized yet
+ mMinimizedPanels.clear();
+ foreach (QWeakPointer<Gui::Panel> p, mPanels) {
+ if (!p)
+ continue;
+
+ if (p.data()->windowState() != Qt::WindowMinimized && p.data()->isVisible()) {
+ mMinimizedPanels.append(p);
+ p.data()->showMinimized();
+ }
+ }
+ }
+ }
+ QWidget::changeEvent(e);
+}
+
+void SdiWindow::Internal::MainWindow::timerEvent(QTimerEvent * e)
+{
+ if (e->timerId() == mTimerId) {
+
+ // Remove panels that are deleted
+ {
+ QList<QWeakPointer<Gui::Panel> >::iterator it = mPanels.begin();
+ while (it != mPanels.end()) {
+ QWeakPointer<Gui::Panel> p = *it;
+ if (!p)
+ it = mPanels.erase(it);
+ else
+ ++it;
+ }
+ }
+
+ // Do the same with panel names
+ {
+ QHash<QString, QWeakPointer<Gui::Panel> >::iterator it = mPanelNames.begin();
+ while (it != mPanelNames.end()) {
+ QWeakPointer<Gui::Panel> p = it.value();
+ if (!p)
+ it = mPanelNames.erase(it);
+ else
+ ++it;
+ }
+ }
+ }
+ else
+ QWidget::timerEvent(e);
+}
+