From ea212046fa2913029c17c14e53ff9c4a707c7ac3 Mon Sep 17 00:00:00 2001 From: kga Date: Wed, 27 Feb 2013 07:15:26 +0000 Subject: [PATCH] Fix a bug with PathList preference item --- src/Qtx/QtxPathEdit.cxx | 19 +++++++++++++++---- src/Qtx/QtxPathEdit.h | 5 +++-- src/Qtx/QtxPathListEdit.cxx | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Qtx/QtxPathEdit.cxx b/src/Qtx/QtxPathEdit.cxx index ae0dbfc69..57b6a8b04 100644 --- a/src/Qtx/QtxPathEdit.cxx +++ b/src/Qtx/QtxPathEdit.cxx @@ -22,10 +22,12 @@ // #include "QtxPathEdit.h" +#include #include #include #include #include +#include #include #include #include @@ -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(); } @@ -206,6 +214,9 @@ void QtxPathEdit::onBrowse( bool /*on*/ ) myPath->setText( QDir::convertSeparators( path ) ); myPath->setFocus(); + + if ( !path.isEmpty() && myBrowse ) + QApplication::postEvent( myPath, new QKeyEvent( QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier ) ); } /*! diff --git a/src/Qtx/QtxPathEdit.h b/src/Qtx/QtxPathEdit.h index de991be89..eb5100edd 100644 --- a/src/Qtx/QtxPathEdit.h +++ b/src/Qtx/QtxPathEdit.h @@ -34,8 +34,8 @@ class QTX_EXPORT QtxPathEdit : public QFrame Q_OBJECT public: - QtxPathEdit( const Qtx::PathType, QWidget* = 0 ); - QtxPathEdit( QWidget* = 0 ); + QtxPathEdit( const Qtx::PathType, QWidget* = 0, bool = false ); + QtxPathEdit( QWidget* = 0, bool = false ); virtual ~QtxPathEdit(); QString path() const; @@ -61,6 +61,7 @@ private: QLineEdit* myPath; Qtx::PathType myType; QString myFilter; + bool myBrowse; }; #endif diff --git a/src/Qtx/QtxPathListEdit.cxx b/src/Qtx/QtxPathListEdit.cxx index 17b3044f9..5a9f98379 100644 --- a/src/Qtx/QtxPathListEdit.cxx +++ b/src/Qtx/QtxPathListEdit.cxx @@ -143,7 +143,7 @@ public: \brief Constructor \internal */ - Editor( QWidget* parent = 0 ) : QtxPathEdit( parent ) + Editor( QWidget* parent = 0 ) : QtxPathEdit( parent, true ) { layout()->setSpacing( 0 ); lineEdit()->setFrame( false ); -- 2.39.2