Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

add search field to menubar popup and custom panel editor - applied the same code for the command bar by manongjohn - made the tree to revert the initial state when clear the field

shun-iwasawa79877c9705b2
diff --git a/toonz/sources/toonz/commandbarpopup.cpp b/toonz/sources/toonz/commandbarpopup.cpp
index 0cf41774f..dbfc5acb8 100644
--- a/toonz/sources/toonz/commandbarpopup.cpp
+++ b/toonz/sources/toonz/commandbarpopup.cpp
@@ -427,6 +427,10 @@ void CommandBarListTree::searchItems(const QString& searchWord) {
for (int i = 0; i < itemCount; ++i) {
displayAll(topLevelItem(i));
}
+
+ // revert to the initial state - expanding "Menu Commands" tree
+ findItems(ShortcutTree::tr("Menu Commands"), Qt::MatchExactly)[0]
+ ->setExpanded(true);
update();
return;
}
diff --git a/toonz/sources/toonz/custompaneleditorpopup.cpp b/toonz/sources/toonz/custompaneleditorpopup.cpp
index 858f4e032..4a15c1fcc 100644
--- a/toonz/sources/toonz/custompaneleditorpopup.cpp
+++ b/toonz/sources/toonz/custompaneleditorpopup.cpp
@@ -390,6 +390,69 @@ void CustomPanelCommandListTree::mousePressEvent(QMouseEvent* event) {
QTreeWidget::mousePressEvent(event);
}
+//-----------------------------------------------------------------------------
+
+void CustomPanelCommandListTree::displayAll(QTreeWidgetItem* item) {
+ int childCount = item->childCount();
+ for (int i = 0; i < childCount; ++i) {
+ displayAll(item->child(i));
+ }
+ item->setHidden(false);
+ item->setExpanded(false);
+}
+
+//-------------------------------------------------------------------
+
+void CustomPanelCommandListTree::hideAll(QTreeWidgetItem* item) {
+ int childCount = item->childCount();
+ for (int i = 0; i < childCount; ++i) {
+ hideAll(item->child(i));
+ }
+ item->setHidden(true);
+ item->setExpanded(false);
+}
+
+//-----------------------------------------------------------------------------
+
+void CustomPanelCommandListTree::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) {
+ displayAll(topLevelItem(i));
+ }
+ // revert to the initial state - expanding "Menu Commands" tree
+ findItems(ShortcutTree::tr("Menu Commands"), Qt::MatchExactly)[0]
+ ->setExpanded(true);
+ update();
+ return;
+ }
+
+ // hide all items first
+ int itemCount = topLevelItemCount();
+ for (int i = 0; i < itemCount; ++i) {
+ hideAll(topLevelItem(i));
+ }
+
+ 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) {
+ while (item) {
+ item->setHidden(false);
+ item->setExpanded(true);
+ item = item->parent();
+ }
+ }
+
+ update();
+}
+
//=============================================================================
// CustomPanelEditorPopup
//-----------------------------------------------------------------------------
@@ -558,7 +621,7 @@ void CustomPanelEditorPopup::updateControls(QWidget* customWidget) {
if (entry.type == Button) {
QString commandId = entry.field->commandId();
QAction* action = CommandManager::instance()->getAction(
- commandId.toStdString().c_str());
+ commandId.toStdString().c_str());
if (!action) continue;
QAbstractButton* button = dynamic_cast<QAbstractButton*>(widget);
QToolButton* tb = dynamic_cast<QToolButton*>(widget);
@@ -717,7 +780,7 @@ void CustomPanelEditorPopup::replaceObjectNames(QDomElement& element) {
while (!n.isNull()) {
if (n.isElement()) {
QDomElement e = n.toElement();
- //�������g���`�F�b�N
+ // �������g���`�F�b�N
if (e.tagName() == "widget" && e.hasAttribute("name")) {
QString objName = e.attribute("name");
QList<int> entryIds = entryIdByObjName(objName);
@@ -814,6 +877,8 @@ CustomPanelEditorPopup::CustomPanelEditorPopup()
QFont f("Arial", 15, QFont::Bold);
commandItemListLabel->setFont(f);
+ QLineEdit* searchEdit = new QLineEdit(this);
+
m_previewArea = new UiPreviewArea(this);
m_UiFieldsContainer = new QWidget(this);
m_templateCombo = new QComboBox(this);
@@ -848,6 +913,14 @@ CustomPanelEditorPopup::CustomPanelEditorPopup()
rightLay->setSpacing(10);
{
rightLay->addWidget(commandItemListLabel, 0);
+ QHBoxLayout* searchLay = new QHBoxLayout();
+ searchLay->setMargin(0);
+ searchLay->setSpacing(5);
+ {
+ searchLay->addWidget(new QLabel(tr("Search:"), this), 0);
+ searchLay->addWidget(searchEdit);
+ }
+ rightLay->addLayout(searchLay, 0);
rightLay->addWidget(m_commandListTree, 1);
}
addLayout(rightLay);
@@ -873,6 +946,8 @@ CustomPanelEditorPopup::CustomPanelEditorPopup()
SLOT(onTemplateSwitched()));
ret = ret &&
connect(registerButton, SIGNAL(clicked()), this, SLOT(onRegister()));
+ ret = ret && connect(searchEdit, SIGNAL(textChanged(const QString&)), this,
+ SLOT(onSearchTextChanged(const QString&)));
assert(ret);
// load template
@@ -884,5 +959,15 @@ CustomPanelEditorPopup::CustomPanelEditorPopup()
//-----------------------------------------------------------------------------
+void CustomPanelEditorPopup::onSearchTextChanged(const QString& text) {
+ static bool busy = false;
+ if (busy) return;
+ busy = true;
+ m_commandListTree->searchItems(text);
+ busy = false;
+}
+
+//-----------------------------------------------------------------------------
+
OpenPopupCommandHandler<CustomPanelEditorPopup> openCustomPanelEditorPopup(
MI_CustomPanelEditor);
\ No newline at end of file
diff --git a/toonz/sources/toonz/custompaneleditorpopup.h b/toonz/sources/toonz/custompaneleditorpopup.h
index b82ae630c..54f20d6fb 100644
--- a/toonz/sources/toonz/custompaneleditorpopup.h
+++ b/toonz/sources/toonz/custompaneleditorpopup.h
@@ -115,6 +115,12 @@ class CustomPanelCommandListTree final : public QTreeWidget {
public:
CustomPanelCommandListTree(QWidget* parent = 0);
+ void searchItems(const QString& searchWord = QString());
+
+private:
+ void displayAll(QTreeWidgetItem* item);
+ void hideAll(QTreeWidgetItem* item);
+
protected:
void mousePressEvent(QMouseEvent*) override;
};
@@ -155,6 +161,7 @@ protected slots:
void onPreviewClicked(int id);
void onPreviewDropped(int id, QString cmdId, bool fromTree);
void onRegister();
+ void onSearchTextChanged(const QString& text);
};
#endif
\ No newline at end of file
diff --git a/toonz/sources/toonz/menubarpopup.cpp b/toonz/sources/toonz/menubarpopup.cpp
index 4dc0466b3..54bbdb0ff 100644
--- a/toonz/sources/toonz/menubarpopup.cpp
+++ b/toonz/sources/toonz/menubarpopup.cpp
@@ -455,6 +455,68 @@ void CommandListTree::mousePressEvent(QMouseEvent* event) {
QTreeWidget::mousePressEvent(event);
}
+//-----------------------------------------------------------------------------
+
+void CommandListTree::displayAll(QTreeWidgetItem* item) {
+ int childCount = item->childCount();
+ for (int i = 0; i < childCount; ++i) {
+ displayAll(item->child(i));
+ }
+ item->setHidden(false);
+ item->setExpanded(false);
+}
+
+//-------------------------------------------------------------------
+
+void CommandListTree::hideAll(QTreeWidgetItem* item) {
+ int childCount = item->childCount();
+ for (int i = 0; i < childCount; ++i) {
+ hideAll(item->child(i));
+ }
+ item->setHidden(true);
+ item->setExpanded(false);
+}
+
+//-----------------------------------------------------------------------------
+
+void CommandListTree::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) {
+ displayAll(topLevelItem(i));
+ }
+ // revert to the initial state - expanding "Menu Commands" tree
+ findItems(ShortcutTree::tr("Menu Commands"), Qt::MatchExactly)[0]
+ ->setExpanded(true);
+ update();
+ return;
+ }
+
+ // hide all items first
+ int itemCount = topLevelItemCount();
+ for (int i = 0; i < itemCount; ++i) {
+ hideAll(topLevelItem(i));
+ }
+
+ 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) {
+ while (item) {
+ item->setHidden(false);
+ item->setExpanded(true);
+ item = item->parent();
+ }
+ }
+
+ update();
+}
//=============================================================================
// MenuBarPopup
@@ -486,6 +548,8 @@ MenuBarPopup::MenuBarPopup(Room* room)
menuBarLabel->setFont(f);
menuItemListLabel->setFont(f);
+ QLineEdit* searchEdit = new QLineEdit(this);
+
QLabel* noticeLabel = new QLabel(
tr("N.B. If you put unique title to submenu, it may not be translated to "
"another language.\nN.B. Duplicated commands will be ignored. Only "
@@ -507,10 +571,19 @@ MenuBarPopup::MenuBarPopup(Room* room)
{
mainUILay->addWidget(menuBarLabel, 0, 0);
mainUILay->addWidget(menuItemListLabel, 0, 1);
- mainUILay->addWidget(m_menuBarTree, 1, 0);
- mainUILay->addWidget(m_commandListTree, 1, 1);
+ mainUILay->addWidget(m_menuBarTree, 1, 0, 2, 1);
+
+ QHBoxLayout* searchLay = new QHBoxLayout();
+ searchLay->setMargin(0);
+ searchLay->setSpacing(5);
+ {
+ searchLay->addWidget(new QLabel(tr("Search:"), this), 0);
+ searchLay->addWidget(searchEdit);
+ }
+ mainUILay->addLayout(searchLay, 1, 1);
+ mainUILay->addWidget(m_commandListTree, 2, 1);
- mainUILay->addWidget(noticeLabel, 2, 0, 1, 2);
+ mainUILay->addWidget(noticeLabel, 3, 0, 1, 2);
}
mainUILay->setRowStretch(0, 0);
mainUILay->setRowStretch(1, 1);
@@ -534,6 +607,8 @@ MenuBarPopup::MenuBarPopup(Room* room)
bool ret = connect(okBtn, SIGNAL(clicked()), this, SLOT(onOkPressed()));
ret = ret && connect(cancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
+ ret = ret && connect(searchEdit, SIGNAL(textChanged(const QString&)), this,
+ SLOT(onSearchTextChanged(const QString&)));
assert(ret);
}
@@ -543,4 +618,14 @@ void MenuBarPopup::onOkPressed() {
m_menuBarTree->saveMenuTree();
accept();
+}
+
+//-----------------------------------------------------------------------------
+
+void MenuBarPopup::onSearchTextChanged(const QString& text) {
+ static bool busy = false;
+ if (busy) return;
+ busy = true;
+ m_commandListTree->searchItems(text);
+ busy = false;
}
\ No newline at end of file
diff --git a/toonz/sources/toonz/menubarpopup.h b/toonz/sources/toonz/menubarpopup.h
index 7d5ac26a3..c5467b6d1 100644
--- a/toonz/sources/toonz/menubarpopup.h
+++ b/toonz/sources/toonz/menubarpopup.h
@@ -55,6 +55,12 @@ class CommandListTree final : public QTreeWidget {
public:
CommandListTree(QWidget* parent = 0);
+ void searchItems(const QString& searchWord = QString());
+
+private:
+ void displayAll(QTreeWidgetItem* item);
+ void hideAll(QTreeWidgetItem* item);
+
protected:
void mousePressEvent(QMouseEvent*) override;
};
@@ -72,6 +78,7 @@ public:
MenuBarPopup(Room* room);
protected slots:
void onOkPressed();
+ void onSearchTextChanged(const QString& text);
};
#endif
\ No newline at end of file