2017-01-17 06:06:57 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-01-17 06:06:57 -06:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-01-17 06:06:57 -06:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2017-01-17 06:06:57 -06:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RimMdiWindowController.h"
|
2017-01-20 09:25:05 -06:00
|
|
|
|
2019-05-06 03:36:05 -05:00
|
|
|
#include "RiaGuiApplication.h"
|
2019-03-20 07:31:01 -05:00
|
|
|
#include "RimProject.h"
|
2017-01-17 06:06:57 -06:00
|
|
|
#include "RimViewWindow.h"
|
2017-01-20 09:25:05 -06:00
|
|
|
#include "RiuMainWindowBase.h"
|
2017-01-17 06:06:57 -06:00
|
|
|
|
2020-10-07 08:00:26 -05:00
|
|
|
#include <QMdiSubWindow>
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_PDM_XML_SOURCE_INIT( RimMdiWindowController, "MdiWindowController" );
|
2017-01-17 06:06:57 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-01-17 06:06:57 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimMdiWindowController::RimMdiWindowController()
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_PDM_InitField( &m_mainWindowID, "MainWindowID", -1, "", "", "", "" );
|
|
|
|
CAF_PDM_InitField( &m_x, "xPos", -1, "", "", "", "" );
|
|
|
|
CAF_PDM_InitField( &m_y, "yPos", -1, "", "", "", "" );
|
|
|
|
CAF_PDM_InitField( &m_width, "Width", -1, "", "", "", "" );
|
|
|
|
CAF_PDM_InitField( &m_height, "Height", -1, "", "", "", "" );
|
|
|
|
CAF_PDM_InitField( &m_isMaximized, "IsMaximized", false, "", "", "", "" );
|
2017-01-17 06:06:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-01-17 06:06:57 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 04:13:38 -06:00
|
|
|
RimMdiWindowController::~RimMdiWindowController()
|
|
|
|
{
|
|
|
|
}
|
2017-01-17 06:06:57 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-01-17 06:06:57 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RimMdiWindowController::setMdiWindowGeometry( const RimMdiWindowGeometry& windowGeometry )
|
2017-01-17 06:06:57 -06:00
|
|
|
{
|
|
|
|
m_mainWindowID = windowGeometry.mainWindowID;
|
2019-09-06 03:40:57 -05:00
|
|
|
m_x = windowGeometry.x;
|
|
|
|
m_y = windowGeometry.y;
|
|
|
|
m_width = windowGeometry.width;
|
|
|
|
m_height = windowGeometry.height;
|
|
|
|
m_isMaximized = windowGeometry.isMaximized;
|
2017-01-17 06:06:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-01-17 06:06:57 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimMdiWindowGeometry RimMdiWindowController::mdiWindowGeometry()
|
|
|
|
{
|
|
|
|
RimMdiWindowGeometry windowGeometry;
|
|
|
|
|
|
|
|
windowGeometry.mainWindowID = m_mainWindowID;
|
2019-09-06 03:40:57 -05:00
|
|
|
windowGeometry.x = m_x;
|
|
|
|
windowGeometry.y = m_y;
|
|
|
|
windowGeometry.width = m_width;
|
|
|
|
windowGeometry.height = m_height;
|
|
|
|
windowGeometry.isMaximized = m_isMaximized;
|
2017-01-17 06:06:57 -06:00
|
|
|
|
|
|
|
return windowGeometry;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-01-17 06:06:57 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimMdiWindowController::handleViewerDeletion()
|
|
|
|
{
|
2017-01-20 09:25:05 -06:00
|
|
|
viewPdmObject()->m_showWindow = false;
|
2019-03-25 08:47:19 -05:00
|
|
|
viewPdmObject()->updateConnectedEditors();
|
2019-04-16 03:41:03 -05:00
|
|
|
viewPdmObject()->updateUiIconFromToggleField();
|
2017-01-17 06:06:57 -06:00
|
|
|
uiCapability()->updateUiIconFromToggleField();
|
2019-04-16 03:41:03 -05:00
|
|
|
removeWindowFromMDI();
|
|
|
|
|
2017-01-17 06:06:57 -06:00
|
|
|
updateConnectedEditors();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-01-17 06:06:57 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimMdiWindowController::removeWindowFromMDI()
|
|
|
|
{
|
|
|
|
RiuMainWindowBase* mainWin = getMainWindow();
|
2019-10-31 07:48:40 -05:00
|
|
|
if ( mainWin && viewWidget() )
|
|
|
|
{
|
|
|
|
mainWin->removeViewer( viewWidget() );
|
|
|
|
}
|
2017-01-17 06:06:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-01-17 06:06:57 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimViewWindow* RimMdiWindowController::viewPdmObject()
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RimViewWindow* viewWindowObj;
|
|
|
|
this->firstAncestorOrThisOfType( viewWindowObj );
|
2017-01-17 06:06:57 -06:00
|
|
|
return viewWindowObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-01-17 06:06:57 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QWidget* RimMdiWindowController::viewWidget()
|
|
|
|
{
|
|
|
|
return viewPdmObject()->viewWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-01-17 06:06:57 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RiuMainWindowBase* RimMdiWindowController::getMainWindow()
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( RiaGuiApplication::isRunning() )
|
2019-05-06 03:36:05 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
return RiaGuiApplication::instance()->mainWindowByID( m_mainWindowID );
|
2019-05-06 03:36:05 -05:00
|
|
|
}
|
|
|
|
return nullptr;
|
2017-01-17 06:06:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-01-17 06:06:57 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimMdiWindowController::setupBeforeSave()
|
|
|
|
{
|
|
|
|
if ( viewWidget() && getMainWindow() )
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
this->setMdiWindowGeometry( getMainWindow()->windowGeometryForViewer( viewWidget() ) );
|
2017-01-17 06:06:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-01-17 06:06:57 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimMdiWindowController::updateViewerWidget()
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RiuMainWindowBase* mainWindow = getMainWindow();
|
2017-01-17 06:06:57 -06:00
|
|
|
if ( !mainWindow ) return;
|
|
|
|
|
2018-01-23 07:23:28 -06:00
|
|
|
if ( viewPdmObject()->isWindowVisible() )
|
2017-01-17 06:06:57 -06:00
|
|
|
{
|
|
|
|
if ( !viewWidget() )
|
|
|
|
{
|
2020-10-07 08:00:26 -05:00
|
|
|
QMdiSubWindow* viewWindow = mainWindow->createViewWindow();
|
|
|
|
QWidget* viewWidget = viewPdmObject()->createViewWidget( viewWindow );
|
|
|
|
mainWindow->initializeViewer( viewWindow, viewWidget, this->mdiWindowGeometry() );
|
2017-01-17 06:06:57 -06:00
|
|
|
|
|
|
|
viewPdmObject()->updateViewWidgetAfterCreation();
|
|
|
|
}
|
|
|
|
|
2017-01-20 04:38:18 -06:00
|
|
|
viewPdmObject()->updateMdiWindowTitle();
|
2017-01-17 06:06:57 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( viewWidget() )
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
this->setMdiWindowGeometry( mainWindow->windowGeometryForViewer( viewWidget() ) );
|
2017-01-17 06:06:57 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
mainWindow->removeViewer( viewWidget() );
|
2017-01-17 06:06:57 -06:00
|
|
|
|
|
|
|
viewPdmObject()->deleteViewWidget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|