Salome HOME
DCQ : Merge with Ecole Ete a6.
[modules/visu.git] / src / VISUGUI / VisuGUI_FileDlg.cxx
1 //  SALOME SALOMEGUI : GUI of VISU module
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : QAD_FileDlg.cxx
8 //  Author : 
9 //  Module : SALOME
10 //  $Header: /dn05/salome/CVS/SALOME_ROOT/SALOME/src/VISUGUI/Visu_FileDlg.cxx
11
12
13 #include <qapplication.h>
14 #include <qlabel.h>
15 #include <qpushbutton.h>
16 #include <qstring.h>
17 #include "QAD_Config.h"
18 #include "VisuGUI_FileDlg.h"
19
20 using namespace std;
21
22 bool VisuGUI_FileDlg::IsBuild = false; 
23
24 /*!
25 Constructor
26 */
27 VisuGUI_FileDlg::VisuGUI_FileDlg( QWidget* parent, bool open, bool showQuickDir, bool modal ) :
28   QAD_FileDlg( parent, open, showQuickDir,  modal )
29
30   myCBuildAll = new QCheckBox( tr("Full loading for current file"), this );
31   QLabel* label = new QLabel("", this);
32   label->setMaximumWidth(0);
33   QPushButton* pb = new QPushButton(this);               
34   pb->setMaximumWidth(0);
35   addWidgets( label, myCBuildAll, pb );
36   QString aIsBuild = QAD_CONFIG->getSetting("Visu:BuildResult");
37   if (aIsBuild.isEmpty()? 0 : aIsBuild.toInt()) myCBuildAll->setChecked(true);
38 }
39
40 /*!
41   Destructor
42 */
43 VisuGUI_FileDlg::~VisuGUI_FileDlg() 
44 {
45 }
46
47 /*!
48   Processes selection : tries to set given path or filename as selection
49 */
50 bool VisuGUI_FileDlg::processPath( const QString& path )
51 {
52   if ( !path.isNull() ) {
53     QFileInfo fi( path );
54     if ( fi.exists() ) {
55       if ( fi.isFile() )
56         setSelection( path );
57       else if ( fi.isDir() )
58         setDir( path );
59       return true;
60     }
61     else {
62       if ( QFileInfo( fi.dirPath() ).exists() ) {
63         setDir( fi.dirPath() );
64         return true;
65       }
66     }
67   }
68   return false;
69 }
70
71 /*!
72   Returns the file name for Open/Save [ static ]
73 */
74 QString VisuGUI_FileDlg::getFileName( QWidget*           parent, 
75                                       const QString&     initial, 
76                                       const QStringList& filters, 
77                                       const QString&     caption,
78                                       bool               open,
79                                       bool               showQuickDir,
80                                       QAD_FileValidator* validator )
81 {            
82   VisuGUI_FileDlg* fd = new VisuGUI_FileDlg( parent, open, showQuickDir, true );    
83   if ( !caption.isEmpty() )
84     fd->setCaption( caption );
85   if ( !initial.isEmpty() ) { 
86     fd->processPath( initial ); // VSR 24/03/03 check for existing of directory has been added to avoid QFileDialog's bug
87   }
88   fd->setFilters( filters );        
89   if ( validator )
90     fd->setValidator( validator );
91   fd->exec();
92   QString filename = fd->selectedFile();
93   
94   VisuGUI_FileDlg::IsBuild = fd->IsChecked();
95   
96   delete fd;
97   qApp->processEvents();
98   
99   return filename;
100 }
101
102 bool VisuGUI_FileDlg::IsChecked() 
103 {
104   return myCBuildAll->isChecked();
105 }