17 : QTableView ( parent ),
18 ContextMenu ( nullptr ),
19 LaunchIncludeEditor ( nullptr ),
20 HideReadOnlyFiles ( nullptr ),
22 FindFileDialog ( nullptr ),
24 NextButton ( nullptr ),
29 setSelectionBehavior ( SelectionBehavior::SelectRows );
30 horizontalHeader()->setSectionResizeMode ( QHeaderView::ResizeMode::Stretch );
31 setSortingEnabled (
true );
36 QShortcut * Shortcut =
new QShortcut ( QKeySequence ( tr (
"Ctrl+F" ) ),
this );
38 FindFile =
new QAction ( tr (
"Find File" ),
this );
39 FindFile->setShortcut ( QKeySequence ( tr (
"Ctrl+F" ) ) );
40 FindFile->setShortcutContext ( Qt::WidgetShortcut );
41 connect ( FindFile, SIGNAL ( triggered() ),
this, SLOT ( FindFileSlot() ) );
42 connect ( Shortcut, SIGNAL ( activated() ),
this, SLOT ( FindFileSlot() ) );
43 ContextMenu->addAction ( FindFile );
45 LaunchIncludeEditor =
new QAction ( tr (
"Add/Remove Files" ),
this );
46 LaunchIncludeEditor->setShortcutContext ( Qt::WidgetShortcut );
47 connect ( LaunchIncludeEditor, SIGNAL ( triggered() ),
this,
48 SLOT ( LaunchIncludeEditorSlot() ) );
49 ContextMenu->addAction ( LaunchIncludeEditor );
51 HideReadOnlyFiles =
new QAction ( tr (
"Hide Read Only Files" ),
this );
52 HideReadOnlyFiles->setShortcutContext ( Qt::WidgetShortcut );
53 HideReadOnlyFiles->setCheckable (
true );
54 HideReadOnlyFiles->setChecked (
false );
55 connect ( HideReadOnlyFiles, SIGNAL ( triggered (
bool ) ),
this,
56 SLOT ( HideReadOnlyFilesSlot (
bool ) ) );
57 ContextMenu->addAction ( HideReadOnlyFiles );
77 QModelIndex Index = indexAt ( Event->pos() );
79 if ( Index.isValid() )
81 setCurrentIndex ( Index );
82 selectionModel()->setCurrentIndex ( Index, QItemSelectionModel::NoUpdate );
83 ContextMenu->exec ( Event->globalPos() );
92 QString UserType = LineEdit->text();
94 if ( UserType.isEmpty() )
99 QAbstractItemModel * Model = model();
101 if ( Model !=
nullptr )
103 QVariant StringCriterium = QVariant ( UserType );
105 QModelIndex find_by_name = Model->index ( 0, 0 );
106 QModelIndex find_by_path = Model->index ( 0, 1 );
108 Qt::MatchFlags options = Qt::MatchContains;
110 if ( CaseSensitiveCheckBox->isChecked() )
112 options = options | Qt::MatchCaseSensitive;
115 if ( WholeWordCheckBox->isChecked() )
117 options = Qt::MatchExactly;
120 ListOfMatch = Model->match ( find_by_name, Qt::DisplayRole, StringCriterium, 1000,
124 Model->match ( find_by_path, Qt::DisplayRole, StringCriterium, 1000, options ) );
126 if ( ListOfMatch.size() > 0 )
129 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
130 selectRow ( ListOfMatch.value ( ListIndex ).row() );
131 resizeColumnToContents ( ListIndex );
133 GoButton->setDisabled (
true );
134 NextButton->setEnabled (
true );
136 disconnect ( LineEdit, SIGNAL ( returnPressed() ),
this, SLOT ( GoToFile() ) );
137 connect ( LineEdit, SIGNAL ( returnPressed() ),
this, SLOT ( GoToNext() ) );
138 ChangeSelection ( ListOfMatch.at ( ListIndex ) );
145 if ( ( LineEdit->text() ).isEmpty() )
152 if ( ListOfMatch.size() > 0 )
154 if ( ( ++ListIndex ) < ListOfMatch.size() )
156 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
157 selectRow ( ListOfMatch.value ( ListIndex ).row() );
158 resizeColumnToContents ( ListIndex );
159 ChangeSelection ( ListOfMatch.at ( ListIndex ) );
164 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
165 selectRow ( ListOfMatch.value ( ListIndex ).row() );
166 resizeColumnToContents ( ListIndex );
167 ChangeSelection ( ListOfMatch.at ( ListIndex ) );
174 if ( FindFileDialog !=
nullptr )
176 delete FindFileDialog;
177 FindFileDialog =
nullptr;
180 FindFileDialog =
new QDialog (
this );
181 FindFileDialog->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Preferred );
182 FindFileDialog->setToolTip (
"Type string to edit line and press Enter." );
183 FindFileDialog->setWindowTitle (
"Search for a file name in the table" );
185 QHBoxLayout * FileLayout =
new QHBoxLayout();
186 QLabel * Label =
new QLabel ( QString (
"Find File:" ) );
187 NextButton =
new QPushButton (
"Next" );
188 GoButton =
new QPushButton (
"Go !" );
189 LineEdit =
new QLineEdit();
190 LineEdit->setToolTip (
"Type string and press Enter" );
192 FileLayout->addWidget ( Label );
193 FileLayout->addWidget ( LineEdit );
194 FileLayout->addWidget ( GoButton );
195 FileLayout->addWidget ( NextButton );
197 QHBoxLayout * ButtonsLayout =
new QHBoxLayout();
198 WholeWordCheckBox =
new QCheckBox (
"Whole String" );
199 CaseSensitiveCheckBox =
new QCheckBox (
"Case Sensitive" );
201 ButtonsLayout->addWidget ( WholeWordCheckBox );
202 ButtonsLayout->addWidget ( CaseSensitiveCheckBox );
204 QVBoxLayout * FindDialogLayout =
new QVBoxLayout();
205 FindDialogLayout->addItem ( FileLayout );
206 FindDialogLayout->addItem ( ButtonsLayout );
208 FindFileDialog->setLayout ( FindDialogLayout );
209 FindFileDialog->show();
212 connect ( LineEdit, SIGNAL ( textEdited ( QString ) ),
this,
213 SLOT ( EditedSearchString ( QString ) ) );
214 connect ( WholeWordCheckBox, SIGNAL ( clicked() ),
this, SLOT ( EditedSearchString() ) );
215 connect ( CaseSensitiveCheckBox, SIGNAL ( clicked() ),
this,
216 SLOT ( EditedSearchString() ) );
218 connect ( LineEdit, SIGNAL ( returnPressed() ),
this, SLOT ( GoToFile() ) );
219 connect ( GoButton, SIGNAL ( clicked() ),
this, SLOT ( GoToFile() ) );
220 connect ( NextButton, SIGNAL ( clicked() ),
this, SLOT ( GoToNext() ) );