diff --git a/panels/project.cpp b/panels/project.cpp index 1bf591aee..80c49ede9 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -130,7 +130,11 @@ Project::Project(QWidget *parent) : connect(toolbar_redo, SIGNAL(clicked(bool)), mainWindow, SLOT(redo())); toolbar->addWidget(toolbar_redo); - toolbar->addStretch(); + QLineEdit* toolbar_search = new QLineEdit(); + toolbar_search->setPlaceholderText(tr("Search media, markers, etc.")); + connect(toolbar_search, SIGNAL(textChanged(QString)), sorter, SLOT(update_search_filter(const QString&))); + toolbar->addWidget(toolbar_search); + QPushButton* toolbar_tree_view = new QPushButton(); QIcon icon6; icon6.addFile(QStringLiteral(":/icons/treeview.png"), QSize(), QIcon::Normal, QIcon::On); diff --git a/project/projectfilter.cpp b/project/projectfilter.cpp index 798174c6e..807ad0bbc 100644 --- a/project/projectfilter.cpp +++ b/project/projectfilter.cpp @@ -1,6 +1,7 @@ #include "projectfilter.h" #include "project/media.h" +#include "project/sequence.h" #include @@ -15,17 +16,49 @@ bool ProjectFilter::get_show_sequences() { void ProjectFilter::set_show_sequences(bool b) { show_sequences = b; - invalidateFilter(); + invalidateFilter(); +} + +void ProjectFilter::update_search_filter(const QString &s) { + search_filter = s; + invalidateFilter(); } bool ProjectFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { + // retrieve media object from index + QModelIndex index = sourceModel()->index(source_row, 0, source_parent); + Media* media = static_cast(index.internalPointer()); + + // hide sequences if show_sequences is false if (!show_sequences) { - // hide sequences if show_sequences is false - QModelIndex index = sourceModel()->index(source_row, 0, source_parent); - Media* media = static_cast(index.internalPointer()); if (media != nullptr && media->get_type() == MEDIA_TYPE_SEQUENCE) { return false; } } + + // filter by search filter string + if (!search_filter.isEmpty()) { + // search markers if media is a sequene + bool marker_contains_search = false; + + if (media->get_type() == MEDIA_TYPE_SEQUENCE) { + Sequence* s = media->to_sequence(); + for (int i=0;imarkers.size();i++) { + qDebug() << "marker name:" << s->markers.at(i).name; + if (s->markers.at(i).name.contains(search_filter, Qt::CaseInsensitive)) { + marker_contains_search = true; + break; + } + } + } + + // hide any rows that don't contain the search string (unless it's a folder) + if (!marker_contains_search + && media->get_type() != MEDIA_TYPE_FOLDER + && !media->get_name().contains(search_filter, Qt::CaseInsensitive)) { + return false; + } + } + return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); } diff --git a/project/projectfilter.h b/project/projectfilter.h index 6b14bb680..848acbffd 100644 --- a/project/projectfilter.h +++ b/project/projectfilter.h @@ -7,13 +7,31 @@ class ProjectFilter : public QSortFilterProxyModel { Q_OBJECT public: ProjectFilter(QObject *parent = nullptr); + + // are sequences visible bool get_show_sequences(); + public slots: + + // set whether sequences are visible void set_show_sequences(bool b); + + // update search filter + void update_search_filter(const QString& s); + protected: - bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; + + // function that filters whether rows are displayed or not + virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; + private: + + // internal variable for whether to show sequences bool show_sequences; + + // search filter variable + QString search_filter; + }; #endif // PROJECTFILTER_H diff --git a/project/undo.cpp b/project/undo.cpp index ce577f855..b4fb804a8 100644 --- a/project/undo.cpp +++ b/project/undo.cpp @@ -842,6 +842,7 @@ void AddMarkerAction::redo() { if (index == -1) { Marker m; m.frame = time; + m.name = name; markers.append(m); } else { old_name = markers.at(index).name;