Files
ResInsight/ApplicationLibCode/UserInterface/RiuMdiArea.cpp
T

145 lines
5.1 KiB
C++
Raw Normal View History

2019-04-02 19:18:00 +02:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor 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 "RiuMdiArea.h"
#include "RiuMainWindow.h"
#include "RiuMdiSubWindow.h"
#include "RiuPlotMainWindow.h"
2022-03-03 10:15:32 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuMdiArea::RiuMdiArea( QWidget* parent /*= nullptr*/ )
: QMdiArea( parent )
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuMdiArea::~RiuMdiArea()
{
}
2019-04-02 19:18:00 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::list<QMdiSubWindow*> RiuMdiArea::subWindowListSortedByPosition()
{
// Tile Windows so the one with the leftmost left edge gets sorted first.
std::list<QMdiSubWindow*> windowList;
for ( QMdiSubWindow* subWindow : subWindowList( QMdiArea::CreationOrder ) )
2019-04-02 19:18:00 +02:00
{
windowList.push_back( subWindow );
2019-04-02 19:18:00 +02:00
}
// Sort of list so we first sort by window position but retain activation order
// for windows with the same position
windowList.sort( [this]( QMdiSubWindow* lhs, QMdiSubWindow* rhs ) {
if ( lhs->frameGeometry().topLeft().rx() == rhs->frameGeometry().topLeft().rx() )
2019-04-02 19:18:00 +02:00
{
return lhs->frameGeometry().topLeft().ry() < rhs->frameGeometry().topLeft().ry();
}
return lhs->frameGeometry().topLeft().rx() < rhs->frameGeometry().topLeft().rx();
} );
2019-04-02 19:18:00 +02:00
return windowList;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMdiArea::resizeEvent( QResizeEvent* resizeEvent )
2019-04-02 19:18:00 +02:00
{
if ( subWindowsAreTiled() )
2019-04-02 19:18:00 +02:00
{
for ( auto subWindow : subWindowList() )
2019-04-02 19:18:00 +02:00
{
auto riuWindow = dynamic_cast<RiuMdiSubWindow*>( subWindow );
riuWindow->blockTilingChanges( true );
2019-04-02 19:18:00 +02:00
}
RiuMainWindowBase* mainWindow = dynamic_cast<RiuMainWindowBase*>( window() );
2019-10-30 10:34:39 +01:00
mainWindow->setBlockSubWindowActivatedSignal( true );
2019-04-02 19:18:00 +02:00
// Workaround for Qt bug #51761: https://bugreports.qt.io/browse/QTBUG-51761
// Set the first window to be the active window then perform resize event and set back.
auto a = activeSubWindow();
setActiveSubWindow( subWindowListSortedByPosition().front() );
2019-04-02 19:18:00 +02:00
QMdiArea::resizeEvent( resizeEvent );
2019-04-02 19:18:00 +02:00
tileSubWindows();
setActiveSubWindow( a );
2019-04-02 19:18:00 +02:00
2019-10-30 10:34:39 +01:00
mainWindow->setBlockSubWindowActivatedSignal( false );
for ( auto subWindow : subWindowList() )
2019-04-02 19:18:00 +02:00
{
auto riuWindow = dynamic_cast<RiuMdiSubWindow*>( subWindow );
riuWindow->blockTilingChanges( false );
2019-04-02 19:18:00 +02:00
}
}
else
{
QMdiArea::resizeEvent( resizeEvent );
2019-04-02 19:18:00 +02:00
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMdiArea::moveEvent( QMoveEvent* event )
2019-04-02 19:18:00 +02:00
{
for ( auto subWindow : subWindowList() )
2019-04-02 19:18:00 +02:00
{
auto riuWindow = dynamic_cast<RiuMdiSubWindow*>( subWindow );
riuWindow->blockTilingChanges( true );
2019-04-02 19:18:00 +02:00
}
QMdiArea::moveEvent( event );
2019-04-02 19:18:00 +02:00
for ( auto subWindow : subWindowList() )
2019-04-02 19:18:00 +02:00
{
auto riuWindow = dynamic_cast<RiuMdiSubWindow*>( subWindow );
riuWindow->blockTilingChanges( false );
2019-04-02 19:18:00 +02:00
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiuMdiArea::subWindowsAreTiled() const
{
RiuMainWindow* mainWindow = dynamic_cast<RiuMainWindow*>( window() );
2019-04-02 19:18:00 +02:00
if ( mainWindow )
2019-04-02 19:18:00 +02:00
{
return mainWindow->subWindowsAreTiled() && subWindowList().size() > 0;
}
else
{
RiuPlotMainWindow* plotWindow = dynamic_cast<RiuPlotMainWindow*>( window() );
if ( plotWindow )
2019-04-02 19:18:00 +02:00
{
return plotWindow->subWindowsAreTiled() && subWindowList().size() > 0;
}
}
return false;
}