OpenToonz - An open-source full-featured 2D animation creation software
C
add search bar in fx browser
pojienie1cc6716cff3e
diff --git a/toonz/sources/toonz/insertfxpopup.cpp b/toonz/sources/toonz/insertfxpopup.cppindex aea4782dc..bc5ea15e8 100644--- a/toonz/sources/toonz/insertfxpopup.cpp+++ b/toonz/sources/toonz/insertfxpopup.cpp@@ -51,6 +51,8 @@#include <QMenu>#include <QContextMenuEvent>#include <QMainWindow>+#include <QLineEdit>+#include <QLabel>#include <memory>@@ -137,6 +139,55 @@ TFx *createMacroFxByPath(TFilePath path) {} // anonymous namespace//-----------------------------------------------------------------------------+//=============================================================================+// FxTree+//=============================================================================++void FxTree::searchItems(const QString &searchWord) {+ // if search word is empty, show all items+ if (searchWord.isEmpty()) {+ int itemCount = topLevelItemCount();+ for (int i = 0; i < itemCount; ++i) {+ QTreeWidgetItem *item = topLevelItem(i);+ int childCount = item->childCount();+ for (int j = 0; j < childCount; ++j) item->child(j)->setHidden(false);+ item->setHidden(false);+ item->setExpanded(false);+ }+ update();+ return;+ }++ // hide all items first+ int itemCount = topLevelItemCount();+ for (int i = 0; i < itemCount; ++i) {+ QTreeWidgetItem *item = topLevelItem(i);+ int childCount = item->childCount();+ for (int j = 0; j < childCount; ++j) item->child(j)->setHidden(true);+ item->setHidden(true);+ item->setExpanded(false);+ }++ QList<QTreeWidgetItem *> foundItems =+ findItems(searchWord, Qt::MatchContains | Qt::MatchRecursive, 0);+ if (foundItems.isEmpty()) { // if nothing is found, do nothing but update+ update();+ return;+ }++ // for each item found, show it and show its parent+ for (auto item : foundItems) {+ item->setHidden(false);+ QTreeWidgetItem *parent = item->parent();+ if (parent) {+ parent->setHidden(false);+ parent->setExpanded(true);+ }+ }++ update();+}+//=============================================================================/*! \class InsertFxPopup\brief The InsertFxPopup class provides a dialog to browse fx@@ -157,7 +208,18 @@ InsertFxPopup::InsertFxPopup()setTopMargin(0);setTopSpacing(0);- m_fxTree = new QTreeWidget();+ QHBoxLayout *searchLay = new QHBoxLayout();+ QLineEdit *searchEdit = new QLineEdit(this);++ searchLay->setMargin(0);+ searchLay->setSpacing(5);+ searchLay->addWidget(new QLabel(tr("Search:"), this), 0);+ searchLay->addWidget(searchEdit);+ addLayout(searchLay);+ connect(searchEdit, SIGNAL(textChanged(const QString &)), this,+ SLOT(onSearchTextChanged(const QString &)));++ m_fxTree = new FxTree();m_fxTree->setIconSize(QSize(21, 17));m_fxTree->setColumnCount(1);m_fxTree->header()->close();@@ -229,6 +291,16 @@ InsertFxPopup::InsertFxPopup()//-------------------------------------------------------------------+void InsertFxPopup::onSearchTextChanged(const QString &text) {+ static bool busy = false;+ if (busy) return;+ busy = true;+ m_fxTree->searchItems(text);+ busy = false;+}++//-------------------------------------------------------------------+void InsertFxPopup::makeItem(QTreeWidgetItem *parent, std::string fxId) {QTreeWidgetItem *fxItem = new QTreeWidgetItem((QTreeWidget *)0,diff --git a/toonz/sources/toonz/insertfxpopup.h b/toonz/sources/toonz/insertfxpopup.hindex 3fdc1bbb8..ab325995b 100644--- a/toonz/sources/toonz/insertfxpopup.h+++ b/toonz/sources/toonz/insertfxpopup.h@@ -3,6 +3,7 @@#ifndef INSERTFXPOPUP_H#define INSERTFXPOPUP_H+#include <QTreeWidget>#include "toonzqt/dvdialog.h"#include "tfilepath.h"#include "tstream.h"@@ -14,6 +15,17 @@ class TFx;#include <QIcon>+//=============================================================================+// FxTree+//-----------------------------------------------------------------------------++class FxTree final : public QTreeWidget {+ Q_OBJECT++public:+ void searchItems(const QString &searchWord = QString());+};+//=============================================================================// InsertFxPopup//-----------------------------------------------------------------------------@@ -21,7 +33,7 @@ class TFx;class InsertFxPopup final : public DVGui::Dialog {Q_OBJECT- QTreeWidget *m_fxTree;+ FxTree *m_fxTree;TIStream *m_is;TFilePath m_presetFolder;@@ -59,6 +71,7 @@ protected:protected slots:void updatePresets();void removePreset();+ void onSearchTextChanged(const QString &text);};#endif // INSERTFXPOPUP_H