2017-04-07 04:24:50 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-04-07 04:24:50 -05: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-04-07 04:24:50 -05: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-04-07 04:24:50 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RiuPlotObjectPicker.h"
|
|
|
|
|
2019-05-06 03:36:05 -05:00
|
|
|
#include "RiaGuiApplication.h"
|
2018-04-26 23:28:08 -05:00
|
|
|
#include "RiuPlotMainWindow.h"
|
2017-04-07 04:24:50 -05:00
|
|
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-04-07 04:24:50 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
RiuPlotObjectPicker::RiuPlotObjectPicker( QWidget* widget, caf::PdmObject* associatedObject )
|
|
|
|
: QObject( widget )
|
|
|
|
, m_associatedObject( associatedObject )
|
2017-04-07 04:24:50 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
widget->installEventFilter( this );
|
2017-04-07 04:24:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-04-07 04:24:50 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
bool RiuPlotObjectPicker::eventFilter( QObject* watchedObject, QEvent* event )
|
2017-04-07 04:24:50 -05:00
|
|
|
{
|
2019-05-06 03:36:05 -05:00
|
|
|
RiuPlotMainWindow* mainPlotWindow = RiaGuiApplication::instance()->mainPlotWindow();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( mainPlotWindow && m_associatedObject.notNull() )
|
2017-04-07 04:24:50 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( event->type() == QEvent::MouseButtonPress )
|
2017-04-07 04:24:50 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QMouseEvent* me = static_cast<QMouseEvent*>( event );
|
|
|
|
if ( me->button() == Qt::RightButton )
|
2017-04-19 00:46:39 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
mainPlotWindow->selectAsCurrentItem( m_associatedObject );
|
2017-04-19 00:46:39 -05:00
|
|
|
}
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
else if ( event->type() == QEvent::MouseButtonRelease )
|
2017-04-19 00:46:39 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QMouseEvent* me = static_cast<QMouseEvent*>( event );
|
|
|
|
if ( me->button() == Qt::LeftButton )
|
2017-04-07 04:24:50 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
mainPlotWindow->selectAsCurrentItem( m_associatedObject );
|
2017-04-07 04:24:50 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// standard event processing
|
2019-09-06 03:40:57 -05:00
|
|
|
return QObject::eventFilter( watchedObject, event );
|
2017-04-07 04:24:50 -05:00
|
|
|
}
|