Skip to content

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

C

refactor: Qt signal/slot modernization

Anderson Prado348ccdbc994d
diff --git a/toonz/sources/toonz/sceneviewercontextmenu.cpp b/toonz/sources/toonz/sceneviewercontextmenu.cpp
index c724093dd..204040a13 100644
--- a/toonz/sources/toonz/sceneviewercontextmenu.cpp
+++ b/toonz/sources/toonz/sceneviewercontextmenu.cpp
@@ -36,22 +36,18 @@
// Qt includes
#include <QMenu>
-#include <QContextMenuEvent>
-#include <QSignalMapper>
SceneViewerContextMenu::SceneViewerContextMenu(SceneViewer *parent)
: QMenu(parent), m_viewer(parent), m_groupIndexToBeEntered(-1) {
TApp *app = TApp::instance();
bool isEditingLevel = app->getCurrentFrame()->isEditingLevel();
- bool ret = true;
- QAction *action = 0;
CommandManager *commandManager = CommandManager::instance();
- /*- サブカメラの消去 -*/
+ /*- Delete subcamera -*/
if (parent->isEditPreviewSubcamera()) {
- action = addAction(tr("Reset Subcamera"));
- ret = ret && parent->connect(action, SIGNAL(triggered()),
- SLOT(doDeleteSubCamera()));
+ QAction *action = addAction(tr("Reset Subcamera"));
+ connect(action, &QAction::triggered, parent,
+ &SceneViewer::doDeleteSubCamera);
addSeparator();
}
@@ -65,84 +61,77 @@ SceneViewerContextMenu::SceneViewerContextMenu(SceneViewer *parent)
m_viewer->parentWidget())) {
bool isFullScreen = (fsWidget->windowState() & Qt::WindowFullScreen) != 0;
- action =
+ QAction *action =
commandManager->createAction(V_ShowHideFullScreen, this, !isFullScreen);
addAction(action);
- ret = ret && parent->connect(action, SIGNAL(triggered()), fsWidget,
- SLOT(toggleFullScreen()));
+ connect(action, &QAction::triggered, fsWidget,
+ &ImageUtils::FullScreenWidget::toggleFullScreen);
}
// swap compared
if (parent->canSwapCompared()) {
- action = addAction(tr("Swap Compared Images"));
- ret = ret &&
- parent->connect(action, SIGNAL(triggered()), SLOT(swapCompared()));
+ QAction *action = addAction(tr("Swap Compared Images"));
+ connect(action, &QAction::triggered, parent, &SceneViewer::swapCompared);
}
if (!isEditingLevel) {
// fit camera
- action = commandManager->createAction(V_ZoomFit, this);
+ QAction *action = commandManager->createAction(V_ZoomFit, this);
addAction(action);
- ret = ret &&
- parent->connect(action, SIGNAL(triggered()), SLOT(fitToCamera()));
+ connect(action, &QAction::triggered, parent, &SceneViewer::fitToCamera);
}
QMenu *flipViewMenu = addMenu(tr("Flip View"));
// flip horizontally
- action = commandManager->createAction(V_FlipX, this);
+ QAction *action = commandManager->createAction(V_FlipX, this);
flipViewMenu->addAction(action);
- ret = ret && parent->connect(action, SIGNAL(triggered()), SLOT(flipX()));
+ connect(action, &QAction::triggered, parent, &SceneViewer::flipX);
// flip vertically
action = commandManager->createAction(V_FlipY, this);
flipViewMenu->addAction(action);
- ret = ret && parent->connect(action, SIGNAL(triggered()), SLOT(flipY()));
+ connect(action, &QAction::triggered, parent, &SceneViewer::flipY);
QMenu *rotateViewMenu = addMenu(tr("Rotate View"));
// Rotate Left
action = commandManager->createAction(V_RotateLeft, this);
rotateViewMenu->addAction(action);
- ret = ret && connect(action, &QAction::triggered, parent,
- &SceneViewer::rotateLeft);
+ connect(action, &QAction::triggered, parent, &SceneViewer::rotateLeft);
// Rotate Right
action = commandManager->createAction(V_RotateRight, this);
rotateViewMenu->addAction(action);
- ret = ret && connect(action, &QAction::triggered, parent,
- &SceneViewer::rotateRight);
+ connect(action, &QAction::triggered, parent, &SceneViewer::rotateRight);
QMenu *resetViewMenu = addMenu(tr("Reset View"));
// reset
action = commandManager->createAction(V_ViewReset, this);
resetViewMenu->addAction(action);
- ret = ret &&
- parent->connect(action, SIGNAL(triggered()), SLOT(resetSceneViewer()));
+ connect(action, &QAction::triggered, parent, &SceneViewer::resetSceneViewer);
// reset zoom
action = commandManager->createAction(V_ZoomReset, this);
resetViewMenu->addAction(action);
- ret = ret && parent->connect(action, SIGNAL(triggered()), SLOT(resetZoom()));
+ connect(action, &QAction::triggered, parent, &SceneViewer::resetZoom);
// reset rotation
action = commandManager->createAction(V_RotateReset, this);
resetViewMenu->addAction(action);
- ret = ret &&
- parent->connect(action, SIGNAL(triggered()), SLOT(resetRotation()));
+ connect(action, &QAction::triggered, parent, &SceneViewer::resetRotation);
// reset position
action = commandManager->createAction(V_PositionReset, this);
resetViewMenu->addAction(action);
- ret = ret &&
- parent->connect(action, SIGNAL(triggered()), SLOT(resetPosition()));
+ connect(action, &QAction::triggered, parent, &SceneViewer::resetPosition);
// actual pixel size
action = commandManager->createAction(V_ActualPixelSize, this);
addAction(action);
- ret = ret && parent->connect(action, SIGNAL(triggered()),
- SLOT(setActualPixelSize()));
+ connect(action, &QAction::triggered, parent,
+ &SceneViewer::setActualPixelSize);
// onion skin
if (Preferences::instance()->isOnionSkinEnabled() &&
@@ -171,9 +160,21 @@ SceneViewerContextMenu::SceneViewerContextMenu(SceneViewer *parent)
guidedDrawingMenu, guidedDrawingGroup);
addOptionAction(tr("All Drawings"), 3, guidedDrawingStatus,
guidedDrawingMenu, guidedDrawingGroup);
- ret =
- ret && parent->connect(guidedDrawingGroup, SIGNAL(triggered(QAction *)),
- this, SLOT(setGuidedDrawingType(QAction *)));
+
+ connect(guidedDrawingGroup, &QActionGroup::triggered, this,
+ [this](QAction *action) {
+ Preferences::instance()->setValue(guidedDrawingType,
+ action->data().toInt());
+
+ QAction *guidedDrawingAction =
+ CommandManager::instance()->getAction(MI_VectorGuidedDrawing);
+ if (guidedDrawingAction)
+ guidedDrawingAction->setChecked(
+ Preferences::instance()->isGuidedDrawingEnabled());
+
+ TApp::instance()->getCurrentScene()->notifyPreferenceChanged(
+ "GuidedDrawingFrame");
+ });
guidedDrawingMenu->addSeparator();
bool enableOption = guidedDrawingStatus == 1 || guidedDrawingStatus == 2;
@@ -181,8 +182,15 @@ SceneViewerContextMenu::SceneViewerContextMenu(SceneViewer *parent)
action->setCheckable(true);
action->setChecked(Preferences::instance()->getGuidedAutoInbetween());
action->setEnabled(enableOption);
- ret = ret && parent->connect(action, SIGNAL(triggered()), this,
- SLOT(setGuidedAutoInbetween()));
+
+ connect(action, &QAction::triggered, this, [this]() {
+ Preferences::instance()->setValue(
+ guidedAutoInbetween,
+ !Preferences::instance()->getGuidedAutoInbetween());
+ TApp::instance()->getCurrentScene()->notifyPreferenceChanged(
+ "GuidedDrawingAutoInbetween");
+ });
+
guidedDrawingMenu->addSeparator();
int guidedInterpolation = Preferences::instance()->getGuidedInterpolation();
QActionGroup *interpolationGroup = new QActionGroup(this);
@@ -194,13 +202,21 @@ SceneViewerContextMenu::SceneViewerContextMenu(SceneViewer *parent)
guidedDrawingMenu, interpolationGroup);
addOptionAction(tr("Ease In/Out Interpolation"), 4, guidedInterpolation,
guidedDrawingMenu, interpolationGroup);
- ret = ret &&
- parent->connect(interpolationGroup, SIGNAL(triggered(QAction *)),
- this, SLOT(setGuidedInterpolationState(QAction *)));
+
+ connect(interpolationGroup, &QActionGroup::triggered, this,
+ [this](QAction *action) {
+ Preferences::instance()->setValue(guidedInterpolationType,
+ action->data().toInt());
+ TApp::instance()->getCurrentScene()->notifyPreferenceChanged(
+ "GuidedDrawingInterpolation");
+ });
+
interpolationGroup->setEnabled(enableOption);
/*
- guidedDrawingMenu->addSeparator();
- action =
+ // Kept for reference and possible future re-enabling or removal in a future
+ revision.
+
+ guidedDrawingMenu->addSeparator(); action =
CommandManager::instance()->getAction(MI_SelectPrevGuideStroke);
action->setEnabled(enableOption);
guidedDrawingMenu->addAction(action);
@@ -246,31 +262,31 @@ SceneViewerContextMenu::SceneViewerContextMenu(SceneViewer *parent)
action = addAction(tr("Save Previewed Frames"));
action->setShortcut(QKeySequence(
CommandManager::instance()->getKeyFromId(MI_SavePreviewedFrames)));
- ret = ret && parent->connect(action, SIGNAL(triggered()), this,
- SLOT(savePreviewedFrames()));
+ connect(action, &QAction::triggered, this, [this]() {
+ Previewer::instance(m_viewer->getPreviewMode() ==
+ SceneViewer::SUBCAMERA_PREVIEW)
+ ->saveRenderedFrames();
+ });
// regenerate preview
action = addAction(tr("Regenerate Preview"));
action->setShortcut(QKeySequence(
CommandManager::instance()->getKeyFromId(MI_RegeneratePreview)));
- ret = ret && parent->connect(action, SIGNAL(triggered()),
- SLOT(regeneratePreview()));
+ connect(action, &QAction::triggered, parent,
+ &SceneViewer::regeneratePreview);
// regenerate frame preview
action = addAction(tr("Regenerate Frame Preview"));
action->setShortcut(QKeySequence(
CommandManager::instance()->getKeyFromId(MI_RegenerateFramePr)));
- ret = ret && parent->connect(action, SIGNAL(triggered()),
- SLOT(regeneratePreviewFrame()));
+ connect(action, &QAction::triggered, parent,
+ &SceneViewer::regeneratePreviewFrame);
}
-
- assert(ret);
}
SceneViewerContextMenu::~SceneViewerContextMenu() {}
void SceneViewerContextMenu::addEnterGroupCommands(const TPointD &pos) {
- bool ret = true;
TVectorImageP vi = (TVectorImageP)TTool::getImage(false);
if (!vi) return;
@@ -282,14 +298,13 @@ void SceneViewerContextMenu::addEnterGroupCommands(const TPointD &pos) {
dynamic_cast<StrokeSelection *>(TSelection::getCurrent());
if (!ss) return;
- for (int i = 0; i < vi->getStrokeCount(); i++)
+ for (int i = 0; i < vi->getStrokeCount(); i++) {
if (ss->isSelected(i) && vi->canEnterGroup(i)) {
m_groupIndexToBeEntered = i;
addAction(CommandManager::instance()->getAction(MI_EnterGroup));
return;
}
-
- assert(ret);
+ }
}
static QString getName(TStageObject *obj) {
@@ -305,8 +320,17 @@ void SceneViewerContextMenu::addShowHideCommand(QMenu *menu,
QString text = isHidden ? tr("Show %1").arg(getName(stageObject))
: tr("Hide %1").arg(getName(stageObject));
QAction *action = new QAction(text, this);
- action->setData(column->getIndex());
- connect(action, SIGNAL(triggered()), this, SLOT(onShowHide()));
+ int columnIndex = column->getIndex();
+
+ connect(action, &QAction::triggered, this, [this, columnIndex]() {
+ TXsheetHandle *xsheetHandle = TApp::instance()->getCurrentXsheet();
+ TXshColumn *column = xsheetHandle->getXsheet()->getColumn(columnIndex);
+ if (column) {
+ column->setCamstandVisible(!column->isCamstandVisible());
+ xsheetHandle->notifyXsheetChanged();
+ }
+ });
+
menu->addAction(action);
}
@@ -318,18 +342,26 @@ void SceneViewerContextMenu::addSelectCommand(QMenu *menu,
QString text = (id.isTable()) ? tr("Table") : getName(stageObject);
if (menu == this) text = tr("Select %1").arg(text);
QAction *action = new QAction(text, this);
- action->setData(id.getCode());
- connect(action, SIGNAL(triggered()), this, SLOT(onSetCurrent()));
+
+ connect(action, &QAction::triggered, this, [this, id]() {
+ TApp *app = TApp::instance();
+ if (id.isColumn()) {
+ app->getCurrentColumn()->setColumnIndex(id.getIndex());
+ app->getCurrentObject()->setObjectId(id);
+ } else {
+ app->getCurrentObject()->setObjectId(id);
+ app->getCurrentTool()->setTool(T_Edit);
+ }
+ });
+
menu->addAction(action);
}
void SceneViewerContextMenu::addLevelCommands(std::vector<int> &indices) {
addSeparator();
TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();
- TStageObjectId currentId =
- TApp::instance()->getCurrentObject()->getObjectId();
- /*- Xsheet内の、空でないColumnを登録 -*/
+ // Register non-empty columns in the xsheet
std::vector<TXshColumn *> columns;
for (int i = 0; i < (int)indices.size(); i++) {
if (xsh->isColumnEmpty(indices[i])) continue;
@@ -345,8 +377,9 @@ void SceneViewerContextMenu::addLevelCommands(std::vector<int> &indices) {
QMenu *subMenu = addMenu(tr("Show / Hide"));
for (int i = 0; i < (int)columns.size(); i++)
addShowHideCommand(subMenu, columns[i]);
- } else
+ } else {
addShowHideCommand(this, columns[0]);
+ }
addSeparator();
}
@@ -360,13 +393,13 @@ void SceneViewerContextMenu::addLevelCommands(std::vector<int> &indices) {
else
*/
- /*-- Scene内の全Objectを選択可能にする --*/
+ /*-- Make all objects in the scene selectable --*/
TStageObjectId id;
QMenu *cameraMenu = addMenu(tr("Select Camera"));
QMenu *pegbarMenu = addMenu(tr("Select Pegbar"));
QMenu *columnMenu = addMenu(tr("Select Column"));
- bool flag = false;
+ bool hasColumns = false;
for (int i = 0; i < xsh->getStageObjectTree()->getStageObjectCount(); i++) {
id = xsh->getStageObjectTree()->getStageObject(i)->getId();
@@ -376,18 +409,19 @@ void SceneViewerContextMenu::addLevelCommands(std::vector<int> &indices) {
continue;
else {
addSelectCommand(columnMenu, id);
- flag = true;
+ hasColumns = true;
}
- } else if (id.isTable())
+ } else if (id.isTable()) {
addSelectCommand(this, id);
- else if (id.isCamera())
+ } else if (id.isCamera()) {
addSelectCommand(cameraMenu, id);
- else if (id.isPegbar())
+ } else if (id.isPegbar()) {
addSelectCommand(pegbarMenu, id);
+ }
}
- /*- カラムがひとつも無かったらDisable -*/
- if (!flag) columnMenu->setEnabled(false);
+ // Disable if no columns
+ if (!hasColumns) columnMenu->setEnabled(false);
}
//-----------------------------------------------------------------------------
@@ -395,8 +429,7 @@ void SceneViewerContextMenu::addLevelCommands(std::vector<int> &indices) {
void SceneViewerContextMenu::enterVectorImageGroup() {
if (m_groupIndexToBeEntered == -1) return;
- TVectorImageP vi =
- (TVectorImageP)TTool::getImage(false); // getCurrentImage();
+ TVectorImageP vi = (TVectorImageP)TTool::getImage(false);
if (!vi) return;
vi->enterGroup(m_groupIndexToBeEntered);
TSelection *selection = TSelection::getCurrent();
@@ -407,78 +440,13 @@ void SceneViewerContextMenu::enterVectorImageGroup() {
//-----------------------------------------------------------------------------
void SceneViewerContextMenu::exitVectorImageGroup() {
- TVectorImageP vi =
- (TVectorImageP)TTool::getImage(false); // getCurrentImage();
+ TVectorImageP vi = (TVectorImageP)TTool::getImage(false);
if (!vi) return;
vi->exitGroup();
m_viewer->update();
}
-//-----------------------------------------------------------------------------
-
-void SceneViewerContextMenu::onShowHide() {
- int columnIndex = qobject_cast<QAction *>(sender())->data().toInt();
- TXsheetHandle *xsheetHandle = TApp::instance()->getCurrentXsheet();
- TXshColumn *column = xsheetHandle->getXsheet()->getColumn(columnIndex);
- if (column) {
- column->setCamstandVisible(!column->isCamstandVisible());
- xsheetHandle->notifyXsheetChanged();
- }
-}
-//-----------------------------------------------------------------------------
-
-void SceneViewerContextMenu::onSetCurrent() {
- TStageObjectId id;
- id.setCode(qobject_cast<QAction *>(sender())->data().toUInt());
- TApp *app = TApp::instance();
- if (id.isColumn()) {
- app->getCurrentColumn()->setColumnIndex(id.getIndex());
- app->getCurrentObject()->setObjectId(id);
- } else {
- app->getCurrentObject()->setObjectId(id);
- app->getCurrentTool()->setTool(T_Edit);
- }
-}
-
-//-----------------------------------------------------------------------------
-void SceneViewerContextMenu::setGuidedDrawingType(QAction *action) {
- Preferences::instance()->setValue(guidedDrawingType, action->data().toInt());
-
- QAction *guidedDrawingAction =
- CommandManager::instance()->getAction(MI_VectorGuidedDrawing);
- if (guidedDrawingAction)
- guidedDrawingAction->setChecked(
- Preferences::instance()->isGuidedDrawingEnabled());
-
- TApp::instance()->getCurrentScene()->notifyPreferenceChanged(
- "GuidedDrawingFrame");
-}
-
-//-----------------------------------------------------------------------------
-void SceneViewerContextMenu::setGuidedAutoInbetween() {
- Preferences::instance()->setValue(
- guidedAutoInbetween, !Preferences::instance()->getGuidedAutoInbetween());
- TApp::instance()->getCurrentScene()->notifyPreferenceChanged(
- "GuidedDrawingAutoInbetween");
-}
-
-//-----------------------------------------------------------------------------
-void SceneViewerContextMenu::setGuidedInterpolationState(QAction *action) {
- Preferences::instance()->setValue(guidedInterpolationType,
- action->data().toInt());
- TApp::instance()->getCurrentScene()->notifyPreferenceChanged(
- "GuidedDrawingInterpolation");
-}
-
-//-----------------------------------------------------------------------------
-
-void SceneViewerContextMenu::savePreviewedFrames() {
- Previewer::instance(m_viewer->getPreviewMode() ==
- SceneViewer::SUBCAMERA_PREVIEW)
- ->saveRenderedFrames();
-}
-
-//-----------------------------------------------------------------------------
+// Helper classes
class ZeroThickToggle : public MenuItemHandler {
public:
ZeroThickToggle() : MenuItemHandler(MI_ZeroThick) {}
@@ -500,13 +468,13 @@ void ZeroThickToggleGui::addZeroThickCommand(QMenu *menu) {
if (Preferences::instance()->getShow0ThickLines()) {
QAction *hideZeroThick =
menu->addAction(QString(QObject::tr("Hide Zero Thickness Lines")));
- menu->connect(hideZeroThick, SIGNAL(triggered()), &switcher,
- SLOT(deactivate()));
+ QObject::connect(hideZeroThick, &QAction::triggered, &switcher,
+ &ZeroThickToggleHandler::deactivate);
} else {
QAction *showZeroThick =
menu->addAction(QString(QObject::tr("Show Zero Thickness Lines")));
- menu->connect(showZeroThick, SIGNAL(triggered()), &switcher,
- SLOT(activate()));
+ QObject::connect(showZeroThick, &QAction::triggered, &switcher,
+ &ZeroThickToggleHandler::activate);
}
}
@@ -538,13 +506,13 @@ void CursorOutlineToggleGui::addCursorOutlineCommand(QMenu *menu) {
if (Preferences::instance()->isCursorOutlineEnabled()) {
QAction *hideCursorOutline =
menu->addAction(QString(QObject::tr("Hide cursor size outline")));
- menu->connect(hideCursorOutline, SIGNAL(triggered()), &switcher,
- SLOT(deactivate()));
+ QObject::connect(hideCursorOutline, &QAction::triggered, &switcher,
+ &CursorOutlineToggleHandler::deactivate);
} else {
QAction *showCursorOutline =
menu->addAction(QString(QObject::tr("Show cursor size outline")));
- menu->connect(showCursorOutline, SIGNAL(triggered()), &switcher,
- SLOT(activate()));
+ QObject::connect(showCursorOutline, &QAction::triggered, &switcher,
+ &CursorOutlineToggleHandler::activate);
}
}
@@ -576,13 +544,13 @@ void ViewerIndicatorToggleGui::addViewerIndicatorCommand(QMenu *menu) {
if (Preferences::instance()->isViewerIndicatorEnabled()) {
QAction *hideViewerIndicator =
menu->addAction(QString(QObject::tr("Hide Viewer Indicators")));
- menu->connect(hideViewerIndicator, SIGNAL(triggered()), &switcher,
- SLOT(deactivate()));
+ QObject::connect(hideViewerIndicator, &QAction::triggered, &switcher,
+ &ViewerIndicatorToggleHandler::deactivate);
} else {
QAction *showViewerIndicator =
menu->addAction(QString(QObject::tr("Show Viewer Indicators")));
- menu->connect(showViewerIndicator, SIGNAL(triggered()), &switcher,
- SLOT(activate()));
+ QObject::connect(showViewerIndicator, &QAction::triggered, &switcher,
+ &ViewerIndicatorToggleHandler::activate);
}
}
diff --git a/toonz/sources/toonz/sceneviewercontextmenu.h b/toonz/sources/toonz/sceneviewercontextmenu.h
index a51fd0c31..103a81f3d 100644
--- a/toonz/sources/toonz/sceneviewercontextmenu.h
+++ b/toonz/sources/toonz/sceneviewercontextmenu.h
@@ -15,6 +15,7 @@ class SceneViewerContextMenu final : public QMenu {
SceneViewer *m_viewer;
int m_groupIndexToBeEntered;
+ // Helper methods for adding menu commands
void addShowHideCommand(QMenu *menu, TXshColumn *column);
void addSelectCommand(QMenu *menu, const TStageObjectId &id);
@@ -22,23 +23,19 @@ public:
SceneViewerContextMenu(SceneViewer *parent);
~SceneViewerContextMenu();
+ // Add commands for entering/exiting vector image groups
void addEnterGroupCommands(const TPointD &pos);
+
+ // Add commands for level operations (show/hide, select)
void addLevelCommands(std::vector<int> &indices);
public slots:
-
- void savePreviewedFrames();
-
+ // Vector image group operations (used by CommandManager actions)
void enterVectorImageGroup();
void exitVectorImageGroup();
- void setGuidedDrawingType(QAction *);
- void setGuidedAutoInbetween();
- void setGuidedInterpolationState(QAction *);
-
- void onShowHide();
- void onSetCurrent();
};
+// Helper GUI class for toggling zero thickness lines visibility
namespace ZeroThickToggleGui {
void addZeroThickCommand(QMenu *menu);
@@ -49,9 +46,9 @@ public slots:
void activate();
void deactivate();
};
+} // namespace ZeroThickToggleGui
-} // Namespace ZeroThickToggleGui
-
+// Helper GUI class for toggling cursor outline visibility
namespace CursorOutlineToggleGui {
void addCursorOutlineCommand(QMenu *menu);
@@ -62,9 +59,9 @@ public slots:
void activate();
void deactivate();
};
+} // namespace CursorOutlineToggleGui
-} // Namespace CursorOutlineToggleGui
-
+// Helper GUI class for toggling viewer indicators visibility
namespace ViewerIndicatorToggleGui {
void addViewerIndicatorCommand(QMenu *menu);
@@ -75,7 +72,6 @@ public slots:
void activate();
void deactivate();
};
-
-} // Namespace ViewerIndicatorToggleGui
+} // namespace ViewerIndicatorToggleGui
#endif
diff --git a/toonz/sources/toonz/tooloptionsshortcutinvoker.cpp b/toonz/sources/toonz/tooloptionsshortcutinvoker.cpp
index abd09a86a..083128a2e 100644
--- a/toonz/sources/toonz/tooloptionsshortcutinvoker.cpp
+++ b/toonz/sources/toonz/tooloptionsshortcutinvoker.cpp
@@ -1,3 +1,5 @@
+
+
#include "tooloptionsshortcutinvoker.h"
#include "tapp.h"
@@ -9,8 +11,6 @@
#include "toonzqt/menubarcommand.h"
#include "menubarcommandids.h"
-#include <QSignalMapper>
-
using namespace ToolOptionsShortcutWorker;
//-----------------------------------------------------------------
@@ -30,21 +30,25 @@ void ToolOptionShortcutConnector::visit(TDoubleProperty* p) {
QAction* a;
if (p->getName() == "Size:") {
a = cm->getAction("A_IncreaseMaxBrushThickness");
- QObject::connect(a, SIGNAL(triggered()), worker, SLOT(increase()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->increase(); });
a = cm->getAction("A_DecreaseMaxBrushThickness");
- QObject::connect(a, SIGNAL(triggered()), worker, SLOT(decrease()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->decrease(); });
} else if (p->getName() == "ModifierSize") {
a = cm->getAction("A_IncreaseMaxBrushThickness");
- QObject::connect(a, SIGNAL(triggered()), worker,
- SLOT(increaseFractional()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->increaseFractional(); });
a = cm->getAction("A_DecreaseMaxBrushThickness");
- QObject::connect(a, SIGNAL(triggered()), worker,
- SLOT(decreaseFractional()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->decreaseFractional(); });
} else if (p->getName() == "Hardness:") {
a = cm->getAction("A_IncreaseBrushHardness");
- QObject::connect(a, SIGNAL(triggered()), worker, SLOT(increase()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->increase(); });
a = cm->getAction("A_DecreaseBrushHardness");
- QObject::connect(a, SIGNAL(triggered()), worker, SLOT(decrease()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->decrease(); });
}
}
@@ -58,14 +62,18 @@ void ToolOptionShortcutConnector::visit(TDoublePairProperty* p) {
CommandManager* cm = CommandManager::instance();
QAction* a;
a = cm->getAction("A_IncreaseMaxBrushThickness");
- QObject::connect(a, SIGNAL(triggered()), worker, SLOT(increaseMaxValue()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->increaseMaxValue(); });
a = cm->getAction("A_DecreaseMaxBrushThickness");
- QObject::connect(a, SIGNAL(triggered()), worker, SLOT(decreaseMaxValue()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->decreaseMaxValue(); });
a = cm->getAction("A_IncreaseMinBrushThickness");
- QObject::connect(a, SIGNAL(triggered()), worker, SLOT(increaseMinValue()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->increaseMinValue(); });
a = cm->getAction("A_DecreaseMinBrushThickness");
- QObject::connect(a, SIGNAL(triggered()), worker, SLOT(decreaseMinValue()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->decreaseMinValue(); });
}
//-----------------------------------------------------------------
@@ -80,14 +88,18 @@ void ToolOptionShortcutConnector::visit(TIntPairProperty* p) {
CommandManager* cm = CommandManager::instance();
QAction* a;
a = cm->getAction("A_IncreaseMaxBrushThickness");
- QObject::connect(a, SIGNAL(triggered()), worker, SLOT(increaseMaxValue()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->increaseMaxValue(); });
a = cm->getAction("A_DecreaseMaxBrushThickness");
- QObject::connect(a, SIGNAL(triggered()), worker, SLOT(decreaseMaxValue()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->decreaseMaxValue(); });
a = cm->getAction("A_IncreaseMinBrushThickness");
- QObject::connect(a, SIGNAL(triggered()), worker, SLOT(increaseMinValue()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->increaseMinValue(); });
a = cm->getAction("A_DecreaseMinBrushThickness");
- QObject::connect(a, SIGNAL(triggered()), worker, SLOT(decreaseMinValue()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->decreaseMinValue(); });
}
//-----------------------------------------------------------------
@@ -99,9 +111,11 @@ void ToolOptionShortcutConnector::visit(TIntProperty* p) {
CommandManager* cm = CommandManager::instance();
QAction* a;
a = cm->getAction("A_IncreaseMaxBrushThickness");
- QObject::connect(a, SIGNAL(triggered()), worker, SLOT(increase()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->increase(); });
a = cm->getAction("A_DecreaseMaxBrushThickness");
- QObject::connect(a, SIGNAL(triggered()), worker, SLOT(decrease()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->decrease(); });
}
//-----------------------------------------------------------------
@@ -115,7 +129,8 @@ void ToolOptionShortcutConnector::visit(TBoolProperty* p) {
BoolWorker* worker = new BoolWorker(invoker, m_tool, p, a);
a->setCheckable(true);
a->setChecked(p->getValue());
- QObject::connect(a, SIGNAL(triggered(bool)), worker, SLOT(doCheck(bool)));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker, a]() { worker->doCheck(a->isChecked()); });
invoker->registerCheckProperty(m_tool, worker);
}
@@ -131,26 +146,21 @@ void ToolOptionShortcutConnector::visit(TEnumProperty* p) {
std::string actionName = "A_ToolOption_" + p->getId();
QAction* a = CommandManager::instance()->getAction(actionName.c_str());
if (a) {
- QObject::connect(a, SIGNAL(triggered()), worker, SLOT(cycleOptions()));
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker]() { worker->cycleOptions(); });
hasAction = true;
}
TEnumProperty::Range range = p->getRange();
TEnumProperty::Range::iterator it;
- QSignalMapper* signalMapper = 0;
- int index = 0;
+ int index = 0;
for (it = range.begin(); it != range.end(); ++it, ++index) {
std::string item = ::to_string(*it);
std::string itemActionName = actionName + ":" + item;
a = CommandManager::instance()->getAction(itemActionName.c_str());
if (a) {
- if (signalMapper == 0) {
- signalMapper = new QSignalMapper(worker);
- QObject::connect(signalMapper, SIGNAL(mapped(int)), worker,
- SLOT(doOnActivated(int)));
- }
- QObject::connect(a, SIGNAL(triggered()), signalMapper, SLOT(map()));
- signalMapper->setMapping(a, index);
+ QObject::connect(a, &QAction::triggered, worker,
+ [worker, index]() { worker->doOnActivated(index); });
hasAction = true;
}
}
@@ -161,7 +171,7 @@ void ToolOptionShortcutConnector::visit(TEnumProperty* p) {
//=============================================================================
void DoubleWorker::increase(double step) {
- // ignore if it is not the current tool
+ // Ignore if it is not the current tool
if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return;
TDoubleProperty::Range range = m_property->getRange();
double value = m_property->getValue();
@@ -179,7 +189,7 @@ void DoubleWorker::increaseFractional() { increase(0.06); }
//-----------------------------------------------------------------
void DoubleWorker::decrease(double step) {
- // ignore if it is not the current tool
+ // Ignore if it is not the current tool
if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return;
TDoubleProperty::Range range = m_property->getRange();
double value = m_property->getValue();
@@ -197,7 +207,7 @@ void DoubleWorker::decreaseFractional() { decrease(0.06); }
//=============================================================================
void DoublePairWorker::increaseMaxValue() {
- // ignore if it is not the current tool
+ // Ignore if it is not the current tool
if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return;
TDoublePairProperty::Value value = m_property->getValue();
TDoublePairProperty::Range range = m_property->getRange();
@@ -211,7 +221,7 @@ void DoublePairWorker::increaseMaxValue() {
//-----------------------------------------------------------------
void DoublePairWorker::decreaseMaxValue() {
- // ignore if it is not the current tool
+ // Ignore if it is not the current tool
if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return;
TDoublePairProperty::Value value = m_property->getValue();
value.second -= 1;
@@ -224,7 +234,7 @@ void DoublePairWorker::decreaseMaxValue() {
//-----------------------------------------------------------------
void DoublePairWorker::increaseMinValue() {
- // ignore if it is not the current tool
+ // Ignore if it is not the current tool
if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return;
TDoublePairProperty::Value value = m_property->getValue();
value.first += 1;
@@ -237,7 +247,7 @@ void DoublePairWorker::increaseMinValue() {
//-----------------------------------------------------------------
void DoublePairWorker::decreaseMinValue() {
- // ignore if it is not the current tool
+ // Ignore if it is not the current tool
if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return;
TDoublePairProperty::Value value = m_property->getValue();
TDoublePairProperty::Range range = m_property->getRange();
@@ -251,13 +261,13 @@ void DoublePairWorker::decreaseMinValue() {
//=============================================================================
void IntPairWorker::increaseMaxValue() {
- // ignore if it is not the current tool
+ // Ignore if it is not the current tool
if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return;
TIntPairProperty::Value value = m_property->getValue();
TIntPairProperty::Range range = m_property->getRange();
value.second += 1;
- // a "cross-like shape" of the brush size = 3 is hard to use. so skip it
+ // A "cross-like shape" of the brush size = 3 is hard to use. so skip it
if (value.second == 3 && m_tool->isPencilModeActive()) value.second += 1;
if (value.second > range.second) value.second = range.second;
@@ -269,12 +279,12 @@ void IntPairWorker::increaseMaxValue() {
//-----------------------------------------------------------------
void IntPairWorker::decreaseMaxValue() {
- // ignore if it is not the current tool
+ // Ignore if it is not the current tool
if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return;
TIntPairProperty::Value value = m_property->getValue();
value.second -= 1;
- // a "cross-like shape" of the brush size = 3 is hard to use. so skip it
+ // A "cross-like shape" of the brush size = 3 is hard to use. so skip it
if (value.second == 3 && m_tool->isPencilModeActive()) value.second -= 1;
if (value.second < value.first) value.second = value.first;
@@ -286,7 +296,7 @@ void IntPairWorker::decreaseMaxValue() {
//-----------------------------------------------------------------
void IntPairWorker::increaseMinValue() {
- // ignore if it is not the current tool
+ // Ignore if it is not the current tool
if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return;
TIntPairProperty::Value value = m_property->getValue();
value.first += 1;
@@ -299,7 +309,7 @@ void IntPairWorker::increaseMinValue() {
//-----------------------------------------------------------------
void IntPairWorker::decreaseMinValue() {
- // ignore if it is not the current tool
+ // Ignore if it is not the current tool
if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return;
TIntPairProperty::Value value = m_property->getValue();
TIntPairProperty::Range range = m_property->getRange();
@@ -313,13 +323,13 @@ void IntPairWorker::decreaseMinValue() {
//=============================================================================
void IntWorker::increase() {
- // ignore if it is not the current tool
+ // Ignore if it is not the current tool
if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return;
TIntProperty::Range range = m_property->getRange();
int value = m_property->getValue();
value += 1;
- // a "cross-like shape" of the brush size = 3 is hard to use. so skip it
+ // A "cross-like shape" of the brush size = 3 is hard to use. so skip it
if (value == 3 && m_tool->isPencilModeActive()) value += 1;
if (value > range.second) value = range.second;
@@ -331,13 +341,13 @@ void IntWorker::increase() {
//-----------------------------------------------------------------
void IntWorker::decrease() {
- // ignore if it is not the current tool
+ // Ignore if it is not the current tool
if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return;
TIntProperty::Range range = m_property->getRange();
double value = m_property->getValue();
value -= 1;
- // a "cross-like shape" of the brush size = 3 is hard to use. so skip it
+ // A "cross-like shape" of the brush size = 3 is hard to use. so skip it
if (value == 3 && m_tool->isPencilModeActive()) value -= 1;
if (value < range.first) value = range.first;
@@ -349,7 +359,7 @@ void IntWorker::decrease() {
//=============================================================================
void BoolWorker::doCheck(bool checked) {
- // ignore if it is not the current tool
+ // Ignore if it is not the current tool
if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return;
if (m_property->getValue() == checked) return;
@@ -370,7 +380,7 @@ void BoolWorker::syncActionState() {
//=============================================================================
void EnumWorker::cycleOptions() {
- // ignore if it is not the current tool
+ // Ignore if it is not the current tool
if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return;
const TEnumProperty::Range& range = m_property->getRange();
int theIndex = m_property->getIndex() + 1;
@@ -381,10 +391,10 @@ void EnumWorker::cycleOptions() {
//-----------------------------------------------------------------
void EnumWorker::doOnActivated(int index) {
- // ignore if it is not the current tool
+ // Ignore if it is not the current tool
if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return;
- // check range
+ // Check range
const TEnumProperty::Range& range = m_property->getRange();
if (index < 0 || index >= (int)range.size()) return;
@@ -399,7 +409,7 @@ void EnumWorker::doOnActivated(int index) {
// If the first item of this combo box is "Normal", enable shortcut key toggle
// can "back and forth" behavior.
if (m_property->getIndex() == index) {
- // estimating that the "Normal" option is located at the index 0
+ // Estimating that the "Normal" option is located at the index 0
m_property->setIndex(0);
} else {
m_property->setIndex(index);
@@ -419,8 +429,8 @@ ToolOptionsShortcutInvoker* ToolOptionsShortcutInvoker::instance() {
//-----------------------------------------------------------------
void ToolOptionsShortcutInvoker::initialize() {
- connect(TApp::instance()->getCurrentTool(), SIGNAL(toolSwitched()), this,
- SLOT(onToolSwitched()));
+ connect(TApp::instance()->getCurrentTool(), &ToolHandle::toolSwitched, this,
+ &ToolOptionsShortcutInvoker::onToolSwitched);
onToolSwitched();
/*-- Animate tool + mode switching shortcuts --*/
@@ -613,7 +623,7 @@ void ToolOptionsShortcutInvoker::registerCheckProperty(TTool* tool,
void ToolOptionsShortcutInvoker::onToolSwitched() {
TTool* tool = TApp::instance()->getCurrentTool()->getTool();
if (!m_tools.contains(tool)) {
- // amount of the property groups
+ // Amount of the property groups
int pgCount = 1;
if (tool->getName() == T_Geometric || tool->getName() == T_Type ||
(tool->getName() == T_Selection &&
@@ -626,14 +636,14 @@ void ToolOptionsShortcutInvoker::onToolSwitched() {
if (!pg) continue;
ToolOptionShortcutConnector connector(tool);
- // connect each property to an associated command
+ // Connect each property to an associated command
pg->accept(connector);
}
m_tools.insert(tool);
}
- // if the tool is already registered
+ // If the tool is already registered
else {
- // synchronize action's check state to the property
+ // Synchronize action's check state to the property
for (auto boolWorker : m_checkProps.values(tool)) {
boolWorker->syncActionState();
}
@@ -968,7 +978,9 @@ void ToolOptionsShortcutInvoker::toggleEraserSegment() {
void ToolOptionsShortcutInvoker::toggleEraserMultiArc() {
CommandManager::instance()->getAction(T_Eraser)->trigger();
CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger();
- CommandManager::instance()->getAction("A_ToolOption_Type:MultiArc")->trigger();
+ CommandManager::instance()
+ ->getAction("A_ToolOption_Type:MultiArc")
+ ->trigger();
}
//---------------------------------------------------------------------------------------
/*-- Tape tool + type/mode switching shortcuts --*/
diff --git a/toonz/sources/toonz/tooloptionsshortcutinvoker.h b/toonz/sources/toonz/tooloptionsshortcutinvoker.h
index 8cfd8ebfa..ad670cbb0 100644
--- a/toonz/sources/toonz/tooloptionsshortcutinvoker.h
+++ b/toonz/sources/toonz/tooloptionsshortcutinvoker.h
@@ -48,7 +48,9 @@ class DoubleWorker : public QObject {
public:
DoubleWorker(QObject* parent, TTool* tool, TDoubleProperty* property)
: QObject(parent), m_tool(tool), m_property(property) {}
-protected slots:
+// Slots made public to allow direct Qt connections from ToolOptionsShortcutInvoker
+// (Qt meta-object system requires public visibility for slots)
+public slots:
void increase(double step = 1.0);
void increaseFractional();
void decrease(double step = 1.0);
@@ -65,7 +67,8 @@ class DoublePairWorker : public QObject {
public:
DoublePairWorker(QObject* parent, TTool* tool, TDoublePairProperty* property)
: QObject(parent), m_tool(tool), m_property(property) {}
-protected slots:
+
+public slots:
void increaseMaxValue();
void decreaseMaxValue();
void increaseMinValue();
@@ -82,7 +85,8 @@ class IntPairWorker : public QObject {
public:
IntPairWorker(QObject* parent, TTool* tool, TIntPairProperty* property)
: QObject(parent), m_tool(tool), m_property(property) {}
-protected slots:
+
+public slots:
void increaseMaxValue();
void decreaseMaxValue();
void increaseMinValue();
@@ -99,7 +103,8 @@ class IntWorker : public QObject {
public:
IntWorker(QObject* parent, TTool* tool, TIntProperty* property)
: QObject(parent), m_tool(tool), m_property(property) {}
-protected slots:
+
+public slots:
void increase();
void decrease();
};
@@ -117,7 +122,8 @@ public:
QAction* action)
: QObject(parent), m_tool(tool), m_property(property), m_action(action) {}
void syncActionState();
-protected slots:
+
+public slots:
void doCheck(bool);
};
@@ -131,7 +137,8 @@ class EnumWorker : public QObject {
public:
EnumWorker(QObject* parent, TTool* tool, TEnumProperty* property)
: QObject(parent), m_tool(tool), m_property(property) {}
-protected slots:
+
+public slots:
void cycleOptions();
void doOnActivated(int);
};
@@ -143,7 +150,7 @@ class ToolOptionsShortcutInvoker : public QObject // singleton
{
Q_OBJECT
QSet<TTool*> m_tools;
- //�c�[�����؂�ւ������ Action��Check��Ԃ𓯊�������
+ // When tool is switched, synchronize Action's Check state
QMultiMap<TTool*, ToolOptionsShortcutWorker::BoolWorker*> m_checkProps;
public:
@@ -154,6 +161,7 @@ public:
private:
ToolOptionsShortcutInvoker(){};
+
protected slots:
void onToolSwitched();
@@ -253,4 +261,4 @@ protected slots:
void TogglePlasticAnimate();
};
-#endif
\ No newline at end of file
+#endif