18 : QTableView ( parent ),
19 ContextMenu ( nullptr ),
20 LaunchIncludeEditor ( nullptr ),
21 HideReadOnlyFiles ( nullptr ),
23 FindFileDialog ( nullptr ),
25 NextButton ( nullptr ),
30 setSelectionBehavior ( SelectionBehavior::SelectRows );
31 horizontalHeader()->setSectionResizeMode ( QHeaderView::ResizeMode::Stretch );
32 setSortingEnabled (
true );
34 connect (
this, SIGNAL(activated(QModelIndex)),
40 LaunchIncludeEditor =
new QAction ( tr (
"Add/Remove Files" ),
this );
41 LaunchIncludeEditor->setShortcutContext ( Qt::WidgetShortcut );
42 connect ( LaunchIncludeEditor, SIGNAL ( triggered() ),
this,
43 SLOT ( LaunchIncludeEditorSlot() ) );
44 ContextMenu->addAction ( LaunchIncludeEditor );
46 m_file_info_action =
new QAction (tr (
"File &information"));
47 connect ( m_file_info_action, SIGNAL(triggered()),
48 this, SLOT(file_info_slot()) );
49 ContextMenu->addAction ( m_file_info_action );
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 );
60 FindFile =
new QAction ( tr (
"Find File" ),
this );
61 FindFile->setShortcut ( QKeySequence ( tr (
"Ctrl+F" ) ) );
62 FindFile->setShortcutContext ( Qt::WidgetShortcut );
63 connect ( FindFile, SIGNAL ( triggered() ),
this, SLOT ( FindFileSlot() ) );
65 ContextMenu->addAction ( FindFile );
85 QModelIndex index = indexAt ( Event->pos() );
87 if ( index.isValid() )
89 if ( model()->data ( model()->index ( index.row(), 2 ) ).toString() ==
"RO" ) {
90 ContextMenu->actions().at ( 0 )->setVisible (
false );
93 ContextMenu->actions().at ( 0 )->setVisible (
true );
95 ContextMenu->actions().at ( 1 )->setVisible (
true );
97 setCurrentIndex ( index );
98 selectionModel()->setCurrentIndex ( index, QItemSelectionModel::NoUpdate );
101 ContextMenu->actions().at(0)->setVisible(
false);
102 ContextMenu->actions().at(1)->setVisible(
false);
104 ContextMenu->exec ( Event->globalPos() );
112 QString UserType = LineEdit->text();
114 if ( UserType.isEmpty() )
119 QAbstractItemModel * Model = model();
121 if ( Model !=
nullptr )
123 QVariant StringCriterium = QVariant ( UserType );
125 QModelIndex find_by_name = Model->index ( 0, 0 );
126 QModelIndex find_by_path = Model->index ( 0, 1 );
128 Qt::MatchFlags options = Qt::MatchContains;
130 if ( CaseSensitiveCheckBox->isChecked() )
132 options = options | Qt::MatchCaseSensitive;
135 if ( WholeWordCheckBox->isChecked() )
137 options = Qt::MatchExactly;
140 ListOfMatch = Model->match ( find_by_name, Qt::DisplayRole, StringCriterium, 1000,
144 Model->match ( find_by_path, Qt::DisplayRole, StringCriterium, 1000, options ) );
146 if ( ListOfMatch.size() > 0 )
149 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
150 selectRow ( ListOfMatch.value ( ListIndex ).row() );
151 resizeColumnToContents ( ListIndex );
153 GoButton->setDisabled (
true );
154 NextButton->setEnabled (
true );
156 disconnect ( LineEdit, SIGNAL ( returnPressed() ),
this, SLOT ( GoToFile() ) );
157 connect ( LineEdit, SIGNAL ( returnPressed() ),
this, SLOT ( GoToNext() ) );
158 ChangeSelection ( ListOfMatch.at ( ListIndex ) );
165 if ( ( LineEdit->text() ).isEmpty() )
172 if ( ListOfMatch.size() > 0 )
174 if ( ( ++ListIndex ) < ListOfMatch.size() )
176 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
177 selectRow ( ListOfMatch.value ( ListIndex ).row() );
178 resizeColumnToContents ( ListIndex );
179 ChangeSelection ( ListOfMatch.at ( ListIndex ) );
184 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
185 selectRow ( ListOfMatch.value ( ListIndex ).row() );
186 resizeColumnToContents ( ListIndex );
187 ChangeSelection ( ListOfMatch.at ( ListIndex ) );
194 if ( FindFileDialog !=
nullptr )
196 delete FindFileDialog;
197 FindFileDialog =
nullptr;
200 FindFileDialog =
new QDialog (
this );
201 FindFileDialog->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Preferred );
202 FindFileDialog->setToolTip (
"Type string to edit line and press Enter." );
203 FindFileDialog->setWindowTitle (
"Search for a file name in the table" );
205 QHBoxLayout * FileLayout =
new QHBoxLayout();
206 QLabel * Label =
new QLabel ( QString (
"Find File:" ) );
207 NextButton =
new QPushButton (
"Next" );
208 GoButton =
new QPushButton (
"Go !" );
209 LineEdit =
new QLineEdit();
210 LineEdit->setToolTip (
"Type string and press Enter" );
212 FileLayout->addWidget ( Label );
213 FileLayout->addWidget ( LineEdit );
214 FileLayout->addWidget ( GoButton );
215 FileLayout->addWidget ( NextButton );
217 QHBoxLayout * ButtonsLayout =
new QHBoxLayout();
218 WholeWordCheckBox =
new QCheckBox (
"Whole String" );
219 CaseSensitiveCheckBox =
new QCheckBox (
"Case Sensitive" );
221 ButtonsLayout->addWidget ( WholeWordCheckBox );
222 ButtonsLayout->addWidget ( CaseSensitiveCheckBox );
224 QVBoxLayout * FindDialogLayout =
new QVBoxLayout();
225 FindDialogLayout->addItem ( FileLayout );
226 FindDialogLayout->addItem ( ButtonsLayout );
228 FindFileDialog->setLayout ( FindDialogLayout );
229 FindFileDialog->show();
232 connect ( LineEdit, SIGNAL ( textEdited ( QString ) ),
this,
233 SLOT ( EditedSearchString ( QString ) ) );
234 connect ( WholeWordCheckBox, SIGNAL ( clicked() ),
this, SLOT ( EditedSearchString() ) );
235 connect ( CaseSensitiveCheckBox, SIGNAL ( clicked() ),
this,
236 SLOT ( EditedSearchString() ) );
238 connect ( LineEdit, SIGNAL ( returnPressed() ),
this, SLOT ( GoToFile() ) );
239 connect ( GoButton, SIGNAL ( clicked() ),
this, SLOT ( GoToFile() ) );
240 connect ( NextButton, SIGNAL ( clicked() ),
this, SLOT ( GoToNext() ) );
259 QModelIndex index = currentIndex();
260 QString file = model()->data ( model()->index ( index.row(), 0,
261 index.parent() ) ).toString();
262 QString path = model()->data ( model()->index ( index.row(), 1,
263 index.parent() ) ).toString();
264 auto full_name = path +
"/" + file;
307 QString file = model()->data ( model()->index ( index.row(), 0,
308 index.parent() ) ).toString();
309 QString path = model()->data ( model()->index ( index.row(), 1,
310 index.parent() ) ).toString();
311 auto full_name = path +
"/" + file;
312 emit stateChanged ( full_name );