]> Creatis software - cpPlugins.git/blob - lib/cpBaseQtApplication/Blocker.cxx
634f25bfa7d170453a0600c2f981945789b1375c
[cpPlugins.git] / lib / cpBaseQtApplication / Blocker.cxx
1 #include <cpBaseQtApplication/Blocker.h>
2 #include <QApplication>
3
4 // -------------------------------------------------------------------------
5 cpBaseQtApplication::Blocker::
6 Blocker( )
7   : QObject( )
8 {
9 }
10
11 // -------------------------------------------------------------------------
12 cpBaseQtApplication::Blocker::
13 ~Blocker( )
14 {
15 }
16
17 // -------------------------------------------------------------------------
18 void cpBaseQtApplication::Blocker::
19 block( )
20 {
21   QApplication* app =
22     dynamic_cast< QApplication* >( QApplication::instance( ) );
23   if( app != NULL )
24   {
25     app->setOverrideCursor( Qt::WaitCursor );
26     app->installEventFilter( this );
27
28   } // fi
29 }
30
31 // -------------------------------------------------------------------------
32 void cpBaseQtApplication::Blocker::
33 unblock( )
34 {
35   QApplication* app =
36     dynamic_cast< QApplication* >( QApplication::instance( ) );
37   if( app != NULL )
38   {
39     while( app->overrideCursor( ) )
40       app->restoreOverrideCursor( );
41     app->removeEventFilter( this );
42
43   } // fi
44 }
45
46 // -------------------------------------------------------------------------
47 bool cpBaseQtApplication::Blocker::
48 eventFilter( QObject* obj, QEvent* event )
49 {
50   return( true ); // -> Block all events
51   /* NOTE: this should be the correct implementation:
52      switch( event->type( ) )
53      {
54      //list event you want to prevent here ...
55      case QEvent::KeyPress:
56      case QEvent::KeyRelease:
57      case QEvent::MouseButtonRelease:
58      case QEvent::MouseButtonPress:
59      case QEvent::MouseButtonDblClick:
60      //...
61      return( true );
62      } // hctiws
63      return( this->QObject::eventFilter( obj, event ) );
64   */
65 }
66
67 // eof - $RCSfile$