Skip to content

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

C

Refactor: Update FingerTool Invert Option Behavior, Add OptionBox for Finger Tool

Abel You72621aaca83a
diff --git a/toonz/sources/include/tools/tooloptions.h b/toonz/sources/include/tools/tooloptions.h
index a4f712bc0..bdf4b4030 100644
--- a/toonz/sources/include/tools/tooloptions.h
+++ b/toonz/sources/include/tools/tooloptions.h
@@ -302,7 +302,7 @@ protected slots:
class DraggableIconView : public QWidget {
Q_OBJECT
public:
- DraggableIconView(QWidget *parent = 0) : QWidget(parent){};
+ DraggableIconView(QWidget *parent = 0) : QWidget(parent) {};
protected:
// these are used for dragging on the icon to
@@ -598,6 +598,26 @@ protected slots:
void onColorModeChanged(int);
};
+//=============================================================================
+//
+// FingerToolOptionsBox
+//
+//=============================================================================
+
+class FingerToolOptionsBox final : public ToolOptionsBox {
+ Q_OBJECT
+
+ ToolOptionCombo *m_colorMode;
+ ToolOptionCheckbox *m_invertMode;
+
+public:
+ FingerToolOptionsBox(QWidget *parent, TTool *tool, TPaletteHandle *pltHandle,
+ ToolHandle *toolHandle);
+
+protected slots:
+ void onColorModeChanged(int);
+};
+
//=============================================================================
//
// RulerToolOptionsBox
diff --git a/toonz/sources/tnztools/fingertool.cpp b/toonz/sources/tnztools/fingertool.cpp
index 9477f89be..c6cee4f3e 100644
--- a/toonz/sources/tnztools/fingertool.cpp
+++ b/toonz/sources/tnztools/fingertool.cpp
@@ -402,8 +402,6 @@ bool FingerTool::onPropertyChanged(std::string propertyName) {
// Mode
else if (propertyName == m_mode.getName()) {
FingerMode = (ColorType)(m_mode.getIndex());
- if (FingerMode == PAINT)
- m_invert.setValue(false);
}
// Pick
@@ -413,7 +411,6 @@ bool FingerTool::onPropertyChanged(std::string propertyName) {
// Invert
else if (propertyName == m_invert.getName()) {
- if (FingerMode == PAINT) m_invert.setValue(false);
FingerInvert = (int)(m_invert.getValue());
}
@@ -439,7 +436,7 @@ void FingerTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {
m_rasterTrack = new RasterStrokeGenerator(
ras, FINGER, (ColorType)m_mode.getIndex(), styleId,
TThickPoint(pos + convert(ras->getCenter()), thickness),
- m_invert.getValue(), 0, false, false);
+ m_mode.getIndex() == 0 ? m_invert.getValue() : false, 0, false, false);
/*-- 作業中Fidを現在のFIDにする --*/
m_workingFrameId = getFrameId();
@@ -497,7 +494,6 @@ void FingerTool::mouseMove(const TPointD &pos, const TMouseEvent &e) {
void FingerTool::onEnter() {
if (m_firstTime) {
m_invert.setValue(FingerInvert ? 1 : 0);
- if (FingerMode == PAINT) m_invert.setValue(false);
m_toolSize.setValue(FingerSize);
m_mode.setIndex(FingerMode);
m_pick.setValue(FingerPick ? 1 : 0);
diff --git a/toonz/sources/tnztools/tooloptions.cpp b/toonz/sources/tnztools/tooloptions.cpp
index 282558374..59ff42ad5 100644
--- a/toonz/sources/tnztools/tooloptions.cpp
+++ b/toonz/sources/tnztools/tooloptions.cpp
@@ -2172,11 +2172,43 @@ void EraserToolOptionsBox::onColorModeChanged(int index) {
}
}
+//=============================================================================
+//
+// EraserToolOptionsBox
+//
+//=============================================================================
+
+FingerToolOptionsBox::FingerToolOptionsBox(QWidget* parent, TTool* tool, TPaletteHandle* pltHandle, ToolHandle* toolHandle)
+: ToolOptionsBox(parent), m_colorMode(0), m_invertMode(0){
+ TPropertyGroup* props = tool->getProperties(0);
+ assert(props->getPropertyCount() > 0);
+
+ ToolOptionControlBuilder builder(this, tool, pltHandle, toolHandle);
+ if (tool && tool->getProperties(0)) tool->getProperties(0)->accept(builder);
+
+ hLayout()->addStretch(1);
+
+ m_colorMode = dynamic_cast<ToolOptionCombo*>(m_controls.value("Mode:"));
+ m_invertMode = dynamic_cast<ToolOptionCheckbox*>(m_controls.value("Invert"));
+
+ bool ret = true;
+ if (m_colorMode) {
+ ret = ret && connect(m_colorMode, SIGNAL(currentIndexChanged(int)), this,
+ SLOT(onColorModeChanged(int)));
+ if (m_invertMode && m_colorMode->currentIndex() == 1)//Paint
+ m_invertMode->setEnabled(false);
+ }
+}
+
+void FingerToolOptionsBox::onColorModeChanged(int i) {
+ if (m_invertMode) m_invertMode->setEnabled(i == 0);
+}
//=============================================================================
//
// RulerToolOptionsBox
//
//=============================================================================
+
class ToolOptionsBarSeparator final : public QWidget {
public:
ToolOptionsBarSeparator(QWidget *parent) : QWidget(parent) {
@@ -2926,50 +2958,55 @@ void ToolOptions::onToolSwitched() {
if (it == m_panels.end()) {
// Create new panel if one doesn't exist for this tool
- if (tool->getName() == T_Edit) {
- TPropertyGroup *pg = tool->getProperties(0);
- panel = new ArrowToolOptionsBox(0, tool, pg, currFrame, currObject,
- currXsheet, currTool);
- } else if (tool->getName() == T_Selection)
- panel = new SelectionToolOptionsBox(0, tool, currPalette, currTool);
- else if (tool->getName() == T_Geometric)
- panel = new GeometricToolOptionsBox(0, tool, currPalette, currTool);
- else if (tool->getName() == T_Type)
- panel = new TypeToolOptionsBox(0, tool, currPalette, currTool);
- else if (tool->getName() == T_PaintBrush)
- panel = new PaintbrushToolOptionsBox(0, tool, currPalette, currTool);
- else if (tool->getName() == T_Fill) {
- if (tool->getTargetType() & TTool::RasterImage)
- panel =
- new FullColorFillToolOptionsBox(0, tool, currPalette, currTool);
+ if (tool->getName() == T_Edit) {
+ TPropertyGroup* pg = tool->getProperties(0);
+ panel = new ArrowToolOptionsBox(0, tool, pg, currFrame, currObject,
+ currXsheet, currTool);
+ }
+ else if (tool->getName() == T_Selection)
+ panel = new SelectionToolOptionsBox(0, tool, currPalette, currTool);
+ else if (tool->getName() == T_Geometric)
+ panel = new GeometricToolOptionsBox(0, tool, currPalette, currTool);
+ else if (tool->getName() == T_Type)
+ panel = new TypeToolOptionsBox(0, tool, currPalette, currTool);
+ else if (tool->getName() == T_PaintBrush)
+ panel = new PaintbrushToolOptionsBox(0, tool, currPalette, currTool);
+ else if (tool->getName() == T_Fill) {
+ if (tool->getTargetType() & TTool::RasterImage)
+ panel =
+ new FullColorFillToolOptionsBox(0, tool, currPalette, currTool);
+ else
+ panel = new FillToolOptionsBox(0, tool, currPalette, currTool);
+ }
+ else if (tool->getName() == T_Eraser)
+ panel = new EraserToolOptionsBox(0, tool, currPalette, currTool);
+ else if (tool->getName() == T_Tape)
+ panel = new TapeToolOptionsBox(0, tool, currPalette, currTool);
+ else if (tool->getName() == T_RGBPicker)
+ panel = new RGBPickerToolOptionsBox(0, tool, currPalette, currTool,
+ app->getPaletteController());
+ else if (tool->getName() == T_Ruler) {
+ RulerToolOptionsBox* p = new RulerToolOptionsBox(0, tool);
+ panel = p;
+ RulerTool* rt = dynamic_cast<RulerTool*>(tool);
+ if (rt) rt->setToolOptionsBox(p);
+ }
+ else if (tool->getName() == T_StylePicker)
+ panel = new StylePickerToolOptionsBox(0, tool, currPalette, currTool,
+ app->getPaletteController());
+ else if (tool->getName() == "T_ShiftTrace")
+ panel = new ShiftTraceToolOptionBox(this, tool);
+ else if (tool->getName() == T_Zoom)
+ panel = new ZoomToolOptionsBox(0, tool, currPalette, currTool);
+ else if (tool->getName() == T_Rotate)
+ panel = new RotateToolOptionsBox(0, tool, currPalette, currTool);
+ else if (tool->getName() == T_Hand)
+ panel = new HandToolOptionsBox(0, tool, currPalette, currTool);
+ else if (tool->getName() == "T_Finger")
+ panel = new FingerToolOptionsBox(0, tool, currPalette, currTool);
else
- panel = new FillToolOptionsBox(0, tool, currPalette, currTool);
- } else if (tool->getName() == T_Eraser)
- panel = new EraserToolOptionsBox(0, tool, currPalette, currTool);
- else if (tool->getName() == T_Tape)
- panel = new TapeToolOptionsBox(0, tool, currPalette, currTool);
- else if (tool->getName() == T_RGBPicker)
- panel = new RGBPickerToolOptionsBox(0, tool, currPalette, currTool,
- app->getPaletteController());
- else if (tool->getName() == T_Ruler) {
- RulerToolOptionsBox *p = new RulerToolOptionsBox(0, tool);
- panel = p;
- RulerTool *rt = dynamic_cast<RulerTool *>(tool);
- if (rt) rt->setToolOptionsBox(p);
- } else if (tool->getName() == T_StylePicker)
- panel = new StylePickerToolOptionsBox(0, tool, currPalette, currTool,
- app->getPaletteController());
- else if (tool->getName() == "T_ShiftTrace")
- panel = new ShiftTraceToolOptionBox(this, tool);
- else if (tool->getName() == T_Zoom)
- panel = new ZoomToolOptionsBox(0, tool, currPalette, currTool);
- else if (tool->getName() == T_Rotate)
- panel = new RotateToolOptionsBox(0, tool, currPalette, currTool);
- else if (tool->getName() == T_Hand)
- panel = new HandToolOptionsBox(0, tool, currPalette, currTool);
- else
- panel = tool->createOptionsBox(); // Future: Use this virtual method
- // for all tools
+ panel = tool->createOptionsBox(); // Future: Use this virtual method
+ // for all tools
m_panels[tool] = panel;
layout()->addWidget(panel);