// ========================================================================= // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) // ========================================================================= #include "FileDialog.h" #include #include #include #include // ------------------------------------------------------------------------- FileDialog:: FileDialog( QWidget* parent ) : QFileDialog( parent ) { this->m_btnOpen = NULL; this->m_listView = NULL; this->m_treeView = NULL; this->m_selectedFiles.clear( ); this->setOption( QFileDialog::DontUseNativeDialog, true ); this->setFileMode( QFileDialog::Directory ); QList< QPushButton* > btns = this->findChildren< QPushButton* >( ); for( int i = 0; i < btns.size( ); ++i ) { QString text = btns[ i ]->text( ); if( text.toLower( ).contains( "open" ) || text.toLower().contains( "choose" ) ) { this->m_btnOpen = btns[i]; break; } // fi } // rof if( !this->m_btnOpen ) return; this->m_btnOpen->installEventFilter( this ); this->m_btnOpen->disconnect( SIGNAL( clicked( ) ) ); this->connect( this->m_btnOpen, SIGNAL( clicked( ) ), this, SLOT( chooseClicked( ) ) ); this->m_listView = findChild< QListView* >( "listView" ); if( this->m_listView ) this->m_listView-> setSelectionMode( QAbstractItemView::ExtendedSelection ); this->m_treeView = findChild< QTreeView* >( ); if( this->m_treeView ) this->m_treeView-> setSelectionMode( QAbstractItemView::ExtendedSelection ); } // ------------------------------------------------------------------------- QStringList FileDialog:: selectedFiles( ) { return( this->m_selectedFiles ); } // ------------------------------------------------------------------------- bool FileDialog:: eventFilter( QObject* watched, QEvent* event ) { QPushButton* btn = qobject_cast< QPushButton* >( watched ); if( btn ) if( event->type( ) == QEvent::EnabledChange ) if( !btn->isEnabled( ) ) btn->setEnabled( true ); return( this->QWidget::eventFilter( watched, event ) ); } // ------------------------------------------------------------------------- void FileDialog:: chooseClicked( ) { QModelIndexList indexList = this->m_listView->selectionModel( )->selectedIndexes( ); foreach( QModelIndex index, indexList ) if( index.column( ) == 0 ) this->m_selectedFiles.append( this->directory( ).absolutePath( ) + QDir::separator( ) + index.data( ).toString( ) ); this->QDialog::accept( ); } // eof - $RCSfile$