]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_FileDlg.cxx
Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/visu.git] / src / VISUGUI / VisuGUI_FileDlg.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : VisuGUI_FileDlg.cxx
21 //  Author : 
22 //  Module : SALOME
23 //  $Header: /dn05/salome/CVS/SALOME_ROOT/SALOME/src/VISUGUI/Visu_FileDlg.cxx
24
25
26 #include <qapplication.h>
27 #include <qpushbutton.h>
28 #include <qcheckbox.h>
29 #include <qstring.h>
30 #include <qlabel.h>
31
32 #include "VISUConfig.hh"
33 #include "VisuGUI_FileDlg.h"
34 #include "SUIT_ResourceMgr.h"
35
36 using namespace std;
37
38 bool VisuGUI_FileDlg::IsBuild = false; 
39
40 /*!
41 Constructor
42 */
43 VisuGUI_FileDlg::VisuGUI_FileDlg (QWidget* parent, 
44                                   bool open, 
45                                   bool showQuickDir, 
46                                   bool modal) :
47   SUIT_FileDlg(parent, open, showQuickDir, modal)
48
49   myCBuildAll = new QCheckBox (tr("FULL_LOAD"), this);
50   QLabel* label = new QLabel("", this);
51   label->setMaximumWidth(0);
52   QPushButton* pb = new QPushButton(this);               
53   pb->setMaximumWidth(0);
54   addWidgets( label, myCBuildAll, pb );
55   bool toBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false);
56   if (toBuildAll) myCBuildAll->setChecked(true);
57 }
58
59 /*!
60   Destructor
61 */
62 VisuGUI_FileDlg::~VisuGUI_FileDlg() 
63 {
64 }
65
66 /*!
67   Processes selection : tries to set given path or filename as selection
68 */
69 bool VisuGUI_FileDlg::processPath( const QString& path )
70 {
71   if ( !path.isNull() ) {
72     QFileInfo fi( path );
73     if ( fi.exists() ) {
74       if ( fi.isFile() )
75         setSelection( path );
76       else if ( fi.isDir() )
77         setDir( path );
78       return true;
79     }
80     else {
81       if ( QFileInfo( fi.dirPath() ).exists() ) {
82         setDir( fi.dirPath() );
83         return true;
84       }
85     }
86   }
87   return false;
88 }
89
90 /*!
91   Returns the file name for Open/Save [ static ]
92 */
93 QString VisuGUI_FileDlg::getFileName( QWidget*           parent, 
94                                       const QString&     initial, 
95                                       const QStringList& filters, 
96                                       const QString&     caption,
97                                       bool               open,
98                                       bool               showQuickDir,
99                                       SUIT_FileValidator* validator )
100 {            
101   VisuGUI_FileDlg* fd = new VisuGUI_FileDlg( parent, open, showQuickDir, true );    
102   if ( !caption.isEmpty() )
103     fd->setCaption( caption );
104   if ( !initial.isEmpty() ) { 
105     fd->processPath( initial ); // VSR 24/03/03 check for existing of directory has been added to avoid QFileDialog's bug
106   }
107   fd->setFilters( filters );        
108   if ( validator )
109     fd->setValidator( validator );
110   fd->exec();
111   QString filename = fd->selectedFile();
112   
113   VisuGUI_FileDlg::IsBuild = fd->IsChecked();
114   
115   delete fd;
116   qApp->processEvents();
117   
118   return filename;
119 }
120
121 bool VisuGUI_FileDlg::IsChecked() 
122 {
123   return myCBuildAll->isChecked();
124 }