diff --git a/stuff/profiles/layouts/shortcuts/defopentoonz.ini b/stuff/profiles/layouts/shortcuts/defopentoonz.ini index ebb88c6..27ec312 100644 --- a/stuff/profiles/layouts/shortcuts/defopentoonz.ini +++ b/stuff/profiles/layouts/shortcuts/defopentoonz.ini @@ -188,7 +188,7 @@ MI_NextDrawing=. MI_NextFrame=Shift+. MI_NextStep= MI_NoShift= -MI_OpacityCheck=1 +MI_OpacityCheck=Alt+1 MI_OpenBatchServers= MI_OpenChild= MI_OpenCleanupSettings= @@ -359,8 +359,8 @@ T_Tape=T T_Tracker= T_Type=Y T_Zoom=Shift+Space -T_ZoomFit=9 -T_ZoomReset=0 +T_ZoomFit=Alt+9 +T_ZoomReset=Alt+0 T_Zoomin=+ T_Zoomout=- MI_LoadRecentImage= diff --git a/stuff/profiles/layouts/shortcuts/otharmony.ini b/stuff/profiles/layouts/shortcuts/otharmony.ini index 8464172..3675e6d 100644 --- a/stuff/profiles/layouts/shortcuts/otharmony.ini +++ b/stuff/profiles/layouts/shortcuts/otharmony.ini @@ -54,8 +54,8 @@ T_Tape=Alt+C T_Type=Alt+9 T_Zoom=Alt+Z T_ZoomReset= -T_Zoomin=2 -T_Zoomout=1 +T_Zoomin=Alt+2 +T_Zoomout=Alt+1 A_DecreaseBrushHardness= A_DecreaseMaxBrushThickness= A_DecreaseMinBrushThickness= @@ -143,7 +143,7 @@ MI_CloneChild= MI_CloneLevel= MI_ClonePreview= MI_CloseChild= -MI_Collapse=0 +MI_Collapse=Alt+0 MI_CollectAssets= MI_CompareToSnapshot= MI_ConvertFileWithInput= diff --git a/toonz/sources/common/tvrender/tpalette.cpp b/toonz/sources/common/tvrender/tpalette.cpp index 902a439..ad236ef 100644 --- a/toonz/sources/common/tvrender/tpalette.cpp +++ b/toonz/sources/common/tvrender/tpalette.cpp @@ -184,7 +184,8 @@ TPalette::TPalette() , m_dirtyFlag(false) , m_mutex(QMutex::Recursive) , m_isLocked(false) - , m_askOverwriteFlag(false) { + , m_askOverwriteFlag(false) + , m_shortcutScopeIndex(0) { QString tempName(QObject::tr("colors")); std::wstring pageName = tempName.toStdWString(); Page *page = addPage(pageName); @@ -878,9 +879,10 @@ void TPalette::assign(const TPalette *src, bool isFromStudioPalette) { j->second = j->second->clone(); m_styleAnimationTable[cit->first] = cit->second; } - m_globalName = src->getGlobalName(); - m_shortcuts = src->m_shortcuts; - m_currentFrame = src->m_currentFrame; + m_globalName = src->getGlobalName(); + m_shortcuts = src->m_shortcuts; + m_currentFrame = src->m_currentFrame; + m_shortcutScopeIndex = src->m_shortcutScopeIndex; // setDirtyFlag(true); } @@ -1080,22 +1082,26 @@ void TPalette::clearKeyframe(int styleId, int frame) { //------------------------------------------------------------------- int TPalette::getShortcutValue(int key) const { - assert('0' <= key && key <= '9'); - std::map::const_iterator it; - it = m_shortcuts.find(key); - if (it == m_shortcuts.end()) return -1; - int styleId = it->second; - return 0 <= styleId && styleId < getStyleCount() ? styleId : -1; + assert(Qt::Key_0 <= key && key <= Qt::Key_9); + + int shortcutIndex = (key == Qt::Key_0) ? 9 : key - Qt::Key_1; + int indexInPage = m_shortcutScopeIndex * 10 + shortcutIndex; + // shortcut is available only in the first page + return getPage(0)->getStyleId(indexInPage); } //------------------------------------------------------------------- int TPalette::getStyleShortcut(int styleId) const { assert(0 <= styleId && styleId < getStyleCount()); - std::map::const_iterator it; - for (it = m_shortcuts.begin(); it != m_shortcuts.end(); ++it) - if (it->second == styleId) return it->first; - return -1; + + Page *page = getStylePage(styleId); + // shortcut is available only in the first page + if (!page || page->getIndex() != 0) return -1; + int indexInPage = page->search(styleId); + int shortcutIndex = indexInPage - m_shortcutScopeIndex * 10; + if (shortcutIndex < 0 || shortcutIndex > 9) return -1; + return (shortcutIndex == 9) ? Qt::Key_0 : Qt::Key_1 + shortcutIndex; } //------------------------------------------------------------------- @@ -1126,4 +1132,20 @@ bool TPalette::hasPickedPosStyle() { if (style->getPickedPosition() != TPoint()) return true; } return false; -} \ No newline at end of file +} + +//------------------------------------------------------------------- + +void TPalette::nextShortcutScope(bool invert) { + if (invert) { + if (m_shortcutScopeIndex > 0) + m_shortcutScopeIndex -= 1; + else + m_shortcutScopeIndex = getPage(0)->getStyleCount() / 10; + } else { + if ((m_shortcutScopeIndex + 1) * 10 < getPage(0)->getStyleCount()) + m_shortcutScopeIndex += 1; + else + m_shortcutScopeIndex = 0; + } +} diff --git a/toonz/sources/include/tools/tooloptions.h b/toonz/sources/include/tools/tooloptions.h index b06a86d..abded96 100644 --- a/toonz/sources/include/tools/tooloptions.h +++ b/toonz/sources/include/tools/tooloptions.h @@ -647,7 +647,9 @@ public slots: void onToolChanged(); void onStageObjectChange(); - // signals: +signals: + // used in ComboViewer to handle Tab focus + void newPanelCreated(); // void toolOptionChange(); }; diff --git a/toonz/sources/include/toonz/preferences.h b/toonz/sources/include/toonz/preferences.h index 37b9bd1..56f7e3e 100644 --- a/toonz/sources/include/toonz/preferences.h +++ b/toonz/sources/include/toonz/preferences.h @@ -307,6 +307,11 @@ public: return m_multiLayerStylePickerEnabled; } + void enableUseNumpadForSwitchingStyles(bool on); + bool isUseNumpadForSwitchingStylesEnabled() const { + return m_useNumpadForSwitchingStyles; + } + // Xsheet tab void setXsheetStep(int step); //!< Sets the step used for the next/prev @@ -516,6 +521,8 @@ private: std::string m_layerNameEncoding = "SJIS"; // Fixed to SJIS for now. You can // add interface if you wanna // change encoding. + // whether to use numpad and tab key shortcut for selecting styles + bool m_useNumpadForSwitchingStyles; private: Preferences(); diff --git a/toonz/sources/include/toonz/tscenehandle.h b/toonz/sources/include/toonz/tscenehandle.h index bc8ded5..75ad8cf 100644 --- a/toonz/sources/include/toonz/tscenehandle.h +++ b/toonz/sources/include/toonz/tscenehandle.h @@ -52,7 +52,9 @@ public: } void notifyNameSceneChange() { emit nameSceneChanged(); } - void notifyPreferenceChanged() { emit preferenceChanged(); } + void notifyPreferenceChanged(const QString &prefName) { + emit preferenceChanged(prefName); + } void notifyPixelUnitSelected(bool on) { emit pixelUnitSelected(on); } @@ -76,7 +78,7 @@ signals: void castChanged(); void castFolderAdded(const TFilePath &path); void nameSceneChanged(); - void preferenceChanged(); + void preferenceChanged(const QString &prefName); void pixelUnitSelected(bool on); }; diff --git a/toonz/sources/include/toonzqt/paletteviewergui.h b/toonz/sources/include/toonzqt/paletteviewergui.h index 3cc54aa..e853458 100644 --- a/toonz/sources/include/toonzqt/paletteviewergui.h +++ b/toonz/sources/include/toonzqt/paletteviewergui.h @@ -199,6 +199,8 @@ protected: void zoomInChip(); void zoomOutChip(); + bool hasShortcut(int indexInPage); + private: DVGui::LineEdit *m_renameTextField; QPoint m_dragStartPosition; diff --git a/toonz/sources/include/tpalette.h b/toonz/sources/include/tpalette.h index a1085ce..e883e6d 100644 --- a/toonz/sources/include/tpalette.h +++ b/toonz/sources/include/tpalette.h @@ -211,6 +211,9 @@ private: //! The confirmation dialog will not be opened unless the palette is edited //! again, //! even if the palette's dirtyflag is true. + + int m_shortcutScopeIndex; + public: TPalette(); ~TPalette(); @@ -420,6 +423,8 @@ between RGBA color components. bool hasPickedPosStyle(); // Returns true if there is at least one style with // picked pos value + void nextShortcutScope(bool invert); + public: // Deprecated functions diff --git a/toonz/sources/tnztools/tooloptions.cpp b/toonz/sources/tnztools/tooloptions.cpp index 28ed771..399b876 100644 --- a/toonz/sources/tnztools/tooloptions.cpp +++ b/toonz/sources/tnztools/tooloptions.cpp @@ -2351,6 +2351,7 @@ un po' di codice... */ m_panels[tool] = panel; layout()->addWidget(panel); + emit newPanelCreated(); } else { // il panel c'e' gia'. panel = it->second; diff --git a/toonz/sources/toonz/CMakeLists.txt b/toonz/sources/toonz/CMakeLists.txt index 43f9bb4..c6849a1 100644 --- a/toonz/sources/toonz/CMakeLists.txt +++ b/toonz/sources/toonz/CMakeLists.txt @@ -141,7 +141,8 @@ set(MOC_HEADERS historypane.h cleanupsettingspane.h penciltestpopup.h - locatorpopup.h + locatorpopup.h + styleshortcutswitchablepanel.h # Tracker file dummyprocessor.h metnum.h @@ -301,7 +302,8 @@ set(SOURCES historypane.cpp cleanupsettingspane.cpp penciltestpopup.cpp - locatorpopup.cpp + locatorpopup.cpp + styleshortcutswitchablepanel.cpp # Tracker file dummyprocessor.cpp metnum.cpp diff --git a/toonz/sources/toonz/comboviewerpane.cpp b/toonz/sources/toonz/comboviewerpane.cpp index 6a10ad9..c592005 100644 --- a/toonz/sources/toonz/comboviewerpane.cpp +++ b/toonz/sources/toonz/comboviewerpane.cpp @@ -86,7 +86,7 @@ ComboViewerPanel::ComboViewerPanel(QWidget *parent, Qt::WindowFlags flags) #else ComboViewerPanel::ComboViewerPanel(QWidget *parent, Qt::WFlags flags) #endif - : TPanel(parent) { + : StyleShortcutSwitchablePanel(parent) { TApp *app = TApp::instance(); QFrame *hbox = new QFrame(this); @@ -103,6 +103,7 @@ ComboViewerPanel::ComboViewerPanel(QWidget *parent, Qt::WFlags flags) ImageUtils::FullScreenWidget *fsWidget = new ImageUtils::FullScreenWidget(this); fsWidget->setWidget(m_sceneViewer = new SceneViewer(fsWidget)); + m_sceneViewer->setIsStyleShortcutSwitchable(); #if defined(Q_OS_WIN) && (QT_VERSION >= 0x050500) && (QT_VERSION < 0x050600) // Workaround for QTBUG-48288 @@ -189,6 +190,9 @@ ComboViewerPanel::ComboViewerPanel(QWidget *parent, Qt::WFlags flags) SLOT(update())); ret = ret && connect(app->getCurrentScene(), SIGNAL(sceneSwitched()), this, SLOT(onSceneSwitched())); + ret = ret && connect(m_toolOptions, SIGNAL(newPanelCreated()), this, + SLOT(updateTabFocus())); + assert(ret); // note: initializeTitleBar() refers to m_sceneViewer @@ -336,7 +340,8 @@ ComboViewerPanel::~ComboViewerPanel() { //----------------------------------------------------------------------------- -void ComboViewerPanel::showEvent(QShowEvent *) { +void ComboViewerPanel::showEvent(QShowEvent *event) { + StyleShortcutSwitchablePanel::showEvent(event); TApp *app = TApp::instance(); TFrameHandle *frameHandle = app->getCurrentFrame(); TSceneHandle *sceneHandle = app->getCurrentScene(); @@ -388,9 +393,6 @@ void ComboViewerPanel::showEvent(QShowEvent *) { ret = ret && connect(app->getCurrentTool(), SIGNAL(toolSwitched()), m_sceneViewer, SLOT(onToolSwitched())); - ret = ret && connect(sceneHandle, SIGNAL(preferenceChanged()), m_flipConsole, - SLOT(onPreferenceChanged())); - m_flipConsole->onPreferenceChanged(); assert(ret); @@ -403,7 +405,8 @@ void ComboViewerPanel::showEvent(QShowEvent *) { //----------------------------------------------------------------------------- -void ComboViewerPanel::hideEvent(QHideEvent *) { +void ComboViewerPanel::hideEvent(QHideEvent *event) { + StyleShortcutSwitchablePanel::hideEvent(event); TApp *app = TApp::instance(); disconnect(app->getCurrentScene()); disconnect(app->getCurrentLevel()); @@ -781,3 +784,12 @@ bool ComboViewerPanel::isFrameAlreadyCached(int frame) { } //----------------------------------------------------------------------------- + +void ComboViewerPanel::onPreferenceChanged(const QString &prefName) { + // if no name specified (on showEvent), then process all updates + if (prefName == "BlankCount" || prefName == "BlankColor" || + prefName.isEmpty()) + m_flipConsole->onPreferenceChanged(); + + StyleShortcutSwitchablePanel::onPreferenceChanged(prefName); +} diff --git a/toonz/sources/toonz/comboviewerpane.h b/toonz/sources/toonz/comboviewerpane.h index 8f935ca..d7f2ea0 100644 --- a/toonz/sources/toonz/comboviewerpane.h +++ b/toonz/sources/toonz/comboviewerpane.h @@ -3,7 +3,7 @@ #ifndef COMBOVIEWER_PANE_INCLUDED #define COMBOVIEWER_PANE_INCLUDED -#include "pane.h" +#include "styleshortcutswitchablepanel.h" #include "sceneviewer.h" #include "toonzqt/intfield.h" #include "toonzqt/keyframenavigator.h" @@ -37,7 +37,8 @@ enum CV_Parts { }; //----------------------------------------------------------------------------- -class ComboViewerPanel final : public TPanel, public FlipConsoleOwner { +class ComboViewerPanel final : public StyleShortcutSwitchablePanel, + public FlipConsoleOwner { Q_OBJECT SceneViewer *m_sceneViewer; @@ -118,6 +119,8 @@ protected slots: void onSceneSwitched(); void enableFullPreview(bool enabled); void enableSubCameraPreview(bool enabled); + + void onPreferenceChanged(const QString &prefName) override; }; #endif diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cpp index afca011..23c7403 100644 --- a/toonz/sources/toonz/mainwindow.cpp +++ b/toonz/sources/toonz/mainwindow.cpp @@ -1689,7 +1689,7 @@ void MainWindow::defineActions() { MenuScanCleanupCommandType); CameraTestCheck::instance()->setToggle(toggle); - createToggle(MI_OpacityCheck, tr("&Opacity Check"), "1", false, + createToggle(MI_OpacityCheck, tr("&Opacity Check"), "Alt+1", false, MenuScanCleanupCommandType); createMenuScanCleanupAction(MI_Cleanup, tr("&Cleanup"), ""); @@ -2047,8 +2047,8 @@ void MainWindow::defineActions() { createViewerAction(V_ZoomIn, tr("Zoom In"), "+"); createViewerAction(V_ZoomOut, tr("Zoom Out"), "-"); - createViewerAction(V_ZoomReset, tr("Reset View"), "0"); - createViewerAction(V_ZoomFit, tr("Fit to Window"), "9"); + createViewerAction(V_ZoomReset, tr("Reset View"), "Alt+0"); + createViewerAction(V_ZoomFit, tr("Fit to Window"), "Alt+9"); createViewerAction(V_ActualPixelSize, tr("Actual Pixel Size"), "N"); createViewerAction(V_ShowHideFullScreen, tr("Show//Hide Full Screen"), "Alt+F"); diff --git a/toonz/sources/toonz/preferencespopup.cpp b/toonz/sources/toonz/preferencespopup.cpp index d9cca43..d9d06f1 100644 --- a/toonz/sources/toonz/preferencespopup.cpp +++ b/toonz/sources/toonz/preferencespopup.cpp @@ -359,7 +359,7 @@ void PreferencesPopup::onChunkSizeChanged() { void PreferencesPopup::onBlankCountChanged() { if (m_blanksCount && m_blankColor) m_pref->setBlankValues(m_blanksCount->getValue(), m_blankColor->getColor()); - TApp::instance()->getCurrentScene()->notifyPreferenceChanged(); + TApp::instance()->getCurrentScene()->notifyPreferenceChanged("BlankCount"); } //----------------------------------------------------------------------------- @@ -378,7 +378,7 @@ void PreferencesPopup::onBlankColorChanged(const TPixel32 &, bool isDragging) { if (m_blanksCount && m_blankColor) m_pref->setBlankValues(m_blanksCount->getValue(), m_blankColor->getColor()); - TApp::instance()->getCurrentScene()->notifyPreferenceChanged(); + TApp::instance()->getCurrentScene()->notifyPreferenceChanged("BlankColor"); } //----------------------------------------------------------------------------- @@ -927,6 +927,47 @@ void PreferencesPopup::onFfmpegTimeoutChanged() { m_pref->setFfmpegTimeout(m_ffmpegTimeout->getValue()); } +//----------------------------------------------------------------------------- + +void PreferencesPopup::onUseNumpadForSwitchingStylesClicked(bool checked) { + if (checked) { + // check if there are any commands with numpadkey shortcuts + CommandManager *cm = CommandManager::instance(); + QList actionsList; + for (int key = Qt::Key_0; key <= Qt::Key_9; key++) { + std::string str = QKeySequence(key).toString().toStdString(); + QAction *action = cm->getActionFromShortcut(str); + if (action) actionsList.append(action); + } + QAction *tabAction = cm->getActionFromShortcut("Tab"); + if (tabAction) actionsList.append(tabAction); + tabAction = cm->getActionFromShortcut("Shift+Tab"); + if (tabAction) actionsList.append(tabAction); + // if there are actions using numpad shortcuts, notify to release them. + if (!actionsList.isEmpty()) { + QString msgStr = + tr("Numpad keys are assigned to the following commands.\nIs it OK to " + "release these shortcuts?"); + for (int a = 0; a < actionsList.size(); a++) { + msgStr += "\n" + actionsList.at(a)->iconText() + " (" + + actionsList.at(a)->shortcut().toString() + ")"; + } + int ret = DVGui::MsgBox(msgStr, tr("OK"), tr("Cancel"), 1); + if (ret == 2 || ret == 0) { // canceled + m_useNumpadForSwitchingStyles->setChecked(false); + return; + } else { // accepted, then release shortcuts + for (int a = 0; a < actionsList.size(); a++) + cm->setShortcut(actionsList[a], ""); + } + } + } + m_pref->enableUseNumpadForSwitchingStyles(checked); + // emit signal to update Palette and Viewer + TApp::instance()->getCurrentScene()->notifyPreferenceChanged( + "NumpadForSwitchingStyles"); +} + //********************************************************************************** // PrefencesPopup's constructor //********************************************************************************** @@ -1097,6 +1138,8 @@ PreferencesPopup::PreferencesPopup() new CheckBox(tr("Use the TLV Savebox to Limit Filling Operations"), this); CheckBox *minimizeSaveboxAfterEditingCB = new CheckBox(tr("Minimize Savebox after Editing"), this); + m_useNumpadForSwitchingStyles = + new CheckBox(tr("Use Numpad and Tab keys for Switching Styles"), this); //--- Xsheet ------------------------------ categoryList->addItem(tr("Xsheet")); @@ -1307,6 +1350,8 @@ PreferencesPopup::PreferencesPopup() minimizeSaveboxAfterEditingCB->setChecked( m_pref->isMinimizeSaveboxAfterEditing()); useSaveboxToLimitFillingOpCB->setChecked(m_pref->getFillOnlySavebox()); + m_useNumpadForSwitchingStyles->setChecked( + m_pref->isUseNumpadForSwitchingStylesEnabled()); QStringList scanLevelTypes; scanLevelTypes << "tif" @@ -1760,6 +1805,9 @@ PreferencesPopup::PreferencesPopup() Qt::AlignLeft | Qt::AlignVCenter); drawingFrameLay->addWidget(multiLayerStylePickerCB, 0, Qt::AlignLeft | Qt::AlignVCenter); + drawingFrameLay->addWidget(m_useNumpadForSwitchingStyles, 0, + Qt::AlignLeft | Qt::AlignVCenter); + drawingFrameLay->addStretch(1); } drawingBox->setLayout(drawingFrameLay); @@ -2105,6 +2153,8 @@ PreferencesPopup::PreferencesPopup() SLOT(onDefLevelParameterChanged())); ret = ret && connect(m_defLevelDpi, SIGNAL(valueChanged()), SLOT(onDefLevelParameterChanged())); + ret = ret && connect(m_useNumpadForSwitchingStyles, SIGNAL(clicked(bool)), + SLOT(onUseNumpadForSwitchingStylesClicked(bool))); //--- Xsheet ---------------------- ret = ret && connect(xsheetAutopanDuringPlaybackCB, SIGNAL(stateChanged(int)), diff --git a/toonz/sources/toonz/preferencespopup.h b/toonz/sources/toonz/preferencespopup.h index 8a49973..ba790d7 100644 --- a/toonz/sources/toonz/preferencespopup.h +++ b/toonz/sources/toonz/preferencespopup.h @@ -71,7 +71,8 @@ private: DVGui::CheckBox *m_inksOnly, *m_enableVersionControl, *m_levelsBackup, *m_onionSkinVisibility, *m_pixelsOnlyCB, *m_projectRootDocuments, *m_projectRootDesktop, *m_projectRootCustom, *m_projectRootStuff, - *m_onionSkinDuringPlayback, *m_autoSaveSceneCB, *m_autoSaveOtherFilesCB; + *m_onionSkinDuringPlayback, *m_autoSaveSceneCB, *m_autoSaveOtherFilesCB, + *m_useNumpadForSwitchingStyles; DVGui::FileField *m_customProjectRootFileField; @@ -167,6 +168,7 @@ private slots: void onShowKeyframesOnCellAreaChanged(int); void onFfmpegPathChanged(); void onFfmpegTimeoutChanged(); + void onUseNumpadForSwitchingStylesClicked(bool); }; //********************************************************************************** diff --git a/toonz/sources/toonz/sceneviewer.h b/toonz/sources/toonz/sceneviewer.h index 0941505..10276dc 100644 --- a/toonz/sources/toonz/sceneviewer.h +++ b/toonz/sources/toonz/sceneviewer.h @@ -138,6 +138,7 @@ class SceneViewer final : public QGLWidget, LocatorPopup *m_locator; bool m_isLocator; + bool m_isStyleShortcutSwitchable; // iwsw commented out temporarily // Ghibli3DLutUtil * m_ghibli3DLutUtil; @@ -235,6 +236,7 @@ public: void setFocus(Qt::FocusReason reason) { QWidget::setFocus(reason); }; void setIsLocator() { m_isLocator = true; } + void setIsStyleShortcutSwitchable() { m_isStyleShortcutSwitchable = true; } public: // SceneViewer's gadget public functions diff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cpp index d07163f..7a7a924 100644 --- a/toonz/sources/toonz/sceneviewerevents.cpp +++ b/toonz/sources/toonz/sceneviewerevents.cpp @@ -16,6 +16,10 @@ #include "comboviewerpane.h" #include "locatorpopup.h" +// TnzQt includes +#include "toonzqt/tselectionhandle.h" +#include "toonzqt/styleselection.h" + // TnzTools includes #include "tools/cursors.h" #include "tools/toolhandle.h" @@ -768,6 +772,19 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) { tool->setViewer(this); + // If this object is child of Viewer or ComboViewer + // (m_isStyleShortcutSelective = true), + // then consider about shortcut for the current style selection. + if (m_isStyleShortcutSwitchable && + Preferences::instance()->isUseNumpadForSwitchingStylesEnabled() && + (!isTextToolActive) && (event->modifiers() == Qt::NoModifier || + event->modifiers() == Qt::KeypadModifier) && + ((Qt::Key_0 <= key && key <= Qt::Key_9) || key == Qt::Key_Tab || + key == Qt::Key_Backtab)) { + event->ignore(); + return; + } + if (key == Qt::Key_Shift) modifiers |= Qt::SHIFT; else if (key == Qt::Key_Control) diff --git a/toonz/sources/toonz/shortcutpopup.cpp b/toonz/sources/toonz/shortcutpopup.cpp index dda5bc8..b51b020 100644 --- a/toonz/sources/toonz/shortcutpopup.cpp +++ b/toonz/sources/toonz/shortcutpopup.cpp @@ -15,6 +15,9 @@ #include "toonzqt/menubarcommand.h" #include "toonzqt/dvdialog.h" +// TnzLib includes +#include "toonz/preferences.h" + // Qt includes #include #include @@ -136,6 +139,14 @@ void ShortcutViewer::keyPressEvent(QKeyEvent *event) { modifiers = 0; } + // If "Use Numpad and Tab keys for Switching Styles" option is activated, + // then prevent to assign such keys + if (Preferences::instance()->isUseNumpadForSwitchingStylesEnabled() && + modifiers == 0 && (key >= Qt::Key_0 && key <= Qt::Key_9)) { + event->ignore(); + return; + } + if (m_action) { CommandManager *cm = CommandManager::instance(); QKeySequence keySequence(key + modifiers); diff --git a/toonz/sources/toonz/styleshortcutswitchablepanel.cpp b/toonz/sources/toonz/styleshortcutswitchablepanel.cpp new file mode 100644 index 0000000..d680521 --- /dev/null +++ b/toonz/sources/toonz/styleshortcutswitchablepanel.cpp @@ -0,0 +1,112 @@ +#include "styleshortcutswitchablepanel.h" + +// TnzLib includes +#include "toonz/tscenehandle.h" +#include "toonz/preferences.h" +#include "toonz/palettecontroller.h" +#include "toonz/tpalettehandle.h" + +// TnzTools includes +#include "tools/toolhandle.h" +#include "tools/toolcommandids.h" + +// TnzQt includes +#include "toonzqt/tselectionhandle.h" +#include "toonzqt/styleselection.h" + +// Tnz6 includes +#include "tapp.h" + +#include + +//----------------------------------------------------------------------------- + +void StyleShortcutSwitchablePanel::keyPressEvent(QKeyEvent *event) { + if (!Preferences::instance()->isUseNumpadForSwitchingStylesEnabled()) return; + TTool *tool = TApp::instance()->getCurrentTool()->getTool(); + if (!tool) return; + if (tool->getName() == T_Type && tool->isActive()) return; + if (event->modifiers() != Qt::NoModifier && + event->modifiers() != Qt::KeypadModifier) + return; + int key = event->key(); + if (Qt::Key_0 <= key && key <= Qt::Key_9) { + TPaletteHandle *ph = + TApp::instance()->getPaletteController()->getCurrentLevelPalette(); + + TPalette *palette = ph->getPalette(); + if (palette) { + int styleId = palette->getShortcutValue(key); + if (styleId >= 0) { + ph->setStyleIndex(styleId); + TStyleSelection *selection = dynamic_cast( + TApp::instance()->getCurrentSelection()->getSelection()); + if (selection) selection->selectNone(); + } + } + event->accept(); + } else if (key == Qt::Key_Tab || key == Qt::Key_Backtab) { + TPaletteHandle *ph = + TApp::instance()->getPaletteController()->getCurrentLevelPalette(); + + TPalette *palette = ph->getPalette(); + if (palette) { + palette->nextShortcutScope(key == Qt::Key_Backtab); + ph->notifyPaletteChanged(); + } + event->accept(); + } +} + +//----------------------------------------------------------------------------- + +void StyleShortcutSwitchablePanel::showEvent(QShowEvent *event) { + TPanel::showEvent(event); + bool ret = connect(TApp::instance()->getCurrentScene(), + SIGNAL(preferenceChanged(const QString &)), this, + SLOT(onPreferenceChanged(const QString &))); + onPreferenceChanged(""); + assert(ret); +} + +//----------------------------------------------------------------------------- + +void StyleShortcutSwitchablePanel::hideEvent(QHideEvent *event) { + TPanel::hideEvent(event); + disconnect(TApp::instance()->getCurrentScene(), + SIGNAL(preferenceChanged(const QString &)), this, + SLOT(onPreferenceChanged(const QString &))); +} + +//----------------------------------------------------------------------------- + +void StyleShortcutSwitchablePanel::onPreferenceChanged( + const QString &prefName) { + if (prefName == "NumpadForSwitchingStyles" || prefName.isEmpty()) + updateTabFocus(); +} + +//----------------------------------------------------------------------------- + +void StyleShortcutSwitchablePanel::updateTabFocus() { + QList widgets = findChildren(); + if (Preferences::instance()->isUseNumpadForSwitchingStylesEnabled()) { + // disable tab focus + foreach (QWidget *widget, widgets) { + Qt::FocusPolicy policy = widget->focusPolicy(); + if (policy == Qt::TabFocus || policy == Qt::StrongFocus || + policy == Qt::WheelFocus) { + m_childrenFocusPolicies[widget] = policy; + widget->setFocusPolicy((policy == Qt::TabFocus) ? Qt::NoFocus + : Qt::ClickFocus); + } + } + } else { + // revert tab focus + QHashIterator i(m_childrenFocusPolicies); + while (i.hasNext()) { + i.next(); + i.key()->setFocusPolicy(i.value()); + } + } +} \ No newline at end of file diff --git a/toonz/sources/toonz/styleshortcutswitchablepanel.h b/toonz/sources/toonz/styleshortcutswitchablepanel.h new file mode 100644 index 0000000..ce68933 --- /dev/null +++ b/toonz/sources/toonz/styleshortcutswitchablepanel.h @@ -0,0 +1,39 @@ +#pragma once + +#ifndef STYLE_SHORTCUT_SWITCHABLE_PANEL_H +#define STYLE_SHORTCUT_SWITCHABLE_PANEL_H + +#include "pane.h" + +//============================================================================= +// StyleShortcutSwitchablePanel +//----------------------------------------------------------------------------- +// StyleShortcutSwitchablePanel class is subclass of TPanel and +// inherited by panels which can select the current style by 0-9 +// number keys if the Preferences option +// "Use Numpad and Tab keys for Switching Styles" is active. +// Currently inherited by ComboViewer, Viewer and Palette +//----------------------------------------------------------------------------- + +class StyleShortcutSwitchablePanel : public TPanel { + Q_OBJECT + + QHash m_childrenFocusPolicies; + +public: + StyleShortcutSwitchablePanel( + QWidget *parent = 0, Qt::WindowFlags flags = 0, + TDockWidget::Orientation orientation = TDockWidget::vertical) + : TPanel(parent, flags, orientation) {} + +protected: + void keyPressEvent(QKeyEvent *event) override; + void showEvent(QShowEvent *) override; + void hideEvent(QHideEvent *) override; + +protected slots: + virtual void onPreferenceChanged(const QString &prefName); + void updateTabFocus(); +}; + +#endif \ No newline at end of file diff --git a/toonz/sources/toonz/tpanels.cpp b/toonz/sources/toonz/tpanels.cpp index 74fee6a..8ed5795 100644 --- a/toonz/sources/toonz/tpanels.cpp +++ b/toonz/sources/toonz/tpanels.cpp @@ -402,7 +402,8 @@ public: // PaletteViewer //----------------------------------------------------------------------------- -PaletteViewerPanel::PaletteViewerPanel(QWidget *parent) : TPanel(parent) { +PaletteViewerPanel::PaletteViewerPanel(QWidget *parent) + : StyleShortcutSwitchablePanel(parent) { m_paletteHandle = new TPaletteHandle(); connect(m_paletteHandle, SIGNAL(colorStyleSwitched()), SLOT(onColorStyleSwitched())); diff --git a/toonz/sources/toonz/tpanels.h b/toonz/sources/toonz/tpanels.h index ed6cbf8..d6501d8 100644 --- a/toonz/sources/toonz/tpanels.h +++ b/toonz/sources/toonz/tpanels.h @@ -4,6 +4,7 @@ #define TPANELS_INCLUDED #include "pane.h" +#include "styleshortcutswitchablepanel.h" #include "tpalette.h" #include "trenderer.h" @@ -27,7 +28,7 @@ class ToolOptions; // PaletteViewerPanel //--------------------------------------------------------- -class PaletteViewerPanel final : public TPanel { +class PaletteViewerPanel final : public StyleShortcutSwitchablePanel { Q_OBJECT TPaletteHandle *m_paletteHandle; diff --git a/toonz/sources/toonz/viewerpane.cpp b/toonz/sources/toonz/viewerpane.cpp index deae824..6fc4ef7 100644 --- a/toonz/sources/toonz/viewerpane.cpp +++ b/toonz/sources/toonz/viewerpane.cpp @@ -77,7 +77,7 @@ SceneViewerPanel::SceneViewerPanel(QWidget *parent, Qt::WindowFlags flags) #else SceneViewerPanel::SceneViewerPanel(QWidget *parent, Qt::WFlags flags) #endif - : TPanel(parent) { + : StyleShortcutSwitchablePanel(parent) { QFrame *hbox = new QFrame(this); hbox->setFrameStyle(QFrame::StyledPanel); hbox->setObjectName("ViewerPanel"); @@ -94,6 +94,7 @@ SceneViewerPanel::SceneViewerPanel(QWidget *parent, Qt::WFlags flags) new ImageUtils::FullScreenWidget(viewer); fsWidget->setWidget(m_sceneViewer = new SceneViewer(fsWidget)); + m_sceneViewer->setIsStyleShortcutSwitchable(); bool ret = true; ret = ret && connect(m_sceneViewer, SIGNAL(onZoomChanged()), @@ -225,7 +226,8 @@ SceneViewerPanel::~SceneViewerPanel() {} //----------------------------------------------------------------------------- -void SceneViewerPanel::showEvent(QShowEvent *) { +void SceneViewerPanel::showEvent(QShowEvent *event) { + StyleShortcutSwitchablePanel::showEvent(event); TApp *app = TApp::instance(); TFrameHandle *frameHandle = app->getCurrentFrame(); TSceneHandle *sceneHandle = app->getCurrentScene(); @@ -264,10 +266,6 @@ void SceneViewerPanel::showEvent(QShowEvent *) { ret = ret && connect(app->getCurrentTool(), SIGNAL(toolSwitched()), m_sceneViewer, SLOT(onToolSwitched())); - ret = ret && connect(sceneHandle, SIGNAL(preferenceChanged()), m_flipConsole, - SLOT(onPreferenceChanged())); - m_flipConsole->onPreferenceChanged(); - assert(ret); // Aggiorno FPS al valore definito nel viewer corrente. @@ -277,7 +275,8 @@ void SceneViewerPanel::showEvent(QShowEvent *) { //----------------------------------------------------------------------------- -void SceneViewerPanel::hideEvent(QHideEvent *) { +void SceneViewerPanel::hideEvent(QHideEvent *event) { + StyleShortcutSwitchablePanel::hideEvent(event); TApp *app = TApp::instance(); TFrameHandle *frameHandle = app->getCurrentFrame(); TSceneHandle *sceneHandle = app->getCurrentScene(); @@ -310,9 +309,6 @@ void SceneViewerPanel::hideEvent(QHideEvent *) { disconnect(app->getCurrentTool(), SIGNAL(toolSwitched()), m_sceneViewer, SLOT(onToolSwitched())); - disconnect(sceneHandle, SIGNAL(preferenceChanged()), m_flipConsole, - SLOT(onPreferenceChanged())); - m_flipConsole->setActive(false); } @@ -658,6 +654,20 @@ void SceneViewerPanel::onFrameTypeChanged() { updateFrameMarkers(); } +//----------------------------------------------------------------------------- + +void SceneViewerPanel::onPreferenceChanged(const QString &prefName) { + // if no name specified (on StyleShortcutSelectivePanel::showEvent), + // then process all updates + if (prefName == "BlankCount" || prefName == "BlankColor" || + prefName.isEmpty()) + m_flipConsole->onPreferenceChanged(); + + StyleShortcutSwitchablePanel::onPreferenceChanged(prefName); +} + +//----------------------------------------------------------------------------- + void SceneViewerPanel::playAudioFrame(int frame) { if (m_first) { m_first = false; @@ -703,4 +713,4 @@ void SceneViewerPanel::onButtonPressed(FlipConsole::EGadget button) { if (button == FlipConsole::eSound) { m_playSound = !m_playSound; } -} \ No newline at end of file +} diff --git a/toonz/sources/toonz/viewerpane.h b/toonz/sources/toonz/viewerpane.h index b398fe4..48e5c11 100644 --- a/toonz/sources/toonz/viewerpane.h +++ b/toonz/sources/toonz/viewerpane.h @@ -3,7 +3,7 @@ #ifndef VIEWER_PANE_INCLUDED #define VIEWER_PANE_INCLUDED -#include "pane.h" +#include "styleshortcutswitchablepanel.h" #include "sceneviewer.h" #include "toonzqt/intfield.h" #include "toonzqt/keyframenavigator.h" @@ -25,7 +25,8 @@ class Ruler; class FlipConsole; class TXshLevel; -class SceneViewerPanel final : public TPanel, public FlipConsoleOwner { +class SceneViewerPanel final : public StyleShortcutSwitchablePanel, + public FlipConsoleOwner { Q_OBJECT friend class SceneViewer; @@ -86,6 +87,7 @@ protected slots: void onPlayingStatusChanged(bool playing); void enableFullPreview(bool enabled); void enableSubCameraPreview(bool enabled); + void onPreferenceChanged(const QString &prefName) override; }; #endif diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cpp index 07f7fcf..b325637 100644 --- a/toonz/sources/toonzlib/preferences.cpp +++ b/toonz/sources/toonzlib/preferences.cpp @@ -23,6 +23,7 @@ // Qt includes #include #include +#include // boost includes #include @@ -294,7 +295,8 @@ Preferences::Preferences() , m_customProjectRoot("") , m_precompute(true) , m_ffmpegTimeout(30) - , m_shortcutPreset("defopentoonz") { + , m_shortcutPreset("defopentoonz") + , m_useNumpadForSwitchingStyles(true) { TCamera camera; m_defLevelType = PLI_XSHLEVEL; m_defLevelWidth = camera.getSize().lx; @@ -563,6 +565,8 @@ Preferences::Preferences() QString shortcutPreset = m_settings->value("shortcutPreset").toString(); if (shortcutPreset != "") m_shortcutPreset = shortcutPreset; setShortcutPreset(m_shortcutPreset.toStdString()); + getValue(*m_settings, "useNumpadForSwitchingStyles", + m_useNumpadForSwitchingStyles); } //----------------------------------------------------------------- @@ -1320,3 +1324,10 @@ int Preferences::matchLevelFormat(const TFilePath &fp) const { return (lft != m_levelFormats.end()) ? lft - m_levelFormats.begin() : -1; } + +//----------------------------------------------------------------- + +void Preferences::enableUseNumpadForSwitchingStyles(bool on) { + m_useNumpadForSwitchingStyles = on; + m_settings->setValue("useNumpadForSwitchingStyles", on ? "1" : "0"); +} \ No newline at end of file diff --git a/toonz/sources/toonzqt/paletteviewergui.cpp b/toonz/sources/toonzqt/paletteviewergui.cpp index c42db3b..4cabe0d 100644 --- a/toonz/sources/toonzqt/paletteviewergui.cpp +++ b/toonz/sources/toonzqt/paletteviewergui.cpp @@ -591,6 +591,18 @@ void PageViewer::paintEvent(QPaintEvent *e) { QRect nameRect = getColorNameRect(i); drawColorName(p, nameRect, style, styleIndex); + // if numpad shortcut is activated, draw shortcut scope + if (Preferences::instance()->isUseNumpadForSwitchingStylesEnabled() && + m_viewType == LEVEL_PALETTE && + palette->getStyleShortcut(styleIndex) >= 0) { + p.setPen(QPen(QColor(0, 0, 0, 128), 2)); + p.drawLine(nameRect.topLeft() + QPoint(2, 1), + nameRect.bottomLeft() + QPoint(2, 0)); + p.setPen(QPen(QColor(255, 255, 255, 128), 2)); + p.drawLine(nameRect.topLeft() + QPoint(4, 1), + nameRect.bottomLeft() + QPoint(4, 0)); + } + // selezione if (m_styleSelection->isSelected(m_page->getIndex(), i)) { p.setPen(Qt::white); @@ -626,10 +638,37 @@ void PageViewer::paintEvent(QPaintEvent *e) { TColorStyle *style = m_page->getStyle(i); int styleIndex = m_page->getStyleId(i); + // if numpad shortcut is activated, draw shortcut scope + if (Preferences::instance()->isUseNumpadForSwitchingStylesEnabled() && + m_viewType == LEVEL_PALETTE && + palette->getStyleShortcut(styleIndex) >= 0) { + QRect itemRect = getItemRect(i); + // paint dark + p.setPen(Qt::NoPen); + p.setBrush(QColor(0, 0, 0, 64)); + p.drawRect(itemRect); + // check the neighbours and draw light lines + p.setPen(QPen(QColor(255, 255, 255, 128), 2)); + // top + if (!hasShortcut(i - m_chipPerRow)) + p.drawLine(itemRect.topLeft(), itemRect.topRight() - QPoint(1, 0)); + // left + if (i % m_chipPerRow == 0 || !hasShortcut(i - 1)) + p.drawLine(itemRect.topLeft() + QPoint(0, 1), itemRect.bottomLeft()); + // bottom + if (!hasShortcut(i + m_chipPerRow)) + p.drawLine(itemRect.bottomLeft() + QPoint(1, 0), + itemRect.bottomRight()); + // right + if ((i + 1) % m_chipPerRow == 0 || !hasShortcut(i + 1)) + p.drawLine(itemRect.topRight(), + itemRect.bottomRight() - QPoint(0, 1)); + } + // draw white frame if the style is selected or current if (m_styleSelection->isSelected(m_page->getIndex(), i) || currentStyleIndex == styleIndex) { - QRect itemRect = getItemRect(i).adjusted(-1, -2, 1, 2); + QRect itemRect = getItemRect(i).adjusted(0, -1, 0, 1); p.setPen(Qt::NoPen); p.setBrush(Qt::white); p.drawRoundRect(itemRect, 7, 25); @@ -795,6 +834,22 @@ void PageViewer::paintEvent(QPaintEvent *e) { p.drawLine(markPos - QPoint(0, 5), markPos + QPoint(0, 5)); } + // if numpad shortcut is activated, draw shortcut number on top + if (Preferences::instance()->isUseNumpadForSwitchingStylesEnabled() && + m_viewType == LEVEL_PALETTE && + palette->getStyleShortcut(styleIndex) >= 0 && + m_viewMode != SmallChips) { + int key = palette->getStyleShortcut(styleIndex); + int shortcut = key - Qt::Key_0; + QRect ssRect(chipRect.center().x() - 8, chipRect.top() - 11, 16, 20); + p.setBrush(Qt::gray); + p.drawChord(ssRect, 0, -180 * 16); + tmpFont.setPointSize(6); + p.setFont(tmpFont); + p.drawText(ssRect.adjusted(0, 10, 0, 0), Qt::AlignCenter, + QString().setNum(shortcut)); + } + // revert font set p.setFont(preFont); // revert brush @@ -1372,6 +1427,15 @@ void PageViewer::onStyleRenamed() { PaletteCmd::renamePaletteStyle(getPaletteHandle(), newName); } +//----------------------------------------------------------------------------- + +bool PageViewer::hasShortcut(int indexInPage) { + if (!m_page) return false; + if (indexInPage < 0 || indexInPage >= m_page->getStyleCount()) return false; + int styleIndex = m_page->getStyleId(indexInPage); + return (m_page->getPalette()->getStyleShortcut(styleIndex) >= 0); +} + //============================================================================= /*! \class PaletteViewerGUI::PaletteTabBar \brief The PaletteTabBar class provides a bar with tab to show