Salome HOME
Join modifications from branch BR_3_1_0deb
[modules/gui.git] / src / SUIT / SUIT_FileDlg.cxx
index ed68b26ff03251340744f1e90602086d9d678029..80a6ad5890b411b4191c320ca3720390c1c52262 100755 (executable)
@@ -1,3 +1,21 @@
+// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either 
+// version 2.1 of the License.
+// 
+// This library is distributed in the hope that it will be useful 
+// but WITHOUT ANY WARRANTY; without even the implied warranty of 
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public  
+// License along with this library; if not, write to the Free Software 
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/
+//
 //*********************************************************************************
 // SUIT_FileDlg class is the extension of the Qt's Open/Save file dialog box.
 // To get the file/directory name(s) call static methods:
 
 #define MIN_COMBO_SIZE 100
 
-// If the selected file name has extension which does not match the selected filter
-// this extension is ignored (and new one will be added). See below for details.
+/*! If the selected file name has extension which does not match the selected filter
+ * this extension is ignored (and new one will be added). See below for details.
+ */
 const bool IGNORE_NON_MATCHING_EXTENSION = true;
 
 QString SUIT_FileDlg::myLastVisitedPath;
 
-/*!
-Constructor
-*/
+/*! Constructor */
 SUIT_FileDlg::SUIT_FileDlg( QWidget* parent, bool open, bool showQuickDir, bool modal ) :
 QFileDialog( parent, 0, modal ),
 myValidator( 0 ),
 myQuickCombo( 0 ), myQuickButton( 0 ), myQuickLab( 0 ),
-myOpen( open ),
-myAccepted( false )
+myOpen( open )//,
+//myAccepted( false )
 {    
+  const QObjectList* child = children();
+  QObjectList::const_iterator anIt = child->begin(), aLast = child->end();
+  for( ; anIt!=aLast; anIt++ )
+    if( (*anIt)->inherits( "QPushButton" ) )
+    {
+      QPushButton* bt = ( QPushButton* )( *anIt );
+      bt->setDefault( false );
+      bt->setAutoDefault( false );
+    }
+
   if ( parent->icon() )
     setIcon( *parent->icon() );       
   setSizeGripEnabled( true );
@@ -129,17 +156,13 @@ myAccepted( false )
   myValidator = new SUIT_FileValidator(this);
 }
 
-/*!
-Destructor
-*/
+/*! Destructor*/
 SUIT_FileDlg::~SUIT_FileDlg() 
 {
   setValidator( 0 );
 }
 
-/*!
-  Redefined from QFileDialog.
-*/
+/*! Redefined from QFileDialog.*/
 void SUIT_FileDlg::polish()
 {
   QFileDialog::polish();
@@ -177,10 +200,9 @@ void SUIT_FileDlg::polish()
   }
 }
 
-/*!
-Sets validator for file names to open/save
-Deletes previous validator if the dialog owns it.
-*/
+/*! Sets validator for file names to open/save
+ * Deletes previous validator if the dialog owns it.
+ */
 void SUIT_FileDlg::setValidator( SUIT_FileValidator* v )
 {
   if ( myValidator && myValidator->parent() == this )
@@ -188,35 +210,32 @@ void SUIT_FileDlg::setValidator( SUIT_FileValidator* v )
   myValidator = v;
 }
 
-/*!
-Returns the selected file
-*/
+/*! Returns the selected file */
 QString SUIT_FileDlg::selectedFile() const
 {
   return mySelectedFile;
 }
 
-/*!
-Returns 'true' if this is 'Open File' dialog 
-and 'false' if 'Save File' dialog
-*/
+/*! Returns 'true' if this is 'Open File' dialog 
+ *  and 'false' if 'Save File' dialog
+ */
 bool SUIT_FileDlg::isOpenDlg() const
 {
   return myOpen;
 }
 
