-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// 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, or (at your option) any later version.
//
-// 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.
//
-// 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
//
-// 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/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
// File: QtxPathEdit.cxx
// Author: Sergey TELKOV
//
#include "QtxPathEdit.h"
+#include <QApplication>
#include <QLayout>
#include <QDirModel>
#include <QLineEdit>
#include <QCompleter>
+#include <QKeyEvent>
#include <QToolButton>
#include <QFileDialog>
#include <QRegExpValidator>
\brief Constructor
\param type widget mode (Qtx::PathType)
\param parent parent widget
+ \param browse if \c true, automatically finish editing of file path when
+ user presses OK in "Select File/Directory" dialog box
\sa pathType(), setPathType()
*/
-QtxPathEdit::QtxPathEdit( const Qtx::PathType type, QWidget* parent )
+QtxPathEdit::QtxPathEdit( const Qtx::PathType type, QWidget* parent, bool browse )
: QFrame( parent ),
- myType( type )
+ myType( type ),
+ myBrowse ( browse )
{
initialize();
}
Qtx::PT_OpenFile mode is used by default.
\param parent parent widget
+ \param browse if \c true, automatically finish editing of file path when
+ user presses OK in "Select File/Directory" dialog box
\sa pathType(), setPathType()
*/
-QtxPathEdit::QtxPathEdit( QWidget* parent )
+QtxPathEdit::QtxPathEdit( QWidget* parent, bool browse )
: QFrame( parent ),
- myType( Qtx::PT_OpenFile )
+ myType( Qtx::PT_OpenFile ),
+ myBrowse ( browse )
{
initialize();
}
void QtxPathEdit::onBrowse( bool /*on*/ )
{
QString path;
- QString initial = QFileInfo( myPath->text() ).path();
+ QString initial = QFileInfo( Qtx::makeEnvVarSubst( myPath->text() ) ).filePath();
switch ( pathType() )
{
case Qtx::PT_OpenFile:
}
if ( !path.isEmpty() )
- myPath->setText( QDir::convertSeparators( path ) );
+ myPath->setText( QDir::toNativeSeparators( path ) );
myPath->setFocus();
+
+ if ( !path.isEmpty() && myBrowse )
+ QApplication::postEvent( myPath, new QKeyEvent( QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier ) );
}
/*!
base->setSpacing( 5 );
base->addWidget( myPath = new QLineEdit( this ) );
- myPath->setValidator( new QRegExpValidator( QRegExp( "^([\\w/]{2}|[A-Z]:)[^:;\\*\\?]*[\\w\\\\/\\.]$" ), myPath ) );
+ myPath->setValidator( new QRegExpValidator( QRegExp( "^([\\$]|[\\%]|[\\w/]{2}|[A-Z]:)[^:;\\*\\?]*[\\w\\\\/\\.]$" ), myPath ) );
QToolButton* browse = new QToolButton( this );
browse->setIcon( QPixmap( browse_icon ) );