2016-08-09 13:09:08 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2016 Statoil ASA
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
2016-08-09 13:09:08 +02: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 10:40:57 +02:00
|
|
|
//
|
2016-08-09 13:09:08 +02: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 10:40:57 +02:00
|
|
|
//
|
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2016-08-09 13:09:08 +02:00
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "RiuPropertyViewTabWidget.h"
|
|
|
|
|
|
2026-06-04 16:33:45 +02:00
|
|
|
#include "RiaPreferencesSystem.h"
|
|
|
|
|
|
2016-08-09 13:09:08 +02:00
|
|
|
#include "cafPdmObject.h"
|
|
|
|
|
#include "cafPdmUiPropertyView.h"
|
|
|
|
|
|
|
|
|
|
#include <QBoxLayout>
|
2019-09-06 10:40:57 +02:00
|
|
|
#include <QDebug>
|
2016-08-09 13:09:08 +02:00
|
|
|
#include <QDialogButtonBox>
|
2026-06-04 16:33:45 +02:00
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QShowEvent>
|
2016-08-09 13:09:08 +02:00
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QTabWidget>
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2016-08-09 13:09:08 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
RiuPropertyViewTabWidget::RiuPropertyViewTabWidget( QWidget* parent,
|
|
|
|
|
caf::PdmObject* object,
|
|
|
|
|
const QString& windowTitle,
|
|
|
|
|
const QStringList& uiConfigNameForTabs )
|
|
|
|
|
: QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
|
2026-06-04 16:33:45 +02:00
|
|
|
, m_windowTitle( windowTitle )
|
|
|
|
|
, m_objectClassKeyword( object ? object->classKeyword() : QString() )
|
2016-08-09 13:09:08 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
setWindowTitle( windowTitle );
|
2016-08-09 13:09:08 +02:00
|
|
|
|
|
|
|
|
QTabWidget* tabWidget = new QTabWidget;
|
2019-09-06 10:40:57 +02:00
|
|
|
|
|
|
|
|
for ( int i = 0; i < uiConfigNameForTabs.size(); i++ )
|
2016-08-09 13:09:08 +02:00
|
|
|
{
|
|
|
|
|
QHBoxLayout* widgetLayout = new QHBoxLayout;
|
2019-09-06 10:40:57 +02:00
|
|
|
widgetLayout->setContentsMargins( 0, 0, 0, 0 );
|
2017-02-22 11:58:56 +01:00
|
|
|
|
|
|
|
|
QWidget* containerWidget = new QWidget;
|
2019-09-06 10:40:57 +02:00
|
|
|
containerWidget->setLayout( widgetLayout );
|
2016-08-09 13:09:08 +02:00
|
|
|
|
|
|
|
|
caf::PdmUiPropertyView* pdmUiPropertyView = new caf::PdmUiPropertyView();
|
2019-09-06 10:40:57 +02:00
|
|
|
pdmUiPropertyView->setUiConfigurationName( uiConfigNameForTabs[i] );
|
2016-08-09 13:09:08 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
widgetLayout->addWidget( pdmUiPropertyView );
|
2016-08-09 13:09:08 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
tabWidget->addTab( containerWidget, uiConfigNameForTabs[i] );
|
|
|
|
|
pdmUiPropertyView->showProperties( object );
|
2016-08-09 13:09:08 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
m_pageWidgets.push_back( pdmUiPropertyView );
|
2016-08-09 13:09:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVBoxLayout* dialogLayout = new QVBoxLayout;
|
2019-09-06 10:40:57 +02:00
|
|
|
setLayout( dialogLayout );
|
2016-08-09 13:09:08 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
dialogLayout->addWidget( tabWidget );
|
2016-08-09 13:09:08 +02:00
|
|
|
|
|
|
|
|
// Buttons
|
2019-09-06 10:40:57 +02:00
|
|
|
m_dialogButtonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
|
|
|
|
|
connect( m_dialogButtonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
|
|
|
|
|
connect( m_dialogButtonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
|
2019-04-14 15:40:37 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
dialogLayout->addWidget( m_dialogButtonBox );
|
2016-08-09 13:09:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2016-08-09 13:09:08 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RiuPropertyViewTabWidget::~RiuPropertyViewTabWidget()
|
|
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
for ( auto w : m_pageWidgets )
|
2016-08-09 13:09:08 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
w->showProperties( nullptr );
|
2016-08-09 13:09:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
2017-02-22 11:58:56 +01:00
|
|
|
|
2019-04-14 15:40:37 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QSize RiuPropertyViewTabWidget::minimumSizeHint() const
|
|
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
QSize maxSizeHint( 0, 0 );
|
2019-04-14 15:40:37 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
for ( auto w : m_pageWidgets )
|
2019-04-14 15:40:37 +02:00
|
|
|
{
|
|
|
|
|
QSize pageSize = w->minimumSizeHint();
|
2019-09-06 10:40:57 +02:00
|
|
|
pageSize += QSize( 0, 100 );
|
2019-04-14 15:40:37 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
maxSizeHint = maxSizeHint.expandedTo( pageSize );
|
2019-04-14 15:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
2026-06-05 16:55:14 +02:00
|
|
|
// The inner scroll area reports an artificially small minimum width, which lets some window
|
|
|
|
|
// managers open the dialog collapsed (issue #14104). Provide a sensible floor.
|
|
|
|
|
return maxSizeHint.expandedTo( QSize( 300, 150 ) );
|
2019-04-14 15:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
2017-02-22 11:58:56 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2017-02-22 11:58:56 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QSize RiuPropertyViewTabWidget::sizeHint() const
|
|
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
QSize maxSizeHint( 0, 0 );
|
2017-02-22 11:58:56 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
for ( auto w : m_pageWidgets )
|
2017-02-22 11:58:56 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
// qDebug() << "tab size hint" << w->sizeHint();
|
2017-02-22 11:58:56 +01:00
|
|
|
|
|
|
|
|
QSize pageSize = w->sizeHint();
|
2025-11-14 12:56:23 +01:00
|
|
|
pageSize += QSize( 100, 100 );
|
2017-02-22 11:58:56 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
maxSizeHint = maxSizeHint.expandedTo( pageSize );
|
2017-02-22 11:58:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return maxSizeHint;
|
|
|
|
|
}
|
2019-04-01 16:21:43 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QDialogButtonBox* RiuPropertyViewTabWidget::dialogButtonBox()
|
|
|
|
|
{
|
|
|
|
|
return m_dialogButtonBox;
|
|
|
|
|
}
|
2026-06-04 16:33:45 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RiuPropertyViewTabWidget::showEvent( QShowEvent* event )
|
|
|
|
|
{
|
2026-06-05 16:55:14 +02:00
|
|
|
// Let the base class perform its initial sizing first, so the dialog is associated with the
|
|
|
|
|
// screen it actually opens on before we adjust its size.
|
|
|
|
|
QDialog::showEvent( event );
|
|
|
|
|
|
|
|
|
|
if ( !m_geometryRestored )
|
2026-06-04 16:33:45 +02:00
|
|
|
{
|
|
|
|
|
m_geometryRestored = true;
|
|
|
|
|
|
2026-06-05 16:55:14 +02:00
|
|
|
// Restore the stored size on first show. Doing this here rather than in the constructor
|
|
|
|
|
// ensures the size is applied reliably for a modal dialog and is not overridden by the
|
|
|
|
|
// initial sizing.
|
|
|
|
|
const bool restored = RiaPreferencesSystem::current()->isFeatureEnabled( "remember-dialog-size" ) && restoreDialogGeometry();
|
|
|
|
|
if ( !restored )
|
|
|
|
|
{
|
|
|
|
|
// No stored size: the dialog was laid out while associated with the screen it was built
|
|
|
|
|
// on, which on a multi-monitor setup can have a different DPI than the screen it ends up
|
|
|
|
|
// on. Recompute the layout for the current screen so the dialog is not shown collapsed
|
|
|
|
|
// (issue #14104). sizeHint()/minimumSizeHint() provide the floor.
|
|
|
|
|
adjustSize();
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-06-04 16:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RiuPropertyViewTabWidget::done( int result )
|
|
|
|
|
{
|
|
|
|
|
if ( RiaPreferencesSystem::current()->isFeatureEnabled( "remember-dialog-size" ) )
|
|
|
|
|
{
|
|
|
|
|
saveDialogGeometry();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QDialog::done( result );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QString RiuPropertyViewTabWidget::settingsKey() const
|
|
|
|
|
{
|
|
|
|
|
QString title = m_windowTitle;
|
|
|
|
|
title.replace( '/', '_' );
|
|
|
|
|
|
2026-06-05 16:47:49 +02:00
|
|
|
return QString( "RiuPropertyViewTabWidget/%1/%2" ).arg( m_objectClassKeyword, title );
|
2026-06-04 16:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2026-06-05 16:47:49 +02:00
|
|
|
/// Restore the dialog size from the stored width and height. Only the size is persisted; the window
|
|
|
|
|
/// position is left to the window manager to avoid the off-screen/wrong-monitor problems that come
|
|
|
|
|
/// with restoring an absolute position.
|
2026-06-04 16:33:45 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
bool RiuPropertyViewTabWidget::restoreDialogGeometry()
|
|
|
|
|
{
|
|
|
|
|
QSettings settings;
|
2026-06-05 16:47:49 +02:00
|
|
|
QVariant width = settings.value( settingsKey() + "/width" );
|
|
|
|
|
QVariant height = settings.value( settingsKey() + "/height" );
|
|
|
|
|
if ( width.isValid() && height.isValid() )
|
2026-06-04 16:33:45 +02:00
|
|
|
{
|
2026-06-05 16:47:49 +02:00
|
|
|
resize( width.toInt(), height.toInt() );
|
|
|
|
|
return true;
|
2026-06-04 16:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RiuPropertyViewTabWidget::saveDialogGeometry()
|
|
|
|
|
{
|
|
|
|
|
QSettings settings;
|
2026-06-05 16:47:49 +02:00
|
|
|
settings.setValue( settingsKey() + "/width", size().width() );
|
|
|
|
|
settings.setValue( settingsKey() + "/height", size().height() );
|
2026-06-04 16:33:45 +02:00
|
|
|
}
|