mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-08 23:23:01 -06:00
#4221 MDI window : Move MDI handling to RiuMainWindowBase
This commit is contained in:
parent
75b0905e26
commit
c4b0bf5890
@ -351,6 +351,51 @@ const char* RiaApplication::getVersionStringApp(bool includeCrtInfo)
|
||||
return szBuf;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RiaMdiMaximizeWindowGuard
|
||||
{
|
||||
public:
|
||||
RiaMdiMaximizeWindowGuard()
|
||||
{
|
||||
{
|
||||
RiuMainWindow* mainWindow = RiaApplication::instance()->mainWindow();
|
||||
if (mainWindow)
|
||||
{
|
||||
mainWindow->enableShowFirstVisibleMdiWindowMaximized(false);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
RiuPlotMainWindow* plotMainWindow = RiaApplication::instance()->mainPlotWindow();
|
||||
if (plotMainWindow)
|
||||
{
|
||||
plotMainWindow->enableShowFirstVisibleMdiWindowMaximized(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~RiaMdiMaximizeWindowGuard()
|
||||
{
|
||||
{
|
||||
RiuMainWindow* mainWindow = RiaApplication::instance()->mainWindow();
|
||||
if (mainWindow)
|
||||
{
|
||||
mainWindow->enableShowFirstVisibleMdiWindowMaximized(true);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
RiuPlotMainWindow* plotMainWindow = RiaApplication::instance()->mainPlotWindow();
|
||||
if (plotMainWindow)
|
||||
{
|
||||
plotMainWindow->enableShowFirstVisibleMdiWindowMaximized(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -362,6 +407,9 @@ bool RiaApplication::loadProject(const QString& projectFileName,
|
||||
|
||||
closeProject();
|
||||
|
||||
// When importing a project, do not maximize the first MDI window to be created
|
||||
RiaMdiMaximizeWindowGuard maximizeWindowGuard;
|
||||
|
||||
RiaLogging::info(QString("Starting to open project file : '%1'").arg(projectFileName));
|
||||
|
||||
// Create a absolute path file name, as this is required for update of file references in the project modifier object
|
||||
|
@ -317,7 +317,7 @@ void RiuMainWindow::createActions()
|
||||
m_viewFromNorth = new QAction(QIcon(":/SouthViewArrow.png"), "Look South", this);
|
||||
m_viewFromNorth->setToolTip("Look South (Ctrl+Alt+S)");
|
||||
m_viewFromNorth->setShortcut(QKeySequence(tr("Ctrl+Alt+S")));
|
||||
|
||||
|
||||
m_viewFromSouth = new QAction(QIcon(":/NorthViewArrow.png"), "Look North", this);
|
||||
m_viewFromSouth->setToolTip("Look North (Ctrl+Alt+N)");
|
||||
m_viewFromSouth->setShortcut(QKeySequence(tr("Ctrl+Alt+N")));
|
||||
@ -1120,13 +1120,8 @@ void RiuMainWindow::removeViewer(QWidget* viewer)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMainWindow::addViewer(QWidget* viewer, const RimMdiWindowGeometry& windowsGeometry)
|
||||
{
|
||||
RiuMdiSubWindow* subWin = new RiuMdiSubWindow;
|
||||
subWin->setAttribute(Qt::WA_DeleteOnClose); // Make sure the contained widget is destroyed when the MDI window is closed
|
||||
subWin->setWidget(viewer);
|
||||
|
||||
QSize subWindowSize;
|
||||
QPoint subWindowPos(-1, -1);
|
||||
bool initialStateMaximized = false;
|
||||
|
||||
if (windowsGeometry.isValid())
|
||||
{
|
||||
@ -1136,35 +1131,9 @@ void RiuMainWindow::addViewer(QWidget* viewer, const RimMdiWindowGeometry& windo
|
||||
else
|
||||
{
|
||||
subWindowSize = QSize(400, 400);
|
||||
|
||||
if (m_mdiArea->subWindowList().size() < 1)
|
||||
{
|
||||
// Show first 3D view maximized
|
||||
initialStateMaximized = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_mdiArea->currentSubWindow() && m_mdiArea->currentSubWindow()->isMaximized())
|
||||
{
|
||||
initialStateMaximized = true;
|
||||
}
|
||||
|
||||
m_mdiArea->addSubWindow(subWin);
|
||||
|
||||
if (subWindowPos.x() > -1)
|
||||
{
|
||||
subWin->move(subWindowPos);
|
||||
}
|
||||
subWin->resize(subWindowSize);
|
||||
|
||||
if (initialStateMaximized)
|
||||
{
|
||||
subWin->showMaximized();
|
||||
}
|
||||
else
|
||||
{
|
||||
subWin->showNormal();
|
||||
}
|
||||
addViewerToMdiArea(m_mdiArea, viewer, subWindowPos, subWindowSize);
|
||||
|
||||
slotRefreshViewActions();
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2016 Statoil ASA
|
||||
//
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
@ -21,25 +21,28 @@
|
||||
#include "RiaVersionInfo.h"
|
||||
|
||||
#include "RiuDockWidgetTools.h"
|
||||
#include "RiuMdiSubWindow.h"
|
||||
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmUiTreeView.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QDockWidget>
|
||||
#include <QMdiArea>
|
||||
#include <QSettings>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuMainWindowBase::RiuMainWindowBase()
|
||||
: m_projectTreeView(nullptr)
|
||||
, m_allowActiveViewChangeFromSelection(true)
|
||||
, m_showFirstVisibleWindowMaximized(true)
|
||||
{
|
||||
setDockNestingEnabled(true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMainWindowBase::loadWinGeoAndDockToolBarLayout()
|
||||
{
|
||||
@ -62,7 +65,7 @@ void RiuMainWindowBase::loadWinGeoAndDockToolBarLayout()
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMainWindowBase::saveWinGeoAndDockToolBarLayout()
|
||||
{
|
||||
@ -79,7 +82,7 @@ void RiuMainWindowBase::saveWinGeoAndDockToolBarLayout()
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMainWindowBase::showWindow()
|
||||
{
|
||||
@ -96,7 +99,7 @@ void RiuMainWindowBase::showWindow()
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiuMainWindowBase::registryFolderName()
|
||||
{
|
||||
@ -115,6 +118,14 @@ void RiuMainWindowBase::selectAsCurrentItem(const caf::PdmObject* object, bool a
|
||||
m_allowActiveViewChangeFromSelection = true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMainWindowBase::enableShowFirstVisibleMdiWindowMaximized(bool enable)
|
||||
{
|
||||
m_showFirstVisibleWindowMaximized = enable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -123,10 +134,10 @@ void RiuMainWindowBase::setExpanded(const caf::PdmUiItem* uiItem, bool expanded)
|
||||
m_projectTreeView->setExpanded(uiItem, expanded);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMainWindowBase::slotDockWidgetToggleViewActionTriggered()
|
||||
{
|
||||
if (!sender()) return;
|
||||
@ -136,10 +147,53 @@ void RiuMainWindowBase::slotDockWidgetToggleViewActionTriggered()
|
||||
{
|
||||
if (dockWidget->isVisible())
|
||||
{
|
||||
// Raise the dock widget to make it visible if the widget is part of a tab widget
|
||||
// Raise the dock widget to make it visible if the widget is part of a tab widget
|
||||
dockWidget->raise();
|
||||
}
|
||||
|
||||
RiuDockWidgetTools::instance()->setDockWidgetVisibility(dockWidget->objectName(), dockWidget->isVisible());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMainWindowBase::addViewerToMdiArea(QMdiArea* mdiArea,
|
||||
QWidget* viewer,
|
||||
const QPoint& subWindowPos,
|
||||
const QSize& subWindowSize)
|
||||
{
|
||||
RiuMdiSubWindow* subWin = new RiuMdiSubWindow;
|
||||
subWin->setAttribute(Qt::WA_DeleteOnClose); // Make sure the contained widget is destroyed when the MDI window is closed
|
||||
subWin->setWidget(viewer);
|
||||
|
||||
bool initialStateMaximized = false;
|
||||
|
||||
if (m_showFirstVisibleWindowMaximized && mdiArea->subWindowList().empty())
|
||||
{
|
||||
// Show first 3D view maximized
|
||||
initialStateMaximized = true;
|
||||
}
|
||||
|
||||
if (mdiArea->currentSubWindow() && mdiArea->currentSubWindow()->isMaximized())
|
||||
{
|
||||
initialStateMaximized = true;
|
||||
}
|
||||
|
||||
mdiArea->addSubWindow(subWin);
|
||||
|
||||
if (subWindowPos.x() > -1)
|
||||
{
|
||||
subWin->move(subWindowPos);
|
||||
}
|
||||
subWin->resize(subWindowSize);
|
||||
|
||||
if (initialStateMaximized)
|
||||
{
|
||||
subWin->showMaximized();
|
||||
}
|
||||
else
|
||||
{
|
||||
subWin->showNormal();
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,9 @@ namespace caf
|
||||
class PdmUiItem;
|
||||
}
|
||||
|
||||
class QMdiArea;
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
@ -55,9 +58,12 @@ public:
|
||||
void setExpanded(const caf::PdmUiItem* uiItem, bool expanded = true);
|
||||
|
||||
void selectAsCurrentItem(const caf::PdmObject* object, bool allowActiveViewChange = true);
|
||||
|
||||
void enableShowFirstVisibleMdiWindowMaximized(bool enable);
|
||||
|
||||
protected slots:
|
||||
void slotDockWidgetToggleViewActionTriggered();
|
||||
void addViewerToMdiArea(QMdiArea* mdiArea, QWidget* viewer, const QPoint& subWindowPos, const QSize& subWindowSize);
|
||||
|
||||
protected:
|
||||
caf::PdmUiTreeView* m_projectTreeView;
|
||||
@ -67,4 +73,7 @@ protected:
|
||||
|
||||
private:
|
||||
QString registryFolderName();
|
||||
|
||||
private:
|
||||
bool m_showFirstVisibleWindowMaximized;
|
||||
};
|
||||
|
@ -66,7 +66,6 @@ RiuPlotMainWindow::RiuPlotMainWindow()
|
||||
, m_blockSlotSubWindowActivated(false)
|
||||
{
|
||||
m_mdiArea = new QMdiArea;
|
||||
m_mdiArea->setOption(QMdiArea::DontMaximizeSubWindowOnActivation, true);
|
||||
connect(m_mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), SLOT(slotSubWindowActivated(QMdiSubWindow*)));
|
||||
setCentralWidget(m_mdiArea);
|
||||
|
||||
@ -596,13 +595,8 @@ void RiuPlotMainWindow::removeViewer(QWidget* viewer)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuPlotMainWindow::addViewer(QWidget* viewer, const RimMdiWindowGeometry& windowsGeometry)
|
||||
{
|
||||
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);
|
||||
|
||||
QSize subWindowSize;
|
||||
QPoint subWindowPos(-1, -1);
|
||||
bool initialStateMaximized = false;
|
||||
|
||||
if (windowsGeometry.isValid())
|
||||
{
|
||||
@ -611,7 +605,7 @@ void RiuPlotMainWindow::addViewer(QWidget* viewer, const RimMdiWindowGeometry& w
|
||||
}
|
||||
else
|
||||
{
|
||||
RiuWellLogPlot* wellLogPlot = dynamic_cast<RiuWellLogPlot*>(subWin->widget());
|
||||
RiuWellLogPlot* wellLogPlot = dynamic_cast<RiuWellLogPlot*>(viewer);
|
||||
if (wellLogPlot)
|
||||
{
|
||||
QSize preferredSize = wellLogPlot->preferredSize();
|
||||
@ -620,38 +614,10 @@ void RiuPlotMainWindow::addViewer(QWidget* viewer, const RimMdiWindowGeometry& w
|
||||
else
|
||||
{
|
||||
subWindowSize = QSize(400, 400);
|
||||
|
||||
if (m_mdiArea->subWindowList().size() < 1)
|
||||
{
|
||||
// Show first 3D view maximized
|
||||
initialStateMaximized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_mdiArea->currentSubWindow() && m_mdiArea->currentSubWindow()->isMaximized())
|
||||
{
|
||||
initialStateMaximized = true;
|
||||
}
|
||||
|
||||
// Qt5: Using show() causes a update issue in MDI area
|
||||
// https://github.com/OPM/ResInsight/issues/4131
|
||||
subWin->showNormal();
|
||||
|
||||
// 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
|
||||
if (subWindowPos.x() > -1)
|
||||
{
|
||||
subWin->move(subWindowPos);
|
||||
}
|
||||
subWin->resize(subWindowSize);
|
||||
|
||||
if (initialStateMaximized)
|
||||
{
|
||||
subWin->showMaximized();
|
||||
}
|
||||
subWin->repaint();
|
||||
addViewerToMdiArea(m_mdiArea, viewer, subWindowPos, subWindowSize);
|
||||
|
||||
refreshToolbars();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user