]> Creatis software - FrontAlgorithms.git/blob - appli/CTArteries/FileDialog.cxx
...
[FrontAlgorithms.git] / appli / CTArteries / FileDialog.cxx
1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
4
5 #include "FileDialog.h"
6
7 #include <QEvent>
8 #include <QListView>
9 #include <QPushButton>
10 #include <QTreeView>
11
12 // -------------------------------------------------------------------------
13 FileDialog::
14 FileDialog( QWidget* parent )
15   : QFileDialog( parent )
16 {
17   this->m_btnOpen = NULL;
18   this->m_listView = NULL;
19   this->m_treeView = NULL;
20   this->m_selectedFiles.clear( );
21
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 )
26   {
27     QString text = btns[ i ]->text( );
28     if(
29       text.toLower( ).contains( "open" ) ||
30       text.toLower().contains( "choose" ) )
31     {
32       this->m_btnOpen = btns[i];
33       break;
34
35     } // fi
36
37   } // rof
38   if( !this->m_btnOpen )
39     return;
40
41   this->m_btnOpen->installEventFilter( this );
42   this->m_btnOpen->disconnect( SIGNAL( clicked( ) ) );
43   this->connect(
44     this->m_btnOpen, SIGNAL( clicked( ) ), this, SLOT( chooseClicked( ) )
45     );
46   this->m_listView = findChild< QListView* >( "listView" );
47   if( this->m_listView )
48     this->m_listView->
49       setSelectionMode( QAbstractItemView::ExtendedSelection );
50
51   this->m_treeView = findChild< QTreeView* >( );
52   if( this->m_treeView )
53     this->m_treeView->
54       setSelectionMode( QAbstractItemView::ExtendedSelection );
55 }
56
57 // -------------------------------------------------------------------------
58 QStringList FileDialog::
59 selectedFiles( )
60 {
61   return( this->m_selectedFiles );
62 }
63
64 // -------------------------------------------------------------------------
65 bool FileDialog::
66 eventFilter( QObject* watched, QEvent* event )
67 {
68   QPushButton* btn = qobject_cast< QPushButton* >( watched );
69   if( btn )
70     if( event->type( ) == QEvent::EnabledChange )
71       if( !btn->isEnabled( ) )
72         btn->setEnabled( true );
73   return( this->QWidget::eventFilter( watched, event ) );
74 }
75
76 // -------------------------------------------------------------------------
77 void FileDialog::
78 chooseClicked( )
79 {
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( ) +
86         QDir::separator( ) +
87         index.data( ).toString( )
88         );
89   this->QDialog::accept( );
90 }
91
92 // eof - $RCSfile$