diff --git a/toonz/sources/toonz/commandbarpopup.cpp b/toonz/sources/toonz/commandbarpopup.cpp index 9e1d725..dbfc5ac 100644 --- a/toonz/sources/toonz/commandbarpopup.cpp +++ b/toonz/sources/toonz/commandbarpopup.cpp @@ -396,6 +396,70 @@ void CommandBarListTree::mousePressEvent(QMouseEvent* event) { QTreeWidget::mousePressEvent(event); } +//----------------------------------------------------------------------------- + +void CommandBarListTree::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 CommandBarListTree::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 CommandBarListTree::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 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(); +} + //============================================================================= // CommandBarPopup //----------------------------------------------------------------------------- @@ -437,6 +501,8 @@ CommandBarPopup::CommandBarPopup(bool isXsheetToolbar) nf.setItalic(true); noticeLabel->setFont(nf); + QLineEdit* searchEdit = new QLineEdit(this); + //--- layout m_topLayout->setMargin(0); m_topLayout->setSpacing(0); @@ -448,10 +514,20 @@ CommandBarPopup::CommandBarPopup(bool isXsheetToolbar) { mainUILay->addWidget(commandBarLabel, 0, 0); mainUILay->addWidget(commandItemListLabel, 0, 1); - mainUILay->addWidget(m_menuBarTree, 1, 0); - mainUILay->addWidget(m_commandListTree, 1, 1); - mainUILay->addWidget(noticeLabel, 2, 0, 1, 2); + 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, 3, 0, 1, 2); } mainUILay->setRowStretch(0, 0); mainUILay->setRowStretch(1, 1); @@ -475,6 +551,9 @@ CommandBarPopup::CommandBarPopup(bool isXsheetToolbar) 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); } @@ -484,4 +563,12 @@ void CommandBarPopup::onOkPressed() { m_menuBarTree->saveMenuTree(m_path); accept(); -} \ No newline at end of file +} + +void CommandBarPopup::onSearchTextChanged(const QString& text) { + static bool busy = false; + if (busy) return; + busy = true; + m_commandListTree->searchItems(text); + busy = false; +} diff --git a/toonz/sources/toonz/commandbarpopup.h b/toonz/sources/toonz/commandbarpopup.h index ac56c74..4a0efd0 100644 --- a/toonz/sources/toonz/commandbarpopup.h +++ b/toonz/sources/toonz/commandbarpopup.h @@ -50,6 +50,12 @@ class CommandBarListTree final : public QTreeWidget { public: CommandBarListTree(QWidget* parent = 0); + void searchItems(const QString& searchWord = QString()); + +private: + void displayAll(QTreeWidgetItem* item); + void hideAll(QTreeWidgetItem* item); + protected: void mousePressEvent(QMouseEvent*) override; }; @@ -68,6 +74,7 @@ public: CommandBarPopup(bool isXsheetToolbar = false); protected slots: void onOkPressed(); + void onSearchTextChanged(const QString& text); }; #endif \ No newline at end of file diff --git a/toonz/sources/toonz/custompaneleditorpopup.cpp b/toonz/sources/toonz/custompaneleditorpopup.cpp index 858f4e0..4a15c1f 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 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(widget); QToolButton* tb = dynamic_cast(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 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 openCustomPanelEditorPopup( MI_CustomPanelEditor); \ No newline at end of file diff --git a/toonz/sources/toonz/custompaneleditorpopup.h b/toonz/sources/toonz/custompaneleditorpopup.h index b82ae63..54f20d6 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 4dc0466..54bbdb0 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 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 7d5ac26..c5467b6 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