]> Creatis software - cpPlugins.git/blobdiff - lib/cpBaseQtApplication/Blocker.cxx
...
[cpPlugins.git] / lib / cpBaseQtApplication / Blocker.cxx
diff --git a/lib/cpBaseQtApplication/Blocker.cxx b/lib/cpBaseQtApplication/Blocker.cxx
new file mode 100644 (file)
index 0000000..634f25b
--- /dev/null
@@ -0,0 +1,67 @@
+#include <cpBaseQtApplication/Blocker.h>
+#include <QApplication>
+
+// -------------------------------------------------------------------------
+cpBaseQtApplication::Blocker::
+Blocker( )
+  : QObject( )
+{
+}
+
+// -------------------------------------------------------------------------
+cpBaseQtApplication::Blocker::
+~Blocker( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpBaseQtApplication::Blocker::
+block( )
+{
+  QApplication* app =
+    dynamic_cast< QApplication* >( QApplication::instance( ) );
+  if( app != NULL )
+  {
+    app->setOverrideCursor( Qt::WaitCursor );
+    app->installEventFilter( this );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpBaseQtApplication::Blocker::
+unblock( )
+{
+  QApplication* app =
+    dynamic_cast< QApplication* >( QApplication::instance( ) );
+  if( app != NULL )
+  {
+    while( app->overrideCursor( ) )
+      app->restoreOverrideCursor( );
+    app->removeEventFilter( this );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+bool cpBaseQtApplication::Blocker::
+eventFilter( QObject* obj, QEvent* event )
+{
+  return( true ); // -> Block all events
+  /* NOTE: this should be the correct implementation:
+     switch( event->type( ) )
+     {
+     //list event you want to prevent here ...
+     case QEvent::KeyPress:
+     case QEvent::KeyRelease:
+     case QEvent::MouseButtonRelease:
+     case QEvent::MouseButtonPress:
+     case QEvent::MouseButtonDblClick:
+     //...
+     return( true );
+     } // hctiws
+     return( this->QObject::eventFilter( obj, event ) );
+  */
+}
+
+// eof - $RCSfile$