From 26d9a1e542629f836efe7e293fe7c1d21b71a65b Mon Sep 17 00:00:00 2001 From: Rodney Date: Apr 23 2021 14:00:09 +0000 Subject: Merge pull request #3927 from shun-iwasawa/fix_tool_options_shortcuts Fix tool options' shortcuts to work without opening tool options bar --- diff --git a/toonz/sources/include/tools/tooloptions.h b/toonz/sources/include/tools/tooloptions.h index aad1d58..81a84e6 100644 --- a/toonz/sources/include/tools/tooloptions.h +++ b/toonz/sources/include/tools/tooloptions.h @@ -154,15 +154,15 @@ private: QHBoxLayout *hLayout() { return m_panel->hLayout(); } QLabel *addLabel(TProperty *p); - void visit(TDoubleProperty *p); - void visit(TDoublePairProperty *p); - void visit(TIntPairProperty *p); - void visit(TIntProperty *p); - void visit(TBoolProperty *p); - void visit(TStringProperty *p); - void visit(TEnumProperty *p); - void visit(TStyleIndexProperty *p); - void visit(TPointerProperty *p); + void visit(TDoubleProperty *p) override; + void visit(TDoublePairProperty *p) override; + void visit(TIntPairProperty *p) override; + void visit(TIntProperty *p) override; + void visit(TBoolProperty *p) override; + void visit(TStringProperty *p) override; + void visit(TEnumProperty *p) override; + void visit(TStyleIndexProperty *p) override; + void visit(TPointerProperty *p) override; }; //*********************************************************************************************** diff --git a/toonz/sources/include/toonz/preferences.h b/toonz/sources/include/toonz/preferences.h index 0ab37f4..0ada02c 100644 --- a/toonz/sources/include/toonz/preferences.h +++ b/toonz/sources/include/toonz/preferences.h @@ -323,9 +323,9 @@ public: } // Tools Tab - bool getDropdownShortcutsCycleOptions() { - return getIntValue(dropdownShortcutsCycleOptions) == 1; - } + // bool getDropdownShortcutsCycleOptions() { + // return getIntValue(dropdownShortcutsCycleOptions) == 1; + //} bool getFillOnlySavebox() const { return getBoolValue(FillOnlysavebox); } bool isMultiLayerStylePickerEnabled() const { return getBoolValue(multiLayerStylePickerEnabled); diff --git a/toonz/sources/include/toonz/preferencesitemids.h b/toonz/sources/include/toonz/preferencesitemids.h index 33876e0..896132b 100644 --- a/toonz/sources/include/toonz/preferencesitemids.h +++ b/toonz/sources/include/toonz/preferencesitemids.h @@ -101,7 +101,7 @@ enum PreferencesItemId { //---------- // Tools - dropdownShortcutsCycleOptions, + // dropdownShortcutsCycleOptions, // removed FillOnlysavebox, multiLayerStylePickerEnabled, cursorBrushType, diff --git a/toonz/sources/tnztools/tooloptions.cpp b/toonz/sources/tnztools/tooloptions.cpp index 7df9b4e..1310199 100644 --- a/toonz/sources/tnztools/tooloptions.cpp +++ b/toonz/sources/tnztools/tooloptions.cpp @@ -56,7 +56,6 @@ #include #include #include -#include #include #include #include @@ -209,36 +208,6 @@ void ToolOptionControlBuilder::visit(TDoubleProperty *p) { hLayout()->addWidget(control, 100); // storing the control in the map for updating values later m_panel->addControl(control); - CommandManager *cm = CommandManager::instance(); - if (p->getName() == "Size:") { - QAction *a; - a = cm->getAction("A_IncreaseMaxBrushThickness"); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered()), control, SLOT(increase())); - a = cm->getAction("A_DecreaseMaxBrushThickness"); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered()), control, SLOT(decrease())); - } - if (p->getName() == "ModifierSize") { - QAction *a; - a = cm->getAction("A_IncreaseMaxBrushThickness"); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered()), control, - SLOT(increaseFractional())); - a = cm->getAction("A_DecreaseMaxBrushThickness"); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered()), control, - SLOT(decreaseFractional())); - } - if (p->getName() == "Hardness:") { - QAction *a; - a = cm->getAction("A_IncreaseBrushHardness"); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered()), control, SLOT(increase())); - a = cm->getAction("A_DecreaseBrushHardness"); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered()), control, SLOT(decrease())); - } hLayout()->addSpacing(5); } @@ -251,23 +220,6 @@ void ToolOptionControlBuilder::visit(TDoublePairProperty *p) { m_tool, p, QObject::tr("Min:"), QObject::tr("Max:"), m_toolHandle); hLayout()->addWidget(control, 150); m_panel->addControl(control); - if (p->getName() == "Size:" || p->getName() == "Size") { - CommandManager *cm = CommandManager::instance(); - QAction *a; - a = cm->getAction("A_IncreaseMaxBrushThickness"); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered()), control, SLOT(increaseMaxValue())); - a = cm->getAction("A_DecreaseMaxBrushThickness"); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered()), control, SLOT(decreaseMaxValue())); - - a = cm->getAction("A_IncreaseMinBrushThickness"); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered()), control, SLOT(increaseMinValue())); - a = cm->getAction("A_DecreaseMinBrushThickness"); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered()), control, SLOT(decreaseMinValue())); - } hLayout()->addSpacing(5); } @@ -280,24 +232,6 @@ void ToolOptionControlBuilder::visit(TIntPairProperty *p) { m_tool, p, QObject::tr("Min:"), QObject::tr("Max:"), m_toolHandle); hLayout()->addWidget(control, 100); m_panel->addControl(control); - if (p->getName() == "Size:" || p->getName() == "Thickness" || - p->getName() == "Size") { - CommandManager *cm = CommandManager::instance(); - QAction *a; - a = cm->getAction("A_IncreaseMaxBrushThickness"); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered()), control, SLOT(increaseMaxValue())); - a = cm->getAction("A_DecreaseMaxBrushThickness"); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered()), control, SLOT(decreaseMaxValue())); - - a = cm->getAction("A_IncreaseMinBrushThickness"); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered()), control, SLOT(increaseMinValue())); - a = cm->getAction("A_DecreaseMinBrushThickness"); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered()), control, SLOT(decreaseMinValue())); - } hLayout()->addSpacing(5); } @@ -316,16 +250,6 @@ void ToolOptionControlBuilder::visit(TIntProperty *p) { } hLayout()->addWidget(control, 100); m_panel->addControl(control); - if (p->getName() == "Size:") { - CommandManager *cm = CommandManager::instance(); - QAction *a; - a = cm->getAction("A_IncreaseMaxBrushThickness"); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered()), control, SLOT(increase())); - a = cm->getAction("A_DecreaseMaxBrushThickness"); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered()), control, SLOT(decrease())); - } hLayout()->addSpacing(5); } @@ -336,17 +260,6 @@ void ToolOptionControlBuilder::visit(TBoolProperty *p) { hLayout()->addWidget(control, 0); m_panel->addControl(control); - - if (p->getId() != "") { - std::string actionName = "A_ToolOption_" + p->getId(); - QAction *a = CommandManager::instance()->getAction(actionName.c_str()); - if (a) { - a->setCheckable(true); - control->addAction(a); - QObject::connect(a, SIGNAL(triggered(bool)), control, - SLOT(doClick(bool))); - } - } hLayout()->addSpacing(5); } @@ -404,35 +317,6 @@ void ToolOptionControlBuilder::visit(TEnumProperty *p) { hLayout()->addWidget(widget, 100); m_panel->addControl(control); hLayout()->addSpacing(5); - - if (p->getId() != "") { - std::string actionName = "A_ToolOption_" + p->getId(); - QAction *a = CommandManager::instance()->getAction(actionName.c_str()); - if (a) { - widget->addAction(a); - QObject::connect(a, SIGNAL(triggered()), widget, SLOT(doShowPopup())); - } - - TEnumProperty::Range range = p->getRange(); - TEnumProperty::Range::iterator it; - QSignalMapper *signalMapper = 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) { - widget->addAction(a); - if (signalMapper == 0) { - signalMapper = new QSignalMapper(widget); - QObject::connect(signalMapper, SIGNAL(mapped(int)), widget, - SLOT(doOnActivated(int))); - } - QObject::connect(a, SIGNAL(triggered()), signalMapper, SLOT(map())); - signalMapper->setMapping(a, index); - } - } - } } //----------------------------------------------------------------------------- @@ -884,38 +768,6 @@ ArrowToolOptionsBox::ArrowToolOptionsBox( connect(m_currentStageObjectCombo, SIGNAL(activated(int)), this, SLOT(onCurrentStageObjectComboActivated(int))); - /* --- Assigning shortcut keys --- */ - if (activeAxisProp->getId() != "") { - std::string actionName = "A_ToolOption_" + activeAxisProp->getId(); - QAction *a = CommandManager::instance()->getAction(actionName.c_str()); - - if (a) { - m_chooseActiveAxisCombo->addAction(a); - QObject::connect(a, SIGNAL(triggered()), m_chooseActiveAxisCombo, - SLOT(doShowPopup())); - } - - TEnumProperty::Range range = activeAxisProp->getRange(); - TEnumProperty::Range::iterator it; - QSignalMapper *signalMapper = 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) { - m_chooseActiveAxisCombo->addAction(a); - if (signalMapper == 0) { - signalMapper = new QSignalMapper(m_chooseActiveAxisCombo); - QObject::connect(signalMapper, SIGNAL(mapped(int)), - m_chooseActiveAxisCombo, SLOT(doOnActivated(int))); - } - QObject::connect(a, SIGNAL(triggered()), signalMapper, SLOT(map())); - signalMapper->setMapping(a, index); - } - } - } - if (scaleConstraintProp) { m_scaleHField->onScaleTypeChanged(m_maintainCombo->currentIndex()); m_scaleVField->onScaleTypeChanged(m_maintainCombo->currentIndex()); @@ -940,16 +792,6 @@ ArrowToolOptionsBox::ArrowToolOptionsBox( connectLabelAndField(m_ewCenterLabel, m_ewCenterField); connectLabelAndField(m_nsCenterLabel, m_nsCenterField); - if (globalKeyProp) { - std::string actionName = "A_ToolOption_" + globalKeyProp->getId(); - QAction *a = CommandManager::instance()->getAction(actionName.c_str()); - if (a) { - a->setCheckable(true); - m_globalKey->addAction(a); - connect(a, SIGNAL(triggered(bool)), m_globalKey, SLOT(doClick(bool))); - } - } - onCurrentAxisChanged(activeAxisProp->getIndex()); } @@ -1034,6 +876,8 @@ void ArrowToolOptionsBox::updateStatus() { m_nsPosField->updateStatus(); m_zField->updateStatus(); m_noScaleZField->updateStatus(); + m_lockEWPosCheckbox->updateStatus(); + m_lockNSPosCheckbox->updateStatus(); m_soField->updateStatus(); // Rotation @@ -1043,15 +887,23 @@ void ArrowToolOptionsBox::updateStatus() { m_globalScaleField->updateStatus(); m_scaleHField->updateStatus(); m_scaleVField->updateStatus(); + m_lockScaleHCheckbox->updateStatus(); + m_lockScaleVCheckbox->updateStatus(); m_maintainCombo->updateStatus(); // Shear m_shearHField->updateStatus(); m_shearVField->updateStatus(); + m_lockShearHCheckbox->updateStatus(); + m_lockShearVCheckbox->updateStatus(); // Center Position m_ewCenterField->updateStatus(); m_nsCenterField->updateStatus(); + m_lockEWCenterCheckbox->updateStatus(); + m_lockNSCenterCheckbox->updateStatus(); + + m_globalKey->updateStatus(); bool splined = isCurrentObjectSplined(); if (splined != m_splined) setSplined(splined); diff --git a/toonz/sources/tnztools/tooloptionscontrols.cpp b/toonz/sources/tnztools/tooloptionscontrols.cpp index 7512f9e..f197f9c 100644 --- a/toonz/sources/tnztools/tooloptionscontrols.cpp +++ b/toonz/sources/tnztools/tooloptionscontrols.cpp @@ -107,10 +107,6 @@ ToolOptionCheckbox::ToolOptionCheckbox(TTool *tool, TBoolProperty *property, void ToolOptionCheckbox::updateStatus() { bool check = m_property->getValue(); - if (!actions().isEmpty() && actions()[0]->isCheckable() && - actions()[0]->isChecked() != check) - actions()[0]->setChecked(check); - if (isChecked() == check) return; setCheckState(check ? Qt::Checked : Qt::Unchecked); @@ -124,23 +120,6 @@ void ToolOptionCheckbox::nextCheckState() { notifyTool(); } -//----------------------------------------------------------------------------- - -void ToolOptionCheckbox::doClick(bool checked) { - if (m_toolHandle && m_toolHandle->getTool() != m_tool) return; - // active only if the belonging combo-viewer is visible - if (!isInVisibleViewer(this)) return; - - if (isChecked() == checked) return; - - setChecked(checked); - m_property->setValue(checked); - notifyTool(); - - // for updating a cursor without any effect to the tool options - if (m_toolHandle) m_toolHandle->notifyToolCursorTypeChanged(); -} - //============================================================================= ToolOptionSlider::ToolOptionSlider(TTool *tool, TDoubleProperty *property, @@ -191,56 +170,6 @@ void ToolOptionSlider::onValueChanged(bool isDragging) { notifyTool(!isDragging); } -//----------------------------------------------------------------------------- - -void ToolOptionSlider::increase(double step) { - if (m_toolHandle && m_toolHandle->getTool() != m_tool) return; - // active only if the belonging combo-viewer is visible - if (!isInVisibleViewer(this)) return; - - double value = getValue(); - double minValue, maxValue; - getRange(minValue, maxValue); - - value += step; - if (value > maxValue) value = maxValue; - - setValue(value); - m_property->setValue(getValue()); - notifyTool(); - // update the interface - repaint(); -} - -//----------------------------------------------------------------------------- - -void ToolOptionSlider::increaseFractional() { increase(0.06); } - -//----------------------------------------------------------------------------- - -void ToolOptionSlider::decrease(double step) { - if (m_toolHandle && m_toolHandle->getTool() != m_tool) return; - // active only if the belonging combo-viewer is visible - if (!isInVisibleViewer(this)) return; - - double value = getValue(); - double minValue, maxValue; - getRange(minValue, maxValue); - - value -= step; - if (value < minValue) value = minValue; - - setValue(value); - m_property->setValue(getValue()); - notifyTool(); - // update the interface - repaint(); -} - -//----------------------------------------------------------------------------- - -void ToolOptionSlider::decreaseFractional() { decrease(0.06); } - //============================================================================= ToolOptionPairSlider::ToolOptionPairSlider(TTool *tool, @@ -297,78 +226,6 @@ void ToolOptionPairSlider::onValuesChanged(bool isDragging) { if (m_toolHandle) m_toolHandle->notifyToolChanged(); } -//----------------------------------------------------------------------------- - -void ToolOptionPairSlider::increaseMaxValue() { - if (m_toolHandle && m_toolHandle->getTool() != m_tool) return; - // active only if the belonging combo-viewer is visible - if (!isInVisibleViewer(this)) return; - - std::pair values = getValues(); - double minValue, maxValue; - getRange(minValue, maxValue); - values.second += 1; - if (values.second > maxValue) values.second = maxValue; - setValues(values); - m_property->setValue(getValues()); - notifyTool(); - // update the interface - repaint(); -} - -//----------------------------------------------------------------------------- - -void ToolOptionPairSlider::decreaseMaxValue() { - if (m_toolHandle && m_toolHandle->getTool() != m_tool) return; - // active only if the belonging combo-viewer is visible - if (!isInVisibleViewer(this)) return; - - std::pair values = getValues(); - values.second -= 1; - if (values.second < values.first) values.second = values.first; - setValues(values); - m_property->setValue(getValues()); - notifyTool(); - // update the interface - repaint(); -} - -//----------------------------------------------------------------------------- - -void ToolOptionPairSlider::increaseMinValue() { - if (m_toolHandle && m_toolHandle->getTool() != m_tool) return; - // active only if the belonging combo-viewer is visible - if (!isInVisibleViewer(this)) return; - - std::pair values = getValues(); - values.first += 1; - if (values.first > values.second) values.first = values.second; - setValues(values); - m_property->setValue(getValues()); - notifyTool(); - // update the interface - repaint(); -} - -//----------------------------------------------------------------------------- - -void ToolOptionPairSlider::decreaseMinValue() { - if (m_toolHandle && m_toolHandle->getTool() != m_tool) return; - // active only if the belonging combo-viewer is visible - if (!isInVisibleViewer(this)) return; - - std::pair values = getValues(); - double minValue, maxValue; - getRange(minValue, maxValue); - values.first -= 1; - if (values.first < minValue) values.first = minValue; - setValues(values); - m_property->setValue(getValues()); - notifyTool(); - // update the interface - repaint(); -} - //============================================================================= ToolOptionIntPairSlider::ToolOptionIntPairSlider(TTool *tool, @@ -408,86 +265,6 @@ void ToolOptionIntPairSlider::onValuesChanged(bool isDragging) { if (m_toolHandle) m_toolHandle->notifyToolChanged(); } -//----------------------------------------------------------------------------- - -void ToolOptionIntPairSlider::increaseMaxValue() { - if (m_toolHandle && m_toolHandle->getTool() != m_tool) return; - // active only if the belonging combo-viewer is visible - if (!isInVisibleViewer(this)) return; - - std::pair values = getValues(); - int minValue, maxValue; - getRange(minValue, maxValue); - values.second += 1; - - // a "cross-like shape" of the brush size = 3 is hard to use. so skip it - if (values.second == 3 && m_tool->isPencilModeActive()) values.second += 1; - - if (values.second > maxValue) values.second = maxValue; - setValues(values); - m_property->setValue(getValues()); - notifyTool(); - // update the interface - repaint(); -} - -//----------------------------------------------------------------------------- - -void ToolOptionIntPairSlider::decreaseMaxValue() { - if (m_toolHandle && m_toolHandle->getTool() != m_tool) return; - // active only if the belonging combo-viewer is visible - if (!isInVisibleViewer(this)) return; - - std::pair values = getValues(); - values.second -= 1; - - // a "cross-like shape" of the brush size = 3 is hard to use. so skip it - if (values.second == 3 && m_tool->isPencilModeActive()) values.second -= 1; - - if (values.second < values.first) values.second = values.first; - setValues(values); - m_property->setValue(getValues()); - notifyTool(); - // update the interface - repaint(); -} - -//----------------------------------------------------------------------------- - -void ToolOptionIntPairSlider::increaseMinValue() { - if (m_toolHandle && m_toolHandle->getTool() != m_tool) return; - // active only if the belonging combo-viewer is visible - if (!isInVisibleViewer(this)) return; - - std::pair values = getValues(); - values.first += 1; - if (values.first > values.second) values.first = values.second; - setValues(values); - m_property->setValue(getValues()); - notifyTool(); - // update the interface - repaint(); -} - -//----------------------------------------------------------------------------- - -void ToolOptionIntPairSlider::decreaseMinValue() { - if (m_toolHandle && m_toolHandle->getTool() != m_tool) return; - // active only if the belonging combo-viewer is visible - if (!isInVisibleViewer(this)) return; - - std::pair values = getValues(); - int minValue, maxValue; - getRange(minValue, maxValue); - values.first -= 1; - if (values.first < minValue) values.first = minValue; - setValues(values); - m_property->setValue(getValues()); - notifyTool(); - // update the interface - repaint(); -} - //============================================================================= ToolOptionIntSlider::ToolOptionIntSlider(TTool *tool, TIntProperty *property, @@ -520,53 +297,6 @@ void ToolOptionIntSlider::updateStatus() { //----------------------------------------------------------------------------- -void ToolOptionIntSlider::increase() { - if (m_toolHandle && m_toolHandle->getTool() != m_tool) return; - // active only if the belonging combo-viewer is visible - if (!isInVisibleViewer(this)) return; - - int value = getValue(); - int minValue, maxValue; - getRange(minValue, maxValue); - value += 1; - // 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 > maxValue) value = maxValue; - - setValue(value); - m_property->setValue(getValue()); - notifyTool(); - // update the interface - repaint(); -} - -//----------------------------------------------------------------------------- - -void ToolOptionIntSlider::decrease() { - if (m_toolHandle && m_toolHandle->getTool() != m_tool) return; - // active only if the belonging combo-viewer is visible - if (!isInVisibleViewer(this)) return; - - int value = getValue(); - int minValue, maxValue; - getRange(minValue, maxValue); - value -= 1; - - // 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 < minValue) value = minValue; - - setValue(value); - m_property->setValue(getValue()); - notifyTool(); - // update the interface - repaint(); -} - -//----------------------------------------------------------------------------- - void ToolOptionIntSlider::onValueChanged(bool isDragging) { m_property->setValue(getValue()); notifyTool(); @@ -627,7 +357,7 @@ void ToolOptionCombo::loadEntries() { }"); } } - int tmpWidth = fontMetrics().width(items[i].UIName); + int tmpWidth = fontMetrics().width(items[i].UIName); if (tmpWidth > maxWidth) maxWidth = tmpWidth; } @@ -657,51 +387,6 @@ void ToolOptionCombo::onActivated(int index) { notifyTool(); } -//----------------------------------------------------------------------------- - -void ToolOptionCombo::doShowPopup() { - if (Preferences::instance()->getDropdownShortcutsCycleOptions()) { - const TEnumProperty::Range &range = m_property->getRange(); - int theIndex = currentIndex() + 1; - if (theIndex >= (int)range.size()) theIndex = 0; - doOnActivated(theIndex); - } else { - if (isVisible()) showPopup(); - } -} - -//----------------------------------------------------------------------------- - -void ToolOptionCombo::doOnActivated(int index) { - if (m_toolHandle && m_toolHandle->getTool() != m_tool) return; - // active only if the belonging combo-viewer is visible - if (!isInVisibleViewer(this)) return; - bool cycleOptions = - Preferences::instance()->getDropdownShortcutsCycleOptions(); - // Just move the index if the first item is not "Normal" - if (m_property->indexOf(L"Normal") != 0) { - onActivated(index); - setCurrentIndex(index); - // for updating the cursor - if (m_toolHandle) m_toolHandle->notifyToolChanged(); - return; - } - - // If the first item of this combo box is "Normal", enable shortcut key toggle - // can "back and forth" behavior. - if (currentIndex() == index) { - // estimating that the "Normal" option is located at the index 0 - onActivated(0); - setCurrentIndex(0); - } else { - onActivated(index); - setCurrentIndex(index); - } - - // for updating a cursor without any effect to the tool options - if (m_toolHandle) m_toolHandle->notifyToolCursorTypeChanged(); -} - //============================================================================= ToolOptionFontCombo::ToolOptionFontCombo(TTool *tool, TEnumProperty *property, @@ -739,21 +424,6 @@ void ToolOptionFontCombo::onActivated(int index) { notifyTool(); } -//----------------------------------------------------------------------------- - -void ToolOptionFontCombo::doShowPopup() { - if (!isInVisibleViewer(this)) return; - if (Preferences::instance()->getDropdownShortcutsCycleOptions()) { - const TEnumProperty::Range &range = m_property->getRange(); - int theIndex = currentIndex() + 1; - if (theIndex >= (int)range.size()) theIndex = 0; - onActivated(theIndex); - setCurrentIndex(theIndex); - } else { - if (isVisible()) showPopup(); - } -} - //============================================================================= ToolOptionPopupButton::ToolOptionPopupButton(TTool *tool, @@ -797,22 +467,10 @@ void ToolOptionPopupButton::onActivated(int index) { //----------------------------------------------------------------------------- -void ToolOptionPopupButton::doShowPopup() { - if (isVisible()) showMenu(); -} - -//----------------------------------------------------------------------------- - void ToolOptionPopupButton::doSetCurrentIndex(int index) { if (isVisible()) setCurrentIndex(index); } -//----------------------------------------------------------------------------- - -void ToolOptionPopupButton::doOnActivated(int index) { - if (isVisible()) onActivated(index); -} - //============================================================================= ToolOptionTextField::ToolOptionTextField(TTool *tool, TStringProperty *property) @@ -1421,8 +1079,8 @@ void PegbarCenterField::onChange(TMeasuredValue *fld, bool addToUndo) { TStageObject *obj = xsh->getStageObject(objId); - double v = fld->getValue(TMeasuredValue::MainUnit); - TPointD center = obj->getCenter(frame); + double v = fld->getValue(TMeasuredValue::MainUnit); + TPointD center = obj->getCenter(frame); if (!m_firstMouseDrag) m_oldCenter = center; if (m_index == 0) center.x = v; @@ -1513,7 +1171,7 @@ PropertyMenuButton::PropertyMenuButton(QWidget *parent, TTool *tool, setIcon(icon); setToolTip(tooltip); - QMenu *menu = new QMenu(tooltip, this); + QMenu *menu = new QMenu(tooltip, this); if (!tooltip.isEmpty()) tooltip = tooltip + " "; QActionGroup *actiongroup = new QActionGroup(this); @@ -1600,13 +1258,13 @@ bool SelectionScaleField::applyChange(bool addToUndo) { using namespace DragSelectionTool; DragTool *scaleTool = createNewScaleTool(m_tool, ScaleType::GLOBAL); double p = getValue(); - if (p == 0) p = 0.00001; - FourPoints points = m_tool->getBBox(); - TPointD center = m_tool->getCenter(); - TPointD p0M = points.getPoint(7); - TPointD p1M = points.getPoint(5); - TPointD pM1 = points.getPoint(6); - TPointD pM0 = points.getPoint(4); + if (p == 0) p = 0.00001; + FourPoints points = m_tool->getBBox(); + TPointD center = m_tool->getCenter(); + TPointD p0M = points.getPoint(7); + TPointD p1M = points.getPoint(5); + TPointD pM1 = points.getPoint(6); + TPointD pM0 = points.getPoint(4); int pointIndex; TPointD sign(1, 1); TPointD scaleFactor = m_tool->m_deformValues.m_scaleValue; diff --git a/toonz/sources/tnztools/tooloptionscontrols.h b/toonz/sources/tnztools/tooloptionscontrols.h index 6698552..074d42a 100644 --- a/toonz/sources/tnztools/tooloptionscontrols.h +++ b/toonz/sources/tnztools/tooloptionscontrols.h @@ -95,8 +95,6 @@ public: ToolOptionCheckbox(TTool *tool, TBoolProperty *property, ToolHandle *toolHandle = 0, QWidget *parent = 0); void updateStatus() override; -public slots: - void doClick(bool); protected: void nextCheckState() override; @@ -117,12 +115,7 @@ public: void updateStatus() override; protected slots: - void onValueChanged(bool isDragging); - void increase(double step = 1.0); - void decrease(double step = 1.0); - void increaseFractional(); - void decreaseFractional(); }; //----------------------------------------------------------------------------- @@ -141,12 +134,7 @@ public: void updateStatus() override; protected slots: - void onValuesChanged(bool isDragging); - void increaseMaxValue(); - void decreaseMaxValue(); - void increaseMinValue(); - void decreaseMinValue(); }; //----------------------------------------------------------------------------- @@ -165,12 +153,7 @@ public: void updateStatus() override; protected slots: - void onValuesChanged(bool isDragging); - void increaseMaxValue(); - void decreaseMaxValue(); - void increaseMinValue(); - void decreaseMinValue(); }; //----------------------------------------------------------------------------- @@ -188,10 +171,7 @@ public: void updateStatus() override; protected slots: - void onValueChanged(bool isDragging); - void increase(); - void decrease(); }; //----------------------------------------------------------------------------- @@ -213,8 +193,6 @@ public slots: void reloadComboBoxList(std::string); void loadEntries(); void onActivated(int); - void doShowPopup(); - void doOnActivated(int); }; //----------------------------------------------------------------------------- @@ -234,9 +212,7 @@ public: TEnumProperty *getProperty() const { return m_property; } public slots: - void onActivated(int); - void doShowPopup(); }; //----------------------------------------------------------------------------- @@ -254,11 +230,8 @@ public: TEnumProperty *getProperty() { return m_property; } public slots: - void onActivated(int); - void doShowPopup(); void doSetCurrentIndex(int); - void doOnActivated(int); }; //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/CMakeLists.txt b/toonz/sources/toonz/CMakeLists.txt index 57407ca..95e5511 100644 --- a/toonz/sources/toonz/CMakeLists.txt +++ b/toonz/sources/toonz/CMakeLists.txt @@ -121,6 +121,7 @@ set(MOC_HEADERS xshtoolbar.h xdtsimportpopup.h expressionreferencemanager.h + tooloptionsshortcutinvoker.h ) if(PLATFORM EQUAL 64) @@ -359,6 +360,7 @@ set(SOURCES xdtsio.cpp xdtsimportpopup.cpp expressionreferencemanager.cpp + tooloptionsshortcutinvoker.cpp # Tracker file dummyprocessor.cpp metnum.cpp diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cpp index 542a796..98de708 100644 --- a/toonz/sources/toonz/mainwindow.cpp +++ b/toonz/sources/toonz/mainwindow.cpp @@ -13,6 +13,7 @@ #include "tapp.h" #include "comboviewerpane.h" #include "startuppopup.h" +#include "tooloptionsshortcutinvoker.h" // TnzTools includes #include "tools/toolcommandids.h" @@ -379,6 +380,10 @@ MainWindow::MainWindow(const QString &argumentLayoutFileName, QWidget *parent, defineActions(); // user defined shortcuts will be loaded here CommandManager::instance()->loadShortcuts(); + + // initialize tool options shortcuts + ToolOptionsShortcutInvoker::instance()->initialize(); + TApp::instance()->getCurrentScene()->setDirtyFlag(false); // La menuBar altro non è che una toolbar @@ -437,126 +442,6 @@ centralWidget->setLayout(centralWidgetLayout);*/ setCommandHandler("MI_ResetRoomLayout", this, &MainWindow::resetRoomsLayout); setCommandHandler(MI_AutoFillToggle, this, &MainWindow::autofillToggle); - /*-- Animate tool + mode switching shortcuts --*/ - setCommandHandler(MI_EditNextMode, this, &MainWindow::toggleEditNextMode); - setCommandHandler(MI_EditPosition, this, &MainWindow::toggleEditPosition); - setCommandHandler(MI_EditRotation, this, &MainWindow::toggleEditRotation); - setCommandHandler(MI_EditScale, this, &MainWindow::toggleEditNextScale); - setCommandHandler(MI_EditShear, this, &MainWindow::toggleEditNextShear); - setCommandHandler(MI_EditCenter, this, &MainWindow::toggleEditNextCenter); - setCommandHandler(MI_EditAll, this, &MainWindow::toggleEditNextAll); - - /*-- Selection tool + type switching shortcuts --*/ - setCommandHandler(MI_SelectionNextType, this, - &MainWindow::toggleSelectionNextType); - setCommandHandler(MI_SelectionRectangular, this, - &MainWindow::toggleSelectionRectangular); - setCommandHandler(MI_SelectionFreehand, this, - &MainWindow::toggleSelectionFreehand); - setCommandHandler(MI_SelectionPolyline, this, - &MainWindow::toggleSelectionPolyline); - - /*-- Geometric tool + shape switching shortcuts --*/ - setCommandHandler(MI_GeometricNextShape, this, - &MainWindow::toggleGeometricNextShape); - setCommandHandler(MI_GeometricRectangle, this, - &MainWindow::toggleGeometricRectangle); - setCommandHandler(MI_GeometricCircle, this, - &MainWindow::toggleGeometricCircle); - setCommandHandler(MI_GeometricEllipse, this, - &MainWindow::toggleGeometricEllipse); - setCommandHandler(MI_GeometricLine, this, &MainWindow::toggleGeometricLine); - setCommandHandler(MI_GeometricPolyline, this, - &MainWindow::toggleGeometricPolyline); - setCommandHandler(MI_GeometricArc, this, &MainWindow::toggleGeometricArc); - setCommandHandler(MI_GeometricMultiArc, this, - &MainWindow::toggleGeometricMultiArc); - setCommandHandler(MI_GeometricPolygon, this, - &MainWindow::toggleGeometricPolygon); - - /*-- Type tool + style switching shortcuts --*/ - setCommandHandler(MI_TypeNextStyle, this, &MainWindow::toggleTypeNextStyle); - setCommandHandler(MI_TypeOblique, this, &MainWindow::toggleTypeOblique); - setCommandHandler(MI_TypeRegular, this, &MainWindow::toggleTypeRegular); - setCommandHandler(MI_TypeBoldOblique, this, - &MainWindow::toggleTypeBoldOblique); - setCommandHandler(MI_TypeBold, this, &MainWindow::toggleTypeBold); - - /*-- Fill tool + type/mode switching shortcuts --*/ - setCommandHandler(MI_FillNextType, this, &MainWindow::toggleFillNextType); - setCommandHandler(MI_FillNormal, this, &MainWindow::toggleFillNormal); - setCommandHandler(MI_FillRectangular, this, - &MainWindow::toggleFillRectangular); - setCommandHandler(MI_FillFreehand, this, &MainWindow::toggleFillFreehand); - setCommandHandler(MI_FillPolyline, this, &MainWindow::toggleFillPolyline); - setCommandHandler(MI_FillNextMode, this, &MainWindow::toggleFillNextMode); - setCommandHandler(MI_FillAreas, this, &MainWindow::toggleFillAreas); - setCommandHandler(MI_FillLines, this, &MainWindow::toggleFillLines); - setCommandHandler(MI_FillLinesAndAreas, this, - &MainWindow::toggleFillLinesAndAreas); - - /*-- Eraser tool + type switching shortcuts --*/ - setCommandHandler(MI_EraserNextType, this, &MainWindow::toggleEraserNextType); - setCommandHandler(MI_EraserNormal, this, &MainWindow::toggleEraserNormal); - setCommandHandler(MI_EraserRectangular, this, - &MainWindow::toggleEraserRectangular); - setCommandHandler(MI_EraserFreehand, this, &MainWindow::toggleEraserFreehand); - setCommandHandler(MI_EraserPolyline, this, &MainWindow::toggleEraserPolyline); - setCommandHandler(MI_EraserSegment, this, &MainWindow::toggleEraserSegment); - - /*-- Tape tool + type/mode switching shortcuts --*/ - setCommandHandler(MI_TapeNextType, this, &MainWindow::toggleTapeNextType); - setCommandHandler(MI_TapeNormal, this, &MainWindow::toggleTapeNormal); - setCommandHandler(MI_TapeRectangular, this, - &MainWindow::toggleTapeRectangular); - setCommandHandler(MI_TapeNextMode, this, &MainWindow::toggleTapeNextMode); - setCommandHandler(MI_TapeEndpointToEndpoint, this, - &MainWindow::toggleTapeEndpointToEndpoint); - setCommandHandler(MI_TapeEndpointToLine, this, - &MainWindow::toggleTapeEndpointToLine); - setCommandHandler(MI_TapeLineToLine, this, &MainWindow::toggleTapeLineToLine); - - /*-- Style Picker tool + mode switching shortcuts --*/ - setCommandHandler(MI_PickStyleNextMode, this, - &MainWindow::togglePickStyleNextMode); - setCommandHandler(MI_PickStyleAreas, this, &MainWindow::togglePickStyleAreas); - setCommandHandler(MI_PickStyleLines, this, &MainWindow::togglePickStyleLines); - setCommandHandler(MI_PickStyleLinesAndAreas, this, - &MainWindow::togglePickStyleLinesAndAreas); - - /*-- RGB Picker tool + type switching shortcuts --*/ - setCommandHandler(MI_RGBPickerNextType, this, - &MainWindow::toggleRGBPickerNextType); - setCommandHandler(MI_RGBPickerNormal, this, - &MainWindow::toggleRGBPickerNormal); - setCommandHandler(MI_RGBPickerRectangular, this, - &MainWindow::toggleRGBPickerRectangular); - setCommandHandler(MI_RGBPickerFreehand, this, - &MainWindow::toggleRGBPickerFreehand); - setCommandHandler(MI_RGBPickerPolyline, this, - &MainWindow::toggleRGBPickerPolyline); - - /*-- Skeleton tool + mode switching shortcuts --*/ - setCommandHandler(MI_SkeletonNextMode, this, - &MainWindow::ToggleSkeletonNextMode); - setCommandHandler(MI_SkeletonBuildSkeleton, this, - &MainWindow::ToggleSkeletonBuildSkeleton); - setCommandHandler(MI_SkeletonAnimate, this, - &MainWindow::ToggleSkeletonAnimate); - setCommandHandler(MI_SkeletonInverseKinematics, this, - &MainWindow::ToggleSkeletonInverseKinematics); - - /*-- Plastic tool + mode switching shortcuts --*/ - setCommandHandler(MI_PlasticNextMode, this, - &MainWindow::TogglePlasticNextMode); - setCommandHandler(MI_PlasticEditMesh, this, - &MainWindow::TogglePlasticEditMesh); - setCommandHandler(MI_PlasticPaintRigid, this, - &MainWindow::TogglePlasticPaintRigid); - setCommandHandler(MI_PlasticBuildSkeleton, this, - &MainWindow::TogglePlasticBuildSkeleton); - setCommandHandler(MI_PlasticAnimate, this, &MainWindow::TogglePlasticAnimate); - setCommandHandler(MI_About, this, &MainWindow::onAbout); setCommandHandler(MI_OpenOnlineManual, this, &MainWindow::onOpenOnlineManual); setCommandHandler(MI_OpenWhatsNew, this, &MainWindow::onOpenWhatsNew); @@ -2950,480 +2835,6 @@ void MainWindow::onInk1CheckTriggered(bool on) { } //----------------------------------------------------------------------------- -/*-- Animate tool + mode switching shortcuts --*/ -void MainWindow::toggleEditNextMode() { - if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Edit) - CommandManager::instance() - ->getAction("A_ToolOption_EditToolActiveAxis") - ->trigger(); - else - CommandManager::instance()->getAction(T_Edit)->trigger(); -} - -void MainWindow::toggleEditPosition() { - CommandManager::instance()->getAction(T_Edit)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_EditToolActiveAxis:Position") - ->trigger(); -} - -void MainWindow::toggleEditRotation() { - CommandManager::instance()->getAction(T_Edit)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_EditToolActiveAxis:Rotation") - ->trigger(); -} - -void MainWindow::toggleEditNextScale() { - CommandManager::instance()->getAction(T_Edit)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_EditToolActiveAxis:Scale") - ->trigger(); -} - -void MainWindow::toggleEditNextShear() { - CommandManager::instance()->getAction(T_Edit)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_EditToolActiveAxis:Shear") - ->trigger(); -} - -void MainWindow::toggleEditNextCenter() { - CommandManager::instance()->getAction(T_Edit)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_EditToolActiveAxis:Center") - ->trigger(); -} - -void MainWindow::toggleEditNextAll() { - CommandManager::instance()->getAction(T_Edit)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_EditToolActiveAxis:All") - ->trigger(); -} - -//--------------------------------------------------------------------------------------- -/*-- Selection tool + type switching shortcuts --*/ -void MainWindow::toggleSelectionNextType() { - if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Selection) - CommandManager::instance()->getAction("A_ToolOption_Type")->trigger(); - else - CommandManager::instance()->getAction(T_Selection)->trigger(); -} - -void MainWindow::toggleSelectionRectangular() { - CommandManager::instance()->getAction(T_Selection)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Type:Rectangular") - ->trigger(); -} - -void MainWindow::toggleSelectionFreehand() { - CommandManager::instance()->getAction(T_Selection)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Type:Freehand") - ->trigger(); -} - -void MainWindow::toggleSelectionPolyline() { - CommandManager::instance()->getAction(T_Selection)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Type:Polyline") - ->trigger(); -} - -//--------------------------------------------------------------------------------------- -/*-- Geometric tool + shape switching shortcuts --*/ -void MainWindow::toggleGeometricNextShape() { - if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Geometric) - CommandManager::instance() - ->getAction("A_ToolOption_GeometricShape") - ->trigger(); - else - CommandManager::instance()->getAction(T_Geometric)->trigger(); -} - -void MainWindow::toggleGeometricRectangle() { - CommandManager::instance()->getAction(T_Geometric)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_GeometricShape:Rectangle") - ->trigger(); -} - -void MainWindow::toggleGeometricCircle() { - CommandManager::instance()->getAction(T_Geometric)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_GeometricShape:Circle") - ->trigger(); -} - -void MainWindow::toggleGeometricEllipse() { - CommandManager::instance()->getAction(T_Geometric)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_GeometricShape:Ellipse") - ->trigger(); -} - -void MainWindow::toggleGeometricLine() { - CommandManager::instance()->getAction(T_Geometric)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_GeometricShape:Line") - ->trigger(); -} - -void MainWindow::toggleGeometricPolyline() { - CommandManager::instance()->getAction(T_Geometric)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_GeometricShape:Polyline") - ->trigger(); -} - -void MainWindow::toggleGeometricArc() { - CommandManager::instance()->getAction(T_Geometric)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_GeometricShape:Arc") - ->trigger(); -} - -void MainWindow::toggleGeometricMultiArc() { - CommandManager::instance()->getAction(T_Geometric)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_GeometricShape:MultiArc") - ->trigger(); -} - -void MainWindow::toggleGeometricPolygon() { - CommandManager::instance()->getAction(T_Geometric)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_GeometricShape:Polygon") - ->trigger(); -} -//--------------------------------------------------------------------------------------- -/*-- Type tool + mode switching shortcuts --*/ -void MainWindow::toggleTypeNextStyle() { - if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Type) - CommandManager::instance()->getAction("A_ToolOption_TypeStyle")->trigger(); - else - CommandManager::instance()->getAction(T_Type)->trigger(); -} - -void MainWindow::toggleTypeOblique() { - CommandManager::instance()->getAction(T_Type)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_TypeStyle:Oblique") - ->trigger(); -} - -void MainWindow::toggleTypeRegular() { - CommandManager::instance()->getAction(T_Type)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_TypeStyle:Regular") - ->trigger(); -} - -void MainWindow::toggleTypeBoldOblique() { - CommandManager::instance()->getAction(T_Type)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_TypeStyle:Bold Oblique") - ->trigger(); -} - -void MainWindow::toggleTypeBold() { - CommandManager::instance()->getAction(T_Type)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_TypeStyle:Bold") - ->trigger(); -} - -//--------------------------------------------------------------------------------------- -/*-- Fill tool + type/mode switching shortcuts --*/ -void MainWindow::toggleFillNextType() { - if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Fill) - CommandManager::instance()->getAction("A_ToolOption_Type")->trigger(); - else - CommandManager::instance()->getAction(T_Fill)->trigger(); -} - -void MainWindow::toggleFillNormal() { - CommandManager::instance()->getAction(T_Fill)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); -} - -void MainWindow::toggleFillRectangular() { - CommandManager::instance()->getAction(T_Fill)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Type:Rectangular") - ->trigger(); -} - -void MainWindow::toggleFillFreehand() { - CommandManager::instance()->getAction(T_Fill)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Type:Freehand") - ->trigger(); -} - -void MainWindow::toggleFillPolyline() { - CommandManager::instance()->getAction(T_Fill)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Type:Polyline") - ->trigger(); -} - -void MainWindow::toggleFillNextMode() { - if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Fill) - CommandManager::instance()->getAction("A_ToolOption_Mode")->trigger(); - else - CommandManager::instance()->getAction(T_Fill)->trigger(); -} - -void MainWindow::toggleFillAreas() { - CommandManager::instance()->getAction(T_Fill)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Mode:Areas")->trigger(); -} - -void MainWindow::toggleFillLines() { - CommandManager::instance()->getAction(T_Fill)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Mode:Lines")->trigger(); -} - -void MainWindow::toggleFillLinesAndAreas() { - CommandManager::instance()->getAction(T_Fill)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Mode:Lines & Areas") - ->trigger(); -} - -//--------------------------------------------------------------------------------------- -/*-- Eraser tool + type switching shortcuts --*/ -void MainWindow::toggleEraserNextType() { - if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Eraser) - CommandManager::instance()->getAction("A_ToolOption_Type")->trigger(); - else - CommandManager::instance()->getAction(T_Eraser)->trigger(); -} - -void MainWindow::toggleEraserNormal() { - CommandManager::instance()->getAction(T_Eraser)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); -} - -void MainWindow::toggleEraserRectangular() { - CommandManager::instance()->getAction(T_Eraser)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Type:Rectangular") - ->trigger(); -} - -void MainWindow::toggleEraserFreehand() { - CommandManager::instance()->getAction(T_Eraser)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Type:Freehand") - ->trigger(); -} - -void MainWindow::toggleEraserPolyline() { - CommandManager::instance()->getAction(T_Eraser)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Type:Polyline") - ->trigger(); -} - -void MainWindow::toggleEraserSegment() { - CommandManager::instance()->getAction(T_Eraser)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Type:Segment")->trigger(); -} -//--------------------------------------------------------------------------------------- -/*-- Tape tool + type/mode switching shortcuts --*/ -void MainWindow::toggleTapeNextType() { - if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Tape) - CommandManager::instance()->getAction("A_ToolOption_Type")->trigger(); - else - CommandManager::instance()->getAction(T_Tape)->trigger(); -} - -void MainWindow::toggleTapeNormal() { - CommandManager::instance()->getAction(T_Tape)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); -} - -void MainWindow::toggleTapeRectangular() { - CommandManager::instance()->getAction(T_Tape)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Type:Rectangular") - ->trigger(); -} - -void MainWindow::toggleTapeNextMode() { - if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Tape) - CommandManager::instance()->getAction("A_ToolOption_Mode")->trigger(); - else - CommandManager::instance()->getAction(T_Tape)->trigger(); -} - -void MainWindow::toggleTapeEndpointToEndpoint() { - CommandManager::instance()->getAction(T_Tape)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Mode:Endpoint to Endpoint") - ->trigger(); -} - -void MainWindow::toggleTapeEndpointToLine() { - CommandManager::instance()->getAction(T_Tape)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Mode:Endpoint to Line") - ->trigger(); -} - -void MainWindow::toggleTapeLineToLine() { - CommandManager::instance()->getAction(T_Tape)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Mode:Line to Line") - ->trigger(); -} - -//--------------------------------------------------------------------------------------- -/*-- Style Picker tool + mode switching shortcuts --*/ -void MainWindow::togglePickStyleNextMode() { - if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_StylePicker) - CommandManager::instance()->getAction("A_ToolOption_Mode")->trigger(); - else - CommandManager::instance()->getAction(T_StylePicker)->trigger(); -} - -void MainWindow::togglePickStyleAreas() { - CommandManager::instance()->getAction(T_StylePicker)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Mode:Areas")->trigger(); -} - -void MainWindow::togglePickStyleLines() { - CommandManager::instance()->getAction(T_StylePicker)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Mode:Lines")->trigger(); -} - -void MainWindow::togglePickStyleLinesAndAreas() { - CommandManager::instance()->getAction(T_StylePicker)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Mode:Lines & Areas") - ->trigger(); -} -//----------------------------------------------------------------------------- -/*-- RGB Picker tool + type switching shortcuts --*/ -void MainWindow::toggleRGBPickerNextType() { - if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_RGBPicker) - CommandManager::instance()->getAction("A_ToolOption_Type")->trigger(); - else - CommandManager::instance()->getAction(T_RGBPicker)->trigger(); -} - -void MainWindow::toggleRGBPickerNormal() { - CommandManager::instance()->getAction(T_RGBPicker)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); -} - -void MainWindow::toggleRGBPickerRectangular() { - CommandManager::instance()->getAction(T_RGBPicker)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Type:Rectangular") - ->trigger(); -} - -void MainWindow::toggleRGBPickerFreehand() { - CommandManager::instance()->getAction(T_RGBPicker)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Type:Freehand") - ->trigger(); -} - -void MainWindow::toggleRGBPickerPolyline() { - CommandManager::instance()->getAction(T_RGBPicker)->trigger(); - CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_Type:Polyline") - ->trigger(); -} -//----------------------------------------------------------------------------- -/*-- Skeleton tool + type switching shortcuts --*/ -void MainWindow::ToggleSkeletonNextMode() { - if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Skeleton) - CommandManager::instance() - ->getAction("A_ToolOption_SkeletonMode") - ->trigger(); - else - CommandManager::instance()->getAction(T_Skeleton)->trigger(); -} - -void MainWindow::ToggleSkeletonBuildSkeleton() { - CommandManager::instance()->getAction(T_Skeleton)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_SkeletonMode:Build Skeleton") - ->trigger(); -} - -void MainWindow::ToggleSkeletonAnimate() { - CommandManager::instance()->getAction(T_Skeleton)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_SkeletonMode:Animate") - ->trigger(); -} - -void MainWindow::ToggleSkeletonInverseKinematics() { - CommandManager::instance()->getAction(T_Skeleton)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_SkeletonMode:Inverse Kinematics") - ->trigger(); -} - -//----------------------------------------------------------------------------- -/*-- Plastic tool + mode switching shortcuts --*/ -void MainWindow::TogglePlasticNextMode() { - if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Plastic) - CommandManager::instance() - ->getAction("A_ToolOption_SkeletonMode") - ->trigger(); - else - CommandManager::instance()->getAction(T_Plastic)->trigger(); -} - -void MainWindow::TogglePlasticEditMesh() { - CommandManager::instance()->getAction(T_Plastic)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_SkeletonMode:Edit Mesh") - ->trigger(); -} - -void MainWindow::TogglePlasticPaintRigid() { - CommandManager::instance()->getAction(T_Plastic)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_SkeletonMode:Paint Rigid") - ->trigger(); -} - -void MainWindow::TogglePlasticBuildSkeleton() { - CommandManager::instance()->getAction(T_Plastic)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_SkeletonMode:Build Skeleton") - ->trigger(); -} - -void MainWindow::TogglePlasticAnimate() { - CommandManager::instance()->getAction(T_Plastic)->trigger(); - CommandManager::instance() - ->getAction("A_ToolOption_SkeletonMode:Animate") - ->trigger(); -} - -//----------------------------------------------------------------------------- void MainWindow::onNewVectorLevelButtonPressed() { int defaultLevelType = Preferences::instance()->getDefLevelType(); diff --git a/toonz/sources/toonz/mainwindow.h b/toonz/sources/toonz/mainwindow.h index cb2ec01..cd7839b 100644 --- a/toonz/sources/toonz/mainwindow.h +++ b/toonz/sources/toonz/mainwindow.h @@ -107,93 +107,6 @@ public: Room *getCurrentRoom() const; void refreshWriteSettings(); - /*-- Animate tool + mode switching shortcuts --*/ - void toggleEditNextMode(); - void toggleEditPosition(); - void toggleEditRotation(); - void toggleEditNextScale(); - void toggleEditNextShear(); - void toggleEditNextCenter(); - void toggleEditNextAll(); - - /*-- Selection tool + mode switching shortcuts --*/ - void toggleSelectionNextType(); - void toggleSelectionRectangular(); - void toggleSelectionFreehand(); - void toggleSelectionPolyline(); - - /*-- Geometric tool + shape switching shortcuts --*/ - void toggleGeometricNextShape(); - void toggleGeometricRectangle(); - void toggleGeometricCircle(); - void toggleGeometricEllipse(); - void toggleGeometricLine(); - void toggleGeometricPolyline(); - void toggleGeometricArc(); - void toggleGeometricMultiArc(); - void toggleGeometricPolygon(); - - /*-- Type tool + style switching shortcuts --*/ - void toggleTypeNextStyle(); - void toggleTypeOblique(); - void toggleTypeRegular(); - void toggleTypeBoldOblique(); - void toggleTypeBold(); - - /*-- Fill tool + mode switching shortcuts --*/ - void toggleFillNextType(); - void toggleFillNormal(); - void toggleFillRectangular(); - void toggleFillFreehand(); - void toggleFillPolyline(); - void toggleFillNextMode(); - void toggleFillAreas(); - void toggleFillLines(); - void toggleFillLinesAndAreas(); - - /*-- Eraser tool + type switching shortcuts --*/ - void toggleEraserNextType(); - void toggleEraserNormal(); - void toggleEraserRectangular(); - void toggleEraserFreehand(); - void toggleEraserPolyline(); - void toggleEraserSegment(); - - /*-- Tape tool + type/mode switching shortcuts --*/ - void toggleTapeNextType(); - void toggleTapeNormal(); - void toggleTapeRectangular(); - void toggleTapeNextMode(); - void toggleTapeEndpointToEndpoint(); - void toggleTapeEndpointToLine(); - void toggleTapeLineToLine(); - - /*-- Style Picker tool + mode switching shortcuts --*/ - void togglePickStyleNextMode(); - void togglePickStyleAreas(); - void togglePickStyleLines(); - void togglePickStyleLinesAndAreas(); - - /*-- RGB Picker tool + type switching shortcuts --*/ - void toggleRGBPickerNextType(); - void toggleRGBPickerNormal(); - void toggleRGBPickerRectangular(); - void toggleRGBPickerFreehand(); - void toggleRGBPickerPolyline(); - - /*-- Skeleton tool + mode switching shortcuts --*/ - void ToggleSkeletonNextMode(); - void ToggleSkeletonBuildSkeleton(); - void ToggleSkeletonAnimate(); - void ToggleSkeletonInverseKinematics(); - - /*-- Plastic tool + mode switching shortcuts --*/ - void TogglePlasticNextMode(); - void TogglePlasticEditMesh(); - void TogglePlasticPaintRigid(); - void TogglePlasticBuildSkeleton(); - void TogglePlasticAnimate(); - void onNewVectorLevelButtonPressed(); void onNewToonzRasterLevelButtonPressed(); void onNewRasterLevelButtonPressed(); diff --git a/toonz/sources/toonz/preferencespopup.cpp b/toonz/sources/toonz/preferencespopup.cpp index 32ffa70..0410e20 100644 --- a/toonz/sources/toonz/preferencespopup.cpp +++ b/toonz/sources/toonz/preferencespopup.cpp @@ -1115,7 +1115,7 @@ QString PreferencesPopup::getUIString(PreferencesItemId id) { tr("Use higher DPI for calculations - Slower but more accurate")}, // Tools - {dropdownShortcutsCycleOptions, tr("Dropdown Shortcuts:")}, + // {dropdownShortcutsCycleOptions, tr("Dropdown Shortcuts:")}, // removed {FillOnlysavebox, tr("Use the TLV Savebox to Limit Filling Operations")}, {multiLayerStylePickerEnabled, tr("Multi Layer Style Picker: Switch Levels by Picking")}, @@ -1257,9 +1257,9 @@ QList PreferencesPopup::getComboItemList( {{tr("Incremental"), 0}, {tr("Use Xsheet as Animation Sheet"), 1}}}, {vectorSnappingTarget, {{tr("Strokes"), 0}, {tr("Guides"), 1}, {tr("All"), 2}}}, - {dropdownShortcutsCycleOptions, - {{tr("Open the dropdown to display all options"), 0}, - {tr("Cycle through the available options"), 1}}}, + //{dropdownShortcutsCycleOptions, + // {{tr("Open the dropdown to display all options"), 0}, + // {tr("Cycle through the available options"), 1}}}, {cursorBrushType, {{tr("Small"), "Small"}, {tr("Large"), "Large"}, @@ -1749,8 +1749,8 @@ QWidget* PreferencesPopup::createToolsPage() { QGridLayout* lay = new QGridLayout(); setupLayout(lay); - insertUI(dropdownShortcutsCycleOptions, lay, - getComboItemList(dropdownShortcutsCycleOptions)); + // insertUI(dropdownShortcutsCycleOptions, lay, + // getComboItemList(dropdownShortcutsCycleOptions)); insertUI(FillOnlysavebox, lay); insertUI(multiLayerStylePickerEnabled, lay); QGridLayout* cursorOptionsLay = insertGroupBox(tr("Cursor Options"), lay); diff --git a/toonz/sources/toonz/tooloptionsshortcutinvoker.cpp b/toonz/sources/toonz/tooloptionsshortcutinvoker.cpp new file mode 100644 index 0000000..f181fe9 --- /dev/null +++ b/toonz/sources/toonz/tooloptionsshortcutinvoker.cpp @@ -0,0 +1,1101 @@ +#include "tooloptionsshortcutinvoker.h" + +#include "tapp.h" +#include "tools/toolhandle.h" + +#include "tools/toolcommandids.h" +#include "tools/tool.h" + +#include "toonzqt/menubarcommand.h" +#include "menubarcommandids.h" + +#include + +using namespace ToolOptionsShortcutWorker; + +//----------------------------------------------------------------- +ToolOptionShortcutConnector::ToolOptionShortcutConnector(TTool* tool) + : m_tool(tool) {} + +//----------------------------------------------------------------- + +void ToolOptionShortcutConnector::visit(TDoubleProperty* p) { + if (p->getName() != "Size:" && p->getName() != "ModifierSize" && + p->getName() != "Hardness:") + return; + + ToolOptionsShortcutInvoker* invoker = ToolOptionsShortcutInvoker::instance(); + DoubleWorker* worker = new DoubleWorker(invoker, m_tool, p); + CommandManager* cm = CommandManager::instance(); + QAction* a; + if (p->getName() == "Size:") { + a = cm->getAction("A_IncreaseMaxBrushThickness"); + QObject::connect(a, SIGNAL(triggered()), worker, SLOT(increase())); + a = cm->getAction("A_DecreaseMaxBrushThickness"); + QObject::connect(a, SIGNAL(triggered()), worker, SLOT(decrease())); + } else if (p->getName() == "ModifierSize") { + a = cm->getAction("A_IncreaseMaxBrushThickness"); + QObject::connect(a, SIGNAL(triggered()), worker, + SLOT(increaseFractional())); + a = cm->getAction("A_DecreaseMaxBrushThickness"); + QObject::connect(a, SIGNAL(triggered()), worker, + SLOT(decreaseFractional())); + } else if (p->getName() == "Hardness:") { + a = cm->getAction("A_IncreaseBrushHardness"); + QObject::connect(a, SIGNAL(triggered()), worker, SLOT(increase())); + a = cm->getAction("A_DecreaseBrushHardness"); + QObject::connect(a, SIGNAL(triggered()), worker, SLOT(decrease())); + } +} + +//----------------------------------------------------------------- + +void ToolOptionShortcutConnector::visit(TDoublePairProperty* p) { + if (p->getName() != "Size:" && p->getName() != "Size") return; + + ToolOptionsShortcutInvoker* invoker = ToolOptionsShortcutInvoker::instance(); + DoublePairWorker* worker = new DoublePairWorker(invoker, m_tool, p); + CommandManager* cm = CommandManager::instance(); + QAction* a; + a = cm->getAction("A_IncreaseMaxBrushThickness"); + QObject::connect(a, SIGNAL(triggered()), worker, SLOT(increaseMaxValue())); + a = cm->getAction("A_DecreaseMaxBrushThickness"); + QObject::connect(a, SIGNAL(triggered()), worker, SLOT(decreaseMaxValue())); + + a = cm->getAction("A_IncreaseMinBrushThickness"); + QObject::connect(a, SIGNAL(triggered()), worker, SLOT(increaseMinValue())); + a = cm->getAction("A_DecreaseMinBrushThickness"); + QObject::connect(a, SIGNAL(triggered()), worker, SLOT(decreaseMinValue())); +} + +//----------------------------------------------------------------- + +void ToolOptionShortcutConnector::visit(TIntPairProperty* p) { + if (p->getName() != "Size:" && p->getName() != "Thickness" && + p->getName() != "Size") + return; + + ToolOptionsShortcutInvoker* invoker = ToolOptionsShortcutInvoker::instance(); + IntPairWorker* worker = new IntPairWorker(invoker, m_tool, p); + CommandManager* cm = CommandManager::instance(); + QAction* a; + a = cm->getAction("A_IncreaseMaxBrushThickness"); + QObject::connect(a, SIGNAL(triggered()), worker, SLOT(increaseMaxValue())); + a = cm->getAction("A_DecreaseMaxBrushThickness"); + QObject::connect(a, SIGNAL(triggered()), worker, SLOT(decreaseMaxValue())); + + a = cm->getAction("A_IncreaseMinBrushThickness"); + QObject::connect(a, SIGNAL(triggered()), worker, SLOT(increaseMinValue())); + a = cm->getAction("A_DecreaseMinBrushThickness"); + QObject::connect(a, SIGNAL(triggered()), worker, SLOT(decreaseMinValue())); +} + +//----------------------------------------------------------------- + +void ToolOptionShortcutConnector::visit(TIntProperty* p) { + if (p->getName() != "Size:") return; + ToolOptionsShortcutInvoker* invoker = ToolOptionsShortcutInvoker::instance(); + IntWorker* worker = new IntWorker(invoker, m_tool, p); + CommandManager* cm = CommandManager::instance(); + QAction* a; + a = cm->getAction("A_IncreaseMaxBrushThickness"); + QObject::connect(a, SIGNAL(triggered()), worker, SLOT(increase())); + a = cm->getAction("A_DecreaseMaxBrushThickness"); + QObject::connect(a, SIGNAL(triggered()), worker, SLOT(decrease())); +} + +//----------------------------------------------------------------- + +void ToolOptionShortcutConnector::visit(TBoolProperty* p) { + if (p->getId() == "") return; + std::string actionName = "A_ToolOption_" + p->getId(); + QAction* a = CommandManager::instance()->getAction(actionName.c_str()); + if (!a) return; + ToolOptionsShortcutInvoker* invoker = ToolOptionsShortcutInvoker::instance(); + 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))); + + invoker->registerCheckProperty(m_tool, worker); +} + +//----------------------------------------------------------------- + +void ToolOptionShortcutConnector::visit(TEnumProperty* p) { + if (p->getId() == "") return; + + ToolOptionsShortcutInvoker* invoker = ToolOptionsShortcutInvoker::instance(); + EnumWorker* worker = new EnumWorker(invoker, m_tool, p); + bool hasAction = false; + 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())); + hasAction = true; + } + + TEnumProperty::Range range = p->getRange(); + TEnumProperty::Range::iterator it; + QSignalMapper* signalMapper = 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); + hasAction = true; + } + } + + if (!hasAction) delete worker; +} + +//============================================================================= + +void DoubleWorker::increase(double step) { + // 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(); + value += step; + if (value > range.second) value = range.second; + m_property->setValue(value); + ToolOptionsShortcutInvoker::instance()->notifyTool(m_tool, m_property); + TApp::instance()->getCurrentTool()->notifyToolChanged(); +} + +//----------------------------------------------------------------- + +void DoubleWorker::increaseFractional() { increase(0.06); } + +//----------------------------------------------------------------- + +void DoubleWorker::decrease(double step) { + // 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(); + value -= step; + if (value < range.first) value = range.first; + m_property->setValue(value); + ToolOptionsShortcutInvoker::instance()->notifyTool(m_tool, m_property); + TApp::instance()->getCurrentTool()->notifyToolChanged(); +} + +//----------------------------------------------------------------- + +void DoubleWorker::decreaseFractional() { decrease(0.06); } + +//============================================================================= + +void DoublePairWorker::increaseMaxValue() { + // 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(); + value.second += 1; + if (value.second > range.second) value.second = range.second; + m_property->setValue(value); + ToolOptionsShortcutInvoker::instance()->notifyTool(m_tool, m_property); + TApp::instance()->getCurrentTool()->notifyToolChanged(); +} + +//----------------------------------------------------------------- + +void DoublePairWorker::decreaseMaxValue() { + // 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; + if (value.second < value.first) value.second = value.first; + m_property->setValue(value); + ToolOptionsShortcutInvoker::instance()->notifyTool(m_tool, m_property); + TApp::instance()->getCurrentTool()->notifyToolChanged(); +} + +//----------------------------------------------------------------- + +void DoublePairWorker::increaseMinValue() { + // 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; + if (value.first > value.second) value.first = value.second; + m_property->setValue(value); + ToolOptionsShortcutInvoker::instance()->notifyTool(m_tool, m_property); + TApp::instance()->getCurrentTool()->notifyToolChanged(); +} + +//----------------------------------------------------------------- + +void DoublePairWorker::decreaseMinValue() { + // 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(); + value.first -= 1; + if (value.first < range.first) value.first = range.first; + m_property->setValue(value); + ToolOptionsShortcutInvoker::instance()->notifyTool(m_tool, m_property); + TApp::instance()->getCurrentTool()->notifyToolChanged(); +} + +//============================================================================= + +void IntPairWorker::increaseMaxValue() { + // 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 + if (value.second == 3 && m_tool->isPencilModeActive()) value.second += 1; + + if (value.second > range.second) value.second = range.second; + m_property->setValue(value); + ToolOptionsShortcutInvoker::instance()->notifyTool(m_tool, m_property); + TApp::instance()->getCurrentTool()->notifyToolChanged(); +} + +//----------------------------------------------------------------- + +void IntPairWorker::decreaseMaxValue() { + // 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 + if (value.second == 3 && m_tool->isPencilModeActive()) value.second -= 1; + + if (value.second < value.first) value.second = value.first; + m_property->setValue(value); + ToolOptionsShortcutInvoker::instance()->notifyTool(m_tool, m_property); + TApp::instance()->getCurrentTool()->notifyToolChanged(); +} + +//----------------------------------------------------------------- + +void IntPairWorker::increaseMinValue() { + // 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; + if (value.first > value.second) value.first = value.second; + m_property->setValue(value); + ToolOptionsShortcutInvoker::instance()->notifyTool(m_tool, m_property); + TApp::instance()->getCurrentTool()->notifyToolChanged(); +} + +//----------------------------------------------------------------- + +void IntPairWorker::decreaseMinValue() { + // 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.first -= 1; + if (value.first < range.first) value.first = range.first; + m_property->setValue(value); + ToolOptionsShortcutInvoker::instance()->notifyTool(m_tool, m_property); + TApp::instance()->getCurrentTool()->notifyToolChanged(); +} + +//============================================================================= + +void IntWorker::increase() { + // 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 + if (value == 3 && m_tool->isPencilModeActive()) value += 1; + + if (value > range.second) value = range.second; + m_property->setValue(value); + ToolOptionsShortcutInvoker::instance()->notifyTool(m_tool, m_property); + TApp::instance()->getCurrentTool()->notifyToolChanged(); +} + +//----------------------------------------------------------------- + +void IntWorker::decrease() { + // 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 + if (value == 3 && m_tool->isPencilModeActive()) value -= 1; + + if (value < range.first) value = range.first; + m_property->setValue(value); + ToolOptionsShortcutInvoker::instance()->notifyTool(m_tool, m_property); + TApp::instance()->getCurrentTool()->notifyToolChanged(); +} + +//============================================================================= + +void BoolWorker::doCheck(bool checked) { + // ignore if it is not the current tool + if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return; + + if (m_property->getValue() == checked) return; + + m_property->setValue(checked); + ToolOptionsShortcutInvoker::instance()->notifyTool(m_tool, m_property); + TApp::instance()->getCurrentTool()->notifyToolChanged(); +} + +//----------------------------------------------------------------- + +void BoolWorker::syncActionState() { + if (m_action && m_action->isCheckable() && + m_action->isChecked() != m_property->getValue()) + m_action->setChecked(m_property->getValue()); +} + +//============================================================================= + +void EnumWorker::cycleOptions() { + // 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; + if (theIndex >= (int)range.size()) theIndex = 0; + doOnActivated(theIndex); +} + +//----------------------------------------------------------------- + +void EnumWorker::doOnActivated(int index) { + // ignore if it is not the current tool + if (TApp::instance()->getCurrentTool()->getTool() != m_tool) return; + + // check range + const TEnumProperty::Range& range = m_property->getRange(); + if (index < 0 || index >= (int)range.size()) return; + + // Just move the index if the first item is not "Normal" + if (m_property->indexOf(L"Normal") != 0) { + m_property->setIndex(index); + ToolOptionsShortcutInvoker::instance()->notifyTool(m_tool, m_property); + TApp::instance()->getCurrentTool()->notifyToolChanged(); + return; + } + + // 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 + m_property->setIndex(0); + } else { + m_property->setIndex(index); + } + + ToolOptionsShortcutInvoker::instance()->notifyTool(m_tool, m_property); + TApp::instance()->getCurrentTool()->notifyToolChanged(); +} + +//============================================================================= + +ToolOptionsShortcutInvoker* ToolOptionsShortcutInvoker::instance() { + static ToolOptionsShortcutInvoker _instance; + return &_instance; +} + +//----------------------------------------------------------------- + +void ToolOptionsShortcutInvoker::initialize() { + connect(TApp::instance()->getCurrentTool(), SIGNAL(toolSwitched()), this, + SLOT(onToolSwitched())); + onToolSwitched(); + + /*-- Animate tool + mode switching shortcuts --*/ + setCommandHandler(MI_EditNextMode, this, + &ToolOptionsShortcutInvoker::toggleEditNextMode); + setCommandHandler(MI_EditPosition, this, + &ToolOptionsShortcutInvoker::toggleEditPosition); + setCommandHandler(MI_EditRotation, this, + &ToolOptionsShortcutInvoker::toggleEditRotation); + setCommandHandler(MI_EditScale, this, + &ToolOptionsShortcutInvoker::toggleEditNextScale); + setCommandHandler(MI_EditShear, this, + &ToolOptionsShortcutInvoker::toggleEditNextShear); + setCommandHandler(MI_EditCenter, this, + &ToolOptionsShortcutInvoker::toggleEditNextCenter); + setCommandHandler(MI_EditAll, this, + &ToolOptionsShortcutInvoker::toggleEditNextAll); + + /*-- Selection tool + type switching shortcuts --*/ + setCommandHandler(MI_SelectionNextType, this, + &ToolOptionsShortcutInvoker::toggleSelectionNextType); + setCommandHandler(MI_SelectionRectangular, this, + &ToolOptionsShortcutInvoker::toggleSelectionRectangular); + setCommandHandler(MI_SelectionFreehand, this, + &ToolOptionsShortcutInvoker::toggleSelectionFreehand); + setCommandHandler(MI_SelectionPolyline, this, + &ToolOptionsShortcutInvoker::toggleSelectionPolyline); + + /*-- Geometric tool + shape switching shortcuts --*/ + setCommandHandler(MI_GeometricNextShape, this, + &ToolOptionsShortcutInvoker::toggleGeometricNextShape); + setCommandHandler(MI_GeometricRectangle, this, + &ToolOptionsShortcutInvoker::toggleGeometricRectangle); + setCommandHandler(MI_GeometricCircle, this, + &ToolOptionsShortcutInvoker::toggleGeometricCircle); + setCommandHandler(MI_GeometricEllipse, this, + &ToolOptionsShortcutInvoker::toggleGeometricEllipse); + setCommandHandler(MI_GeometricLine, this, + &ToolOptionsShortcutInvoker::toggleGeometricLine); + setCommandHandler(MI_GeometricPolyline, this, + &ToolOptionsShortcutInvoker::toggleGeometricPolyline); + setCommandHandler(MI_GeometricArc, this, + &ToolOptionsShortcutInvoker::toggleGeometricArc); + setCommandHandler(MI_GeometricMultiArc, this, + &ToolOptionsShortcutInvoker::toggleGeometricMultiArc); + setCommandHandler(MI_GeometricPolygon, this, + &ToolOptionsShortcutInvoker::toggleGeometricPolygon); + + /*-- Type tool + style switching shortcuts --*/ + setCommandHandler(MI_TypeNextStyle, this, + &ToolOptionsShortcutInvoker::toggleTypeNextStyle); + setCommandHandler(MI_TypeOblique, this, + &ToolOptionsShortcutInvoker::toggleTypeOblique); + setCommandHandler(MI_TypeRegular, this, + &ToolOptionsShortcutInvoker::toggleTypeRegular); + setCommandHandler(MI_TypeBoldOblique, this, + &ToolOptionsShortcutInvoker::toggleTypeBoldOblique); + setCommandHandler(MI_TypeBold, this, + &ToolOptionsShortcutInvoker::toggleTypeBold); + + /*-- Fill tool + type/mode switching shortcuts --*/ + setCommandHandler(MI_FillNextType, this, + &ToolOptionsShortcutInvoker::toggleFillNextType); + setCommandHandler(MI_FillNormal, this, + &ToolOptionsShortcutInvoker::toggleFillNormal); + setCommandHandler(MI_FillRectangular, this, + &ToolOptionsShortcutInvoker::toggleFillRectangular); + setCommandHandler(MI_FillFreehand, this, + &ToolOptionsShortcutInvoker::toggleFillFreehand); + setCommandHandler(MI_FillPolyline, this, + &ToolOptionsShortcutInvoker::toggleFillPolyline); + setCommandHandler(MI_FillNextMode, this, + &ToolOptionsShortcutInvoker::toggleFillNextMode); + setCommandHandler(MI_FillAreas, this, + &ToolOptionsShortcutInvoker::toggleFillAreas); + setCommandHandler(MI_FillLines, this, + &ToolOptionsShortcutInvoker::toggleFillLines); + setCommandHandler(MI_FillLinesAndAreas, this, + &ToolOptionsShortcutInvoker::toggleFillLinesAndAreas); + + /*-- Eraser tool + type switching shortcuts --*/ + setCommandHandler(MI_EraserNextType, this, + &ToolOptionsShortcutInvoker::toggleEraserNextType); + setCommandHandler(MI_EraserNormal, this, + &ToolOptionsShortcutInvoker::toggleEraserNormal); + setCommandHandler(MI_EraserRectangular, this, + &ToolOptionsShortcutInvoker::toggleEraserRectangular); + setCommandHandler(MI_EraserFreehand, this, + &ToolOptionsShortcutInvoker::toggleEraserFreehand); + setCommandHandler(MI_EraserPolyline, this, + &ToolOptionsShortcutInvoker::toggleEraserPolyline); + setCommandHandler(MI_EraserSegment, this, + &ToolOptionsShortcutInvoker::toggleEraserSegment); + + /*-- Tape tool + type/mode switching shortcuts --*/ + setCommandHandler(MI_TapeNextType, this, + &ToolOptionsShortcutInvoker::toggleTapeNextType); + setCommandHandler(MI_TapeNormal, this, + &ToolOptionsShortcutInvoker::toggleTapeNormal); + setCommandHandler(MI_TapeRectangular, this, + &ToolOptionsShortcutInvoker::toggleTapeRectangular); + setCommandHandler(MI_TapeNextMode, this, + &ToolOptionsShortcutInvoker::toggleTapeNextMode); + setCommandHandler(MI_TapeEndpointToEndpoint, this, + &ToolOptionsShortcutInvoker::toggleTapeEndpointToEndpoint); + setCommandHandler(MI_TapeEndpointToLine, this, + &ToolOptionsShortcutInvoker::toggleTapeEndpointToLine); + setCommandHandler(MI_TapeLineToLine, this, + &ToolOptionsShortcutInvoker::toggleTapeLineToLine); + + /*-- Style Picker tool + mode switching shortcuts --*/ + setCommandHandler(MI_PickStyleNextMode, this, + &ToolOptionsShortcutInvoker::togglePickStyleNextMode); + setCommandHandler(MI_PickStyleAreas, this, + &ToolOptionsShortcutInvoker::togglePickStyleAreas); + setCommandHandler(MI_PickStyleLines, this, + &ToolOptionsShortcutInvoker::togglePickStyleLines); + setCommandHandler(MI_PickStyleLinesAndAreas, this, + &ToolOptionsShortcutInvoker::togglePickStyleLinesAndAreas); + + /*-- RGB Picker tool + type switching shortcuts --*/ + setCommandHandler(MI_RGBPickerNextType, this, + &ToolOptionsShortcutInvoker::toggleRGBPickerNextType); + setCommandHandler(MI_RGBPickerNormal, this, + &ToolOptionsShortcutInvoker::toggleRGBPickerNormal); + setCommandHandler(MI_RGBPickerRectangular, this, + &ToolOptionsShortcutInvoker::toggleRGBPickerRectangular); + setCommandHandler(MI_RGBPickerFreehand, this, + &ToolOptionsShortcutInvoker::toggleRGBPickerFreehand); + setCommandHandler(MI_RGBPickerPolyline, this, + &ToolOptionsShortcutInvoker::toggleRGBPickerPolyline); + + /*-- Skeleton tool + mode switching shortcuts --*/ + setCommandHandler(MI_SkeletonNextMode, this, + &ToolOptionsShortcutInvoker::ToggleSkeletonNextMode); + setCommandHandler(MI_SkeletonBuildSkeleton, this, + &ToolOptionsShortcutInvoker::ToggleSkeletonBuildSkeleton); + setCommandHandler(MI_SkeletonAnimate, this, + &ToolOptionsShortcutInvoker::ToggleSkeletonAnimate); + setCommandHandler( + MI_SkeletonInverseKinematics, this, + &ToolOptionsShortcutInvoker::ToggleSkeletonInverseKinematics); + + /*-- Plastic tool + mode switching shortcuts --*/ + setCommandHandler(MI_PlasticNextMode, this, + &ToolOptionsShortcutInvoker::TogglePlasticNextMode); + setCommandHandler(MI_PlasticEditMesh, this, + &ToolOptionsShortcutInvoker::TogglePlasticEditMesh); + setCommandHandler(MI_PlasticPaintRigid, this, + &ToolOptionsShortcutInvoker::TogglePlasticPaintRigid); + setCommandHandler(MI_PlasticBuildSkeleton, this, + &ToolOptionsShortcutInvoker::TogglePlasticBuildSkeleton); + setCommandHandler(MI_PlasticAnimate, this, + &ToolOptionsShortcutInvoker::TogglePlasticAnimate); +} + +//----------------------------------------------------------------------------- + +void ToolOptionsShortcutInvoker::notifyTool(TTool* tool, TProperty* p, + bool addToUndo) { + std::string tempPropertyName = p->getName(); + if (addToUndo && tempPropertyName == "Maximum Gap") + tempPropertyName = tempPropertyName + "withUndo"; + tool->onPropertyChanged(tempPropertyName); +} + +//----------------------------------------------------------------------------- + +void ToolOptionsShortcutInvoker::registerCheckProperty(TTool* tool, + BoolWorker* worker) { + m_checkProps.insert(tool, worker); +} + +//----------------------------------------------------------------------------- + +void ToolOptionsShortcutInvoker::onToolSwitched() { + TTool* tool = TApp::instance()->getCurrentTool()->getTool(); + if (!m_tools.contains(tool)) { + // amount of the property groups + int pgCount = 1; + if (tool->getName() == T_Geometric || tool->getName() == T_Type || + (tool->getName() == T_Selection && + (tool->getTargetType() & TTool::Vectors)) || + (tool->getName() == T_Brush && + (tool->getTargetType() & TTool::Vectors))) + pgCount = 2; + for (int pgId = 0; pgId < pgCount; pgId++) { + TPropertyGroup* pg = tool->getProperties(pgId); + if (!pg) continue; + + ToolOptionShortcutConnector connector(tool); + // connect each property to an associated command + pg->accept(connector); + } + m_tools.insert(tool); + } + // if the tool is already registered + else { + // synchronize action's check state to the property + for (auto boolWorker : m_checkProps.values(tool)) { + boolWorker->syncActionState(); + } + } +} + +//----------------------------------------------------------------------------- +/*-- Animate tool + mode switching shortcuts --*/ +void ToolOptionsShortcutInvoker::toggleEditNextMode() { + if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Edit) + CommandManager::instance() + ->getAction("A_ToolOption_EditToolActiveAxis") + ->trigger(); + else + CommandManager::instance()->getAction(T_Edit)->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleEditPosition() { + CommandManager::instance()->getAction(T_Edit)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_EditToolActiveAxis:Position") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleEditRotation() { + CommandManager::instance()->getAction(T_Edit)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_EditToolActiveAxis:Rotation") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleEditNextScale() { + CommandManager::instance()->getAction(T_Edit)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_EditToolActiveAxis:Scale") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleEditNextShear() { + CommandManager::instance()->getAction(T_Edit)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_EditToolActiveAxis:Shear") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleEditNextCenter() { + CommandManager::instance()->getAction(T_Edit)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_EditToolActiveAxis:Center") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleEditNextAll() { + CommandManager::instance()->getAction(T_Edit)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_EditToolActiveAxis:All") + ->trigger(); +} + +//--------------------------------------------------------------------------------------- +/*-- Selection tool + type switching shortcuts --*/ +void ToolOptionsShortcutInvoker::toggleSelectionNextType() { + if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Selection) + CommandManager::instance()->getAction("A_ToolOption_Type")->trigger(); + else + CommandManager::instance()->getAction(T_Selection)->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleSelectionRectangular() { + CommandManager::instance()->getAction(T_Selection)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Type:Rectangular") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleSelectionFreehand() { + CommandManager::instance()->getAction(T_Selection)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Type:Freehand") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleSelectionPolyline() { + CommandManager::instance()->getAction(T_Selection)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Type:Polyline") + ->trigger(); +} + +//--------------------------------------------------------------------------------------- +/*-- Geometric tool + shape switching shortcuts --*/ +void ToolOptionsShortcutInvoker::toggleGeometricNextShape() { + if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Geometric) + CommandManager::instance() + ->getAction("A_ToolOption_GeometricShape") + ->trigger(); + else + CommandManager::instance()->getAction(T_Geometric)->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleGeometricRectangle() { + CommandManager::instance()->getAction(T_Geometric)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_GeometricShape:Rectangle") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleGeometricCircle() { + CommandManager::instance()->getAction(T_Geometric)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_GeometricShape:Circle") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleGeometricEllipse() { + CommandManager::instance()->getAction(T_Geometric)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_GeometricShape:Ellipse") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleGeometricLine() { + CommandManager::instance()->getAction(T_Geometric)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_GeometricShape:Line") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleGeometricPolyline() { + CommandManager::instance()->getAction(T_Geometric)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_GeometricShape:Polyline") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleGeometricArc() { + CommandManager::instance()->getAction(T_Geometric)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_GeometricShape:Arc") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleGeometricMultiArc() { + CommandManager::instance()->getAction(T_Geometric)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_GeometricShape:MultiArc") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleGeometricPolygon() { + CommandManager::instance()->getAction(T_Geometric)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_GeometricShape:Polygon") + ->trigger(); +} +//--------------------------------------------------------------------------------------- +/*-- Type tool + mode switching shortcuts --*/ +void ToolOptionsShortcutInvoker::toggleTypeNextStyle() { + if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Type) + CommandManager::instance()->getAction("A_ToolOption_TypeStyle")->trigger(); + else + CommandManager::instance()->getAction(T_Type)->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleTypeOblique() { + CommandManager::instance()->getAction(T_Type)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_TypeStyle:Oblique") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleTypeRegular() { + CommandManager::instance()->getAction(T_Type)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_TypeStyle:Regular") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleTypeBoldOblique() { + CommandManager::instance()->getAction(T_Type)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_TypeStyle:Bold Oblique") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleTypeBold() { + CommandManager::instance()->getAction(T_Type)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_TypeStyle:Bold") + ->trigger(); +} + +//--------------------------------------------------------------------------------------- +/*-- Fill tool + type/mode switching shortcuts --*/ +void ToolOptionsShortcutInvoker::toggleFillNextType() { + if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Fill) + CommandManager::instance()->getAction("A_ToolOption_Type")->trigger(); + else + CommandManager::instance()->getAction(T_Fill)->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleFillNormal() { + CommandManager::instance()->getAction(T_Fill)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleFillRectangular() { + CommandManager::instance()->getAction(T_Fill)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Type:Rectangular") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleFillFreehand() { + CommandManager::instance()->getAction(T_Fill)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Type:Freehand") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleFillPolyline() { + CommandManager::instance()->getAction(T_Fill)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Type:Polyline") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleFillNextMode() { + if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Fill) + CommandManager::instance()->getAction("A_ToolOption_Mode")->trigger(); + else + CommandManager::instance()->getAction(T_Fill)->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleFillAreas() { + CommandManager::instance()->getAction(T_Fill)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Mode:Areas")->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleFillLines() { + CommandManager::instance()->getAction(T_Fill)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Mode:Lines")->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleFillLinesAndAreas() { + CommandManager::instance()->getAction(T_Fill)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Mode:Lines & Areas") + ->trigger(); +} + +//--------------------------------------------------------------------------------------- +/*-- Eraser tool + type switching shortcuts --*/ +void ToolOptionsShortcutInvoker::toggleEraserNextType() { + if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Eraser) + CommandManager::instance()->getAction("A_ToolOption_Type")->trigger(); + else + CommandManager::instance()->getAction(T_Eraser)->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleEraserNormal() { + CommandManager::instance()->getAction(T_Eraser)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleEraserRectangular() { + CommandManager::instance()->getAction(T_Eraser)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Type:Rectangular") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleEraserFreehand() { + CommandManager::instance()->getAction(T_Eraser)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Type:Freehand") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleEraserPolyline() { + CommandManager::instance()->getAction(T_Eraser)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Type:Polyline") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleEraserSegment() { + CommandManager::instance()->getAction(T_Eraser)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Type:Segment")->trigger(); +} +//--------------------------------------------------------------------------------------- +/*-- Tape tool + type/mode switching shortcuts --*/ +void ToolOptionsShortcutInvoker::toggleTapeNextType() { + if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Tape) + CommandManager::instance()->getAction("A_ToolOption_Type")->trigger(); + else + CommandManager::instance()->getAction(T_Tape)->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleTapeNormal() { + CommandManager::instance()->getAction(T_Tape)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleTapeRectangular() { + CommandManager::instance()->getAction(T_Tape)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Type:Rectangular") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleTapeNextMode() { + if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Tape) + CommandManager::instance()->getAction("A_ToolOption_Mode")->trigger(); + else + CommandManager::instance()->getAction(T_Tape)->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleTapeEndpointToEndpoint() { + CommandManager::instance()->getAction(T_Tape)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Mode:Endpoint to Endpoint") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleTapeEndpointToLine() { + CommandManager::instance()->getAction(T_Tape)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Mode:Endpoint to Line") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleTapeLineToLine() { + CommandManager::instance()->getAction(T_Tape)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Mode:Line to Line") + ->trigger(); +} + +//--------------------------------------------------------------------------------------- +/*-- Style Picker tool + mode switching shortcuts --*/ +void ToolOptionsShortcutInvoker::togglePickStyleNextMode() { + if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_StylePicker) + CommandManager::instance()->getAction("A_ToolOption_Mode")->trigger(); + else + CommandManager::instance()->getAction(T_StylePicker)->trigger(); +} + +void ToolOptionsShortcutInvoker::togglePickStyleAreas() { + CommandManager::instance()->getAction(T_StylePicker)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Mode:Areas")->trigger(); +} + +void ToolOptionsShortcutInvoker::togglePickStyleLines() { + CommandManager::instance()->getAction(T_StylePicker)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Mode:Lines")->trigger(); +} + +void ToolOptionsShortcutInvoker::togglePickStyleLinesAndAreas() { + CommandManager::instance()->getAction(T_StylePicker)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Mode:Lines & Areas") + ->trigger(); +} +//----------------------------------------------------------------------------- +/*-- RGB Picker tool + type switching shortcuts --*/ +void ToolOptionsShortcutInvoker::toggleRGBPickerNextType() { + if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_RGBPicker) + CommandManager::instance()->getAction("A_ToolOption_Type")->trigger(); + else + CommandManager::instance()->getAction(T_RGBPicker)->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleRGBPickerNormal() { + CommandManager::instance()->getAction(T_RGBPicker)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleRGBPickerRectangular() { + CommandManager::instance()->getAction(T_RGBPicker)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Type:Rectangular") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleRGBPickerFreehand() { + CommandManager::instance()->getAction(T_RGBPicker)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Type:Freehand") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::toggleRGBPickerPolyline() { + CommandManager::instance()->getAction(T_RGBPicker)->trigger(); + CommandManager::instance()->getAction("A_ToolOption_Type:Normal")->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_Type:Polyline") + ->trigger(); +} +//----------------------------------------------------------------------------- +/*-- Skeleton tool + type switching shortcuts --*/ +void ToolOptionsShortcutInvoker::ToggleSkeletonNextMode() { + if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Skeleton) + CommandManager::instance() + ->getAction("A_ToolOption_SkeletonMode") + ->trigger(); + else + CommandManager::instance()->getAction(T_Skeleton)->trigger(); +} + +void ToolOptionsShortcutInvoker::ToggleSkeletonBuildSkeleton() { + CommandManager::instance()->getAction(T_Skeleton)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_SkeletonMode:Build Skeleton") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::ToggleSkeletonAnimate() { + CommandManager::instance()->getAction(T_Skeleton)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_SkeletonMode:Animate") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::ToggleSkeletonInverseKinematics() { + CommandManager::instance()->getAction(T_Skeleton)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_SkeletonMode:Inverse Kinematics") + ->trigger(); +} + +//----------------------------------------------------------------------------- +/*-- Plastic tool + mode switching shortcuts --*/ +void ToolOptionsShortcutInvoker::TogglePlasticNextMode() { + if (TApp::instance()->getCurrentTool()->getTool()->getName() == T_Plastic) + CommandManager::instance() + ->getAction("A_ToolOption_SkeletonMode") + ->trigger(); + else + CommandManager::instance()->getAction(T_Plastic)->trigger(); +} + +void ToolOptionsShortcutInvoker::TogglePlasticEditMesh() { + CommandManager::instance()->getAction(T_Plastic)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_SkeletonMode:Edit Mesh") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::TogglePlasticPaintRigid() { + CommandManager::instance()->getAction(T_Plastic)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_SkeletonMode:Paint Rigid") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::TogglePlasticBuildSkeleton() { + CommandManager::instance()->getAction(T_Plastic)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_SkeletonMode:Build Skeleton") + ->trigger(); +} + +void ToolOptionsShortcutInvoker::TogglePlasticAnimate() { + CommandManager::instance()->getAction(T_Plastic)->trigger(); + CommandManager::instance() + ->getAction("A_ToolOption_SkeletonMode:Animate") + ->trigger(); +} diff --git a/toonz/sources/toonz/tooloptionsshortcutinvoker.h b/toonz/sources/toonz/tooloptionsshortcutinvoker.h new file mode 100644 index 0000000..f372e1d --- /dev/null +++ b/toonz/sources/toonz/tooloptionsshortcutinvoker.h @@ -0,0 +1,248 @@ +#pragma once +#ifndef TOOLOPTIONSSHORTCUTINVOKER_H +#define TOOLOPTIONSSHORTCUTINVOKER_H + +#include "tproperty.h" + +#include +#include +#include + +class TProperty; +class QAction; +class TTool; + +namespace ToolOptionsShortcutWorker { +class BoolWorker; +} + +class ToolOptionShortcutConnector final : public TProperty::Visitor { + TTool* m_tool; + +public: + ToolOptionShortcutConnector(TTool* tool); + +private: + void visit(TDoubleProperty* p) override; + void visit(TDoublePairProperty* p) override; + void visit(TIntPairProperty* p) override; + void visit(TIntProperty* p) override; + void visit(TBoolProperty* p) override; + void visit(TStringProperty* p) override {} + void visit(TEnumProperty* p) override; + void visit(TStyleIndexProperty* p) override {} + void visit(TPointerProperty* p) override {} +}; + +//============================================================================= + +namespace ToolOptionsShortcutWorker { + +//----------------------------------------------------------------- + +class DoubleWorker : public QObject { + Q_OBJECT + TTool* m_tool; + TDoubleProperty* m_property; + +public: + DoubleWorker(QObject* parent, TTool* tool, TDoubleProperty* property) + : QObject(parent), m_tool(tool), m_property(property) {} +protected slots: + void increase(double step = 1.0); + void increaseFractional(); + void decrease(double step = 1.0); + void decreaseFractional(); +}; + +//----------------------------------------------------------------- + +class DoublePairWorker : public QObject { + Q_OBJECT + TTool* m_tool; + TDoublePairProperty* m_property; + +public: + DoublePairWorker(QObject* parent, TTool* tool, TDoublePairProperty* property) + : QObject(parent), m_tool(tool), m_property(property) {} +protected slots: + void increaseMaxValue(); + void decreaseMaxValue(); + void increaseMinValue(); + void decreaseMinValue(); +}; + +//----------------------------------------------------------------- + +class IntPairWorker : public QObject { + Q_OBJECT + TTool* m_tool; + TIntPairProperty* m_property; + +public: + IntPairWorker(QObject* parent, TTool* tool, TIntPairProperty* property) + : QObject(parent), m_tool(tool), m_property(property) {} +protected slots: + void increaseMaxValue(); + void decreaseMaxValue(); + void increaseMinValue(); + void decreaseMinValue(); +}; + +//----------------------------------------------------------------- + +class IntWorker : public QObject { + Q_OBJECT + TTool* m_tool; + TIntProperty* m_property; + +public: + IntWorker(QObject* parent, TTool* tool, TIntProperty* property) + : QObject(parent), m_tool(tool), m_property(property) {} +protected slots: + void increase(); + void decrease(); +}; + +//----------------------------------------------------------------- + +class BoolWorker : public QObject { + Q_OBJECT + TTool* m_tool; + TBoolProperty* m_property; + QAction* m_action; + +public: + BoolWorker(QObject* parent, TTool* tool, TBoolProperty* property, + QAction* action) + : QObject(parent), m_tool(tool), m_property(property), m_action(action) {} + void syncActionState(); +protected slots: + void doCheck(bool); +}; + +//----------------------------------------------------------------- + +class EnumWorker : public QObject { + Q_OBJECT + TTool* m_tool; + TEnumProperty* m_property; + +public: + EnumWorker(QObject* parent, TTool* tool, TEnumProperty* property) + : QObject(parent), m_tool(tool), m_property(property) {} +protected slots: + void cycleOptions(); + void doOnActivated(int); +}; +} // namespace ToolOptionsShortcutWorker + +//============================================================================= + +class ToolOptionsShortcutInvoker : public QObject // singleton +{ + Q_OBJECT + QSet m_tools; + //�c�[�����؂�ւ������ Action��Check��Ԃ𓯊������� + QMultiMap m_checkProps; + +public: + static ToolOptionsShortcutInvoker* instance(); + void initialize(); + void notifyTool(TTool*, TProperty*, bool = false); + void registerCheckProperty(TTool*, ToolOptionsShortcutWorker::BoolWorker*); + +private: + ToolOptionsShortcutInvoker(){}; +protected slots: + void onToolSwitched(); + + /*-- Animate tool + mode switching shortcuts --*/ + void toggleEditNextMode(); + void toggleEditPosition(); + void toggleEditRotation(); + void toggleEditNextScale(); + void toggleEditNextShear(); + void toggleEditNextCenter(); + void toggleEditNextAll(); + + /*-- Selection tool + mode switching shortcuts --*/ + void toggleSelectionNextType(); + void toggleSelectionRectangular(); + void toggleSelectionFreehand(); + void toggleSelectionPolyline(); + + /*-- Geometric tool + shape switching shortcuts --*/ + void toggleGeometricNextShape(); + void toggleGeometricRectangle(); + void toggleGeometricCircle(); + void toggleGeometricEllipse(); + void toggleGeometricLine(); + void toggleGeometricPolyline(); + void toggleGeometricArc(); + void toggleGeometricMultiArc(); + void toggleGeometricPolygon(); + + /*-- Type tool + style switching shortcuts --*/ + void toggleTypeNextStyle(); + void toggleTypeOblique(); + void toggleTypeRegular(); + void toggleTypeBoldOblique(); + void toggleTypeBold(); + + /*-- Fill tool + mode switching shortcuts --*/ + void toggleFillNextType(); + void toggleFillNormal(); + void toggleFillRectangular(); + void toggleFillFreehand(); + void toggleFillPolyline(); + void toggleFillNextMode(); + void toggleFillAreas(); + void toggleFillLines(); + void toggleFillLinesAndAreas(); + + /*-- Eraser tool + type switching shortcuts --*/ + void toggleEraserNextType(); + void toggleEraserNormal(); + void toggleEraserRectangular(); + void toggleEraserFreehand(); + void toggleEraserPolyline(); + void toggleEraserSegment(); + + /*-- Tape tool + type/mode switching shortcuts --*/ + void toggleTapeNextType(); + void toggleTapeNormal(); + void toggleTapeRectangular(); + void toggleTapeNextMode(); + void toggleTapeEndpointToEndpoint(); + void toggleTapeEndpointToLine(); + void toggleTapeLineToLine(); + + /*-- Style Picker tool + mode switching shortcuts --*/ + void togglePickStyleNextMode(); + void togglePickStyleAreas(); + void togglePickStyleLines(); + void togglePickStyleLinesAndAreas(); + + /*-- RGB Picker tool + type switching shortcuts --*/ + void toggleRGBPickerNextType(); + void toggleRGBPickerNormal(); + void toggleRGBPickerRectangular(); + void toggleRGBPickerFreehand(); + void toggleRGBPickerPolyline(); + + /*-- Skeleton tool + mode switching shortcuts --*/ + void ToggleSkeletonNextMode(); + void ToggleSkeletonBuildSkeleton(); + void ToggleSkeletonAnimate(); + void ToggleSkeletonInverseKinematics(); + + /*-- Plastic tool + mode switching shortcuts --*/ + void TogglePlasticNextMode(); + void TogglePlasticEditMesh(); + void TogglePlasticPaintRigid(); + void TogglePlasticBuildSkeleton(); + void TogglePlasticAnimate(); +}; + +#endif \ No newline at end of file diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cpp index ee1b157..1f820d2 100644 --- a/toonz/sources/toonzlib/preferences.cpp +++ b/toonz/sources/toonzlib/preferences.cpp @@ -530,9 +530,10 @@ void Preferences::definePreferenceItems() { QMetaType::Bool, false); // Tools - define(dropdownShortcutsCycleOptions, "dropdownShortcutsCycleOptions", - QMetaType::Int, - 1); // Cycle through the available options (changed from bool to int) + // define(dropdownShortcutsCycleOptions, "dropdownShortcutsCycleOptions", + // QMetaType::Int, + // 1); // Cycle through the available options (changed from bool to + // int) define(FillOnlysavebox, "FillOnlysavebox", QMetaType::Bool, false); define(multiLayerStylePickerEnabled, "multiLayerStylePickerEnabled", QMetaType::Bool, false);