mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Allow deleting of the last sub plot and have nice visible drop targets
This commit is contained in:
@@ -78,8 +78,8 @@ RiuGridPlotWindow::RiuGridPlotWindow( RimGridPlotWindow* plotDefinition, QWidget
|
||||
m_plotLayout->addWidget( m_plotWidgetFrame, 1 );
|
||||
|
||||
m_gridLayout = new QGridLayout( m_plotWidgetFrame );
|
||||
m_gridLayout->setMargin( 0 );
|
||||
m_gridLayout->setSpacing( 2 );
|
||||
m_gridLayout->setContentsMargins( 1, 1, 1, 1 );
|
||||
m_gridLayout->setSpacing( 1 );
|
||||
|
||||
QPalette newPalette( palette() );
|
||||
newPalette.setColor( QPalette::Background, Qt::white );
|
||||
@@ -96,6 +96,13 @@ RiuGridPlotWindow::RiuGridPlotWindow( RimGridPlotWindow* plotDefinition, QWidget
|
||||
|
||||
new RiuPlotObjectPicker( m_plotTitle, m_plotDefinition );
|
||||
|
||||
m_dropTargetPlaceHolder = new QLabel( "Drag plots here" );
|
||||
m_dropTargetPlaceHolder->setAlignment( Qt::AlignCenter );
|
||||
m_dropTargetPlaceHolder->setObjectName(
|
||||
QString( "%1" ).arg( reinterpret_cast<uint64_t>( m_dropTargetPlaceHolder.data() ) ) );
|
||||
m_dropTargetStyleSheet = createDropTargetStyleSheet();
|
||||
m_dropTargetStyleSheet.applyToWidget( m_dropTargetPlaceHolder );
|
||||
|
||||
this->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
|
||||
|
||||
setFocusPolicy( Qt::StrongFocus );
|
||||
@@ -105,6 +112,8 @@ RiuGridPlotWindow::RiuGridPlotWindow( RimGridPlotWindow* plotDefinition, QWidget
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
int defaultFontSize = RiaFontCache::pointSizeFromFontSizeEnum( app->preferences()->defaultPlotFontSize() );
|
||||
setFontSize( defaultFontSize );
|
||||
|
||||
this->setObjectName( QString( "%1" ).arg( reinterpret_cast<uint64_t>( this ) ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -202,28 +211,6 @@ void RiuGridPlotWindow::setPlotTitle( const QString& plotTitle )
|
||||
m_plotTitle->setText( plotTitle );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiuGridPlotWindow::preferredWidth() const
|
||||
{
|
||||
int titleWidth = 0;
|
||||
if ( m_plotTitle && m_plotTitle->isVisible() )
|
||||
{
|
||||
titleWidth = m_plotTitle->width();
|
||||
}
|
||||
|
||||
QList<QPointer<RiuQwtPlotWidget>> visiblePlotWidgets = this->visiblePlotWidgets();
|
||||
auto rowAndColumnCount = this->rowAndColumnCount( visiblePlotWidgets.size() );
|
||||
|
||||
int sumColumnWidths = 0;
|
||||
for ( int visibleIndex = 0; visibleIndex < rowAndColumnCount.second; ++visibleIndex )
|
||||
{
|
||||
sumColumnWidths += visiblePlotWidgets[visibleIndex]->width();
|
||||
}
|
||||
return std::max( titleWidth, sumColumnWidths );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -390,8 +377,10 @@ void RiuGridPlotWindow::showEvent( QShowEvent* event )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGridPlotWindow::dragEnterEvent( QDragEnterEvent* event )
|
||||
{
|
||||
if ( this->geometry().contains( event->pos() ) )
|
||||
RiuQwtPlotWidget* source = dynamic_cast<RiuQwtPlotWidget*>( event->source() );
|
||||
if ( source )
|
||||
{
|
||||
setWidgetState( RiuWidgetStyleSheet::DRAG_TARGET_INTO );
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
@@ -401,11 +390,13 @@ void RiuGridPlotWindow::dragEnterEvent( QDragEnterEvent* event )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGridPlotWindow::dragMoveEvent( QDragMoveEvent* event )
|
||||
{
|
||||
if ( this->geometry().contains( event->pos() ) )
|
||||
if ( event->answerRect().intersects( this->geometry() ) )
|
||||
{
|
||||
RiuQwtPlotWidget* source = dynamic_cast<RiuQwtPlotWidget*>( event->source() );
|
||||
if ( source )
|
||||
{
|
||||
setWidgetState( RiuWidgetStyleSheet::DRAG_TARGET_INTO );
|
||||
|
||||
QRect originalGeometry = source->geometry();
|
||||
QPoint offset = source->dragStartPosition();
|
||||
QRect newRect( event->pos() - offset, originalGeometry.size() );
|
||||
@@ -431,9 +422,8 @@ void RiuGridPlotWindow::dragMoveEvent( QDragMoveEvent* event )
|
||||
{
|
||||
int insertAfterIndex = insertBeforeIndex - 1;
|
||||
visiblePlotWidgets[insertAfterIndex]->setWidgetState( RiuWidgetStyleSheet::DRAG_TARGET_AFTER );
|
||||
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -443,6 +433,8 @@ void RiuGridPlotWindow::dragMoveEvent( QDragMoveEvent* event )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGridPlotWindow::dragLeaveEvent( QDragLeaveEvent* event )
|
||||
{
|
||||
setWidgetState( RiuWidgetStyleSheet::DEFAULT );
|
||||
|
||||
for ( int tIdx = 0; tIdx < m_plotWidgets.size(); ++tIdx )
|
||||
{
|
||||
m_plotWidgets[tIdx]->setWidgetState( RiuWidgetStyleSheet::DEFAULT );
|
||||
@@ -454,6 +446,8 @@ void RiuGridPlotWindow::dragLeaveEvent( QDragLeaveEvent* event )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGridPlotWindow::dropEvent( QDropEvent* event )
|
||||
{
|
||||
setWidgetState( RiuWidgetStyleSheet::DEFAULT );
|
||||
|
||||
for ( int tIdx = 0; tIdx < m_plotWidgets.size(); ++tIdx )
|
||||
{
|
||||
m_plotWidgets[tIdx]->setWidgetState( RiuWidgetStyleSheet::DEFAULT );
|
||||
@@ -533,6 +527,14 @@ void RiuGridPlotWindow::onSelectionManagerSelectionChanged( const std::set<int>&
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGridPlotWindow::setWidgetState( RiuWidgetStyleSheet::StateTag widgetState )
|
||||
{
|
||||
m_dropTargetStyleSheet.setWidgetState( m_dropTargetPlaceHolder, widgetState );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -589,54 +591,65 @@ void RiuGridPlotWindow::reinsertPlotWidgetsAndScrollbar()
|
||||
QList<QPointer<RiuQwtPlotWidget>> plotWidgets = this->visiblePlotWidgets();
|
||||
QList<QPointer<RiuQwtPlotLegend>> legends = this->visibleLegends();
|
||||
|
||||
auto rowAndColumnCount = this->rowAndColumnCount( plotWidgets.size() );
|
||||
|
||||
for ( int visibleIndex = 0; visibleIndex < plotWidgets.size(); ++visibleIndex )
|
||||
if ( plotWidgets.empty() )
|
||||
{
|
||||
int row = visibleIndex / rowAndColumnCount.second;
|
||||
int column = visibleIndex % rowAndColumnCount.second;
|
||||
|
||||
m_gridLayout->addWidget( legends[visibleIndex], 2 * row, column );
|
||||
m_gridLayout->addWidget( plotWidgets[visibleIndex], 2 * row + 1, column );
|
||||
|
||||
if ( m_plotDefinition->legendsVisible() )
|
||||
{
|
||||
int legendColumns = 1;
|
||||
if ( m_plotDefinition->legendsHorizontal() )
|
||||
{
|
||||
legendColumns = 0; // unlimited
|
||||
}
|
||||
legends[visibleIndex]->setMaxColumns( legendColumns );
|
||||
int minimumHeight = legends[visibleIndex]->heightForWidth( plotWidgets[visibleIndex]->width() );
|
||||
legends[visibleIndex]->setMinimumHeight( minimumHeight );
|
||||
QFont legendFont = legends[visibleIndex]->font();
|
||||
legendFont.setPointSize( fontSize() - 1 );
|
||||
legends[visibleIndex]->setFont( legendFont );
|
||||
legends[visibleIndex]->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
legends[visibleIndex]->hide();
|
||||
}
|
||||
|
||||
plotWidgets[visibleIndex]->setAxisLabelsAndTicksEnabled( QwtPlot::yLeft, column == 0 );
|
||||
plotWidgets[visibleIndex]->setAxisTitleEnabled( QwtPlot::yLeft, column == 0 );
|
||||
|
||||
plotWidgets[visibleIndex]->show();
|
||||
|
||||
int widthScaleFactor = plotWidgets[visibleIndex]->widthScaleFactor();
|
||||
if ( column == 0 )
|
||||
{
|
||||
widthScaleFactor += 1; // Give it a bit extra room due to axis
|
||||
}
|
||||
m_gridLayout->setColumnStretch( column,
|
||||
std::max( m_gridLayout->columnStretch( column ),
|
||||
plotWidgets[visibleIndex]->widthScaleFactor() ) );
|
||||
m_gridLayout->setRowStretch( 2 * row + 1, 1 );
|
||||
m_gridLayout->addWidget( m_dropTargetPlaceHolder, 0, 0 );
|
||||
m_dropTargetPlaceHolder->setVisible( true );
|
||||
m_scrollBar->setVisible( false );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dropTargetPlaceHolder->setVisible( false );
|
||||
|
||||
auto rowAndColumnCount = this->rowAndColumnCount( plotWidgets.size() );
|
||||
|
||||
for ( int visibleIndex = 0; visibleIndex < plotWidgets.size(); ++visibleIndex )
|
||||
{
|
||||
int row = visibleIndex / rowAndColumnCount.second;
|
||||
int column = visibleIndex % rowAndColumnCount.second;
|
||||
|
||||
m_gridLayout->addWidget( legends[visibleIndex], 2 * row, column );
|
||||
m_gridLayout->addWidget( plotWidgets[visibleIndex], 2 * row + 1, column );
|
||||
|
||||
if ( m_plotDefinition->legendsVisible() )
|
||||
{
|
||||
int legendColumns = 1;
|
||||
if ( m_plotDefinition->legendsHorizontal() )
|
||||
{
|
||||
legendColumns = 0; // unlimited
|
||||
}
|
||||
legends[visibleIndex]->setMaxColumns( legendColumns );
|
||||
int minimumHeight = legends[visibleIndex]->heightForWidth( plotWidgets[visibleIndex]->width() );
|
||||
legends[visibleIndex]->setMinimumHeight( minimumHeight );
|
||||
QFont legendFont = legends[visibleIndex]->font();
|
||||
legendFont.setPointSize( fontSize() - 1 );
|
||||
legends[visibleIndex]->setFont( legendFont );
|
||||
legends[visibleIndex]->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
legends[visibleIndex]->hide();
|
||||
}
|
||||
|
||||
plotWidgets[visibleIndex]->setAxisLabelsAndTicksEnabled( QwtPlot::yLeft, column == 0 );
|
||||
plotWidgets[visibleIndex]->setAxisTitleEnabled( QwtPlot::yLeft, column == 0 );
|
||||
|
||||
plotWidgets[visibleIndex]->show();
|
||||
|
||||
int widthScaleFactor = plotWidgets[visibleIndex]->widthScaleFactor();
|
||||
if ( column == 0 )
|
||||
{
|
||||
widthScaleFactor += 1; // Give it a bit extra room due to axis
|
||||
}
|
||||
m_gridLayout->setColumnStretch( column,
|
||||
std::max( m_gridLayout->columnStretch( column ),
|
||||
plotWidgets[visibleIndex]->widthScaleFactor() ) );
|
||||
m_gridLayout->setRowStretch( 2 * row + 1, 1 );
|
||||
}
|
||||
m_gridLayout->addLayout( m_scrollBarLayout, 1, rowAndColumnCount.second, rowAndColumnCount.first * 2 - 1, 1 );
|
||||
m_gridLayout->setColumnStretch( rowAndColumnCount.second, 0 );
|
||||
m_scrollBar->setVisible( true );
|
||||
}
|
||||
m_gridLayout->addLayout( m_scrollBarLayout, 1, rowAndColumnCount.second, rowAndColumnCount.first * 2 - 1, 1 );
|
||||
m_gridLayout->setColumnStretch( rowAndColumnCount.second, 0 );
|
||||
m_scrollBar->setVisible( plotWidgets.size() > 0 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -662,6 +675,22 @@ void RiuGridPlotWindow::clearGridLayout()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuWidgetStyleSheet RiuGridPlotWindow::createDropTargetStyleSheet()
|
||||
{
|
||||
RiuWidgetStyleSheet styleSheet;
|
||||
|
||||
styleSheet.set( "background-color", "white" );
|
||||
styleSheet.set( "border", "1px solid black" );
|
||||
styleSheet.set( "font-size", "14pt" );
|
||||
styleSheet.state( RiuWidgetStyleSheet::DRAG_TARGET_INTO ).set( "border", "1px solid lime" );
|
||||
styleSheet.state( RiuWidgetStyleSheet::DRAG_TARGET_INTO ).set( "background-color", "#DDFFDD" );
|
||||
|
||||
return styleSheet;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "RiuInterfaceToViewWindow.h"
|
||||
#include "RiuWidgetStyleSheet.h"
|
||||
|
||||
#include "cafPdmPointer.h"
|
||||
#include "cafSelectionChangedReceiver.h"
|
||||
@@ -64,7 +65,6 @@ public:
|
||||
void removePlot( RiuQwtPlotWidget* plotWidget );
|
||||
|
||||
void setPlotTitle( const QString& plotTitle );
|
||||
int preferredWidth() const;
|
||||
|
||||
void setTitleVisible( bool visible );
|
||||
void setScrollbarVisible( bool visible );
|
||||
@@ -95,13 +95,15 @@ protected:
|
||||
|
||||
virtual void onSelectionManagerSelectionChanged( const std::set<int>& changedSelectionLevels ) override;
|
||||
|
||||
void setWidgetState( RiuWidgetStyleSheet::StateTag widgetState );
|
||||
private slots:
|
||||
void performUpdate();
|
||||
|
||||
private:
|
||||
void alignCanvasTopsAndScrollbar();
|
||||
void reinsertPlotWidgetsAndScrollbar();
|
||||
void clearGridLayout();
|
||||
void alignCanvasTopsAndScrollbar();
|
||||
void reinsertPlotWidgetsAndScrollbar();
|
||||
void clearGridLayout();
|
||||
RiuWidgetStyleSheet createDropTargetStyleSheet();
|
||||
|
||||
QList<QPointer<RiuQwtPlotWidget>> visiblePlotWidgets() const;
|
||||
QList<QPointer<RiuQwtPlotLegend>> visibleLegends() const;
|
||||
@@ -118,6 +120,9 @@ protected:
|
||||
QList<int> m_legendColumns;
|
||||
QList<QPointer<RiuQwtPlotWidget>> m_plotWidgets;
|
||||
caf::PdmPointer<RimGridPlotWindow> m_plotDefinition;
|
||||
QPointer<QLabel> m_dropTargetPlaceHolder;
|
||||
|
||||
RiuWidgetStyleSheet m_dropTargetStyleSheet;
|
||||
|
||||
private:
|
||||
friend class RiaPlotWindowRedrawScheduler;
|
||||
|
||||
@@ -631,15 +631,7 @@ void RiuPlotMainWindow::addViewer( QWidget* viewer, const RimMdiWindowGeometry&
|
||||
}
|
||||
else
|
||||
{
|
||||
RiuGridPlotWindow* wellLogPlot = dynamic_cast<RiuGridPlotWindow*>( viewer );
|
||||
if ( wellLogPlot )
|
||||
{
|
||||
subWindowSize = QSize( wellLogPlot->preferredWidth(), m_mdiArea->height() );
|
||||
}
|
||||
else
|
||||
{
|
||||
subWindowSize = QSize( 400, 400 );
|
||||
}
|
||||
subWindowSize = QSize( 400, 400 );
|
||||
}
|
||||
|
||||
addViewerToMdiArea( m_mdiArea, viewer, subWindowPos, subWindowSize );
|
||||
|
||||
@@ -448,21 +448,7 @@ void RiuQwtPlotWidget::scheduleReplot()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQwtPlotWidget::setWidgetState( RiuWidgetStyleSheet::StateTag widgetState )
|
||||
{
|
||||
// Set all existing dynamic properties to false
|
||||
for ( QByteArray existingProperty : dynamicPropertyNames() )
|
||||
{
|
||||
setProperty( existingProperty, false );
|
||||
}
|
||||
|
||||
// Set current property state to true
|
||||
QString propertyName = RiuWidgetStyleSheet::propertyName( widgetState );
|
||||
if ( !propertyName.isEmpty() )
|
||||
{
|
||||
setProperty( propertyName.toLatin1(), true );
|
||||
}
|
||||
|
||||
// Trigger style update
|
||||
m_plotStyleSheet.refreshWidget( this );
|
||||
m_plotStyleSheet.setWidgetState( this, widgetState );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "cafAssert.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
#include <QStyle>
|
||||
#include <QWidget>
|
||||
@@ -30,8 +31,9 @@ void RiuWidgetStyleSheet::StateTagEnum::setUp()
|
||||
{
|
||||
addItem( RiuWidgetStyleSheet::DEFAULT, "", "" );
|
||||
addItem( RiuWidgetStyleSheet::SELECTED, "selected", "selected" );
|
||||
addItem( RiuWidgetStyleSheet::DRAG_TARGET_BEFORE, "dragTargetBefore", "drop Before" );
|
||||
addItem( RiuWidgetStyleSheet::DRAG_TARGET_AFTER, "dragTargetAfter", "drop After" );
|
||||
addItem( RiuWidgetStyleSheet::DRAG_TARGET_BEFORE, "dragTargetBefore", "drop before" );
|
||||
addItem( RiuWidgetStyleSheet::DRAG_TARGET_AFTER, "dragTargetAfter", "drop after" );
|
||||
addItem( RiuWidgetStyleSheet::DRAG_TARGET_INTO, "dragTargetInto", "drop into" );
|
||||
addItem( RiuWidgetStyleSheet::HOVER, "hover", "hover" );
|
||||
setDefault( RiuWidgetStyleSheet::DEFAULT );
|
||||
}
|
||||
@@ -136,6 +138,7 @@ QString RiuWidgetStyleSheet::propertyName( StateTag state )
|
||||
void RiuWidgetStyleSheet::applyToWidget( QWidget* widget ) const
|
||||
{
|
||||
QString completeStyleSheet = fullText( QString( widget->metaObject()->className() ), widget->objectName() );
|
||||
// qDebug().noquote() << completeStyleSheet;
|
||||
widget->setStyleSheet( completeStyleSheet );
|
||||
refreshWidget( widget );
|
||||
}
|
||||
@@ -149,6 +152,28 @@ void RiuWidgetStyleSheet::refreshWidget( QWidget* widget ) const
|
||||
widget->style()->polish( widget );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuWidgetStyleSheet::setWidgetState( QWidget* widget, StateTag widgetState ) const
|
||||
{
|
||||
// Set all existing dynamic properties to false
|
||||
for ( QByteArray existingProperty : widget->dynamicPropertyNames() )
|
||||
{
|
||||
widget->setProperty( existingProperty, false );
|
||||
}
|
||||
|
||||
// Set current property state to true
|
||||
QString propertyName = RiuWidgetStyleSheet::propertyName( widgetState );
|
||||
if ( !propertyName.isEmpty() )
|
||||
{
|
||||
widget->setProperty( propertyName.toLatin1(), true );
|
||||
}
|
||||
|
||||
// Trigger style update
|
||||
this->refreshWidget( widget );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
SELECTED = 0x0001,
|
||||
DRAG_TARGET_BEFORE = 0x0002,
|
||||
DRAG_TARGET_AFTER = 0x0004,
|
||||
DRAG_TARGET_INTO = 0x0008,
|
||||
// Pseudo States:
|
||||
PSEUDO_STATE_LIMIT = 0x1000,
|
||||
HOVER = 0x1000
|
||||
@@ -72,6 +73,7 @@ public:
|
||||
|
||||
void applyToWidget( QWidget* widget ) const;
|
||||
void refreshWidget( QWidget* widget ) const;
|
||||
void setWidgetState( QWidget* widget, StateTag widgetState ) const;
|
||||
|
||||
private:
|
||||
friend class RiuWidgetStyleSheetManager;
|
||||
|
||||
Reference in New Issue
Block a user