diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp index 40a4c7deb0..b3458f6d0c 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp @@ -401,8 +401,6 @@ void RimWellLogPlot::handleViewerDeletion() if (m_viewer) { - windowGeometry = RiuMainWindow::instance()->windowGeometryForViewer(m_viewer); - detachAllCurves(); m_viewer = NULL; } diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlot.h b/ApplicationCode/ProjectDataModel/RimWellLogPlot.h index 0a1e0e0bfb..6692167a5e 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlot.h +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlot.h @@ -77,6 +77,9 @@ public: virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; } + caf::PdmField< std::vector > windowGeometry; + + protected: // Overridden PDM methods @@ -97,7 +100,6 @@ private: QPointer m_viewer; caf::PdmField m_showWindow; - caf::PdmField< std::vector > windowGeometry; caf::PdmChildArrayField traces; diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index de20804d68..a082564e2c 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -104,15 +104,9 @@ RiuMainWindow::RiuMainWindow() { CVF_ASSERT(sm_mainWindowInstance == NULL); -#if 0 - m_CentralFrame = new QFrame; - QHBoxLayout* frameLayout = new QHBoxLayout(m_CentralFrame); - setCentralWidget(m_CentralFrame); -#else m_mdiArea = new QMdiArea; connect(m_mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow *)), SLOT(slotSubWindowActivated(QMdiSubWindow*))); setCentralWidget(m_mdiArea); -#endif //m_mainViewer = createViewer(); @@ -1168,29 +1162,55 @@ QMdiSubWindow* RiuMainWindow::findMdiSubWindow(QWidget* viewer) //-------------------------------------------------------------------------------------------------- void RiuMainWindow::removeViewer(QWidget* viewer) { -#if 0 - m_CentralFrame->layout()->removeWidget(viewer->layoutWidget()); -#else m_mdiArea->removeSubWindow( findMdiSubWindow(viewer)); -#endif caf::CmdFeatureManager::instance()->refreshEnabledState(QStringList() << "RicLinkVisibleViewsFeature"); } + +// Helper class used to trap the close event of an QMdiSubWindow +class RiuMdiSubWindow : public QMdiSubWindow +{ +public: + RiuMdiSubWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0) + : QMdiSubWindow(parent, flags) + { + } + +protected: + virtual void closeEvent(QCloseEvent* event) + { + QWidget* mainWidget = widget(); + + RiuWellLogPlot* wellLogPlot = dynamic_cast(mainWidget); + if (wellLogPlot) + { + wellLogPlot->ownerPlotDefinition()->windowGeometry = RiuMainWindow::instance()->windowGeometryForWidget(this); + } + else + { + RiuViewer* viewer = mainWidget->findChild(); + if (viewer) + { + viewer->ownerReservoirView()->windowGeometry = RiuMainWindow::instance()->windowGeometryForWidget(this); + } + } + + QMdiSubWindow::closeEvent(event); + } +}; + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuMainWindow::addViewer(QWidget* viewer, const std::vector& windowsGeometry) { -#if 0 - m_CentralFrame->layout()->addWidget(viewer->layoutWidget()); -#else - QMdiSubWindow * subWin = m_mdiArea->addSubWindow(viewer); + RiuMdiSubWindow* subWin = new RiuMdiSubWindow(m_mdiArea); + subWin->setAttribute(Qt::WA_DeleteOnClose); // Make sure the contained widget is destroyed when the MDI window is closed + subWin->setWidget(viewer); if (windowsGeometry.size() == 5) { - subWin->move(QPoint(windowsGeometry[0], windowsGeometry[1])); - subWin->resize(QSize(windowsGeometry[2], windowsGeometry[3])); if (windowsGeometry[4] > 0) { subWin->showMaximized(); @@ -1199,6 +1219,12 @@ void RiuMainWindow::addViewer(QWidget* viewer, const std::vector& windowsGe { subWin->show(); } + + // Move and resize must be done after window is visible + // If not, the position and size of the window is different to specification (Windows 7) + // Might be a Qt bug, must be tested on Linux + subWin->move(QPoint(windowsGeometry[0], windowsGeometry[1])); + subWin->resize(QSize(windowsGeometry[2], windowsGeometry[3])); } else { @@ -1214,14 +1240,10 @@ void RiuMainWindow::addViewer(QWidget* viewer, const std::vector& windowsGe subWin->show(); } } -#endif caf::CmdFeatureManager::instance()->refreshEnabledState(QStringList() << "RicLinkVisibleViewsFeature"); } - - - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -2183,16 +2205,30 @@ void RiuMainWindow::customMenuRequested(const QPoint& pos) //-------------------------------------------------------------------------------------------------- std::vector RiuMainWindow::windowGeometryForViewer(QWidget* viewer) { - std::vector geo; - QMdiSubWindow* mdiWindow = findMdiSubWindow(viewer); if (mdiWindow) { - geo.push_back(mdiWindow->pos().x()); - geo.push_back(mdiWindow->pos().y()); - geo.push_back(mdiWindow->size().width()); - geo.push_back(mdiWindow->size().height()); - geo.push_back(mdiWindow->isMaximized()); + return windowGeometryForWidget(mdiWindow); + } + + std::vector geo; + return geo; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RiuMainWindow::windowGeometryForWidget(QWidget* widget) +{ + std::vector geo; + + if (widget) + { + geo.push_back(widget->pos().x()); + geo.push_back(widget->pos().y()); + geo.push_back(widget->size().width()); + geo.push_back(widget->size().height()); + geo.push_back(widget->isMaximized()); } return geo; diff --git a/ApplicationCode/UserInterface/RiuMainWindow.h b/ApplicationCode/UserInterface/RiuMainWindow.h index 54b625e6cf..38a3456494 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.h +++ b/ApplicationCode/UserInterface/RiuMainWindow.h @@ -110,6 +110,7 @@ public: void removeRecentFiles(const QString& file); std::vector windowGeometryForViewer(QWidget* viewer); + std::vector windowGeometryForWidget(QWidget* widget); protected: virtual void closeEvent(QCloseEvent* event); @@ -194,11 +195,10 @@ private: QToolBar* m_snapshotToolbar; - QFrame* m_CentralFrame; QMdiArea* m_mdiArea; - RiuViewer* m_mainViewer; - RiuResultInfoPanel* m_resultInfoPanel; - RiuProcessMonitor* m_processMonitor; + RiuViewer* m_mainViewer; + RiuResultInfoPanel* m_resultInfoPanel; + RiuProcessMonitor* m_processMonitor; QMenu* m_windowMenu;