1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
5 #include "FileDialog.h"
12 // -------------------------------------------------------------------------
14 FileDialog( QWidget* parent )
15 : QFileDialog( parent )
17 this->m_btnOpen = NULL;
18 this->m_listView = NULL;
19 this->m_treeView = NULL;
20 this->m_selectedFiles.clear( );
22 this->setOption( QFileDialog::DontUseNativeDialog, true );
23 this->setFileMode( QFileDialog::Directory );
24 QList< QPushButton* > btns = this->findChildren< QPushButton* >( );
25 for( int i = 0; i < btns.size( ); ++i )
27 QString text = btns[ i ]->text( );
29 text.toLower( ).contains( "open" ) ||
30 text.toLower().contains( "choose" ) )
32 this->m_btnOpen = btns[i];
38 if( !this->m_btnOpen )
41 this->m_btnOpen->installEventFilter( this );
42 this->m_btnOpen->disconnect( SIGNAL( clicked( ) ) );
44 this->m_btnOpen, SIGNAL( clicked( ) ), this, SLOT( chooseClicked( ) )
46 this->m_listView = findChild< QListView* >( "listView" );
47 if( this->m_listView )
49 setSelectionMode( QAbstractItemView::ExtendedSelection );
51 this->m_treeView = findChild< QTreeView* >( );
52 if( this->m_treeView )
54 setSelectionMode( QAbstractItemView::ExtendedSelection );
57 // -------------------------------------------------------------------------
58 QStringList FileDialog::
61 return( this->m_selectedFiles );
64 // -------------------------------------------------------------------------
66 eventFilter( QObject* watched, QEvent* event )
68 QPushButton* btn = qobject_cast< QPushButton* >( watched );
70 if( event->type( ) == QEvent::EnabledChange )
71 if( !btn->isEnabled( ) )
72 btn->setEnabled( true );
73 return( this->QWidget::eventFilter( watched, event ) );
76 // -------------------------------------------------------------------------
80 QModelIndexList indexList =
81 this->m_listView->selectionModel( )->selectedIndexes( );
82 foreach( QModelIndex index, indexList )
83 if( index.column( ) == 0 )
84 this->m_selectedFiles.append(
85 this->directory( ).absolutePath( ) +
87 index.data( ).toString( )
89 this->QDialog::accept( );