]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_DialogRunner.cxx
Salome HOME
f8e15e861d93f3f7db6a2b535e66b054fd98f694
[modules/visu.git] / src / VISUGUI / VisuGUI_DialogRunner.cxx
1 // File:        VisuGUI_DialogRunner.cxx
2 // Created:     Thu Oct  6 10:17:39 2005
3 // Author:      Alexander SOLOVYOV
4 //              <asl@multiplex.nnov.opencascade.com>
5
6 #include "VisuGUI_DialogRunner.h"
7
8 #include <qdialog.h>
9 #include <qapplication.h>
10
11 VisuGUI_DialogRunner::VisuGUI_DialogRunner( QDialog* dlg )
12 : QObject(),
13   myDlg( dlg ),
14   myInLoop( false )
15 {
16   if( myDlg )
17   {
18     connect( myDlg, SIGNAL( destroyed() ), this, SLOT( onDialogDelete() ) );
19     myDlg->installEventFilter( this );
20   }
21 }
22
23 VisuGUI_DialogRunner::~VisuGUI_DialogRunner()
24 {
25 }
26
27 int VisuGUI_DialogRunner::run( const bool modal )
28 {
29   if( myInLoop || !myDlg )
30     return -1;
31
32   qDebug( "start" );
33   if( modal )
34     return myDlg->exec();
35
36   myInLoop = true;
37   myDlg->show();
38   qDebug( "enter loop" );
39   qApp->enter_loop();
40   qDebug( "after loop" );
41   return myDlg->result();
42 }
43
44 void VisuGUI_DialogRunner::onDialogDelete()
45 {
46   if( myInLoop )
47     qApp->exit_loop();
48
49   myDlg = 0;
50   myInLoop = false;
51 }
52
53 bool VisuGUI_DialogRunner::eventFilter( QObject* o, QEvent* e )
54 {
55   if( o==myDlg && e && ( e->type()==QEvent::Close || e->type()==QEvent::Hide ) )
56   {
57     if( myInLoop && !myDlg->isMinimized() )
58     {
59       myInLoop = false;
60       qApp->exit_loop();
61     }
62     return false;
63   }
64   else
65     return QObject::eventFilter( o, e );
66 }