<commit_before>/*=========================================================================

Program:   Medical Imaging & Interaction Toolkit
Module:    $RCSfile$
Language:  C++
Date:      $Date$
Version:   $Revision$

Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "mitkVolumeDataVtkMapper3D.h"
#include "QmitkAbortEventFilter.h"
#include "QmitkRenderWindow.h"
#include "mitkRenderingManager.h"

#include <qapplication.h>
#include <qeventloop.h>

QmitkAbortEventFilter*
QmitkAbortEventFilter
::GetInstance()
{
  static QmitkAbortEventFilter instance;
  return &instance;
}

QmitkAbortEventFilter::QmitkAbortEventFilter()
{
}
QmitkAbortEventFilter::~QmitkAbortEventFilter()

{
}

bool QmitkAbortEventFilter::eventFilter( QObject *object, QEvent *event )
{ 
  if (mitk::RenderingManager::GetInstance()->IsRendering() )
  {
    switch ( event->type() )
    {
   
    case QEvent::MouseButtonPress:
    { 
      m_ButtonPressed = true;
      //std::cout << "#BP ";

      mitk::RenderingManager::GetInstance()->AbortRendering( NULL );
      QMouseEvent* me = ( QMouseEvent* )( event );

      QMouseEvent* newEvent = new QMouseEvent(
        me->type(), me->pos(), me->globalPos(), me->button(), me->state()
      );
      m_EventQueue.push( ObjectEventPair(object, newEvent) );
      return true;
    }

    
    case QEvent::MouseButtonDblClick:
    { 
      mitk::RenderingManager::GetInstance()->AbortRendering( NULL );
      QMouseEvent* me = ( QMouseEvent* )( event );

      QMouseEvent* newEvent = new QMouseEvent(
        me->type(), me->pos(), me->globalPos(), me->button(), me->state()
      );
      m_EventQueue.push( ObjectEventPair(object, newEvent) );
      return true;
    }

    case QEvent::MouseButtonRelease:
    { 
      m_ButtonPressed = false;
      //std::cout << "#BR ";
      
      QMouseEvent* me = ( QMouseEvent* )( event );

      QMouseEvent* newEvent = new QMouseEvent(
        me->type(), me->pos(), me->globalPos(), me->button(), me->state()
      );
      m_EventQueue.push( ObjectEventPair(object, newEvent) );
      return true;
    }

    case QEvent::MouseMove:
    { 
      if(m_ButtonPressed)
      {

        QMouseEvent* me = ( QMouseEvent* )( event );
        QMouseEvent* newEvent = new QMouseEvent(
          me->type(), me->pos(), me->globalPos(), me->button(), me->state()
        );
        m_EventQueue.push( ObjectEventPair(object, newEvent) );

  //std::cout << "#MM ";
        if(mitk::RenderingManager::GetInstance()->GetCurrentLOD()!=0)
        {
          mitk::RenderingManager::GetInstance()->SetCurrentLOD(0);
          mitk::RenderingManager::GetInstance()->AbortRendering( NULL );
        }
      }
      return true;
    }
    
   
    case QEvent::Resize:
      { 
        //std::cout << "#R ";
        mitk::RenderingManager::GetInstance()->AbortRendering( NULL );

        QResizeEvent* re = ( QResizeEvent* )( event );

        QResizeEvent* newResizeEvent = new QResizeEvent( re->size(), re->oldSize() );
        m_EventQueue.push( ObjectEventPair(object, newResizeEvent) );
        return true;
      }

    case QEvent::Paint:
      { 
        //std::cout << "#P ";
        QPaintEvent* pe = ( QPaintEvent* )( event );
        QPaintEvent* newPaintEvent = new QPaintEvent( pe->region() );
        m_EventQueue.push( ObjectEventPair(object, newPaintEvent) );
        return true;
      }

     case QEvent::ShowWindowRequest:
      { 
        //std::cout << "#WR ";
        return false;
      }

      case QEvent::LayoutHint:
      { 
        //std::cout << "#L ";
        return false;
      }
     case QEvent::ChildInserted: //change Layout (Big3D, 2D images up, etc.)
      {
        //std::cout << "#CI ";
        mitk::RenderingManager::GetInstance()->SetCurrentLOD(0);
        mitk::RenderingManager::GetInstance()->AbortRendering( NULL );
        return false;
      }

      case QEvent::KeyPress:
      { 
        //std::cout << "#KP ";
        mitk::RenderingManager::GetInstance()->AbortRendering( NULL );
        QKeyEvent* ke = ( QKeyEvent* )( event );
        QKeyEvent* newEvent = new QKeyEvent(
          ke->type(), ke->key(), ke->ascii(), ke->state(), ke->text(), false, ke->count()
        );
        m_EventQueue.push( ObjectEventPair(object, newEvent) );
        return true;
      }

      //std::cout<<"Event Type: (Rendering)"<<event->type()<<std::endl;
      default:
      {
        return false;
      }
    }
  }
 else
  {
    if(event->type()==QEvent::MouseButtonPress)<commit_msg>ENH: Added handling of QEvent::Timer<commit_after>/*=========================================================================

Program:   Medical Imaging & Interaction Toolkit
Module:    $RCSfile$
Language:  C++
Date:      $Date$
Version:   $Revision$

Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "mitkVolumeDataVtkMapper3D.h"
#include "QmitkAbortEventFilter.h"
#include "QmitkRenderWindow.h"
#include "mitkRenderingManager.h"

#include <qapplication.h>
#include <qeventloop.h>

QmitkAbortEventFilter*
QmitkAbortEventFilter
::GetInstance()
{
  static QmitkAbortEventFilter instance;
  return &instance;
}

QmitkAbortEventFilter::QmitkAbortEventFilter()
{
}
QmitkAbortEventFilter::~QmitkAbortEventFilter()

{
}

bool QmitkAbortEventFilter::eventFilter( QObject *object, QEvent *event )
{ 
  if (mitk::RenderingManager::GetInstance()->IsRendering() )
  {
    switch ( event->type() )
    {
   
    case QEvent::MouseButtonPress:
    { 
      m_ButtonPressed = true;
      //std::cout << "#BP ";

      mitk::RenderingManager::GetInstance()->AbortRendering( NULL );
      QMouseEvent* me = ( QMouseEvent* )( event );

      QMouseEvent* newEvent = new QMouseEvent(
        me->type(), me->pos(), me->globalPos(), me->button(), me->state()
      );
      m_EventQueue.push( ObjectEventPair(object, newEvent) );
      return true;
    }

    
    case QEvent::MouseButtonDblClick:
    { 
      mitk::RenderingManager::GetInstance()->AbortRendering( NULL );
      QMouseEvent* me = ( QMouseEvent* )( event );

      QMouseEvent* newEvent = new QMouseEvent(
        me->type(), me->pos(), me->globalPos(), me->button(), me->state()
      );
      m_EventQueue.push( ObjectEventPair(object, newEvent) );
      return true;
    }

    case QEvent::MouseButtonRelease:
    { 
      m_ButtonPressed = false;
      //std::cout << "#BR ";
      
      QMouseEvent* me = ( QMouseEvent* )( event );

      QMouseEvent* newEvent = new QMouseEvent(
        me->type(), me->pos(), me->globalPos(), me->button(), me->state()
      );
      m_EventQueue.push( ObjectEventPair(object, newEvent) );
      return true;
    }

    case QEvent::MouseMove:
    { 
      if(m_ButtonPressed && mitk::RenderingManager::GetInstance()->GetCurrentLOD()!=0)
      {
      //std::cout << "#MM ";
          mitk::RenderingManager::GetInstance()->SetCurrentLOD(0);
          mitk::RenderingManager::GetInstance()->AbortRendering( NULL );
      }
      return true;
    }
    
   
    case QEvent::Resize:
      { 
        //std::cout << "#R ";
        mitk::RenderingManager::GetInstance()->AbortRendering( NULL );

        QResizeEvent* re = ( QResizeEvent* )( event );

        QResizeEvent* newResizeEvent = new QResizeEvent( re->size(), re->oldSize() );
        m_EventQueue.push( ObjectEventPair(object, newResizeEvent) );
        return true;
      }

    case QEvent::Paint:
      { 
        //std::cout << "#P ";
        QPaintEvent* pe = ( QPaintEvent* )( event );
        QPaintEvent* newPaintEvent = new QPaintEvent( pe->region() );
        m_EventQueue.push( ObjectEventPair(object, newPaintEvent) );
        return true;
      }

     case QEvent::ShowWindowRequest:
      { 
        //std::cout << "#WR ";
        return false;
      }

      case QEvent::LayoutHint:
      { 
        //std::cout << "#L ";
        return false;
      }
     case QEvent::ChildInserted: //change Layout (Big3D, 2D images up, etc.)
      {
        //std::cout << "#CI ";
        mitk::RenderingManager::GetInstance()->SetCurrentLOD(0);
        mitk::RenderingManager::GetInstance()->AbortRendering( NULL );
        return false;
      }

      case QEvent::KeyPress:
      { 
        //std::cout << "#KP ";
        mitk::RenderingManager::GetInstance()->AbortRendering( NULL );
        QKeyEvent* ke = ( QKeyEvent* )( event );
        QKeyEvent* newEvent = new QKeyEvent(
          ke->type(), ke->key(), ke->ascii(), ke->state(), ke->text(), false, ke->count()
        );
        m_EventQueue.push( ObjectEventPair(object, newEvent) );
        return true;
      }

      case QEvent::Timer:
      { 
        //std::cout << "#T ";
        QTimerEvent* te = ( QTimerEvent* )( event );
        QTimerEvent* newEvent = new QTimerEvent(te->timerId());
        m_EventQueue.push( ObjectEventPair(object, newEvent) );
        return true;
      }

      default:
      {
        //std::cout<<"Event Type: (Rendering)"<<event->type()<<std::endl;
        return false;
      }
    }
  }
 else
  {
    if(event->type()==QEvent::MouseButtonPress)
{'fraction_non_alphanumeric': 0.17190839694656487, 'fraction_numerical': 0.0012213740458015267, 'mean_word_length': 2.8624213836477987, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5371914', 'n_tokens_mistral': 2997, 'n_tokens_neox': 2966, 'n_words': 594}