OpenToonz - An open-source full-featured 2D animation creation software
C
Modify menubar commands tree by Contrail Co.,Ltd.
shun-iwasawa563e65332759
diff --git a/toonz/sources/toonz/commandbarpopup.cpp b/toonz/sources/toonz/commandbarpopup.cppindex dbfc5acb8..043bf7e01 100644--- a/toonz/sources/toonz/commandbarpopup.cpp+++ b/toonz/sources/toonz/commandbarpopup.cpp@@ -33,42 +33,239 @@#include <QLabel>//=============================================================================-// CommandBarCommandItem+// CommandItem//------------------------------------------------------------------------------class CommandBarCommandItem final : public QTreeWidgetItem {- QAction* m_action;--public:- CommandBarCommandItem(QTreeWidgetItem* parent, QAction* action)- : QTreeWidgetItem(parent, UserType), m_action(action) {- setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled |- Qt::ItemNeverHasChildren);- QString tempText = m_action->text();- // removing accelerator key indicator- tempText = tempText.replace(QRegExp("&([^& ])"), "\\1");- // removing doubled &s- tempText = tempText.replace("&&", "&");- setText(0, tempText);- setToolTip(0, QObject::tr("[Drag] to move position"));- }- QAction* getAction() const { return m_action; }-};+CommandItem::CommandItem(QTreeWidgetItem* parent, QAction* action)+ : QTreeWidgetItem(parent, UserType), m_action(action) {+ setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled |+ Qt::ItemNeverHasChildren);+ QString tempText = m_action->text();+ // removing accelerator key indicator+ tempText = tempText.replace(QRegExp("&([^& ])"), "\\1");+ // removing doubled &s+ tempText = tempText.replace("&&", "&");+ setText(0, tempText);+ setToolTip(0, QObject::tr("[Drag] to move position"));+}++//=============================================================================+// SeparatorItem+//-----------------------------------------------------------------------------++SeparatorItem::SeparatorItem(QTreeWidgetItem* parent)+ : QTreeWidgetItem(parent, UserType) {+ setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled |+ Qt::ItemNeverHasChildren);+ setText(0, QObject::tr("----Separator----"));+ setToolTip(0, QObject::tr("[Drag] to move position"));+}//=============================================================================-// CommandBarSeparatorItem+// CommandListTree+//-----------------------------------------------------------------------------++CommandListTree::CommandListTree(const QString& dropTargetString,+ QWidget* parent, bool withSeparator)+ : m_dropTargetString(dropTargetString), QTreeWidget(parent) {+ setObjectName("SolidLineFrame");+ setAlternatingRowColors(true);+ setDragEnabled(true);+ setDragDropMode(QAbstractItemView::DragOnly);+ setColumnCount(1);+ setIconSize(QSize(21, 18));+ header()->close();++ QIcon menuFolderIcon(createQIcon("folder_project", true));+ invisibleRootItem()->setIcon(0, menuFolderIcon);++ QTreeWidgetItem* menuCommandFolder = new QTreeWidgetItem(this);+ menuCommandFolder->setFlags(Qt::ItemIsEnabled);+ menuCommandFolder->setText(+ 0, "1"); // set tentative name for "Menu Commands" folder+ menuCommandFolder->setExpanded(true);+ menuCommandFolder->setIcon(0, invisibleRootItem()->icon(0));++ addFolder(ShortcutTree::tr("File"), MenuFileCommandType, menuCommandFolder);+ addFolder(ShortcutTree::tr("Edit"), MenuEditCommandType, menuCommandFolder);+ addFolder(ShortcutTree::tr("Scan & Cleanup"), MenuScanCleanupCommandType,+ menuCommandFolder);+ addFolder(ShortcutTree::tr("Level"), MenuLevelCommandType, menuCommandFolder);+ addFolder(ShortcutTree::tr("Xsheet"), MenuXsheetCommandType,+ menuCommandFolder);+ addFolder(ShortcutTree::tr("Cells"), MenuCellsCommandType, menuCommandFolder);+ addFolder(ShortcutTree::tr("Play"), MenuPlayCommandType, menuCommandFolder);+ addFolder(ShortcutTree::tr("Render"), MenuRenderCommandType,+ menuCommandFolder);+ addFolder(ShortcutTree::tr("View"), MenuViewCommandType, menuCommandFolder);+ addFolder(ShortcutTree::tr("Windows"), MenuWindowsCommandType,+ menuCommandFolder);+ addFolder(ShortcutTree::tr("Help"), MenuHelpCommandType, menuCommandFolder);+ addFolder(ShortcutTree::tr("SubMenu Commands"), MenuCommandType,+ menuCommandFolder);++ // set tentative name for "Tools" folder+ QTreeWidgetItem* toolsFolder = addFolder("2", ToolCommandType);++ QTreeWidgetItem* advancedFolder = new QTreeWidgetItem(this);+ advancedFolder->setFlags(Qt::ItemIsEnabled);+ advancedFolder->setText(0, "3"); // set tentative name for "Advanced" folder+ advancedFolder->setIcon(0, invisibleRootItem()->icon(0));++ addFolder(ShortcutTree::tr("Fill"), FillCommandType, advancedFolder);+ QTreeWidgetItem* rcmSubFolder =+ addFolder(ShortcutTree::tr("Right-click Menu Commands"),+ RightClickMenuCommandType, advancedFolder);+ addFolder(ShortcutTree::tr("Cell Mark"), CellMarkCommandType, rcmSubFolder);+ addFolder(ShortcutTree::tr("Tool Modifiers"), ToolModifierCommandType,+ advancedFolder);+ addFolder(ShortcutTree::tr("Visualization"), VisualizationButtonCommandType,+ advancedFolder);+ addFolder(ShortcutTree::tr("Misc"), MiscCommandType, advancedFolder);+ addFolder(ShortcutTree::tr("RGBA Channels"), RGBACommandType, advancedFolder);++ sortItems(0, Qt::AscendingOrder);+ // set the actual names after sorting items+ menuCommandFolder->setText(0, ShortcutTree::tr("Menu Commands"));+ toolsFolder->setText(0, ShortcutTree::tr("Tools"));+ advancedFolder->setText(0, ShortcutTree::tr("Advanced"));++ if (withSeparator) {+ SeparatorItem* sep = new SeparatorItem(0);+ sep->setToolTip(0, QObject::tr("[Drag&Drop] to copy separator to %1")+ .arg(m_dropTargetString));+ addTopLevelItem(sep);+ }+}+//------------------------------------------------------------------------------class CommandBarSeparatorItem final : public QTreeWidgetItem {-public:- CommandBarSeparatorItem(QTreeWidgetItem* parent)- : QTreeWidgetItem(parent, UserType) {- setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled |- Qt::ItemNeverHasChildren);- setText(0, QObject::tr("----Separator----"));- setToolTip(0, QObject::tr("[Drag] to move position"));+QTreeWidgetItem* CommandListTree::addFolder(const QString& title,+ int commandType,+ QTreeWidgetItem* parentFolder) {+ QTreeWidgetItem* folder;+ if (!parentFolder)+ folder = new QTreeWidgetItem(this);+ else+ folder = new QTreeWidgetItem(parentFolder);+ assert(folder);+ folder->setText(0, title);+ folder->setIcon(0, invisibleRootItem()->icon(0));++ std::vector<QAction*> actions;+ CommandManager::instance()->getActions((CommandType)commandType, actions);+ for (int i = 0; i < (int)actions.size(); i++) {+ CommandItem* item = new CommandItem(folder, actions[i]);+ item->setToolTip(0, QObject::tr("[Drag&Drop] to copy command to %1")+ .arg(m_dropTargetString));}-};+ return folder;+}++//-----------------------------------------------------------------------------++void CommandListTree::mousePressEvent(QMouseEvent* event) {+ setCurrentItem(itemAt(event->pos()));+ CommandItem* commandItem = dynamic_cast<CommandItem*>(itemAt(event->pos()));+ SeparatorItem* separatorItem =+ dynamic_cast<SeparatorItem*>(itemAt(event->pos()));++ if (commandItem || separatorItem) {+ std::string dragStr;+ QString dragPixmapTxt;+ if (commandItem) {+ dragStr =+ CommandManager::instance()->getIdFromAction(commandItem->getAction());+ dragPixmapTxt = commandItem->getAction()->text();+ dragPixmapTxt.remove("&");+ } else {+ dragStr = "separator";+ dragPixmapTxt = tr("----Separator----");+ }++ QMimeData* mimeData = new QMimeData;+ mimeData->setText(QString::fromStdString(dragStr));++ QFontMetrics fm(QApplication::font());+ QPixmap pix(fm.boundingRect(dragPixmapTxt).adjusted(-2, -2, 2, 2).size());+ QPainter painter(&pix);+ painter.fillRect(pix.rect(), Qt::white);+ painter.setPen(Qt::black);+ painter.drawText(pix.rect(), Qt::AlignCenter, dragPixmapTxt);++ QDrag* drag = new QDrag(this);+ drag->setMimeData(mimeData);+ drag->setPixmap(pix);++ drag->exec(Qt::CopyAction);+ }++ 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();+}//=============================================================================// CommandBarTree@@ -122,11 +319,11 @@ void CommandBarTree::loadMenuTree(const TFilePath& fp) {QAction* action = CommandManager::instance()->getAction(cmdName.toStdString().c_str());if (action) {- CommandBarCommandItem* item = new CommandBarCommandItem(0, action);+ CommandItem* item = new CommandItem(0, action);addTopLevelItem(item);}} else if (reader.name() == "separator") {- CommandBarSeparatorItem* sep = new CommandBarSeparatorItem(0);+ SeparatorItem* sep = new SeparatorItem(0);addTopLevelItem(sep);reader.skipCurrentElement();} else@@ -150,22 +347,18 @@ void CommandBarTree::loadMenuRecursive(QXmlStreamReader& reader,QString cmdName = reader.readElementText();QAction* action =CommandManager::instance()->getAction(cmdName.toStdString().c_str());- if (action)- CommandBarCommandItem* item =- new CommandBarCommandItem(parentItem, action);+ if (action) CommandItem* item = new CommandItem(parentItem, action);} else if (reader.name() == "command_debug") {#ifndef NDEBUGQString cmdName = reader.readElementText();QAction* action =CommandManager::instance()->getAction(cmdName.toStdString().c_str());- if (action)- CommandBarCommandItem* item =- new CommandBarCommandItem(parentItem, action);+ if (action) CommandItem* item = new CommandItem(parentItem, action);#elsereader.skipCurrentElement();#endif} else if (reader.name() == "separator") {- CommandBarSeparatorItem* sep = new CommandBarSeparatorItem(parentItem);+ SeparatorItem* sep = new SeparatorItem(parentItem);reader.skipCurrentElement();} elsereader.skipCurrentElement();@@ -197,10 +390,8 @@ void CommandBarTree::saveMenuTree(TFilePath& path) {void CommandBarTree::saveMenuRecursive(QXmlStreamWriter& writer,QTreeWidgetItem* parentItem) {for (int c = 0; c < parentItem->childCount(); c++) {- CommandBarCommandItem* command =- dynamic_cast<CommandBarCommandItem*>(parentItem->child(c));- CommandBarSeparatorItem* sep =- dynamic_cast<CommandBarSeparatorItem*>(parentItem->child(c));+ CommandItem* command = dynamic_cast<CommandItem*>(parentItem->child(c));+ SeparatorItem* sep = dynamic_cast<SeparatorItem*>(parentItem->child(c));if (command)writer.writeTextElement(@@ -221,12 +412,12 @@ bool CommandBarTree::dropMimeData(QTreeWidgetItem* parent, int index,QString txt = data->text();QTreeWidgetItem* item;if (txt == "separator")- item = new CommandBarSeparatorItem(0);+ item = new SeparatorItem(0);else {QAction* act =CommandManager::instance()->getAction(txt.toStdString().c_str());if (!act) return false;- item = new CommandBarCommandItem(0, act);+ item = new CommandItem(0, act);}if (parent)@@ -279,187 +470,6 @@ void CommandBarTree::removeItem() {delete item;}-//=============================================================================-// CommandListTree-//-------------------------------------------------------------------------------CommandBarListTree::CommandBarListTree(QWidget* parent) : QTreeWidget(parent) {- setObjectName("SolidLineFrame");- setAlternatingRowColors(true);- setDragEnabled(true);- setDragDropMode(QAbstractItemView::DragOnly);- setColumnCount(1);- setIconSize(QSize(21, 18));- header()->close();-- QIcon menuFolderIcon(createQIcon("folder_project", true));- invisibleRootItem()->setIcon(0, menuFolderIcon);-- QTreeWidgetItem* menuCommandFolder = new QTreeWidgetItem(this);- menuCommandFolder->setFlags(Qt::ItemIsEnabled);- menuCommandFolder->setText(0, ShortcutTree::tr("Menu Commands"));- menuCommandFolder->setExpanded(true);- menuCommandFolder->setIcon(0, invisibleRootItem()->icon(0));-- addFolder(ShortcutTree::tr("File"), MenuFileCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Edit"), MenuEditCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Scan & Cleanup"), MenuScanCleanupCommandType,- menuCommandFolder);- addFolder(ShortcutTree::tr("Level"), MenuLevelCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Xsheet"), MenuXsheetCommandType,- menuCommandFolder);- addFolder(ShortcutTree::tr("Cells"), MenuCellsCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Play"), MenuPlayCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Render"), MenuRenderCommandType,- menuCommandFolder);- addFolder(ShortcutTree::tr("View"), MenuViewCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Windows"), MenuWindowsCommandType,- menuCommandFolder);- addFolder(ShortcutTree::tr("Help"), MenuHelpCommandType, menuCommandFolder);-- addFolder(ShortcutTree::tr("Tools"), ToolCommandType);- addFolder(ShortcutTree::tr("Fill"), FillCommandType);- addFolder(ShortcutTree::tr("Right-click Menu Commands"),- RightClickMenuCommandType);- addFolder(ShortcutTree::tr("Tool Modifiers"), ToolModifierCommandType);- addFolder(ShortcutTree::tr("Visualization"), VisualizationButtonCommandType);- addFolder(ShortcutTree::tr("Misc"), MiscCommandType);- addFolder(ShortcutTree::tr("RGBA Channels"), RGBACommandType);-- sortItems(0, Qt::AscendingOrder);-- CommandBarSeparatorItem* sep = new CommandBarSeparatorItem(0);- sep->setToolTip(0, QObject::tr("[Drag&Drop] to copy separator to menu bar"));- addTopLevelItem(sep);-}--//-------------------------------------------------------------------------------void CommandBarListTree::addFolder(const QString& title, int commandType,- QTreeWidgetItem* parentFolder) {- QTreeWidgetItem* folder;- if (!parentFolder)- folder = new QTreeWidgetItem(this);- else- folder = new QTreeWidgetItem(parentFolder);- assert(folder);- folder->setText(0, title);- folder->setIcon(0, invisibleRootItem()->icon(0));-- std::vector<QAction*> actions;- CommandManager::instance()->getActions((CommandType)commandType, actions);- for (int i = 0; i < (int)actions.size(); i++) {- CommandBarCommandItem* item = new CommandBarCommandItem(folder, actions[i]);- item->setToolTip(0, QObject::tr("[Drag&Drop] to copy command to menu bar"));- }-}--//-------------------------------------------------------------------------------void CommandBarListTree::mousePressEvent(QMouseEvent* event) {- setCurrentItem(itemAt(event->pos()));- CommandBarCommandItem* commandItem =- dynamic_cast<CommandBarCommandItem*>(itemAt(event->pos()));- CommandBarSeparatorItem* separatorItem =- dynamic_cast<CommandBarSeparatorItem*>(itemAt(event->pos()));-- if (commandItem || separatorItem) {- std::string dragStr;- QString dragPixmapTxt;- if (commandItem) {- dragStr =- CommandManager::instance()->getIdFromAction(commandItem->getAction());- dragPixmapTxt = commandItem->getAction()->text();- dragPixmapTxt.remove("&");- } else {- dragStr = "separator";- dragPixmapTxt = tr("----Separator----");- }-- QMimeData* mimeData = new QMimeData;- mimeData->setText(QString::fromStdString(dragStr));-- QFontMetrics fm(QApplication::font());- QPixmap pix(fm.boundingRect(dragPixmapTxt).adjusted(-2, -2, 2, 2).size());- QPainter painter(&pix);- painter.fillRect(pix.rect(), Qt::white);- painter.setPen(Qt::black);- painter.drawText(pix.rect(), Qt::AlignCenter, dragPixmapTxt);-- QDrag* drag = new QDrag(this);- drag->setMimeData(mimeData);- drag->setPixmap(pix);-- drag->exec(Qt::CopyAction);- }-- 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<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();-}-//=============================================================================// CommandBarPopup//-----------------------------------------------------------------------------@@ -478,7 +488,7 @@ CommandBarPopup::CommandBarPopup(bool isXsheetToolbar)setWindowTitle(tr("Customize Command Bar"));}- m_commandListTree = new CommandBarListTree(this);+ m_commandListTree = new CommandListTree(commandBarLabel->text(), this);m_menuBarTree = new CommandBarTree(m_path, this);QPushButton* okBtn = new QPushButton(tr("OK"), this);diff --git a/toonz/sources/toonz/commandbarpopup.h b/toonz/sources/toonz/commandbarpopup.hindex 4a0efd01b..c80f60a53 100644--- a/toonz/sources/toonz/commandbarpopup.h+++ b/toonz/sources/toonz/commandbarpopup.h@@ -14,41 +14,42 @@ class QXmlStreamReader;class QXmlStreamWriter;//=============================================================================-// CommandBarTree+// CommandItem//------------------------------------------------------------------------------class CommandBarTree final : public QTreeWidget {- Q_OBJECT-- void loadMenuTree(const TFilePath& fp);- void loadMenuRecursive(QXmlStreamReader& reader, QTreeWidgetItem* parentItem);- void saveMenuRecursive(QXmlStreamWriter& writer, QTreeWidgetItem* parentItem);+class CommandItem final : public QTreeWidgetItem {+ QAction* m_action;public:- CommandBarTree(TFilePath& path, QWidget* parent = 0);- void saveMenuTree(TFilePath& path);+ CommandItem(QTreeWidgetItem* parent, QAction* action);+ QAction* getAction() const { return m_action; }+};-protected:- bool dropMimeData(QTreeWidgetItem* parent, int index, const QMimeData* data,- Qt::DropAction action) override;- QStringList mimeTypes() const override;- void contextMenuEvent(QContextMenuEvent* event) override;-protected slots:- void removeItem();+//=============================================================================+// SeparatorItem+//-----------------------------------------------------------------------------++class SeparatorItem final : public QTreeWidgetItem {+public:+ SeparatorItem(QTreeWidgetItem* parent);};//=============================================================================-// CommandBarListTree+// CommandListTree+// shared by menubar popup and cutom panel editor popup//------------------------------------------------------------------------------class CommandBarListTree final : public QTreeWidget {+class CommandListTree final : public QTreeWidget {Q_OBJECT- void addFolder(const QString& title, int commandType,- QTreeWidgetItem* parentFolder = 0);+ QString m_dropTargetString;++ QTreeWidgetItem* addFolder(const QString& title, int commandType,+ QTreeWidgetItem* parentFolder = 0);public:- CommandBarListTree(QWidget* parent = 0);+ CommandListTree(const QString& dropTargetString, QWidget* parent = 0,+ bool withSeparator = true);void searchItems(const QString& searchWord = QString());@@ -60,13 +61,37 @@ protected:void mousePressEvent(QMouseEvent*) override;};+//=============================================================================+// CommandBarTree+//-----------------------------------------------------------------------------++class CommandBarTree final : public QTreeWidget {+ Q_OBJECT++ void loadMenuTree(const TFilePath& fp);+ void loadMenuRecursive(QXmlStreamReader& reader, QTreeWidgetItem* parentItem);+ void saveMenuRecursive(QXmlStreamWriter& writer, QTreeWidgetItem* parentItem);++public:+ CommandBarTree(TFilePath& path, QWidget* parent = 0);+ void saveMenuTree(TFilePath& path);++protected:+ bool dropMimeData(QTreeWidgetItem* parent, int index, const QMimeData* data,+ Qt::DropAction action) override;+ QStringList mimeTypes() const override;+ void contextMenuEvent(QContextMenuEvent* event) override;+protected slots:+ void removeItem();+};+//=============================================================================// CommandBarPopup//-----------------------------------------------------------------------------class CommandBarPopup final : public DVGui::Dialog {Q_OBJECT- CommandBarListTree* m_commandListTree;+ CommandListTree* m_commandListTree;CommandBarTree* m_menuBarTree;TFilePath m_path;diff --git a/toonz/sources/toonz/custompaneleditorpopup.cpp b/toonz/sources/toonz/custompaneleditorpopup.cppindex 4a15c1fcc..2a92a042f 100644--- a/toonz/sources/toonz/custompaneleditorpopup.cpp+++ b/toonz/sources/toonz/custompaneleditorpopup.cpp@@ -5,6 +5,7 @@#include "menubarcommandids.h"#include "shortcutpopup.h"#include "custompanelmanager.h"+#include "commandbarpopup.h"// TnzQt includes#include "toonzqt/gutil.h"@@ -257,202 +258,6 @@ void UiPreviewArea::resizeEvent(QResizeEvent* event) {QScrollArea::resizeEvent(event);}-//=============================================================================-// CommandBarCommandItem-//-------------------------------------------------------------------------------class CustomPanelCommandItem final : public QTreeWidgetItem {- QAction* m_action;--public:- CustomPanelCommandItem(QTreeWidgetItem* parent, QAction* action)- : QTreeWidgetItem(parent, UserType), m_action(action) {- setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled |- Qt::ItemNeverHasChildren);- QString tempText = m_action->text();- // removing accelerator key indicator- tempText = tempText.replace(QRegExp("&([^& ])"), "\\1");- // removing doubled &s- tempText = tempText.replace("&&", "&");- setText(0, tempText);- setToolTip(0, QObject::tr("[Drag] to move position"));- }- QAction* getAction() const { return m_action; }-};--//=============================================================================-// CustomPanelCommandListTree-//-------------------------------------------------------------------------------void CustomPanelCommandListTree::addFolder(const QString& title,- int commandType,- QTreeWidgetItem* parentFolder) {- QTreeWidgetItem* folder;- if (!parentFolder)- folder = new QTreeWidgetItem(this);- else- folder = new QTreeWidgetItem(parentFolder);- assert(folder);- folder->setText(0, title);- folder->setIcon(0, invisibleRootItem()->icon(0));-- std::vector<QAction*> actions;- CommandManager::instance()->getActions((CommandType)commandType, actions);- for (int i = 0; i < (int)actions.size(); i++) {- CustomPanelCommandItem* item =- new CustomPanelCommandItem(folder, actions[i]);- item->setToolTip(- 0, QObject::tr(- "[Drag&Drop] to set command to control in the custom panel"));- }-}--CustomPanelCommandListTree::CustomPanelCommandListTree(QWidget* parent)- : QTreeWidget(parent) {- setObjectName("SolidLineFrame");- setAlternatingRowColors(true);- setDragEnabled(true);- setDragDropMode(QAbstractItemView::DragOnly);- setColumnCount(1);- setIconSize(QSize(21, 18));- header()->close();-- QIcon menuFolderIcon(createQIcon("folder_project", true));- invisibleRootItem()->setIcon(0, menuFolderIcon);-- QTreeWidgetItem* menuCommandFolder = new QTreeWidgetItem(this);- menuCommandFolder->setFlags(Qt::ItemIsEnabled);- menuCommandFolder->setText(0, ShortcutTree::tr("Menu Commands"));- menuCommandFolder->setExpanded(true);- menuCommandFolder->setIcon(0, invisibleRootItem()->icon(0));-- addFolder(ShortcutTree::tr("File"), MenuFileCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Edit"), MenuEditCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Scan & Cleanup"), MenuScanCleanupCommandType,- menuCommandFolder);- addFolder(ShortcutTree::tr("Level"), MenuLevelCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Xsheet"), MenuXsheetCommandType,- menuCommandFolder);- addFolder(ShortcutTree::tr("Cells"), MenuCellsCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Play"), MenuPlayCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Render"), MenuRenderCommandType,- menuCommandFolder);- addFolder(ShortcutTree::tr("View"), MenuViewCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Windows"), MenuWindowsCommandType,- menuCommandFolder);- addFolder(ShortcutTree::tr("Help"), MenuHelpCommandType, menuCommandFolder);-- addFolder(ShortcutTree::tr("Tools"), ToolCommandType);- addFolder(ShortcutTree::tr("Fill"), FillCommandType);- addFolder(ShortcutTree::tr("Right-click Menu Commands"),- RightClickMenuCommandType);- QTreeWidgetItem* rcmSubFolder =- invisibleRootItem()->child(invisibleRootItem()->childCount() - 1);- addFolder(ShortcutTree::tr("Cell Mark"), CellMarkCommandType, rcmSubFolder);- addFolder(ShortcutTree::tr("Tool Modifiers"), ToolModifierCommandType);- addFolder(ShortcutTree::tr("Visualization"), VisualizationButtonCommandType);- addFolder(ShortcutTree::tr("Misc"), MiscCommandType);- addFolder(ShortcutTree::tr("RGBA Channels"), RGBACommandType);-- sortItems(0, Qt::AscendingOrder);-}--void CustomPanelCommandListTree::mousePressEvent(QMouseEvent* event) {- setCurrentItem(itemAt(event->pos()));- CustomPanelCommandItem* commandItem =- dynamic_cast<CustomPanelCommandItem*>(itemAt(event->pos()));-- if (commandItem) {- std::string dragStr;- QString dragPixmapTxt;- dragStr =- CommandManager::instance()->getIdFromAction(commandItem->getAction());- dragPixmapTxt = commandItem->getAction()->text();- dragPixmapTxt.remove("&");-- QMimeData* mimeData = new QMimeData;- mimeData->setText(QString::fromStdString(dragStr));-- QFontMetrics fm(QApplication::font());- QPixmap pix(fm.boundingRect(dragPixmapTxt).adjusted(-2, -2, 2, 2).size());- QPainter painter(&pix);- painter.fillRect(pix.rect(), Qt::white);- painter.setPen(Qt::black);- painter.drawText(pix.rect(), Qt::AlignCenter, dragPixmapTxt);-- QDrag* drag = new QDrag(this);- drag->setMimeData(mimeData);- drag->setPixmap(pix);-- drag->exec(Qt::CopyAction);- }-- 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//-----------------------------------------------------------------------------@@ -871,7 +676,8 @@ CustomPanelEditorPopup::CustomPanelEditorPopup()"CustomPanelEditorPopup") {setWindowTitle(tr("Custom Panel Editor"));- m_commandListTree = new CustomPanelCommandListTree(this);+ m_commandListTree =+ new CommandListTree(tr("a control in the panel"), this, false);QLabel* commandItemListLabel = new QLabel(tr("Command List"), this);QFont f("Arial", 15, QFont::Bold);diff --git a/toonz/sources/toonz/custompaneleditorpopup.h b/toonz/sources/toonz/custompaneleditorpopup.hindex 54f20d6fb..2aa841d90 100644--- a/toonz/sources/toonz/custompaneleditorpopup.h+++ b/toonz/sources/toonz/custompaneleditorpopup.h@@ -17,6 +17,7 @@#include <QDomElement>class QComboBox;class CustomPanelUIField;+class CommandListTree;enum UiType { Button = 0, Scroller_Back, Scroller_Fore, TypeCount };struct UiEntry {@@ -102,29 +103,6 @@ protected:void resizeEvent(QResizeEvent* event) override;};-//=============================================================================-// CustomPanelCommandListTree-//-------------------------------------------------------------------------------class CustomPanelCommandListTree final : public QTreeWidget {- Q_OBJECT-- void addFolder(const QString& title, int commandType,- QTreeWidgetItem* parentFolder = 0);--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;-};-//=============================================================================// CustomPanelEditorPopup//-----------------------------------------------------------------------------@@ -132,7 +110,7 @@ protected:class CustomPanelEditorPopup : public DVGui::Dialog {Q_OBJECTprivate:- CustomPanelCommandListTree* m_commandListTree;+ CommandListTree* m_commandListTree;QWidget* m_UiFieldsContainer;UiPreviewArea* m_previewArea;diff --git a/toonz/sources/toonz/menubarpopup.cpp b/toonz/sources/toonz/menubarpopup.cppindex 54bbdb0ff..5890207f6 100644--- a/toonz/sources/toonz/menubarpopup.cpp+++ b/toonz/sources/toonz/menubarpopup.cpp@@ -5,6 +5,7 @@#include "mainwindow.h"#include "menubar.h"#include "shortcutpopup.h"+#include "commandbarpopup.h"// TnzQt includes#include "toonzqt/gutil.h"@@ -33,39 +34,6 @@#include <QApplication>#include <QLabel>-//=============================================================================-// MenuBarCommandItem-//-------------------------------------------------------------------------------class MenuBarCommandItem final : public QTreeWidgetItem {- QAction* m_action;--public:- MenuBarCommandItem(QTreeWidgetItem* parent, QAction* action)- : QTreeWidgetItem(parent, UserType), m_action(action) {- setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled |- Qt::ItemNeverHasChildren);- setText(0, m_action->text().remove("&"));- setToolTip(0, QObject::tr("[Drag] to move position"));- }- QAction* getAction() const { return m_action; }-};--//=============================================================================-// MenuBarSeparatorItem-//-------------------------------------------------------------------------------class MenuBarSeparatorItem final : public QTreeWidgetItem {-public:- MenuBarSeparatorItem(QTreeWidgetItem* parent)- : QTreeWidgetItem(parent, UserType) {- setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled |- Qt::ItemNeverHasChildren);- setText(0, QObject::tr("----Separator----"));- setToolTip(0, QObject::tr("[Drag] to move position"));- }-};-//=============================================================================// MenuBarSubmenuItem//-----------------------------------------------------------------------------@@ -151,7 +119,7 @@ void MenuBarTree::loadMenuTree(const TFilePath& fp) {QAction* action = CommandManager::instance()->getAction(cmdName.toStdString().c_str());if (action) {- MenuBarCommandItem* item = new MenuBarCommandItem(0, action);+ CommandItem* item = new CommandItem(0, action);addTopLevelItem(item);}} else@@ -179,20 +147,18 @@ void MenuBarTree::loadMenuRecursive(QXmlStreamReader& reader,QString cmdName = reader.readElementText();QAction* action =CommandManager::instance()->getAction(cmdName.toStdString().c_str());- if (action)- MenuBarCommandItem* item = new MenuBarCommandItem(parentItem, action);+ if (action) CommandItem* item = new CommandItem(parentItem, action);} else if (reader.name() == "command_debug") {#ifndef NDEBUGQString cmdName = reader.readElementText();QAction* action =CommandManager::instance()->getAction(cmdName.toStdString().c_str());- if (action)- MenuBarCommandItem* item = new MenuBarCommandItem(parentItem, action);+ if (action) CommandItem* item = new CommandItem(parentItem, action);#elsereader.skipCurrentElement();#endif} else if (reader.name() == "separator") {- MenuBarSeparatorItem* sep = new MenuBarSeparatorItem(parentItem);+ SeparatorItem* sep = new SeparatorItem(parentItem);reader.skipCurrentElement();} elsereader.skipCurrentElement();@@ -224,10 +190,8 @@ void MenuBarTree::saveMenuTree() {void MenuBarTree::saveMenuRecursive(QXmlStreamWriter& writer,QTreeWidgetItem* parentItem) {for (int c = 0; c < parentItem->childCount(); c++) {- MenuBarCommandItem* command =- dynamic_cast<MenuBarCommandItem*>(parentItem->child(c));- MenuBarSeparatorItem* sep =- dynamic_cast<MenuBarSeparatorItem*>(parentItem->child(c));+ CommandItem* command = dynamic_cast<CommandItem*>(parentItem->child(c));+ SeparatorItem* sep = dynamic_cast<SeparatorItem*>(parentItem->child(c));MenuBarSubmenuItem* subMenu =dynamic_cast<MenuBarSubmenuItem*>(parentItem->child(c));if (command)@@ -258,12 +222,12 @@ bool MenuBarTree::dropMimeData(QTreeWidgetItem* parent, int index,QString txt = data->text();QTreeWidgetItem* item;if (txt == "separator")- item = new MenuBarSeparatorItem(0);+ item = new SeparatorItem(0);else {QAction* act =CommandManager::instance()->getAction(txt.toStdString().c_str());if (!act) return false;- item = new MenuBarCommandItem(0, act);+ item = new CommandItem(0, act);}if (parent)@@ -344,180 +308,6 @@ void MenuBarTree::onItemChanged(QTreeWidgetItem* item, int column) {submenuItem->setOrgTitle(submenuItem->text(0));}-//=============================================================================-// CommandListTree-//-------------------------------------------------------------------------------CommandListTree::CommandListTree(QWidget* parent) : QTreeWidget(parent) {- setObjectName("SolidLineFrame");- setAlternatingRowColors(true);- setDragEnabled(true);- setDragDropMode(QAbstractItemView::DragOnly);- setColumnCount(1);- setIconSize(QSize(21, 18));- header()->close();-- QIcon menuFolderIcon(createQIcon("folder_project", true));- invisibleRootItem()->setIcon(0, menuFolderIcon);-- QTreeWidgetItem* menuCommandFolder = new QTreeWidgetItem(this);- menuCommandFolder->setFlags(Qt::ItemIsEnabled);- menuCommandFolder->setText(0, ShortcutTree::tr("Menu Commands"));- menuCommandFolder->setExpanded(true);- menuCommandFolder->setIcon(0, invisibleRootItem()->icon(0));-- addFolder(ShortcutTree::tr("File"), MenuFileCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Edit"), MenuEditCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Scan & Cleanup"), MenuScanCleanupCommandType,- menuCommandFolder);- addFolder(ShortcutTree::tr("Level"), MenuLevelCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Xsheet"), MenuXsheetCommandType,- menuCommandFolder);- addFolder(ShortcutTree::tr("Cells"), MenuCellsCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Play"), MenuPlayCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Render"), MenuRenderCommandType,- menuCommandFolder);- addFolder(ShortcutTree::tr("View"), MenuViewCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Windows"), MenuWindowsCommandType,- menuCommandFolder);- addFolder(ShortcutTree::tr("Help"), MenuHelpCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("SubMenu Commands"), MenuCommandType,- menuCommandFolder);-- addFolder(ShortcutTree::tr("Tools"), ToolCommandType);-- sortItems(0, Qt::AscendingOrder);-- MenuBarSeparatorItem* sep = new MenuBarSeparatorItem(0);- sep->setToolTip(0, QObject::tr("[Drag&Drop] to copy separator to menu bar"));- addTopLevelItem(sep);-}--//-------------------------------------------------------------------------------void CommandListTree::addFolder(const QString& title, int commandType,- QTreeWidgetItem* parentFolder) {- QTreeWidgetItem* folder;- if (!parentFolder)- folder = new QTreeWidgetItem(this);- else- folder = new QTreeWidgetItem(parentFolder);- assert(folder);- folder->setText(0, title);- folder->setIcon(0, invisibleRootItem()->icon(0));-- std::vector<QAction*> actions;- CommandManager::instance()->getActions((CommandType)commandType, actions);- for (int i = 0; i < (int)actions.size(); i++) {- MenuBarCommandItem* item = new MenuBarCommandItem(folder, actions[i]);- item->setToolTip(0, QObject::tr("[Drag&Drop] to copy command to menu bar"));- }-}--//-------------------------------------------------------------------------------void CommandListTree::mousePressEvent(QMouseEvent* event) {- setCurrentItem(itemAt(event->pos()));- MenuBarCommandItem* commandItem =- dynamic_cast<MenuBarCommandItem*>(itemAt(event->pos()));- MenuBarSeparatorItem* separatorItem =- dynamic_cast<MenuBarSeparatorItem*>(itemAt(event->pos()));-- if (commandItem || separatorItem) {- std::string dragStr;- QString dragPixmapTxt;- if (commandItem) {- dragStr =- CommandManager::instance()->getIdFromAction(commandItem->getAction());- dragPixmapTxt = commandItem->getAction()->text();- dragPixmapTxt.remove("&");- } else {- dragStr = "separator";- dragPixmapTxt = tr("----Separator----");- }-- QMimeData* mimeData = new QMimeData;- mimeData->setText(QString::fromStdString(dragStr));-- QFontMetrics fm(QApplication::font());- QPixmap pix(fm.boundingRect(dragPixmapTxt).adjusted(-2, -2, 2, 2).size());- QPainter painter(&pix);- painter.fillRect(pix.rect(), Qt::white);- painter.setPen(Qt::black);- painter.drawText(pix.rect(), Qt::AlignCenter, dragPixmapTxt);-- QDrag* drag = new QDrag(this);- drag->setMimeData(mimeData);- drag->setPixmap(pix);-- drag->exec(Qt::CopyAction);- }-- 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//-----------------------------------------------------------------------------@@ -531,7 +321,11 @@ MenuBarPopup::MenuBarPopup(Room* room)std::string mbFileName = room->getPath().getName() + "_menubar.xml";TFilePath mbPath = ToonzFolder::getMyRoomsDir() + mbFileName;- m_commandListTree = new CommandListTree(this);+ QLabel* menuBarLabel =+ new QLabel(tr("%1 Menu Bar").arg(room->getName()), this);+ QLabel* menuItemListLabel = new QLabel(tr("Menu Items"), this);++ m_commandListTree = new CommandListTree(menuBarLabel->text(), this);m_menuBarTree = new MenuBarTree(mbPath, this);QPushButton* okBtn = new QPushButton(tr("OK"), this);@@ -540,10 +334,6 @@ MenuBarPopup::MenuBarPopup(Room* room)okBtn->setFocusPolicy(Qt::NoFocus);cancelBtn->setFocusPolicy(Qt::NoFocus);- QLabel* menuBarLabel =- new QLabel(tr("%1 Menu Bar").arg(room->getName()), this);- QLabel* menuItemListLabel = new QLabel(tr("Menu Items"), this);-QFont f("Arial", 15, QFont::Bold);menuBarLabel->setFont(f);menuItemListLabel->setFont(f);diff --git a/toonz/sources/toonz/menubarpopup.h b/toonz/sources/toonz/menubarpopup.hindex c5467b6d1..902c57e54 100644--- a/toonz/sources/toonz/menubarpopup.h+++ b/toonz/sources/toonz/menubarpopup.h@@ -13,6 +13,7 @@class Room;class QXmlStreamReader;class QXmlStreamWriter;+class CommandListTree;//=============================================================================// MenuBarTree@@ -42,29 +43,6 @@ protected slots:void onItemChanged(QTreeWidgetItem*, int);};-//=============================================================================-// CommandListTree-//-------------------------------------------------------------------------------class CommandListTree final : public QTreeWidget {- Q_OBJECT-- void addFolder(const QString& title, int commandType,- QTreeWidgetItem* parentFolder = 0);--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;-};-//=============================================================================// MenuBarPopup//-----------------------------------------------------------------------------