From: stv Date: Thu, 15 May 2008 13:42:54 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FBR_ATLAS_dev;p=modules%2Fgui.git *** empty log message *** --- diff --git a/src/Qtx/QtxPathEdit.cxx b/src/Qtx/QtxPathEdit.cxx index 3e0c37fa0..78bd5e150 100644 --- a/src/Qtx/QtxPathEdit.cxx +++ b/src/Qtx/QtxPathEdit.cxx @@ -1,17 +1,17 @@ // 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 +// 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 +// +// 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 +// 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 @@ -59,14 +59,14 @@ static const char* browse_icon[] = { \brief The QtxPathEdit class represents a widget for file or directory path preference items editing. - The path preference item is represented as the line edit box for the + The path preference item is represented as the line edit box for the direct path editing and small button clicking on which invokes browse - dialog box. The widget can be used in different modes: "Open File", + dialog box. The widget can be used in different modes: "Open File", "Save File", "Select Directory". The mode defines the type of the standard browse dialog box which is invoked on the button clicking. Initial path value can be set with setPath() method. Chosen path - can be retrieved with the path() method. The widget mode can be set + can be retrieved with the path() method. The widget mode can be set with setPathType() and retrieved with pathType() method. In addition, file/direcrory filters (wildcards) can be set with the @@ -144,7 +144,7 @@ QString QtxPathEdit::path() const /*! \brief Set path. - \param txt file or directory path + \param txt file or directory path \sa path() */ void QtxPathEdit::setPath( const QString& txt ) @@ -176,8 +176,19 @@ void QtxPathEdit::setPathFilter( const QString& f ) updateState(); } +bool QtxPathEdit::isReadOnly() const +{ + return myPath->isReadOnly(); +} + +void QtxPathEdit::setReadOnly( const bool on ) +{ + myPath->setReadOnly( on ); + myBrowse->setEnabled( !on ); +} + /*! - \brief Called when user clicks "Browse" button. + \brief Called when user clicks "Browse" button. Invokes standard browsng dialog box depending on the used widget mode. @@ -186,27 +197,20 @@ void QtxPathEdit::setPathFilter( const QString& f ) */ void QtxPathEdit::onBrowse( bool /*on*/ ) { - QString path; QString initial = QFileInfo( myPath->text() ).path(); - switch ( pathType() ) - { - case Qtx::PT_OpenFile: - path = QFileDialog::getOpenFileName( myPath, QString(), initial, pathFilter() ); - break; - case Qtx::PT_SaveFile: - path = QFileDialog::getSaveFileName( myPath, QString(), initial, pathFilter() ); - break; - case Qtx::PT_Directory: - path = QFileDialog::getExistingDirectory( myPath, QString(), initial ); - break; - } + QString path = browsePath( pathType(), initial ); if ( !path.isEmpty() ) - myPath->setText( QDir::convertSeparators( path ) ); + myPath->setText( QDir::convertSeparators( path ) ); myPath->setFocus(); } +void QtxPathEdit::onTextChanged( const QString& txt ) +{ + emit pathChanged( txt ); +} + /*! \brief Get internal line edit widget. \return line edit box widget @@ -216,6 +220,24 @@ QLineEdit* QtxPathEdit::lineEdit() const return myPath; } +QString QtxPathEdit::browsePath( const Qtx::PathType type, const QString& initial ) +{ + QString path; + switch ( type ) + { + case Qtx::PT_OpenFile: + path = QFileDialog::getOpenFileName( myPath, QString(), initial, pathFilter() ); + break; + case Qtx::PT_SaveFile: + path = QFileDialog::getSaveFileName( myPath, QString(), initial, pathFilter() ); + break; + case Qtx::PT_Directory: + path = QFileDialog::getExistingDirectory( myPath, QString(), initial ); + break; + } + return path; +} + /*! \brief Perform internal widget intialization. */ @@ -228,11 +250,12 @@ void QtxPathEdit::initialize() base->addWidget( myPath = new QLineEdit( this ) ); myPath->setValidator( new QRegExpValidator( QRegExp( "^([\\w/]{2}|[A-Z]:)[^:;\\*\\?]*[\\w\\\\/\\.]$" ), myPath ) ); - QToolButton* browse = new QToolButton( this ); - browse->setIcon( QPixmap( browse_icon ) ); - base->addWidget( browse ); + myBrowse = new QToolButton( this ); + myBrowse->setIcon( QPixmap( browse_icon ) ); + base->addWidget( myBrowse ); - connect( browse, SIGNAL( clicked( bool ) ), this, SLOT( onBrowse( bool ) ) ); + connect( myBrowse, SIGNAL( clicked( bool ) ), this, SLOT( onBrowse( bool ) ) ); + connect( myPath, SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); setFocusProxy( myPath ); diff --git a/src/Qtx/QtxPathEdit.h b/src/Qtx/QtxPathEdit.h index c4fe189c6..f5371e1bf 100644 --- a/src/Qtx/QtxPathEdit.h +++ b/src/Qtx/QtxPathEdit.h @@ -1,17 +1,17 @@ // 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 +// 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 +// +// 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 +// 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 @@ -27,6 +27,7 @@ #include class QLineEdit; +class QToolButton; class QTX_EXPORT QtxPathEdit : public QFrame { @@ -37,29 +38,38 @@ public: QtxPathEdit( QWidget* = 0 ); virtual ~QtxPathEdit(); - QString path() const; - void setPath( const QString& ); + QString path() const; + void setPath( const QString& ); + + Qtx::PathType pathType() const; + void setPathType( const Qtx::PathType ); + + QString pathFilter() const; + void setPathFilter( const QString& ); - Qtx::PathType pathType() const; - void setPathType( const Qtx::PathType ); + bool isReadOnly() const; + void setReadOnly( const bool ); - QString pathFilter() const; - void setPathFilter( const QString& ); +signals: + void pathChanged( const QString& ); private slots: - void onBrowse( bool = false ); + void onBrowse( bool = false ); + void onTextChanged( const QString& ); protected: - QLineEdit* lineEdit() const; + QLineEdit* lineEdit() const; + virtual QString browsePath( const Qtx::PathType, const QString& ); private: - void initialize(); - void updateState(); + void initialize(); + void updateState(); private: - QLineEdit* myPath; - Qtx::PathType myType; - QString myFilter; + QLineEdit* myPath; + Qtx::PathType myType; + QToolButton* myBrowse; + QString myFilter; }; #endif