ResInsight/ApplicationCode/UserInterface/RiuMdiSubWindow.cpp
Gaute Lindkvist 57b33b0d4c
First implementation of Headless (#4392)
* Revert "#4377 Octave : Use RiaLogging for error messages instead of QErrorMessage "

This reverts commit f758a8edb2.

* Revert "#4380 Preferences : Changing scene font size when geo mech view is open causes crash"

This reverts commit df62a41397.

* Revert "#4379 Documentation : Update command line parser for import of summary files"

This reverts commit d0b5357ed4.

* Unfinished WIP

* Builds but crashes

* Refactored code now builds and runs

* ResInsight can now run the unittests headless

* Can run some command files successfully

* Build on Linux

* Extra headless hack header

* Moved PdmUiItem hack to cpp file

* Fix headless crash in RimWellAllocationPlot

* Handle error gracefully if ExportSnapshots command is executed from console

* Add caf::QIconProvider and remove some hacks

* Also made the greying out of disabled icons work for a couple of cases where it didn't.

* Linux build fix

* #4380 Reimplement fix df62a41397 by @magnesj on top of Headless code changes

* #4379 Reintroduce kode from d0b5357ed4 by @magnesj

* #4377 Restore f758a8edb2 in new Headless code
2019-05-06 10:36:05 +02:00

172 lines
5.3 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// 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>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiuMdiSubWindow.h"
#include "RiaGuiApplication.h"
#include "Rim3dView.h"
#include "RimSummaryPlot.h"
#include "RimWellLogPlot.h"
#include "RiuMainWindow.h"
#include "RiuPlotMainWindow.h"
#include "RiuViewer.h"
#include "RiuWellLogPlot.h"
#include <QWindowStateChangeEvent>
#include <QDebug>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuMdiSubWindow::RiuMdiSubWindow(QWidget* parent /*= 0*/, Qt::WindowFlags flags /*= 0*/)
: QMdiSubWindow(parent, flags)
, m_normalWindowGeometry(QRect())
, m_blockTilingChanges(false)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuMdiSubWindow::~RiuMdiSubWindow()
{
RiuMainWindow::instance()->slotRefreshViewActions();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimMdiWindowGeometry RiuMdiSubWindow::windowGeometry() const
{
RimMdiWindowGeometry geo;
int mainWinID = 0;
if (window() == RiaGuiApplication::instance()->mainPlotWindow())
{
mainWinID = 1;
}
geo.mainWindowID = mainWinID;
geo.isMaximized = isMaximized();
// Save normal/non-maximized size and position so this can be restored
QRect currentGeometry = frameGeometry();
if (isMaximized() && !m_normalWindowGeometry.isNull())
{
currentGeometry = m_normalWindowGeometry;
}
geo.x = currentGeometry.topLeft().x();
geo.y = currentGeometry.topLeft().y();
geo.width = currentGeometry.width();
geo.height = currentGeometry.height();
return geo;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMdiSubWindow::blockTilingChanges(bool block)
{
m_blockTilingChanges = block;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMdiSubWindow::closeEvent(QCloseEvent* event)
{
QWidget* mainWidget = widget();
RimViewWindow* viewWindow = RiuInterfaceToViewWindow::viewWindowFromWidget(mainWidget);
if (!viewWindow)
{
RiuViewer* viewer = mainWidget->findChild<RiuViewer*>();
if (viewer)
{
viewWindow = viewer->ownerViewWindow();
}
}
if (viewWindow)
{
viewWindow->setMdiWindowGeometry(windowGeometry());
viewWindow->handleMdiWindowClosed();
event->accept();
}
else
{
QMdiSubWindow::closeEvent(event);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMdiSubWindow::resizeEvent(QResizeEvent* resizeEvent)
{
if (!isMaximized())
{
m_normalWindowGeometry = frameGeometry();
}
if (!m_blockTilingChanges)
{
if (window() == RiaGuiApplication::instance()->mainWindow())
{
RiaGuiApplication::instance()->mainWindow()->storeSubWindowTiling(false);
}
else if (window() == RiaGuiApplication::instance()->mainPlotWindow())
{
RiaGuiApplication::instance()->mainPlotWindow()->storeSubWindowTiling(false);
}
}
QMdiSubWindow::resizeEvent(resizeEvent);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMdiSubWindow::moveEvent(QMoveEvent* moveEvent)
{
if (!isMaximized())
{
m_normalWindowGeometry = frameGeometry();
}
if (!m_blockTilingChanges)
{
if (window() == RiaGuiApplication::instance()->mainWindow())
{
RiaGuiApplication::instance()->mainWindow()->storeSubWindowTiling(false);
}
else if (window() == RiaGuiApplication::instance()->mainPlotWindow())
{
RiaGuiApplication::instance()->mainPlotWindow()->storeSubWindowTiling(false);
}
}
QMdiSubWindow::moveEvent(moveEvent);
}