Skip to content

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

C

refactor: Qt modernization and code cleanup

Anderson Prado627e242219fb
diff --git a/toonz/sources/include/toonzqt/fxschematicscene.h b/toonz/sources/include/toonzqt/fxschematicscene.h
index 04662e2c7..2cefabcbb 100644
--- a/toonz/sources/include/toonzqt/fxschematicscene.h
+++ b/toonz/sources/include/toonzqt/fxschematicscene.h
@@ -199,6 +199,25 @@ signals:
void doExplodeChild(const QList<TFxP> &);
void editObject();
+public slots:
+ void requestDisconnectFromXSheet() { onDisconnectFromXSheet(); }
+ void requestConnectToXSheet() { onConnectToXSheet(); }
+ void requestPreview() { onPreview(); }
+ void requestCacheFx() { onCacheFx(); }
+ void requestUncacheFx() { onUncacheFx(); }
+ void requestDeleteFx() { onDeleteFx(); }
+ void requestDuplicateFx() { onDuplicateFx(); }
+ void requestUnlinkFx() { onUnlinkFx(); }
+ void requestMacroFx() { onMacroFx(); }
+ void requestExplodeMacroFx() { onExplodeMacroFx(); }
+ void requestOpenMacroFx() { onOpenMacroFx(); }
+ void requestSavePresetFx() { onSavePresetFx(); }
+ void requestActivateOutput() { onActivateOutput(); }
+ void requestInsertPaste() { onInsertPaste(); }
+ void requestAddPaste() { onAddPaste(); }
+ void requestReplacePaste() { onReplacePaste(); }
+ void requestEditGroup() { onEditGroup(); }
+
protected slots:
void onSelectionSwitched(TSelection *oldSel, TSelection *newSel) override;
void onSelectionChanged();
@@ -245,4 +264,4 @@ private:
const FxSchematicScene &operator=(const FxSchematicScene &);
};
-#endif // FXSCHEMATIC_H
+#endif // FXSCHEMATIC_H
\ No newline at end of file
diff --git a/toonz/sources/include/toonzqt/studiopaletteviewer.h b/toonz/sources/include/toonzqt/studiopaletteviewer.h
index 38cdbb8a1..257e22761 100644
--- a/toonz/sources/include/toonzqt/studiopaletteviewer.h
+++ b/toonz/sources/include/toonzqt/studiopaletteviewer.h
@@ -121,8 +121,7 @@ protected slots:
void onCurrentItemChanged(QTreeWidgetItem *current,
QTreeWidgetItem *previous);
- /*! When expand a tree, prepare the child items of it */
- void onTreeItemExpanded(QTreeWidgetItem *);
+
/*! Refresh tree only when this widget has focus*/
void onRefreshTreeShortcutTriggered();
@@ -166,10 +165,10 @@ protected:
/*! Return current item path. */
TFilePath getCurrentFolderPath();
- /*! Return item identified by \b path; if it doesn't exist return 0. */
+ /*! Return item identified by \b path; if it doesn't exist return nullptr. */
QTreeWidgetItem *getItem(const TFilePath path);
/*! Return item child of \b parent identified by \b path; if it doesn't exist
- * return 0. */
+ * return nullptr. */
QTreeWidgetItem *getFolderItem(QTreeWidgetItem *parent, const TFilePath path);
void resetDropItem();
@@ -177,10 +176,6 @@ protected:
void paintEvent(QPaintEvent *event) override;
/*! Open a context menu considering current item data role \b Qt::UserRole. */
void contextMenuEvent(QContextMenuEvent *event) override;
- /*! Add an action to menu \b menu; the action has text \b name and its
- \b triggered() signal is connetted with \b slot. */
- void createMenuAction(QMenu &menu, const char *id, QString name,
- const char *slot);
/*! If button left is pressed start drag and drop. */
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
@@ -196,7 +191,7 @@ protected:
/*! Execute drop event. If dropped palette is in studio palette folder move
palette, otherwise copy palette in current folder. */
void dropEvent(QDropEvent *event) override;
- /*! Set dropItem to 0 and update the tree. */
+ /*! Set dropItem to nullptr and update the tree. */
void dragLeaveEvent(QDragLeaveEvent *event) override;
};
@@ -252,4 +247,4 @@ public:
AdjustPaletteDialog();
};
-#endif // STUDIOPALETTEVIEWER_H
+#endif // STUDIOPALETTEVIEWER_H
\ No newline at end of file
diff --git a/toonz/sources/toonzqt/fxschematicnode.cpp b/toonz/sources/toonzqt/fxschematicnode.cpp
index c2668e756..a810ed5dc 100644
--- a/toonz/sources/toonzqt/fxschematicnode.cpp
+++ b/toonz/sources/toonzqt/fxschematicnode.cpp
@@ -54,12 +54,14 @@
#include <QMenu>
#include <QGraphicsSceneMouseEvent>
#include <QDesktopWidget>
+#include <cassert>
//********************************************************************************
// Local namespace
//********************************************************************************
namespace {
+// Check if the FX is an inner macro FX
bool isAInnerMacroFx(TFx *fx, TXsheet *xsh) {
if (!fx) return false;
TColumnFx *cfx = dynamic_cast<TColumnFx *>(fx);
@@ -71,6 +73,7 @@ bool isAInnerMacroFx(TFx *fx, TXsheet *xsh) {
//-----------------------------------------------------
+// Draw a cached FX flap indicator
void drawCachedFxFlap(QPainter *painter, const QPointF &pos) {
painter->save();
painter->setPen(QColor(0, 0, 0, 255));
@@ -96,6 +99,7 @@ void drawCachedFxFlap(QPainter *painter, const QPointF &pos) {
//-----------------------------------------------------
+// Get the index of a port in a vector of ports
int getIndex(TFxPort *port, const std::vector<TFxPort *> &ports) {
std::vector<TFxPort *>::const_iterator it =
std::find(ports.begin(), ports.end(), port);
@@ -105,6 +109,7 @@ int getIndex(TFxPort *port, const std::vector<TFxPort *> &ports) {
//-----------------------------------------------------
+// Get the index of an input port in its owner FX
int getInputPortIndex(TFxPort *port, TFx *fx) {
int count = fx->getInputPortCount();
int i;
@@ -117,7 +122,7 @@ int getInputPortIndex(TFxPort *port, TFx *fx) {
//*****************************************************
//
-// FxColumnPainter
+// FxColumnPainter - Painter for column nodes in the FX schematic
//
//*****************************************************
@@ -131,8 +136,8 @@ FxColumnPainter::FxColumnPainter(FxSchematicColumnNode *parent, double width,
setFlag(QGraphicsItem::ItemIsMovable, false);
setFlag(QGraphicsItem::ItemIsSelectable, false);
setFlag(QGraphicsItem::ItemIsFocusable, false);
- connect(IconGenerator::instance(), SIGNAL(iconGenerated()), this,
- SLOT(onIconGenerated()));
+ connect(IconGenerator::instance(), &IconGenerator::iconGenerated, this,
+ &FxColumnPainter::onIconGenerated);
TLevelColumnFx *lcfx = dynamic_cast<TLevelColumnFx *>(parent->getFx());
if (lcfx) {
@@ -244,10 +249,18 @@ void FxColumnPainter::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
QAction *copy = CommandManager::instance()->getAction("MI_Copy");
QAction *cut = CommandManager::instance()->getAction("MI_Cut");
- bool enebleInsertAction =
+ bool enableInsertAction =
!m_parent->getFx()->getAttributes()->isGrouped() ||
m_parent->getFx()->getAttributes()->isGroupEditing();
- if (enebleInsertAction) {
+
+ // Declare actions that might be used later
+ QAction *addPaste = nullptr;
+ QAction *disconnectFromXSheet = nullptr;
+ QAction *connectToXSheet = nullptr;
+ QAction *preview = nullptr;
+ QAction *cacheFx = nullptr;
+
+ if (enableInsertAction) {
// repeat the latest action
if (cme->modifiers() & Qt::ControlModifier) {
menu.addAction(fxScene->getAgainAction(AddFxContextMenu::Add |
@@ -263,34 +276,42 @@ void FxColumnPainter::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
fxScene->initCursorScenePos();
QMenu *addMenu = fxScene->getAddFxMenu();
- QAction *disconnectFromXSheet =
- new QAction(tr("&Disconnect from Xsheet"), &menu);
- connect(disconnectFromXSheet, SIGNAL(triggered()), fxScene,
- SLOT(onDisconnectFromXSheet()));
-
- QAction *connectToXSheet = new QAction(tr("&Connect to Xsheet"), &menu);
- connect(connectToXSheet, SIGNAL(triggered()), fxScene,
- SLOT(onConnectToXSheet()));
+ // Create actions only if they might be used
+ if (enableInsertAction) {
+ disconnectFromXSheet = new QAction(tr("&Disconnect from Xsheet"), &menu);
+ connect(disconnectFromXSheet, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestDisconnectFromXSheet);
+
+ connectToXSheet = new QAction(tr("&Connect to Xsheet"), &menu);
+ connect(connectToXSheet, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestConnectToXSheet);
+
+ preview = new QAction(tr("&Preview"), &menu);
+ connect(preview, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestPreview);
+
+ bool cacheEnabled =
+ TPassiveCacheManager::instance()->cacheEnabled(m_parent->getFx());
+
+ cacheFx =
+ new QAction(cacheEnabled ? tr("&Uncache Fx") : tr("&Cache FX"), &menu);
+ if (cacheEnabled)
+ connect(cacheFx, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestUncacheFx);
+ else
+ connect(cacheFx, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestCacheFx);
+ }
QAction *addOutputFx =
CommandManager::instance()->getAction("MI_NewOutputFx");
- QAction *addPaste =
- new QAction(createQIcon("paste_duplicate"), tr("&Paste Add"), &menu);
- connect(addPaste, SIGNAL(triggered()), fxScene, SLOT(onAddPaste()));
-
- QAction *preview = new QAction(tr("&Preview"), &menu);
- connect(preview, SIGNAL(triggered()), fxScene, SLOT(onPreview()));
-
- bool cacheEnabled =
- TPassiveCacheManager::instance()->cacheEnabled(m_parent->getFx());
-
- QAction *cacheFx =
- new QAction(cacheEnabled ? tr("&Uncache Fx") : tr("&Cache FX"), &menu);
- if (cacheEnabled)
- connect(cacheFx, SIGNAL(triggered()), fxScene, SLOT(onUncacheFx()));
- else
- connect(cacheFx, SIGNAL(triggered()), fxScene, SLOT(onCacheFx()));
+ if (enableInsertAction) {
+ addPaste =
+ new QAction(createQIcon("paste_duplicate"), tr("&Paste Add"), &menu);
+ connect(addPaste, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestAddPaste);
+ }
QAction *collapse = CommandManager::instance()->getAction("MI_Collapse");
@@ -301,40 +322,44 @@ void FxColumnPainter::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
QAction *group = CommandManager::instance()->getAction("MI_Group");
- menu.addMenu(insertMenu);
- menu.addMenu(addMenu);
- menu.addSeparator();
- if (!m_parent->getFx()->getAttributes()->isGrouped()) {
- menu.addAction(copy);
- menu.addAction(cut);
- menu.addAction(addPaste);
- }
- menu.addSeparator();
- if (fxScene->getXsheet()->getFxDag()->getTerminalFxs()->containsFx(
- m_parent->getFx()))
- menu.addAction(disconnectFromXSheet);
- else
- menu.addAction(connectToXSheet);
- if (!m_parent->getFx()->getAttributes()->isGrouped())
- menu.addAction(addOutputFx);
- menu.addAction(preview);
- menu.addAction(cacheFx);
- menu.addSeparator();
- if (enebleInsertAction) {
+ if (enableInsertAction) {
+ menu.addMenu(insertMenu);
+ menu.addMenu(addMenu);
+ menu.addSeparator();
+ if (!m_parent->getFx()->getAttributes()->isGrouped()) {
+ menu.addAction(copy);
+ menu.addAction(cut);
+ if (addPaste) menu.addAction(addPaste);
+ }
+ menu.addSeparator();
+ if (fxScene->getXsheet()->getFxDag()->getTerminalFxs()->containsFx(
+ m_parent->getFx())) {
+ if (disconnectFromXSheet) menu.addAction(disconnectFromXSheet);
+ } else {
+ if (connectToXSheet) menu.addAction(connectToXSheet);
+ }
+ if (!m_parent->getFx()->getAttributes()->isGrouped()) {
+ menu.addAction(addOutputFx);
+ }
+ if (preview) menu.addAction(preview);
+ if (cacheFx) menu.addAction(cacheFx);
+ menu.addSeparator();
menu.addAction(collapse);
}
TFrameHandle *frameHandle = fxScene->getFrameHandle();
- if (frameHandle->getFrameType() == TFrameHandle::SceneFrame) {
+ if (frameHandle->getFrameType() == TFrameHandle::SceneFrame &&
+ enableInsertAction) {
TLevelColumnFx *colFx = dynamic_cast<TLevelColumnFx *>(m_parent->getFx());
- assert(colFx);
- int col = colFx->getColumnIndex();
- int fr = frameHandle->getFrame();
- TXsheet *xsh = fxScene->getXsheet();
- TXshCell cell = xsh->getCell(fr, col);
- if (dynamic_cast<TXshChildLevel *>(cell.m_level.getPointer())) {
- menu.addAction(openSubxsh);
- menu.addAction(explodeChild);
+ if (colFx) {
+ int col = colFx->getColumnIndex();
+ int fr = frameHandle->getFrame();
+ TXsheet *xsh = fxScene->getXsheet();
+ TXshCell cell = xsh->getCell(fr, col);
+ if (dynamic_cast<TXshChildLevel *>(cell.m_level.getPointer())) {
+ menu.addAction(openSubxsh);
+ menu.addAction(explodeChild);
+ }
}
}
menu.addSeparator();
@@ -381,7 +406,7 @@ void FxColumnPainter::onIconGenerated() {
//*****************************************************
//
-// FxPalettePainter
+// FxPalettePainter - Painter for palette column nodes
//
//*****************************************************
@@ -477,48 +502,81 @@ void FxPalettePainter::paint(QPainter *painter,
//-----------------------------------------------------
void FxPalettePainter::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
+ // Get the FxSchematicScene from the current scene
FxSchematicScene *fxScene = dynamic_cast<FxSchematicScene *>(scene());
- QMenu menu(fxScene->views()[0]);
- QAction *disconnectFromXSheet =
- new QAction(tr("&Disconnect from Xsheet"), &menu);
- connect(disconnectFromXSheet, SIGNAL(triggered()), fxScene,
- SLOT(onDisconnectFromXSheet()));
+ // If the scene is invalid, do nothing
+ if (!fxScene) return;
- QAction *connectToXSheet = new QAction(tr("&Connect to Xsheet"), &menu);
- connect(connectToXSheet, SIGNAL(triggered()), fxScene,
- SLOT(onConnectToXSheet()));
+ // Create a context menu, parented to the first view of the scene
+ QMenu menu(fxScene->views().isEmpty() ? nullptr : fxScene->views()[0]);
- QAction *preview = new QAction(tr("&Preview"), &menu);
- connect(preview, SIGNAL(triggered()), fxScene, SLOT(onPreview()));
+ // Initialize actions as nullptr
+ QAction *disconnectFromXSheet = nullptr;
+ QAction *connectToXSheet = nullptr;
+ QAction *preview = nullptr;
+ // Retrieve standard actions from the command manager
QAction *collapse = CommandManager::instance()->getAction("MI_Collapse");
+ QAction *group = CommandManager::instance()->getAction("MI_Group");
- QAction *group = CommandManager::instance()->getAction("MI_Group");
-
- bool enebleInsertAction =
+ // Determine whether insert actions should be enabled
+ bool enableInsertAction =
!m_parent->getFx()->getAttributes()->isGrouped() ||
m_parent->getFx()->getAttributes()->isGroupEditing();
- if (enebleInsertAction) {
- if (fxScene->getXsheet()->getFxDag()->getTerminalFxs()->containsFx(
- m_parent->getFx()))
+ // Only create and connect actions if insertion is allowed
+ if (enableInsertAction) {
+ // Create "Disconnect from Xsheet" action
+ disconnectFromXSheet = new QAction(tr("&Disconnect from Xsheet"), &menu);
+ if (disconnectFromXSheet && fxScene) {
+ connect(disconnectFromXSheet, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestDisconnectFromXSheet);
+ }
+
+ // Create "Connect to Xsheet" action
+ connectToXSheet = new QAction(tr("&Connect to Xsheet"), &menu);
+ if (connectToXSheet && fxScene) {
+ connect(connectToXSheet, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestConnectToXSheet);
+ }
+
+ // Create "Preview" action
+ preview = new QAction(tr("&Preview"), &menu);
+ if (preview && fxScene) {
+ connect(preview, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestPreview);
+ }
+
+ // Check if this Fx is a terminal Fx in the scene
+ bool isTerminalFx =
+ fxScene->getXsheet()->getFxDag()->getTerminalFxs()->containsFx(
+ m_parent->getFx());
+
+ // Add the appropriate action based on terminal status
+ if (isTerminalFx && disconnectFromXSheet) {
menu.addAction(disconnectFromXSheet);
- else
+ } else if (connectToXSheet) {
menu.addAction(connectToXSheet);
- menu.addAction(preview);
- menu.addSeparator();
- menu.addAction(collapse);
- menu.addSeparator();
+ }
+
+ // Add preview and collapse actions to the menu
+ if (preview) menu.addAction(preview);
+ if (collapse) menu.addSeparator();
+ if (collapse) menu.addAction(collapse);
+ if (collapse) menu.addSeparator();
}
- menu.addAction(group);
+ // Always add the group action at the end
+ if (group) menu.addAction(group);
+
+ // Execute the context menu at the mouse position
menu.exec(cme->screenPos());
}
//*****************************************************
//
-// FxPainter
+// FxPainter - Painter for standard FX nodes
//
//*****************************************************
@@ -674,6 +732,23 @@ void FxPainter::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
bool enableInsertAction =
enableGroupAction && (fx->getAttributes()->isGroupEditing() ||
!fx->getAttributes()->isGrouped());
+
+ // Declare all actions that might be created conditionally
+ QAction *replacePaste = nullptr;
+ QAction *addPaste = nullptr;
+ QAction *deleteFx = nullptr;
+ QAction *disconnectFromXSheet = nullptr;
+ QAction *connectToXSheet = nullptr;
+ QAction *duplicateFx = nullptr;
+ QAction *unlinkFx = nullptr;
+ QAction *macroFx = nullptr;
+ QAction *explodeMacroFx = nullptr;
+ QAction *openMacroFx = nullptr;
+ QAction *savePresetFx = nullptr;
+ QAction *preview = nullptr;
+ QAction *cacheFx = nullptr;
+ QAction *editGroup = nullptr;
+
if (enableInsertAction) {
// repeat the last command
if (cme->modifiers() & Qt::ControlModifier) {
@@ -701,74 +776,91 @@ void FxPainter::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
QAction *group = CommandManager::instance()->getAction("MI_Group");
QAction *ungroup = CommandManager::instance()->getAction("MI_Ungroup");
- QAction *editGroup =
- new QAction(createQIcon("enter_group"), tr("&Open Group"), &menu);
- connect(editGroup, SIGNAL(triggered()), fxScene, SLOT(onEditGroup()));
-
- QAction *replacePaste =
- new QAction(createQIcon("convert"), tr("&Paste Replace"), &menu);
- connect(replacePaste, SIGNAL(triggered()), fxScene, SLOT(onReplacePaste()));
-
- QAction *addPaste =
- new QAction(createQIcon("paste_duplicate"), tr("&Paste Add"), &menu);
- connect(addPaste, SIGNAL(triggered()), fxScene, SLOT(onAddPaste()));
-
QAction *addOutputFx =
CommandManager::instance()->getAction("MI_NewOutputFx");
+ QAction *collapse = CommandManager::instance()->getAction("MI_Collapse");
- QAction *deleteFx = new QAction(createQIcon("delete"), tr("&Delete"), &menu);
- connect(deleteFx, SIGNAL(triggered()), fxScene, SLOT(onDeleteFx()));
-
- QAction *disconnectFromXSheet = new QAction(
- createQIcon("xsheet_disconnect"), tr("&Disconnect from Xsheet"), &menu);
- connect(disconnectFromXSheet, SIGNAL(triggered()), fxScene,
- SLOT(onDisconnectFromXSheet()));
-
- QAction *connectToXSheet = new QAction(createQIcon("xsheet_connect"),
- tr("&Connect to Xsheet"), &menu);
- connect(connectToXSheet, SIGNAL(triggered()), fxScene,
- SLOT(onConnectToXSheet()));
-
- QAction *duplicateFx =
- new QAction(createQIcon("link"), tr("&Create Linked FX"), &menu);
- connect(duplicateFx, SIGNAL(triggered()), fxScene, SLOT(onDuplicateFx()));
-
- QAction *unlinkFx = new QAction(createQIcon("unlink"), tr("&Unlink"), &menu);
- connect(unlinkFx, SIGNAL(triggered()), fxScene, SLOT(onUnlinkFx()));
-
- QAction *macroFx =
- new QAction(createQIcon("macro"), tr("&Make Macro FX"), &menu);
- connect(macroFx, SIGNAL(triggered()), fxScene, SLOT(onMacroFx()));
-
- QAction *explodeMacroFx =
- new QAction(createQIcon("sub_explode"), tr("&Explode Macro FX"), &menu);
- connect(explodeMacroFx, SIGNAL(triggered()), fxScene,
- SLOT(onExplodeMacroFx()));
-
- QAction *openMacroFx =
- new QAction(createQIcon("sub_enter"), tr("&Open Macro FX"), &menu);
- connect(openMacroFx, SIGNAL(triggered()), fxScene, SLOT(onOpenMacroFx()));
-
- QAction *savePresetFx =
- new QAction(createQIcon("preset"), tr("&Save As Preset..."), &menu);
- connect(savePresetFx, SIGNAL(triggered()), fxScene, SLOT(onSavePresetFx()));
+ TZeraryColumnFx *zsrc = dynamic_cast<TZeraryColumnFx *>(fx);
- QAction *preview = new QAction(createQIcon("preview"), tr("&Preview"), &menu);
- connect(preview, SIGNAL(triggered()), fxScene, SLOT(onPreview()));
+ // Create actions only when they will be used
+ if (enableInsertAction) {
+ replacePaste =
+ new QAction(createQIcon("convert"), tr("&Paste Replace"), &menu);
+ connect(replacePaste, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestReplacePaste);
+
+ addPaste =
+ new QAction(createQIcon("paste_duplicate"), tr("&Paste Add"), &menu);
+ connect(addPaste, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestAddPaste);
+
+ deleteFx = new QAction(createQIcon("delete"), tr("&Delete"), &menu);
+ connect(deleteFx, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestDeleteFx);
+
+ disconnectFromXSheet = new QAction(createQIcon("xsheet_disconnect"),
+ tr("&Disconnect from Xsheet"), &menu);
+ connect(disconnectFromXSheet, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestDisconnectFromXSheet);
+
+ connectToXSheet = new QAction(createQIcon("xsheet_connect"),
+ tr("&Connect to Xsheet"), &menu);
+ connect(connectToXSheet, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestConnectToXSheet);
+
+ duplicateFx =
+ new QAction(createQIcon("link"), tr("&Create Linked FX"), &menu);
+ connect(duplicateFx, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestDuplicateFx);
+
+ unlinkFx = new QAction(createQIcon("unlink"), tr("&Unlink"), &menu);
+ connect(unlinkFx, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestUnlinkFx);
+
+ macroFx = new QAction(createQIcon("macro"), tr("&Make Macro FX"), &menu);
+ connect(macroFx, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestMacroFx);
- bool cacheEnabled = m_parent->isCached();
+ if (scene()->selectedItems().size() == 1 && m_parent->isA(eMacroFx)) {
+ explodeMacroFx = new QAction(createQIcon("sub_explode"),
+ tr("&Explode Macro FX"), &menu);
+ connect(explodeMacroFx, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestExplodeMacroFx);
+
+ openMacroFx =
+ new QAction(createQIcon("sub_enter"), tr("&Open Macro FX"), &menu);
+ connect(openMacroFx, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestOpenMacroFx);
+ }
- QAction *cacheFx = new QAction(
- cacheEnabled ? createQIcon("uncache_fx") : createQIcon("cache_fx"),
- cacheEnabled ? tr("&Uncache FX") : tr("&Cache FX"), &menu);
- if (cacheEnabled)
- connect(cacheFx, SIGNAL(triggered()), fxScene, SLOT(onUncacheFx()));
- else
- connect(cacheFx, SIGNAL(triggered()), fxScene, SLOT(onCacheFx()));
+ savePresetFx =
+ new QAction(createQIcon("preset"), tr("&Save As Preset..."), &menu);
+ connect(savePresetFx, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestSavePresetFx);
+
+ preview = new QAction(createQIcon("preview"), tr("&Preview"), &menu);
+ connect(preview, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestPreview);
+
+ bool cacheEnabled = m_parent->isCached();
+ cacheFx = new QAction(
+ cacheEnabled ? createQIcon("uncache_fx") : createQIcon("cache_fx"),
+ cacheEnabled ? tr("&Uncache FX") : tr("&Cache FX"), &menu);
+ if (cacheEnabled)
+ connect(cacheFx, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestUncacheFx);
+ else
+ connect(cacheFx, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestCacheFx);
+ }
- QAction *collapse = CommandManager::instance()->getAction("MI_Collapse");
+ if (m_type == eGroupedFx) {
+ editGroup =
+ new QAction(createQIcon("enter_group"), tr("&Open Group"), &menu);
+ connect(editGroup, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestEditGroup);
+ }
- TZeraryColumnFx *zsrc = dynamic_cast<TZeraryColumnFx *>(fx);
// if(m_type != eGroupedFx)
// {
if (enableInsertAction) {
@@ -782,39 +874,39 @@ void FxPainter::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
menu.addAction(copy);
menu.addAction(cut);
if (m_type != eGroupedFx && !fx->getAttributes()->isGrouped()) {
- menu.addAction(replacePaste);
- menu.addAction(addPaste);
+ if (replacePaste) menu.addAction(replacePaste);
+ if (addPaste) menu.addAction(addPaste);
}
- menu.addAction(deleteFx);
+ if (deleteFx) menu.addAction(deleteFx);
menu.addSeparator();
if (fxScene->getXsheetHandle()
->getXsheet()
->getFxDag()
->getTerminalFxs()
- ->containsFx(m_parent->getFx()))
- menu.addAction(disconnectFromXSheet);
- else
- menu.addAction(connectToXSheet);
- menu.addAction(duplicateFx);
+ ->containsFx(m_parent->getFx())) {
+ if (disconnectFromXSheet) menu.addAction(disconnectFromXSheet);
+ } else {
+ if (connectToXSheet) menu.addAction(connectToXSheet);
+ }
+ if (duplicateFx) menu.addAction(duplicateFx);
if ((zsrc && zsrc->getZeraryFx() &&
zsrc->getZeraryFx()->getLinkedFx() != zsrc->getZeraryFx()) ||
- fx->getLinkedFx() != fx)
- menu.addAction(unlinkFx);
+ fx->getLinkedFx() != fx) {
+ if (unlinkFx) menu.addAction(unlinkFx);
+ }
}
menu.addSeparator();
//}
if (!fx->getAttributes()->isGrouped()) menu.addAction(addOutputFx);
- menu.addAction(preview);
- if (enableGroupAction) menu.addAction(cacheFx);
+ if (preview) menu.addAction(preview);
+ if (enableGroupAction && cacheFx) menu.addAction(cacheFx);
menu.addSeparator();
if (m_type != eGroupedFx && enableInsertAction) {
- menu.addAction(macroFx);
- if (scene()->selectedItems().size() == 1 && m_parent->isA(eMacroFx)) {
- menu.addAction(explodeMacroFx);
- menu.addAction(openMacroFx);
- }
- menu.addAction(savePresetFx);
+ if (macroFx) menu.addAction(macroFx);
+ if (explodeMacroFx) menu.addAction(explodeMacroFx);
+ if (openMacroFx) menu.addAction(openMacroFx);
+ if (savePresetFx) menu.addAction(savePresetFx);
if (zsrc) {
menu.addSeparator();
menu.addAction(collapse);
@@ -825,7 +917,7 @@ void FxPainter::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
menu.addAction(group);
if (m_type == eGroupedFx) {
menu.addAction(ungroup);
- menu.addAction(editGroup);
+ if (editGroup) menu.addAction(editGroup);
}
}
menu.exec(cme->screenPos());
@@ -912,7 +1004,7 @@ void FxPainter::paint_small(QPainter *painter) {
//*****************************************************
//
-// FxXSheetPainter
+// FxXSheetPainter - Painter for XSheet node
//
//*****************************************************
@@ -994,10 +1086,12 @@ void FxXSheetPainter::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
CommandManager::instance()->getAction("MI_NewOutputFx");
QAction *addPaste = new QAction(tr("&Paste Add"), &menu);
- connect(addPaste, SIGNAL(triggered()), fxScene, SLOT(onAddPaste()));
+ connect(addPaste, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestAddPaste);
QAction *preview = new QAction(tr("&Preview"), &menu);
- connect(preview, SIGNAL(triggered()), fxScene, SLOT(onPreview()));
+ connect(preview, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestPreview);
menu.addMenu(insertMenu);
menu.addMenu(addMenu);
@@ -1010,7 +1104,7 @@ void FxXSheetPainter::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
//*****************************************************
//
-// FxOutputPainter
+// FxOutputPainter - Painter for output nodes
//
//*****************************************************
@@ -1082,11 +1176,12 @@ void FxOutputPainter::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
QMenu menu(fxScene->views()[0]);
if (fxScene->getXsheet()->getFxDag()->getOutputFxCount() > 1) {
QAction *removeOutput = new QAction(tr("&Delete"), &menu);
- connect(removeOutput, SIGNAL(triggered()), fxScene, SLOT(onDeleteFx()));
+ connect(removeOutput, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestDeleteFx);
QAction *activateOutput = new QAction(tr("&Activate"), &menu);
- connect(activateOutput, SIGNAL(triggered()), fxScene,
- SLOT(onActivateOutput()));
+ connect(activateOutput, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestActivateOutput);
TFx *currentOutFx = fxScene->getXsheet()->getFxDag()->getCurrentOutputFx();
if (currentOutFx != m_parent->getFx()) menu.addAction(activateOutput);
@@ -1101,7 +1196,7 @@ void FxOutputPainter::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
//*****************************************************
//
-// FxSchematicLink
+// FxSchematicLink - Links between FX nodes
//
//*****************************************************
@@ -1130,10 +1225,12 @@ void FxSchematicLink::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
}
QAction *deleteFx = new QAction(tr("&Delete"), &menu);
- connect(deleteFx, SIGNAL(triggered()), fxScene, SLOT(onDeleteFx()));
+ connect(deleteFx, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestDeleteFx);
QAction *insertPaste = new QAction(tr("&Paste Insert"), &menu);
- connect(insertPaste, SIGNAL(triggered()), fxScene, SLOT(onInsertPaste()));
+ connect(insertPaste, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestInsertPaste);
menu.addMenu(fxScene->getInsertFxMenu());
menu.addSeparator();
@@ -1145,7 +1242,7 @@ void FxSchematicLink::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
//*****************************************************
//
-// FxSchematicPort
+// FxSchematicPort - Ports on FX nodes
//
//*****************************************************
@@ -1599,12 +1696,12 @@ void FxSchematicPort::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
QAction *disconnectFromXSheet =
new QAction(tr("&Disconnect from Xsheet"), &menu);
- connect(disconnectFromXSheet, SIGNAL(triggered()), fxScene,
- SLOT(onDisconnectFromXSheet()));
+ connect(disconnectFromXSheet, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestDisconnectFromXSheet);
QAction *connectToXSheet = new QAction(tr("&Connect to Xsheet"), &menu);
- connect(connectToXSheet, SIGNAL(triggered()), fxScene,
- SLOT(onConnectToXSheet()));
+ connect(connectToXSheet, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestConnectToXSheet);
QAction *fxEditorPopup =
CommandManager::instance()->getAction(MI_FxParamEditor);
@@ -1819,7 +1916,7 @@ TFx *FxSchematicPort::getOwnerFx() const {
//*****************************************************
//
-// FxSchematicDock
+// FxSchematicDock - Dock containing ports on FX nodes
//
//*****************************************************
@@ -1856,8 +1953,10 @@ FxSchematicDock::FxSchematicDock(FxSchematicNode *parent, const QString &name,
}
}
}
- connect(m_port, SIGNAL(sceneChanged()), parent, SIGNAL(sceneChanged()));
- connect(m_port, SIGNAL(xsheetChanged()), parent, SIGNAL(xsheetChanged()));
+ connect(m_port, &FxSchematicPort::sceneChanged, parent,
+ &FxSchematicNode::sceneChanged);
+ connect(m_port, &FxSchematicPort::xsheetChanged, parent,
+ &FxSchematicNode::xsheetChanged);
}
//-----------------------------------------------------
@@ -1903,7 +2002,7 @@ FxSchematicNode *FxSchematicDock::getNode() {
//*****************************************************
//
-// FxSchematicNode
+// FxSchematicNode - Base class for all FX schematic nodes
//
//*****************************************************
@@ -2079,8 +2178,7 @@ void FxSchematicNode::addDynamicInputPort(int groupIdx) const {
!m_actualFx->addInputPort(
group->portsPrefix() + QString::number(n).toStdString(), port,
groupIdx);
- ++n)
- ;
+ ++n);
}
//-----------------------------------------------------
@@ -2229,7 +2327,7 @@ void FxSchematicNode::updatePortsPosition() {
//*****************************************************
//
-// FxSchematicOutputNode
+// FxSchematicOutputNode - Output FX node
//
//*****************************************************
@@ -2297,7 +2395,7 @@ void FxSchematicOutputNode::mousePressEvent(QGraphicsSceneMouseEvent *me) {
//*****************************************************
//
-// FxSchematicXSheetNode
+// FxSchematicXSheetNode - XSheet FX node
//
//*****************************************************
@@ -2374,11 +2472,11 @@ void FxSchematicXSheetNode::mousePressEvent(QGraphicsSceneMouseEvent *me) {
//*****************************************************
//
-// FxSchematicNormalFxNode
+// FxSchematicNormalFxNode - Normal FX node
//
//*****************************************************
-// TODO: Fxの分類、各Fxに自己申告させるべき 2016/1/8 shun_iwasawa
+// TODO: FX classification, each FX should self-report 2016/1/8 shun_iwasawa
namespace {
bool isImageAdjustFx(std::string id) {
if (id == "STD_toneCurveFx" || id == "STD_inoChannelSelectorFx" ||
@@ -2535,9 +2633,10 @@ FxSchematicNormalFxNode::FxSchematicNormalFxNode(FxSchematicScene *scene,
m_renderToggle->setZValue(2);
m_painter->setZValue(1);
- connect(m_nameItem, SIGNAL(focusOut()), this, SLOT(onNameChanged()));
- connect(m_renderToggle, SIGNAL(toggled(bool)), this,
- SLOT(onRenderToggleClicked(bool)));
+ connect(m_nameItem, &SchematicName::focusOut, this,
+ &FxSchematicNormalFxNode::onNameChanged);
+ connect(m_renderToggle, &SchematicToggle::toggled, this,
+ &FxSchematicNormalFxNode::onRenderToggleClicked);
m_nameItem->hide();
int i, inputPorts = fx->getInputPortCount();
@@ -2716,7 +2815,7 @@ void FxSchematicNormalFxNode::resize(bool maximized) {}
//*****************************************************
//
-// FxSchematicZeraryNode
+// FxSchematicZeraryNode - Zerary FX node
//
//*****************************************************
@@ -2818,14 +2917,15 @@ FxSchematicZeraryNode::FxSchematicZeraryNode(FxSchematicScene *scene,
m_cameraStandToggle->setZValue(2);
m_painter->setZValue(1);
- connect(m_nameItem, SIGNAL(focusOut()), this, SLOT(onNameChanged()));
- connect(m_renderToggle, SIGNAL(toggled(bool)), this,
- SLOT(onRenderToggleClicked(bool)));
+ connect(m_nameItem, &SchematicName::focusOut, this,
+ &FxSchematicZeraryNode::onNameChanged);
+ connect(m_renderToggle, &SchematicToggle::toggled, this,
+ &FxSchematicZeraryNode::onRenderToggleClicked);
if (Preferences::instance()->isUnifyColumnVisibilityTogglesEnabled())
m_cameraStandToggle->hide();
else
- connect(m_cameraStandToggle, SIGNAL(stateChanged(int)), this,
- SLOT(onCameraStandToggleClicked(int)));
+ connect(m_cameraStandToggle, &SchematicToggle::stateChanged, this,
+ &FxSchematicZeraryNode::onCameraStandToggleClicked);
if (zeraryFx) {
int i, inputPorts = zeraryFx->getInputPortCount();
@@ -2993,7 +3093,7 @@ void FxSchematicZeraryNode::resize(bool maximized) {}
//*****************************************************
//
-// FxSchematicColumnNode
+// FxSchematicColumnNode - Column FX node
//
//*****************************************************
@@ -3014,9 +3114,9 @@ FxSchematicColumnNode::FxSchematicColumnNode(FxSchematicScene *scene,
m_name = QString::fromStdString(name);
m_resizeItem = new SchematicThumbnailToggle(
- this, fx->getAttributes()->isOpened()); // サムネイル矢印
- m_nameItem = new SchematicName(this, 54, 20); // リネーム部分
- m_outDock = new FxSchematicDock(this, "", 0, eFxOutputPort); // Outポート
+ this, fx->getAttributes()->isOpened()); // Thumbnail arrow
+ m_nameItem = new SchematicName(this, 54, 20); // Rename area
+ m_outDock = new FxSchematicDock(this, "", 0, eFxOutputPort); // Out port
m_renderToggle =
new SchematicToggle(this, viewer->getSchematicPreviewButtonOnImage(),
viewer->getSchematicPreviewButtonBgOnColor(),
@@ -3082,17 +3182,18 @@ FxSchematicColumnNode::FxSchematicColumnNode(FxSchematicScene *scene,
m_columnPainter->setZValue(1);
bool ret = true;
- ret = ret && connect(m_resizeItem, SIGNAL(toggled(bool)), this,
- SLOT(onChangedSize(bool)));
- ret = ret &&
- connect(m_nameItem, SIGNAL(focusOut()), this, SLOT(onNameChanged()));
- ret = ret && connect(m_renderToggle, SIGNAL(toggled(bool)), this,
- SLOT(onRenderToggleClicked(bool)));
+ ret = ret && connect(m_resizeItem, &SchematicThumbnailToggle::toggled, this,
+ &FxSchematicColumnNode::onChangedSize);
+ ret = ret && connect(m_nameItem, &SchematicName::focusOut, this,
+ &FxSchematicColumnNode::onNameChanged);
+ ret = ret && connect(m_renderToggle, &SchematicToggle::toggled, this,
+ &FxSchematicColumnNode::onRenderToggleClicked);
if (Preferences::instance()->isUnifyColumnVisibilityTogglesEnabled())
m_cameraStandToggle->hide();
else
- ret = ret && connect(m_cameraStandToggle, SIGNAL(stateChanged(int)), this,
- SLOT(onCameraStandToggleClicked(int)));
+ ret = ret &&
+ connect(m_cameraStandToggle, &SchematicToggle::stateChanged, this,
+ &FxSchematicColumnNode::onCameraStandToggleClicked);
assert(ret);
@@ -3298,7 +3399,7 @@ void FxSchematicColumnNode::renameObject(const TStageObjectId &id,
//*****************************************************
//
-// FxSchematicPaletteNode
+// FxSchematicPaletteNode - Palette column node
//
//*****************************************************
@@ -3360,9 +3461,10 @@ FxSchematicPaletteNode::FxSchematicPaletteNode(FxSchematicScene *scene,
m_renderToggle->setZValue(2);
m_palettePainter->setZValue(1);
- connect(m_nameItem, SIGNAL(focusOut()), this, SLOT(onNameChanged()));
- connect(m_renderToggle, SIGNAL(toggled(bool)), this,
- SLOT(onRenderToggleClicked(bool)));
+ connect(m_nameItem, &SchematicName::focusOut, this,
+ &FxSchematicPaletteNode::onNameChanged);
+ connect(m_renderToggle, &SchematicToggle::toggled, this,
+ &FxSchematicPaletteNode::onRenderToggleClicked);
m_nameItem->hide();
prepareGeometryChange();
@@ -3484,7 +3586,7 @@ void FxSchematicPaletteNode::renameObject(const TStageObjectId &id,
//*****************************************************
//
-// FxGroupNode
+// FxGroupNode - Grouped FX node
//
//*****************************************************
@@ -3560,9 +3662,10 @@ FxGroupNode::FxGroupNode(FxSchematicScene *scene, const QList<TFxP> &groupedFx,
inDock->setZValue(2);
m_painter->setZValue(1);
- connect(m_nameItem, SIGNAL(focusOut()), this, SLOT(onNameChanged()));
- connect(m_renderToggle, SIGNAL(toggled(bool)), this,
- SLOT(onRenderToggleClicked(bool)));
+ connect(m_nameItem, &SchematicName::focusOut, this,
+ &FxGroupNode::onNameChanged);
+ connect(m_renderToggle, &SchematicToggle::toggled, this,
+ &FxGroupNode::onRenderToggleClicked);
m_nameItem->hide();
setPos(computePos());
@@ -3654,8 +3757,8 @@ QPointF FxGroupNode::computePos() const {
return QPointF(pos.x / fxCount, pos.y / fxCount);
else if (fxCount == 0 && pos != TPointD())
return QPointF(pos.x, pos.y);
- return QPointF(25000, 25000); // Qualcosa e' andato male... posiziono nel
- // cebntro della scena per non far danni
+ return QPointF(25000, 25000); // Something went wrong... position in the
+ // center of the scene to avoid damage
}
//-----------------------------------------------------
@@ -3673,8 +3776,8 @@ void FxGroupNode::onNameChanged() {
FxSchematicScene *fxScene = dynamic_cast<FxSchematicScene *>(scene());
if (!fxScene) return;
std::list<TFxP> fxsList(m_groupedFxs.begin(), m_groupedFxs.end());
- TFxCommand::renameGroup(fxsList, m_name.toStdWString(),
- false, fxScene->getXsheetHandle());
+ TFxCommand::renameGroup(fxsList, m_name.toStdWString(), false,
+ fxScene->getXsheetHandle());
update();
}
@@ -3759,7 +3862,7 @@ bool FxGroupNode::isCached() const {
//*****************************************************
//
-// FxPassThroughPainter
+// FxPassThroughPainter - Painter for pass-through nodes
//
//*****************************************************
@@ -3850,10 +3953,12 @@ void FxPassThroughPainter::contextMenuEvent(
CommandManager::instance()->getAction("MI_NewOutputFx");
QAction *addPaste = new QAction(tr("&Paste Add"), &menu);
- connect(addPaste, SIGNAL(triggered()), fxScene, SLOT(onAddPaste()));
+ connect(addPaste, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestAddPaste);
QAction *preview = new QAction(tr("&Preview"), &menu);
- connect(preview, SIGNAL(triggered()), fxScene, SLOT(onPreview()));
+ connect(preview, &QAction::triggered, fxScene,
+ &FxSchematicScene::requestPreview);
menu.addMenu(insertMenu);
menu.addMenu(addMenu);
@@ -3866,7 +3971,7 @@ void FxPassThroughPainter::contextMenuEvent(
//*****************************************************
//
-// FxSchematicPassThroughNode
+// FxSchematicPassThroughNode - Pass-through FX node
//
//*****************************************************
@@ -3931,7 +4036,8 @@ FxSchematicPassThroughNode::FxSchematicPassThroughNode(FxSchematicScene *scene,
m_nameItem->setZValue(3);
- connect(m_nameItem, SIGNAL(focusOut()), this, SLOT(onNameChanged()));
+ connect(m_nameItem, &SchematicName::focusOut, this,
+ &FxSchematicPassThroughNode::onNameChanged);
}
//-----------------------------------------------------
diff --git a/toonz/sources/toonzqt/studiopaletteviewer.cpp b/toonz/sources/toonzqt/studiopaletteviewer.cpp
index b32cc24b2..88066b8b7 100644
--- a/toonz/sources/toonzqt/studiopaletteviewer.cpp
+++ b/toonz/sources/toonzqt/studiopaletteviewer.cpp
@@ -45,9 +45,8 @@
#include <QDrag>
#include <QApplication>
-#include <time.h>
+#include <ctime>
-using namespace std;
using namespace PaletteViewerGUI;
using namespace DVGui;
@@ -97,14 +96,14 @@ StudioPaletteTreeViewer::StudioPaletteTreeViewer(
TPaletteHandle *levelPaletteHandle, TXsheetHandle *xsheetHandle,
TXshLevelHandle *currentLevelHandle)
: QTreeWidget(parent)
- , m_dropItem(0)
+ , m_dropItem(nullptr)
, m_studioPaletteHandle(studioPaletteHandle)
, m_levelPaletteHandle(levelPaletteHandle)
, m_currentLevelHandle(currentLevelHandle)
, m_xsheetHandle(xsheetHandle)
, m_folderIcon(QIcon())
- , m_levelPaletteIcon(QIcon())
- , m_studioPaletteIcon(QIcon())
+ , m_levelPaletteIcon(QIcon(":Resources/palette.svg"))
+ , m_studioPaletteIcon(QIcon(":Resources/studiopalette.svg"))
, m_startPos() {
setIndentation(14);
setAlternatingRowColors(true);
@@ -115,11 +114,6 @@ StudioPaletteTreeViewer::StudioPaletteTreeViewer(
QList<QTreeWidgetItem *> paletteItems;
- QString levelPaletteIcon = QString(":Resources/palette.svg");
- m_levelPaletteIcon.addPixmap(levelPaletteIcon, QIcon::Normal, QIcon::On);
- QString studioPaletteIcon = QString(":Resources/studiopalette.svg");
- m_studioPaletteIcon.addPixmap(studioPaletteIcon, QIcon::Normal, QIcon::On);
-
StudioPalette *studioPalette = StudioPalette::instance();
TFilePath levelPalettePath = studioPalette->getLevelPalettesRoot();
@@ -131,37 +125,30 @@ StudioPaletteTreeViewer::StudioPaletteTreeViewer(
insertTopLevelItems(0, paletteItems);
- bool ret = connect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int)),
- SLOT(onItemChanged(QTreeWidgetItem *, int)));
- ret = ret && connect(this, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
- SLOT(onItemClicked(QTreeWidgetItem *, int)));
- ret =
- ret &&
- connect(this,
- SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
- SLOT(onCurrentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
- ret = ret && connect(this, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this,
- SLOT(onTreeItemExpanded(QTreeWidgetItem *)));
+ connect(this, &QTreeWidget::itemChanged, this,
+ &StudioPaletteTreeViewer::onItemChanged);
+ connect(this, &QTreeWidget::itemClicked, this,
+ &StudioPaletteTreeViewer::onItemClicked);
+ connect(this, &QTreeWidget::currentItemChanged, this,
+ &StudioPaletteTreeViewer::onCurrentItemChanged);
// refresh tree with shortcut key
QAction *refreshAct = CommandManager::instance()->getAction(MI_RefreshTree);
- ret = ret && connect(refreshAct, SIGNAL(triggered()), this,
- SLOT(onRefreshTreeShortcutTriggered()));
+ connect(refreshAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::onRefreshTreeShortcutTriggered);
addAction(refreshAct);
m_palettesScanPopup = new PalettesScanPopup();
setAcceptDrops(true);
- // Per la selezione multipla
+ // For multiple selection
setSelectionMode(QAbstractItemView::ExtendedSelection);
StudioPalette::instance()->addListener(this);
TProjectManager::instance()->addListener(this);
refresh();
-
- assert(ret);
}
//-----------------------------------------------------------------------------
@@ -197,7 +184,7 @@ QTreeWidgetItem *StudioPaletteTreeViewer::createRootItem(TFilePath path) {
QString rootName = QString::fromStdWString(path.getWideName());
if (rootName != "Global Palettes") rootName = "Project Palettes";
QTreeWidgetItem *rootItem =
- new QTreeWidgetItem((QTreeWidget *)0, QStringList(rootName));
+ new QTreeWidgetItem((QTreeWidget *)nullptr, QStringList(rootName));
rootItem->setIcon(0, createQIcon("folder", true));
rootItem->setData(1, Qt::UserRole, toQString(path));
@@ -226,7 +213,7 @@ QTreeWidgetItem *StudioPaletteTreeViewer::createItem(const TFilePath path) {
StudioPalette *studioPalette = StudioPalette::instance();
QString itemName = toQString(TFilePath(path.getWideName()));
QTreeWidgetItem *item =
- new QTreeWidgetItem((QTreeWidget *)0, QStringList(itemName));
+ new QTreeWidgetItem((QTreeWidget *)nullptr, QStringList(itemName));
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable |
Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
if (studioPalette->isPalette(path)) {
@@ -264,7 +251,7 @@ TFilePath StudioPaletteTreeViewer::getCurrentFolderPath() {
QTreeWidgetItem *StudioPaletteTreeViewer::getItem(const TFilePath path) {
QList<QTreeWidgetItem *> oldItems =
findItems(QString(""), Qt::MatchContains, 0);
- if (oldItems.isEmpty()) return 0;
+ if (oldItems.isEmpty()) return nullptr;
int i;
for (i = 0; i < (int)oldItems.size(); i++) {
TFilePath oldItemPath(
@@ -276,7 +263,7 @@ QTreeWidgetItem *StudioPaletteTreeViewer::getItem(const TFilePath path) {
if (item) return item;
}
}
- return 0;
+ return nullptr;
}
//-----------------------------------------------------------------------------
@@ -294,14 +281,14 @@ QTreeWidgetItem *StudioPaletteTreeViewer::getFolderItem(QTreeWidgetItem *parent,
if (item) return item;
}
}
- return 0;
+ return nullptr;
}
//-----------------------------------------------------------------------------
void StudioPaletteTreeViewer::resetDropItem() {
if (!m_dropItem) return;
- m_dropItem = 0;
+ m_dropItem = nullptr;
}
//-----------------------------------------------------------------------------
@@ -328,19 +315,7 @@ void StudioPaletteTreeViewer::refresh() {
}
//-----------------------------------------------------------------------------
-/*!When expand a tree, prepare the child items of it
- */
-void StudioPaletteTreeViewer::onTreeItemExpanded(QTreeWidgetItem *item) {
- if (!item) return;
-
- // if this item was not yet opened, then get the children of this item
- if (!m_openedItems.contains(item)) refreshItem(item);
- // expand the item
- item->setExpanded(!item->isExpanded());
-}
-
-//-----------------------------------------------------------------------------
/*! Refresh tree only when this widget has focus
*/
void StudioPaletteTreeViewer::onRefreshTreeShortcutTriggered() {
@@ -382,7 +357,7 @@ void StudioPaletteTreeViewer::refreshItem(QTreeWidgetItem *item) {
(pathIndex < childrenPathCount) ? childrenPath[pathIndex] : TFilePath();
QTreeWidgetItem *currentItem =
- (itemIndex < currentChildCount) ? currentChildren[itemIndex] : 0;
+ (itemIndex < currentChildCount) ? currentChildren[itemIndex] : nullptr;
TFilePath currentItemPath = getItemPath(currentItem);
if (path == currentItemPath) {
@@ -409,24 +384,23 @@ void StudioPaletteTreeViewer::resetProjectPaletteFolder() {
int projectPaletteIndex = 1;
TFilePath projectPalettePath =
StudioPalette::instance()->getProjectPalettesRoot();
- // Prendo l'item del project palette.
+ // Get the project palette item
QTreeWidgetItem *projectPaletteItem = topLevelItem(projectPaletteIndex);
if (projectPaletteItem) {
- // Se il path dell'item e' uguale a quello del project palette corrente
- // ritorno.
+ // If the item's path equals the current project palette path, return
if (getItemPath(projectPaletteItem) == projectPalettePath) return;
- // Altrimenti lo rimuovo.
+ // Otherwise remove it
removeItemWidget(projectPaletteItem, 0);
delete projectPaletteItem;
- // clear the item list in order to search the folder from scratch
+ // clear the item list to search the folder from scratch
m_openedItems.clear();
// Toonz Palette is not changed, so resurrect the ToonzPaletteRoot
m_openedItems.insert(topLevelItem(0));
}
if (!TSystem::doesExistFileOrLevel(projectPalettePath)) return;
- // Creo il nuovo item con il nuovo project folder e lo inserisco nell'albero.
+ // Create the new item with the new project folder and insert it into the tree
// Items in the ProjectPaletteRoot are refreshed here. Stored in openedItems
- // as well.
+ // as well
QTreeWidgetItem *newProjectPaletteItem = createRootItem(projectPalettePath);
insertTopLevelItem(projectPaletteIndex, newProjectPaletteItem);
@@ -435,10 +409,33 @@ void StudioPaletteTreeViewer::resetProjectPaletteFolder() {
//-----------------------------------------------------------------------------
+/*! Unified click handler for both folders and palettes */
void StudioPaletteTreeViewer::onItemClicked(QTreeWidgetItem *item, int column) {
- if (currentItem() && m_studioPaletteHandle && m_currentPalette.getPointer()) {
- // if(m_studioPaletteHandle->getPalette() != m_currentPalette.getPointer())
- {
+ if (!item || !m_studioPaletteHandle) return;
+
+ TFilePath path = getItemPath(item);
+ StudioPalette *studioPalette = StudioPalette::instance();
+
+ if (studioPalette->isFolder(path)) {
+ // Handle folder click: toggle expansion with lazy loading
+ if (!m_openedItems.contains(item)) {
+ refreshItem(item);
+ m_openedItems.insert(item);
+ }
+
+ // Toggle expansion state
+ bool wasExpanded = item->isExpanded();
+ item->setExpanded(!wasExpanded);
+
+ } else if (studioPalette->isPalette(path)) {
+ // Handle palette click: load palette
+ if (m_currentPalette && getItemPath(currentItem()) == path) {
+ return; // Already current, no need to reload
+ }
+
+ m_currentPalette = studioPalette->getPalette(path, false);
+
+ if (m_currentPalette && m_currentPalette.getPointer()) {
m_studioPaletteHandle->setPalette(m_currentPalette.getPointer());
m_studioPaletteHandle->notifyPaletteSwitched();
StudioPaletteCmd::updateAllLinkedStyles(m_levelPaletteHandle,
@@ -446,12 +443,11 @@ void StudioPaletteTreeViewer::onItemClicked(QTreeWidgetItem *item, int column) {
}
}
}
-
//-----------------------------------------------------------------------------
void StudioPaletteTreeViewer::onItemChanged(QTreeWidgetItem *item, int column) {
if (item != currentItem() || isRootItem(item)) return;
- wstring name = item->text(column).toStdWString();
+ std::wstring name = item->text(column).toStdWString();
TFilePath oldPath = getCurrentFolderPath();
if (oldPath.isEmpty() || name.empty() || oldPath.getWideName() == name)
return;
@@ -483,7 +479,7 @@ void StudioPaletteTreeViewer::onCurrentItemChanged(QTreeWidgetItem *current,
TFilePath oldPath = StudioPalette::instance()->getPalettePath(
m_currentPalette->getGlobalName());
if (oldPath == newPath) return;
- wstring gname = m_currentPalette->getGlobalName();
+ std::wstring gname = m_currentPalette->getGlobalName();
QString question =
tr("The current palette %1\nin the studio palette has been modified. "
"Do you want to "
@@ -594,7 +590,8 @@ void StudioPaletteTreeViewer::convertToStudioPalette() {
// apply global name
time_t ltime;
time(&ltime);
- wstring gname = std::to_wstring(ltime) + L"_" + std::to_wstring(rand());
+ std::wstring gname =
+ std::to_wstring(ltime) + L"_" + std::to_wstring(rand());
m_currentPalette->setGlobalName(gname);
studioPalette->setStylesGlobalNames(m_currentPalette.getPointer());
studioPalette->save(path, m_currentPalette.getPointer());
@@ -673,22 +670,22 @@ void StudioPaletteTreeViewer::setAsDefault() {
TFilePath srcPath = getCurrentItemPath();
if (srcPath.isEmpty()) return;
StudioPalette *studioPalette = StudioPalette::instance();
-
+
std::string fileName;
TFilePath folderPath;
TFilePath dstPath;
- QString label =
- QObject::tr("Set As...");
+ QString label = QObject::tr("Set As...");
QStringList radioButtons;
radioButtons.append(QString("Default Toonz Raster Palette"));
radioButtons.append(QString("Default Toonz Vector Palette"));
radioButtons.append(QString("Default Raster Drawing Palette"));
radioButtons.append(QString("Default Cleanup Palette"));
-
- int type = DVGui::RadioButtonMsgBox(DVGui::QUESTION,label, radioButtons, this);
- switch (type) {
+ int type =
+ DVGui::RadioButtonMsgBox(DVGui::QUESTION, label, radioButtons, this);
+
+ switch (type) {
case 1:
fileName = "Toonz_Raster_Palette.tpl";
break;
@@ -699,17 +696,17 @@ void StudioPaletteTreeViewer::setAsDefault() {
fileName = "Raster_Drawing_Palette.tpl";
break;
case 4:
- fileName = "Cleanup_Palette.tpl";
+ fileName = "Cleanup_Palette.tpl";
folderPath = studioPalette->getLevelPalettesRoot() + "Default Palettes";
TSystem::copyFile(folderPath + fileName, srcPath, true);
return;
- default :
+ default:
return;
}
TPalette *srcPalette = studioPalette->getPalette(srcPath);
if (!srcPalette) return;
-
+
// Remove all Link
for (int i = 0; i < srcPalette->getPageCount(); ++i) {
TPalette::Page *page = srcPalette->getPage(i);
@@ -721,12 +718,11 @@ void StudioPaletteTreeViewer::setAsDefault() {
// Save Palette
folderPath = studioPalette->getProjectPalettesRoot();
- dstPath = folderPath + fileName;
+ dstPath = folderPath + fileName;
if (TSystem::doesExistFileOrLevel(dstPath))
TSystem::removeFileOrLevel(dstPath);
TOStream os(dstPath);
- if(srcPalette)
- os << srcPalette;
+ if (srcPalette) os << srcPalette;
int policy = DVGui::MsgBox(QString("Apply to Global?"), QString("Yes"),
QString("No"), 0, this);
@@ -769,7 +765,7 @@ public:
//-----------------------------------------------------------------------------
AdjustPaletteDialog::AdjustPaletteDialog()
- : Dialog(0, true, true, "Adjust Current Level to This Palette") {
+ : Dialog(nullptr, true, true, "Adjust Current Level to This Palette") {
setWindowTitle(tr("Adjust Current Level to This Palette"));
beginVLayout();
@@ -782,9 +778,9 @@ AdjustPaletteDialog::AdjustPaletteDialog()
QPushButton *okBtn = new QPushButton(tr("Apply"), this);
okBtn->setDefault(true);
QPushButton *cancelBtn = new QPushButton(tr("Cancel"), this);
- bool ret = connect(okBtn, SIGNAL(clicked()), this, SLOT(accept()));
- ret = ret && connect(cancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
- assert(ret);
+ bool ret1 = connect(okBtn, &QPushButton::clicked, this, &QDialog::accept);
+ bool ret2 = connect(cancelBtn, &QPushButton::clicked, this, &QDialog::reject);
+ assert(ret1 && ret2);
addButtonBarWidget(okBtn, cancelBtn);
}
@@ -828,8 +824,8 @@ that the last operation is the icon refresh...
m_currentLevelHandle->getSimpleLevel()->setDirtyFlag(true);
- //TApp::instance()->getCurrentLevel()->notifyLevelChange();
- //No need to notice user
+ // TApp::instance()->getCurrentLevel()->notifyLevelChange();
+ // No need to notice user
TUndoManager::manager()->add(new InvalidateIconsUndo(m_currentLevelHandle));
@@ -955,7 +951,7 @@ void StudioPaletteTreeViewer::contextMenuEvent(QContextMenuEvent *event) {
StudioPalette *studioPalette = StudioPalette::instance();
- // Menu' per la selezione singola
+ // Menu for single selection
QList<QTreeWidgetItem *> items = selectedItems();
int count = items.size();
if (count == 1) {
@@ -968,56 +964,81 @@ void StudioPaletteTreeViewer::contextMenuEvent(QContextMenuEvent *event) {
QMenu menu(this);
if (isFolder) {
- createMenuAction(menu, "", tr("New Palette"), "addNewPalette()");
- createMenuAction(menu, "", tr("New Folder"), "addNewFolder()");
+ QAction *newPaletteAct = menu.addAction(tr("New Palette"));
+ connect(newPaletteAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::addNewPalette);
+
+ QAction *newFolderAct = menu.addAction(tr("New Folder"));
+ connect(newFolderAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::addNewFolder);
}
if (studioPalette->isFolder(path) &&
studioPalette->getLevelPalettesRoot() != path &&
studioPalette->getProjectPalettesRoot() != path) {
menu.addSeparator();
- createMenuAction(menu, "", tr("Delete Folder"), "deleteItems()");
+ QAction *deleteFolderAct = menu.addAction(tr("Delete Folder"));
+ connect(deleteFolderAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::deleteItems);
} else if (studioPalette->isPalette(path)) {
if (m_studioPaletteHandle->getPalette()) {
- createMenuAction(menu, "", tr("Set As..."), "setAsDefault()");
+ QAction *setAsDefaultAct = menu.addAction(tr("Set As..."));
+ connect(setAsDefaultAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::setAsDefault);
+
menu.addSeparator();
- createMenuAction(menu, "MI_LoadIntoCurrentPalette",
- tr("Load into Current Palette"),
- "loadInCurrentPalette()");
- createMenuAction(menu, "MI_AdjustCurrentLevelToPalette",
- tr("Adjust Current Level to This Palette"),
- "loadInCurrentPaletteAndAdaptLevel()");
- createMenuAction(menu, "MI_MergeToCurrentPalette",
- tr("Merge to Current Palette"),
- "mergeToCurrentPalette()");
+
+ QAction *loadIntoCurrentAct =
+ menu.addAction(tr("Load into Current Palette"));
+ connect(loadIntoCurrentAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::loadInCurrentPalette);
+
+ QAction *adjustLevelAct =
+ menu.addAction(tr("Adjust Current Level to This Palette"));
+ connect(adjustLevelAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::loadInCurrentPaletteAndAdaptLevel);
+
+ QAction *mergeToCurrentAct =
+ menu.addAction(tr("Merge to Current Palette"));
+ connect(mergeToCurrentAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::mergeToCurrentPalette);
+
if (!m_studioPaletteHandle->getPalette()->isLocked()) {
- createMenuAction(menu, "MI_ReplaceWithCurrentPalette",
- tr("Replace with Current Palette"),
- "replaceCurrentPalette()");
+ QAction *replaceWithCurrentAct =
+ menu.addAction(tr("Replace with Current Palette"));
+ connect(replaceWithCurrentAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::replaceCurrentPalette);
+
menu.addSeparator();
- createMenuAction(menu, "MI_DeletePalette", tr("Delete Palette"),
- "deleteItems()");
+ QAction *deletePaletteAct = menu.addAction(tr("Delete Palette"));
+ connect(deletePaletteAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::deleteItems);
}
}
if (!studioPalette->hasGlobalName(path)) {
menu.addSeparator();
- createMenuAction(menu, "",
- tr("Convert to Studio Palette and Overwrite"),
- "convertToStudioPalette()");
+ QAction *convertAct =
+ menu.addAction(tr("Convert to Studio Palette and Overwrite"));
+ connect(convertAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::convertToStudioPalette);
}
}
if (isFolder) {
menu.addSeparator();
- createMenuAction(menu, "", tr("Search for Palettes"),
- "searchForPalette()");
- createMenuAction(menu, "", tr("Refresh"), "onRefreshClicked()");
+ QAction *searchAct = menu.addAction(tr("Search for Palettes"));
+ connect(searchAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::searchForPalette);
+
+ QAction *refreshAct = menu.addAction(tr("Refresh"));
+ connect(refreshAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::refresh);
}
menu.exec(event->globalPos());
return;
}
- // Menu' per la selezione multipla
+ // Menu for multiple selection
// Verify if click position is in a row containing an item.
bool areAllPalette = true;
bool isClickInSelection = false;
@@ -1034,27 +1055,26 @@ void StudioPaletteTreeViewer::contextMenuEvent(QContextMenuEvent *event) {
QMenu menu(this);
if (areAllPalette) {
- createMenuAction(menu, "", tr("Load into Current Palette"),
- "loadInCurrentPalette()");
- createMenuAction(menu, "", tr("Merge to Current Palette"),
- "mergeToCurrentPalette()");
- createMenuAction(menu, "", tr("Replace with Current Palette"),
- "replaceCurrentPalette()");
+ QAction *loadAct = menu.addAction(tr("Load into Current Palette"));
+ connect(loadAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::loadInCurrentPalette);
+
+ QAction *mergeAct = menu.addAction(tr("Merge to Current Palette"));
+ connect(mergeAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::mergeToCurrentPalette);
+
+ QAction *replaceAct = menu.addAction(tr("Replace with Current Palette"));
+ connect(replaceAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::replaceCurrentPalette);
+
menu.addSeparator();
}
- createMenuAction(menu, "", tr("Delete"), "deleteItems()");
- menu.exec(event->globalPos());
-}
-
-//-----------------------------------------------------------------------------
+ QAction *deleteAct = menu.addAction(tr("Delete"));
+ connect(deleteAct, &QAction::triggered, this,
+ &StudioPaletteTreeViewer::deleteItems);
-void StudioPaletteTreeViewer::createMenuAction(QMenu &menu, const char *id,
- QString name, const char *slot) {
- QAction *act = menu.addAction(name);
- string slotName(slot);
- slotName = string("1") + slotName;
- connect(act, SIGNAL(triggered()), slotName.c_str());
+ menu.exec(event->globalPos());
}
//-----------------------------------------------------------------------------
@@ -1088,26 +1108,24 @@ void StudioPaletteTreeViewer::startDragDrop() {
TRepetitionGuard guard;
if (!guard.hasLock()) return;
- QDrag *drag = new QDrag(this);
- QMimeData *mimeData = new QMimeData;
QList<QUrl> urls;
-
- QList<QTreeWidgetItem *> items = selectedItems();
- int i;
-
- for (i = 0; i < items.size(); i++) {
- // Sposto solo le palette.
- TFilePath path = getItemPath(items[i]);
+ for (QTreeWidgetItem *item : selectedItems()) {
+ TFilePath path = getItemPath(item);
if (!path.isEmpty() &&
(path.getType() == "tpl" || path.getType() == "pli" ||
- path.getType() == "tlv" || path.getType() == "tnz"))
- urls.append(pathToUrl(path));
+ path.getType() == "tlv" || path.getType() == "tnz")) {
+ urls << pathToUrl(path);
+ }
}
+
if (urls.isEmpty()) return;
+
+ QMimeData *mimeData = new QMimeData;
mimeData->setUrls(urls);
+
+ QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
- Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
- viewport()->update();
+ drag->exec(Qt::CopyAction | Qt::MoveAction);
}
//-----------------------------------------------------------------------------
@@ -1121,7 +1139,7 @@ void StudioPaletteTreeViewer::dragEnterEvent(QDragEnterEvent *event) {
int count = urls.size();
if (count == 0) return;
- // Controllo che almeno un url del drag sia una palette da spostare.
+ // Check that at least one url in the drag is a palette to move.
bool isPalette = false;
int i;
for (i = 0; i < count; i++) {
@@ -1155,7 +1173,7 @@ void StudioPaletteTreeViewer::dragMoveEvent(QDragMoveEvent *event) {
TFilePath path =
TFilePath(mimeData->urls()[0].toLocalFile().toStdWString());
if (path == getItemPath(item)) {
- m_dropItem = 0;
+ m_dropItem = nullptr;
event->ignore();
viewport()->update();
return;
@@ -1169,7 +1187,7 @@ void StudioPaletteTreeViewer::dragMoveEvent(QDragMoveEvent *event) {
m_dropItem = item;
event->acceptProposedAction();
} else {
- m_dropItem = 0;
+ m_dropItem = nullptr;
event->ignore();
}
viewport()->update();
@@ -1285,7 +1303,7 @@ StudioPaletteViewer::StudioPaletteViewer(QWidget *parent,
// First Splitter Widget
QWidget *treeWidget = new QWidget(this);
QVBoxLayout *treeVLayout = new QVBoxLayout(treeWidget);
- treeVLayout->setMargin(0);
+ treeVLayout->setContentsMargins(0, 0, 0, 0);
treeVLayout->setSpacing(0);
m_studioPaletteTreeViewer = new StudioPaletteTreeViewer(