Modify menubar commands tree by Contrail Co.,Ltd.

This commit is contained in:
shun-iwasawa 2023-03-03 16:06:58 +09:00 committed by manongjohn
parent 156ae0d3fd
commit 2c2ba38537
4 changed files with 294 additions and 477 deletions

View file

@ -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();
if (tempText.indexOf("&") == 0) {
tempText = tempText.remove(0, 1);
}
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"));
}
//=============================================================================
// CommandBarSeparatorItem
// SeparatorItem
//-----------------------------------------------------------------------------
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"));
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"));
}
//=============================================================================
// 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);
}
};
}
//-----------------------------------------------------------------------------
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
@ -125,11 +322,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
@ -153,22 +350,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 NDEBUG
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
reader.skipCurrentElement();
#endif
} else if (reader.name() == "separator") {
CommandBarSeparatorItem* sep = new CommandBarSeparatorItem(parentItem);
SeparatorItem* sep = new SeparatorItem(parentItem);
reader.skipCurrentElement();
} else
reader.skipCurrentElement();
@ -200,10 +393,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(
@ -224,12 +415,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)
@ -283,192 +474,9 @@ void CommandBarTree::removeItem() {
}
//=============================================================================
// 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("Scene"), 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("Panels"), 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);
addFolder(ShortcutTree::tr("Stop Motion"), StopMotionCommandType);
sortItems(0, Qt::AscendingOrder);
CommandBarSeparatorItem* sep = new CommandBarSeparatorItem(0);
sep->setToolTip(0, QObject::tr("[Drag&Drop] to copy separator to toolbar"));
addTopLevelItem(sep);
connect(this, SIGNAL(clicked(const QModelIndex&)), this,
SLOT(onItemClicked(const QModelIndex&)));
}
//-----------------------------------------------------------------------------
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 toolbar"));
}
}
//-----------------------------------------------------------------------------
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();
}
//-----------------------------------------------------------------------------
void CommandBarListTree::onItemClicked(const QModelIndex& index) {
void CommandListTree::onItemClicked(const QModelIndex& index) {
isExpanded(index) ? collapse(index) : expand(index);
}
@ -497,7 +505,7 @@ CommandBarPopup::CommandBarPopup(QString barId, bool isQuickToolbar)
setWindowTitle(tr("Customize Command Bar"));
}
m_commandListTree = new CommandBarListTree(this);
m_commandListTree = new CommandListTree(commandBarLabel->text(), this);
m_menuBarTree = new CommandBarTree(m_path, m_defaultPath, this);
QPushButton* okBtn = new QPushButton(tr("OK"), this);

View file

@ -14,6 +14,57 @@
class QXmlStreamReader;
class QXmlStreamWriter;
//=============================================================================
// CommandItem
//-----------------------------------------------------------------------------
class CommandItem final : public QTreeWidgetItem {
QAction* m_action;
public:
CommandItem(QTreeWidgetItem* parent, QAction* action);
QAction* getAction() const { return m_action; }
};
//=============================================================================
// SeparatorItem
//-----------------------------------------------------------------------------
class SeparatorItem final : public QTreeWidgetItem {
public:
SeparatorItem(QTreeWidgetItem* parent);
};
//=============================================================================
// CommandListTree
// shared by menubar popup and cutom panel editor popup
//-----------------------------------------------------------------------------
class CommandListTree final : public QTreeWidget {
Q_OBJECT
QString m_dropTargetString;
QTreeWidgetItem* addFolder(const QString& title, int commandType,
QTreeWidgetItem* parentFolder = 0);
public:
CommandListTree(const QString& dropTargetString, QWidget* parent = 0,
bool withSeparator = true);
void searchItems(const QString& searchWord = QString());
public slots:
void onItemClicked(const QModelIndex&);
private:
void displayAll(QTreeWidgetItem* item);
void hideAll(QTreeWidgetItem* item);
protected:
void mousePressEvent(QMouseEvent*) override;
};
//=============================================================================
// CommandBarTree
//-----------------------------------------------------------------------------
@ -38,39 +89,13 @@ protected slots:
void removeItem();
};
//=============================================================================
// CommandBarListTree
//-----------------------------------------------------------------------------
class CommandBarListTree final : public QTreeWidget {
Q_OBJECT
void addFolder(const QString& title, int commandType,
QTreeWidgetItem* parentFolder = 0);
public:
CommandBarListTree(QWidget* parent = 0);
void searchItems(const QString& searchWord = QString());
public slots:
void onItemClicked(const QModelIndex&);
private:
void displayAll(QTreeWidgetItem* item);
void hideAll(QTreeWidgetItem* item);
protected:
void mousePressEvent(QMouseEvent*) override;
};
//=============================================================================
// CommandBarPopup
//-----------------------------------------------------------------------------
class CommandBarPopup final : public DVGui::Dialog {
Q_OBJECT
CommandBarListTree* m_commandListTree;
CommandListTree* m_commandListTree;
CommandBarTree* m_menuBarTree;
QCheckBox* m_saveAsDefaultCB;
TFilePath m_path, m_defaultPath;

View file

@ -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
//-----------------------------------------------------------------------------
@ -876,7 +681,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);

View file

@ -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_OBJECT
private:
CustomPanelCommandListTree* m_commandListTree;
CommandListTree* m_commandListTree;
QWidget* m_UiFieldsContainer;
UiPreviewArea* m_previewArea;