+// 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 );
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();
}
}
-/*!
-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 )
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();
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
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;
}
}
-/*!
- 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() ) {
}
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