-/*!
-Closes this dialog and sets the return code to 'Accepted'
-if the selected name is valid ( see 'acceptData()' )
-*/
+/*! Closes this dialog and sets the return code to 'Accepted'
+ * if the selected name is valid ( see 'acceptData()' )
+ */
 void SUIT_FileDlg::accept()
 {
-  /* myAccepted flag is used to warkaround the Qt 2.2.2 BUG: 
-     accept() method is called twice if user presses 'Enter' key 
-     in file name editor while file name is not acceptable by acceptData()
-     (e.g. permission denied)
-  */
-  if ( !myAccepted ) {
+  /* myAccepted 
+   * flag is used to warkaround the Qt 2.2.2 BUG: 
+   * accept() method is called twice if user presses 'Enter' key 
+   * in file name editor while file name is not acceptable by acceptData()
+   * (e.g. permission denied)
+   */
+//  if ( !myAccepted ) {
     if ( mode() != ExistingFiles ) {
       mySelectedFile = QFileDialog::selectedFile();
       addExtension();
@@ -225,54 +244,55 @@ void SUIT_FileDlg::accept()
     if ( acceptData() ) {
       myLastVisitedPath = dirPath();
       QFileDialog::accept();        
-      myAccepted = true;
+//      myAccepted = true;
     }
-  }
-  myAccepted = !myAccepted;
+//  }
+//  myAccepted = !myAccepted;
 }
 
-/*!
-Closes this dialog and sets the return code to 'Rejected'    
-*/
+/*! Closes this dialog and sets the return code to 'Rejected' */
 void SUIT_FileDlg::reject()
 {
   mySelectedFile = QString::null;
   QFileDialog::reject();        
 }
 
-/*!
-Returns 'true' if selected file is valid.
-The validity is checked by a file validator, 
-if there is no validator the file is always
-considered as valid    
-*/
+/*! Returns 'true' if selected file is valid.
+ * The validity is checked by a file validator, 
+ * if there is no validator the file is always
+ * considered as valid    
+ */
 bool SUIT_FileDlg::acceptData()
 {    
   if ( myValidator )
   {
     if ( isOpenDlg() )
-      if ( mode() == ExistingFiles ) {
-       QStringList fileNames = selectedFiles();
-       for ( int i = 0; i < fileNames.count(); i++ ) {
-         if ( !myValidator->canOpen( fileNames[i] ) )
-           return false;
-       }
-       return true;
+    {
+      if ( mode() == ExistingFiles )
+      {
+             QStringList fileNames = selectedFiles();
+             for ( int i = 0; i < (int)fileNames.count(); i++ )
+        {
+               if ( !myValidator->canOpen( fileNames[i] ) )
+                 return false;
+             }
+             return true;
       }
-      else {
-       return myValidator->canOpen( selectedFile() );
+      else
+      {
+             return myValidator->canOpen( selectedFile() );
       }
-    else 
+    }
+    else
       return myValidator->canSave( selectedFile() );
   }
   return true;
 }
 
-/*!
-Adds an extension to the selected file name
-if the file has not it.
-The extension is extracted from the active filter.
-*/
+/*! Adds an extension to the selected file name
+ * if the file has not it.
+ * The extension is extracted from the active filter.
+ */
 void SUIT_FileDlg::addExtension()
 {
   // check if file name entered is empty
@@ -328,15 +348,18 @@ void SUIT_FileDlg::addExtension()
     QRegExp anExtRExp( "^("+ aPattern + ")$" );
 
     // Check if the current file extension matches the pattern
-    if ( anExtRExp.match( anExt ) < 0 ) { 
+    if ( anExtRExp.match( anExt ) < 0 )
+    {
       // find first appropriate extension in the selected filter 
       // (it should be without wildcard symbols)
-      for ( int i = 0; i < extList.count(); i++ ) {
+      for ( int i = 0; i < (int)extList.count(); i++ )
+      {
         QString newExt = extList[i].replace( QRegExp( "[\\\\][+]" ),"+" );
         int res = newExt.findRev( '.' );
-        if ( res >= 0 ) 
+        if ( res >= 0 )
           newExt = newExt.mid( res + 1 );
-        if ( newExt.find( QRegExp("[*|?]" ) ) < 0 ) {
+        if ( newExt.find( QRegExp("[*|?]" ) ) < 0 )
+        {
           mySelectedFile.stripWhiteSpace();
           mySelectedFile += mySelectedFile.endsWith(".") ? newExt : QString(".") + newExt;
           break;
@@ -346,9 +369,7 @@ void SUIT_FileDlg::addExtension()
   }
 }
 
-/*!
-  Processes selection : tries to set given path or filename as selection
-*/
+/*! Processes selection : tries to set given path or filename as selection */
 bool SUIT_FileDlg::processPath( const QString& path )
 {
   if ( !path.isNull() ) {
@@ -370,23 +391,19 @@ bool SUIT_FileDlg::processPath( const QString& path )
   }
   return false;
 }
-/*!
-  Called when user selects item from "Quick Dir" combo box
-*/
+/*! Called when user selects item from "Quick Dir" combo box */
 void SUIT_FileDlg::quickDir(const QString& dirPath)
 {
   QString aPath = dirPath;
   if ( !QDir(aPath).exists() ) {
     aPath = QDir::homeDirPath();
-    /*    SUIT_MessageBox::error1(this, 
-                          tr("ERR_ERROR"),
-                          tr("ERR_DIR_NOT_EXIST").arg(dirPath), 
-                          tr("BUT_OK"));*/
-    
+    SUIT_MessageBox::error1(this, 
+                  tr("ERR_ERROR"),
+                  tr("ERR_DIR_NOT_EXIST").arg(dirPath), 
+                  tr("BUT_OK"));    
   }
-  //  else {
+  else
   processPath(aPath);
-    //  }
 }
 /*!
   Called when user presses "Add" button - adds current directory to quick directory