OpenToonz - An open-source full-featured 2D animation creation software
C
feat(panels): enhance Custom Panel Editor with BTR and hot shortcuts
Ahl764d74885a4b6f
diff --git a/toonz/sources/toonz/commandbarpopup.cpp b/toonz/sources/toonz/commandbarpopup.cppindex 353cf9503..e76198c31 100644--- a/toonz/sources/toonz/commandbarpopup.cpp+++ b/toonz/sources/toonz/commandbarpopup.cpp@@ -30,6 +30,7 @@#include <QMimeData>#include <QDrag>#include <QMouseEvent>+#include <QMap>#include <QPainter>#include <QApplication>#include <QLabel>@@ -106,8 +107,10 @@ CommandListTree::CommandListTree(const QString& dropTargetString,addFolder(ShortcutTree::tr("Render"), MenuRenderCommandType,menuCommandFolder);addFolder(ShortcutTree::tr("View"), MenuViewCommandType, menuCommandFolder);- addFolder(ShortcutTree::tr("Windows"), MenuWindowsCommandType,+ QTreeWidgetItem* windowsFolder = addFolder(ShortcutTree::tr("Windows"), MenuWindowsCommandType,menuCommandFolder);+ addFolder(ShortcutTree::tr("Custom Panels"), CustomPanelCommandType,+ windowsFolder);addFolder(ShortcutTree::tr("Help"), MenuHelpCommandType, menuCommandFolder);addFolder(ShortcutTree::tr("SubMenu Commands"), MenuCommandType,menuCommandFolder);@@ -125,8 +128,13 @@ CommandListTree::CommandListTree(const QString& dropTargetString,addFolder(ShortcutTree::tr("Right-click Menu Commands"),RightClickMenuCommandType, advancedFolder);addFolder(ShortcutTree::tr("Cell Mark"), CellMarkCommandType, rcmSubFolder);- addFolder(ShortcutTree::tr("Tool Modifiers"), ToolModifierCommandType,- advancedFolder);+ QTreeWidgetItem* toolModifiersFolder =+ addFolder(ShortcutTree::tr("Tool Modifiers"), ToolModifierCommandType,+ advancedFolder);+ addFolder(ShortcutTree::tr("Brush Presets"), BrushPresetCommandType,+ toolModifiersFolder);+ addFolder(ShortcutTree::tr("Brush Sizes"), BrushSizeCommandType,+ toolModifiersFolder);addFolder(ShortcutTree::tr("Visualization"), VisualizationButtonCommandType,advancedFolder);addFolder(ShortcutTree::tr("Misc"), MiscCommandType, advancedFolder);@@ -148,6 +156,88 @@ CommandListTree::CommandListTree(const QString& dropTargetString,//-----------------------------------------------------------------------------+void CommandListTree::refreshTree() {+ // Save expansion state+ QMap<QString, bool> expandedState;+ for (int i = 0; i < topLevelItemCount(); ++i) {+ QTreeWidgetItem* item = topLevelItem(i);+ if (item) {+ expandedState[item->text(0)] = item->isExpanded();+ }+ }++ // Clear and rebuild+ clear();++ QIcon menuFolderIcon(createQIcon("folder_project"));+ invisibleRootItem()->setIcon(0, menuFolderIcon);++ QTreeWidgetItem* menuCommandFolder = new QTreeWidgetItem(this);+ menuCommandFolder->setFlags(Qt::ItemIsEnabled);+ menuCommandFolder->setText(0, "1");+ 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);+ QTreeWidgetItem* windowsFolder = addFolder(ShortcutTree::tr("Windows"), MenuWindowsCommandType,+ menuCommandFolder);+ addFolder(ShortcutTree::tr("Custom Panels"), CustomPanelCommandType,+ windowsFolder);+ addFolder(ShortcutTree::tr("Help"), MenuHelpCommandType, menuCommandFolder);+ addFolder(ShortcutTree::tr("SubMenu Commands"), MenuCommandType,+ menuCommandFolder);++ QTreeWidgetItem* toolsFolder = addFolder("2", ToolCommandType);++ QTreeWidgetItem* advancedFolder = new QTreeWidgetItem(this);+ advancedFolder->setFlags(Qt::ItemIsEnabled);+ advancedFolder->setText(0, "3");+ 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);+ QTreeWidgetItem* toolModifiersFolder =+ addFolder(ShortcutTree::tr("Tool Modifiers"), ToolModifierCommandType,+ advancedFolder);+ addFolder(ShortcutTree::tr("Brush Presets"), BrushPresetCommandType,+ toolModifiersFolder);+ addFolder(ShortcutTree::tr("Brush Sizes"), BrushSizeCommandType,+ toolModifiersFolder);+ addFolder(ShortcutTree::tr("Visualization"), VisualizationButtonCommandType,+ advancedFolder);+ addFolder(ShortcutTree::tr("Misc"), MiscCommandType, advancedFolder);+ addFolder(ShortcutTree::tr("RGBA Channels"), RGBACommandType, advancedFolder);++ sortItems(0, Qt::AscendingOrder);+ menuCommandFolder->setText(0, ShortcutTree::tr("Menu Commands"));+ toolsFolder->setText(0, ShortcutTree::tr("Tools"));+ advancedFolder->setText(0, ShortcutTree::tr("Advanced"));++ // Restore expansion state+ for (int i = 0; i < topLevelItemCount(); ++i) {+ QTreeWidgetItem* item = topLevelItem(i);+ if (item && expandedState.contains(item->text(0))) {+ item->setExpanded(expandedState[item->text(0)]);+ }+ }+}++//-----------------------------------------------------------------------------+QTreeWidgetItem* CommandListTree::addFolder(const QString& title,int commandType,QTreeWidgetItem* parentFolder) {diff --git a/toonz/sources/toonz/commandbarpopup.h b/toonz/sources/toonz/commandbarpopup.hindex 5067f91b1..c2f1c63bb 100644--- a/toonz/sources/toonz/commandbarpopup.h+++ b/toonz/sources/toonz/commandbarpopup.h@@ -54,6 +54,7 @@ public:bool withSeparator = true);void searchItems(const QString& searchWord = QString());+ void refreshTree(); // Rebuild tree with updated commandsprivate:void displayAll(QTreeWidgetItem* item);diff --git a/toonz/sources/toonz/custompaneleditorpopup.cpp b/toonz/sources/toonz/custompaneleditorpopup.cppindex 488e8d24c..a38c153f1 100644--- a/toonz/sources/toonz/custompaneleditorpopup.cpp+++ b/toonz/sources/toonz/custompaneleditorpopup.cpp@@ -8,6 +8,7 @@#include "shortcutpopup.h"#include "custompanelmanager.h"#include "commandbarpopup.h"+#include "toolpresetcommandmanager.h"// TnzQt includes#include "toonzqt/gutil.h"@@ -866,6 +867,20 @@ CustomPanelEditorPopup::CustomPanelEditorPopup()//-----------------------------------------------------------------------------+void CustomPanelEditorPopup::showEvent(QShowEvent* event) {+ // Refresh brush preset and size commands to ensure they're up-to-date+ ToolPresetCommandManager::instance()->refreshPresetCommands();+ ToolPresetCommandManager::instance()->refreshSizeCommands();++ // Refresh the command list tree to show new commands+ m_commandListTree->refreshTree();+ m_commandListTree->searchItems(); // Clear any search filter++ Dialog::showEvent(event);+}++//-----------------------------------------------------------------------------+void CustomPanelEditorPopup::onSearchTextChanged(const QString& text) {static bool busy = false;if (busy) {diff --git a/toonz/sources/toonz/custompaneleditorpopup.h b/toonz/sources/toonz/custompaneleditorpopup.hindex de9a98098..1bbf853ca 100644--- a/toonz/sources/toonz/custompaneleditorpopup.h+++ b/toonz/sources/toonz/custompaneleditorpopup.h@@ -145,9 +145,12 @@ private:QWidget* customWidget); // Update widget using current entriespublic:- explicit CustomPanelEditorPopup();--private slots:+ CustomPanelEditorPopup();++protected:+ void showEvent(QShowEvent* event) override;++protected slots:void onTemplateSwitched();void onHighlight(int id);void onCommandChanged(const QString& oldCmdId, const QString& newCmdId);diff --git a/toonz/sources/toonz/custompanelmanager.cpp b/toonz/sources/toonz/custompanelmanager.cppindex 81391b3b8..eb8a413d2 100644--- a/toonz/sources/toonz/custompanelmanager.cpp+++ b/toonz/sources/toonz/custompanelmanager.cpp@@ -3,6 +3,10 @@#include "menubarcommandids.h"#include "floatingpanelcommand.h"#include "pane.h"+#include "mainwindow.h"+#include "shortcutpopup.h"+#include "tapp.h"+#include "toolpresetcommandmanager.h"// ToonzLib#include "toonz/toonzfolders.h"@@ -111,6 +115,17 @@ void CustomPanelManager::loadCustomPanelEntries() {// in order to prevent double calling of the commandmenu->addAction(CommandManager::instance()->getAction(MI_CustomPanelEditor)->text());++ registerCustomPanelCommands();++ // Register tool presets as commands for Custom Panels+ ToolPresetCommandManager::instance()->registerToolPresetCommands();++ // Register universal size commands+ ToolPresetCommandManager::instance()->registerSizeCommands();++ // Initialize signal connections for automatic checked state updates+ ToolPresetCommandManager::instance()->initialize();}//-----------------------------------------------------------------------------@@ -136,17 +151,22 @@ TPanel* CustomPanelManager::createCustomPanel(const QString panelName,panel->setWindowTitle(panelName);panel->setWidget(customWidget);+ // Enable room binding feature (handled by TPanel base class)+ panel->addRoomBindButton();+return panel;}//-----------------------------------------------------------------------------void CustomPanelManager::initializeControl(QWidget* customWidget) {+ // Update checked states before initializing controls+ ToolPresetCommandManager::instance()->updateCheckedStates();+// connect buttons and commandsQList<QAbstractButton*> allButtons =customWidget->findChildren<QAbstractButton*>();for (auto button : allButtons) {- std::cout << button->objectName().toStdString() << std::endl;QAction* action = CommandManager::instance()->getAction(button->objectName().toStdString().c_str());if (!action) continue;@@ -157,13 +177,31 @@ void CustomPanelManager::initializeControl(QWidget* customWidget) {if (QToolButton* tb = dynamic_cast<QToolButton*>(button)) {tb->setDefaultAction(action);tb->setObjectName("CustomPanelButton");++ // Build stylesheet with visible checked state+ QString styleSheet;+if (tb->toolButtonStyle() == Qt::ToolButtonTextUnderIcon) {int padding = (tb->height() - button->iconSize().height() -tb->font().pointSize() * 1.33) /3;- if (padding > 0)- tb->setStyleSheet(QString("padding-top: %1;").arg(padding));+ if (padding > 0) {+ styleSheet = QString("QToolButton#CustomPanelButton { padding-top: %1; }").arg(padding);+ }+ }++ // Add checked state styles ONLY for new commands+ // (Brush Presets and Universal Sizes)+ std::string cmdId = button->objectName().toStdString();+ bool isBrushPreset = (cmdId.find("MI_BrushPreset_") == 0);+ bool isUniversalSize = (cmdId.find("MI_ToolSize_") == 0);++ // No custom stylesheet - let buttons inherit colors from the application theme+ // This ensures proper adaptation when the user switches themes+ if (!styleSheet.isEmpty()) {+ tb->setStyleSheet(styleSheet);}+continue;}@@ -181,6 +219,8 @@ void CustomPanelManager::initializeControl(QWidget* customWidget) {if (!button->text().isEmpty()) button->setText(action->text());button->setIcon(action->icon());++ // No custom stylesheet for checked buttons - let them inherit from theme// button->addAction(action);}@@ -220,6 +260,110 @@ void CustomPanelManager::initializeControl(QWidget* customWidget) {//-----------------------------------------------------------------------------+void CustomPanelManager::registerCustomPanelCommands() {+ TFilePath customPanelsFolder = customPaneFolderPath();+ if (!TSystem::doesExistFileOrLevel(customPanelsFolder)) return;++ TFilePathSet fileList =+ TSystem::readDirectory(customPanelsFolder, false, true, false);++ QList<QString> currentPanels;+ for (auto file : fileList) {+ if (file.getType() != "ui") continue;+ currentPanels.append(QString::fromStdString(file.getName()));+ }++ m_registeredPanelIds.clear();++ MainWindow* mainWindow = dynamic_cast<MainWindow*>(TApp::instance()->getMainWindow());+ if (!mainWindow) return;++ for (const QString& panelName : currentPanels) {+ QString commandId = "MI_CustomPanel_" + panelName;++ QAction* existingAction = CommandManager::instance()->getAction(+ commandId.toStdString().c_str(), false);+ if (existingAction) {+ m_registeredPanelIds.append(commandId);+ continue;+ }++ // Improved display name for better searchability+ // Replace underscores and hyphens with spaces for readability+ QString cleanName = panelName;+ cleanName.replace('_', ' ');+ cleanName.replace('-', ' ');++ // Create display name with [Panel] prefix+ QString displayName = "[Panel] " + cleanName;++ QAction* action = new DVAction(displayName, mainWindow);+ mainWindow->addAction(action);++ // Define command with improved naming for search+ // Add searchable keywords in the command definition+ CommandManager::instance()->define(+ commandId.toStdString().c_str(),+ CustomPanelCommandType, // Custom Panels subcategory under Windows+ "",+ action,+ "");++ class CustomPanelHandler : public CommandHandlerInterface {+ QString m_panelName;+ public:+ CustomPanelHandler(const QString& name) : m_panelName(name) {}+ void execute() override {+ TMainWindow* currentRoom = TApp::instance()->getCurrentRoom();+ if (!currentRoom) return;++ std::string panelType = ("Custom_" + m_panelName).toStdString();+ QList<TPanel*> panels = currentRoom->findChildren<TPanel*>();++ for (TPanel* panel : panels) {+ if (panel->getPanelType() == panelType && !panel->isHidden()) {+ panel->close();+ return;+ }+ }++ OpenFloatingPanel::getOrOpenFloatingPanel(panelType);+ }+ };++ CommandManager::instance()->setHandler(+ commandId.toStdString().c_str(),+ new CustomPanelHandler(panelName));++ m_registeredPanelIds.append(commandId);+ }++ // Notify ShortcutPopup to refresh if it's currently open+ // This allows new custom panel commands to appear immediately without restarting+ ShortcutPopup::refreshIfOpen();++ TFilePath shortcutsFile = ToonzFolder::getMyModuleDir() + TFilePath("shortcuts.ini");+ if (!TFileStatus(shortcutsFile).doesExist()) return;++ QSettings settings(toQString(shortcutsFile), QSettings::IniFormat);+ settings.beginGroup("shortcuts");++ for (const QString& commandId : m_registeredPanelIds) {+ QString savedShortcut = settings.value(commandId, "").toString();+ if (!savedShortcut.isEmpty()) {+ QAction* action = CommandManager::instance()->getAction(+ commandId.toStdString().c_str(), false);+ if (action) {+ action->setShortcut(QKeySequence(savedShortcut));+ }+ }+ }++ settings.endGroup();+}++//-----------------------------------------------------------------------------+class OpenCustomPanelCommandHandler final : public MenuItemHandler {public:OpenCustomPanelCommandHandler() : MenuItemHandler(MI_OpenCustomPanels) {}diff --git a/toonz/sources/toonz/custompanelmanager.h b/toonz/sources/toonz/custompanelmanager.hindex 7b27ccda5..976526036 100644--- a/toonz/sources/toonz/custompanelmanager.h+++ b/toonz/sources/toonz/custompanelmanager.h@@ -7,6 +7,7 @@#include <QString>#include <QWidget>+#include <QList>class TPanel;@@ -46,10 +47,13 @@ protected:class CustomPanelManager { // singletonCustomPanelManager(){};++ QList<QString> m_registeredPanelIds;public:static CustomPanelManager* instance();void loadCustomPanelEntries();+ void registerCustomPanelCommands();TPanel* createCustomPanel(const QString panelName, QWidget* parent);