Salome HOME
updated copyright message
[modules/gui.git] / src / Qtx / QtxPathEdit.cxx
index ae0dbfc69bb5a8c498871226827293ca13eecc32..cd881b9a9a75dd2363975fda90d7de33319c960a 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
 //
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 //
 #include "QtxPathEdit.h"
 
+#include <QApplication>
 #include <QLayout>
 #include <QDirModel>
 #include <QLineEdit>
 #include <QCompleter>
+#include <QKeyEvent>
 #include <QToolButton>
 #include <QFileDialog>
 #include <QRegExpValidator>
@@ -78,11 +80,14 @@ static const char* browse_icon[] = {
   \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();
 }
@@ -93,11 +98,14 @@ QtxPathEdit::QtxPathEdit( const Qtx::PathType type, QWidget* parent )
   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();
 }
@@ -203,9 +211,12 @@ void QtxPathEdit::onBrowse( bool /*on*/ )
   }
 
   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 ) );
 }
 
 /*!