OpenToonz - An open-source full-featured 2D animation creation software
C
enable shortcut in paletteviewer
shun_iwasawacede7cbd4792
diff --git a/toonz/sources/toonz/CMakeLists.txt b/toonz/sources/toonz/CMakeLists.txtindex 62ee33824..a14ea2c62 100644--- a/toonz/sources/toonz/CMakeLists.txt+++ b/toonz/sources/toonz/CMakeLists.txt@@ -142,6 +142,7 @@ set(MOC_HEADERScleanupsettingspane.hpenciltestpopup.hlocatorpopup.h+ styleshortcutselectivepanel.h# Tracker filedummyprocessor.hmetnum.h@@ -302,6 +303,7 @@ set(SOURCEScleanupsettingspane.cpppenciltestpopup.cpplocatorpopup.cpp+ styleshortcutselectivepanel.cpp# Tracker filedummyprocessor.cppmetnum.cppdiff --git a/toonz/sources/toonz/comboviewerpane.cpp b/toonz/sources/toonz/comboviewerpane.cppindex 8a05db105..325f01aab 100644--- a/toonz/sources/toonz/comboviewerpane.cpp+++ b/toonz/sources/toonz/comboviewerpane.cpp@@ -86,7 +86,7 @@ ComboViewerPanel::ComboViewerPanel(QWidget *parent, Qt::WindowFlags flags)#elseComboViewerPanel::ComboViewerPanel(QWidget *parent, Qt::WFlags flags)#endif- : TPanel(parent) {+ : StyleShortcutSelectivePanel(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->setIsStyleShortcutSelective();#if defined(Q_OS_WIN) && (QT_VERSION >= 0x050500) && (QT_VERSION < 0x050600)// Workaround for QTBUG-48288@@ -339,7 +340,8 @@ ComboViewerPanel::~ComboViewerPanel() {//------------------------------------------------------------------------------void ComboViewerPanel::showEvent(QShowEvent *) {+void ComboViewerPanel::showEvent(QShowEvent *event) {+ StyleShortcutSelectivePanel::showEvent(event);TApp *app = TApp::instance();TFrameHandle *frameHandle = app->getCurrentFrame();TSceneHandle *sceneHandle = app->getCurrentScene();@@ -391,9 +393,6 @@ void ComboViewerPanel::showEvent(QShowEvent *) {ret = ret && connect(app->getCurrentTool(), SIGNAL(toolSwitched()),m_sceneViewer, SLOT(onToolSwitched()));- ret = ret && connect(sceneHandle, SIGNAL(preferenceChanged(const QString &)),- this, SLOT(onPreferenceChanged(const QString &)));- onPreferenceChanged("");assert(ret);@@ -406,7 +405,8 @@ void ComboViewerPanel::showEvent(QShowEvent *) {//------------------------------------------------------------------------------void ComboViewerPanel::hideEvent(QHideEvent *) {+void ComboViewerPanel::hideEvent(QHideEvent *event) {+ StyleShortcutSelectivePanel::hideEvent(event);TApp *app = TApp::instance();disconnect(app->getCurrentScene());disconnect(app->getCurrentLevel());@@ -791,31 +791,5 @@ void ComboViewerPanel::onPreferenceChanged(const QString &prefName) {prefName.isEmpty())m_flipConsole->onPreferenceChanged();- if (prefName == "NumpadForSwitchingStyles" || prefName.isEmpty())- updateTabFocus();+ StyleShortcutSelectivePanel::onPreferenceChanged(prefName);}--//-------------------------------------------------------------------------------void ComboViewerPanel::updateTabFocus() {- QList<QWidget *> widgets = findChildren<QWidget *>();- 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<QWidget *, Qt::FocusPolicy> i(m_childrenFocusPolicies);- while (i.hasNext()) {- i.next();- i.key()->setFocusPolicy(i.value());- }- }-}\ No newline at end of filediff --git a/toonz/sources/toonz/comboviewerpane.h b/toonz/sources/toonz/comboviewerpane.hindex c68643811..e8368300e 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 "styleshortcutselectivepanel.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 StyleShortcutSelectivePanel,+ public FlipConsoleOwner {Q_OBJECTSceneViewer *m_sceneViewer;@@ -55,8 +56,6 @@ class ComboViewerPanel final : public TPanel, public FlipConsoleOwner {TPanelTitleBarButton *m_previewButton;TPanelTitleBarButton *m_subcameraPreviewButton;- QHash<QWidget *, Qt::FocusPolicy> m_childrenFocusPolicies;-public:#if QT_VERSION >= 0x050500ComboViewerPanel(QWidget *parent = 0, Qt::WindowFlags flags = 0);@@ -121,8 +120,7 @@ protected slots:void enableFullPreview(bool enabled);void enableSubCameraPreview(bool enabled);- void onPreferenceChanged(const QString &prefName);- void updateTabFocus();+ void onPreferenceChanged(const QString &prefName) override;};#endifdiff --git a/toonz/sources/toonz/sceneviewer.h b/toonz/sources/toonz/sceneviewer.hindex 0941505b6..1362f661e 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_isStyleShortcutSelective;// 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 setIsStyleShortcutSelective() { m_isStyleShortcutSelective = true; }public:// SceneViewer's gadget public functionsdiff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cppindex 201a5530d..c7270fd47 100644--- a/toonz/sources/toonz/sceneviewerevents.cpp+++ b/toonz/sources/toonz/sceneviewerevents.cpp@@ -772,36 +772,15 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) {tool->setViewer(this);- if (Preferences::instance()->isUseNumpadForSwitchingStylesEnabled() &&- (!isTextToolActive)) {- 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<TStyleSelection *>(- TApp::instance()->getCurrentSelection()->getSelection());- if (selection) selection->selectNone();- }- }- event->accept();- return;- } 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();- return;- }+ // If this object is child of Viewer or ComboViewer+ // (m_isStyleShortcutSelective = true),+ // then consider about shortcut for the current style selection.+ if (m_isStyleShortcutSelective &&+ Preferences::instance()->isUseNumpadForSwitchingStylesEnabled() &&+ (!isTextToolActive) && ((Qt::Key_0 <= key && key <= Qt::Key_9) ||+ key == Qt::Key_Tab || key == Qt::Key_Backtab)) {+ event->ignore();+ return;}if (key == Qt::Key_Shift)diff --git a/toonz/sources/toonz/styleshortcutselectivepanel.cpp b/toonz/sources/toonz/styleshortcutselectivepanel.cppnew file mode 100644index 000000000..57b1fab6f--- /dev/null+++ b/toonz/sources/toonz/styleshortcutselectivepanel.cpp@@ -0,0 +1,109 @@+#include "styleshortcutselectivepanel.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 <QKeyEvent>++//-----------------------------------------------------------------------------++void StyleShortcutSelectivePanel::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;++ 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<TStyleSelection *>(+ 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 StyleShortcutSelectivePanel::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 StyleShortcutSelectivePanel::hideEvent(QHideEvent *event) {+ TPanel::hideEvent(event);+ disconnect(TApp::instance()->getCurrentScene(),+ SIGNAL(preferenceChanged(const QString &)), this,+ SLOT(onPreferenceChanged(const QString &)));+}++//-----------------------------------------------------------------------------++void StyleShortcutSelectivePanel::onPreferenceChanged(const QString &prefName) {+ if (prefName == "NumpadForSwitchingStyles" || prefName.isEmpty())+ updateTabFocus();+}++//-----------------------------------------------------------------------------++void StyleShortcutSelectivePanel::updateTabFocus() {+ QList<QWidget *> widgets = findChildren<QWidget *>();+ 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<QWidget *, Qt::FocusPolicy> i(m_childrenFocusPolicies);+ while (i.hasNext()) {+ i.next();+ i.key()->setFocusPolicy(i.value());+ }+ }+}\ No newline at end of filediff --git a/toonz/sources/toonz/styleshortcutselectivepanel.h b/toonz/sources/toonz/styleshortcutselectivepanel.hnew file mode 100644index 000000000..cacf5ce09--- /dev/null+++ b/toonz/sources/toonz/styleshortcutselectivepanel.h@@ -0,0 +1,38 @@+#pragma once++#ifndef STYLE_SHORTCUT_SELECTIVE_PANEL_H+#define STYLE_SHORTCUT_SELECTIVE_PANEL_H++#include "pane.h"++//=============================================================================+// StyleShortcutSelectivePanel+//-----------------------------------------------------------------------------+// StyleShortcutSelectivePanel class is 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 StyleShortcutSelectivePanel : public TPanel {+ Q_OBJECT++ QHash<QWidget *, Qt::FocusPolicy> m_childrenFocusPolicies;++public:+ StyleShortcutSelectivePanel(+ 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 filediff --git a/toonz/sources/toonz/tpanels.cpp b/toonz/sources/toonz/tpanels.cppindex 74fee6a76..70dc4b138 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)+ : StyleShortcutSelectivePanel(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.hindex ed6cbf83f..c0ff58b6f 100644--- a/toonz/sources/toonz/tpanels.h+++ b/toonz/sources/toonz/tpanels.h@@ -4,6 +4,7 @@#define TPANELS_INCLUDED#include "pane.h"+#include "styleshortcutselectivepanel.h"#include "tpalette.h"#include "trenderer.h"@@ -27,7 +28,7 @@ class ToolOptions;// PaletteViewerPanel//----------------------------------------------------------class PaletteViewerPanel final : public TPanel {+class PaletteViewerPanel final : public StyleShortcutSelectivePanel {Q_OBJECTTPaletteHandle *m_paletteHandle;diff --git a/toonz/sources/toonz/viewerpane.cpp b/toonz/sources/toonz/viewerpane.cppindex f10ad1a84..ca8db6c10 100644--- a/toonz/sources/toonz/viewerpane.cpp+++ b/toonz/sources/toonz/viewerpane.cpp@@ -77,7 +77,7 @@ SceneViewerPanel::SceneViewerPanel(QWidget *parent, Qt::WindowFlags flags)#elseSceneViewerPanel::SceneViewerPanel(QWidget *parent, Qt::WFlags flags)#endif- : TPanel(parent) {+ : StyleShortcutSelectivePanel(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->setIsStyleShortcutSelective();bool ret = true;ret = ret && connect(m_sceneViewer, SIGNAL(onZoomChanged()),@@ -220,7 +221,8 @@ SceneViewerPanel::~SceneViewerPanel() {}//------------------------------------------------------------------------------void SceneViewerPanel::showEvent(QShowEvent *) {+void SceneViewerPanel::showEvent(QShowEvent *event) {+ StyleShortcutSelectivePanel::showEvent(event);TApp *app = TApp::instance();TFrameHandle *frameHandle = app->getCurrentFrame();TSceneHandle *sceneHandle = app->getCurrentScene();@@ -259,10 +261,6 @@ void SceneViewerPanel::showEvent(QShowEvent *) {ret = ret && connect(app->getCurrentTool(), SIGNAL(toolSwitched()),m_sceneViewer, SLOT(onToolSwitched()));- ret = ret && connect(sceneHandle, SIGNAL(preferenceChanged(const QString &)),- this, SLOT(onPreferenceChanged(const QString &)));- onPreferenceChanged("");-assert(ret);// Aggiorno FPS al valore definito nel viewer corrente.@@ -272,7 +270,8 @@ void SceneViewerPanel::showEvent(QShowEvent *) {//------------------------------------------------------------------------------void SceneViewerPanel::hideEvent(QHideEvent *) {+void SceneViewerPanel::hideEvent(QHideEvent *event) {+ StyleShortcutSelectivePanel::hideEvent(event);TApp *app = TApp::instance();TFrameHandle *frameHandle = app->getCurrentFrame();TSceneHandle *sceneHandle = app->getCurrentScene();@@ -305,9 +304,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);}@@ -605,33 +601,13 @@ void SceneViewerPanel::onFrameTypeChanged() {//-----------------------------------------------------------------------------void SceneViewerPanel::onPreferenceChanged(const QString &prefName) {- // if no name specified (on showEvent), then process all updates+ // if no name specified (on StyleShortcutSelectivePanel::showEvent),+ // then process all updatesif (prefName == "BlankCount" || prefName == "BlankColor" ||prefName.isEmpty())m_flipConsole->onPreferenceChanged();- if (prefName == "NumpadForSwitchingStyles" || prefName.isEmpty()) {- QList<QWidget *> widgets = findChildren<QWidget *>();- if (Preferences::instance()->isUseNumpadForSwitchingStylesEnabled()) {- // disable tab key- 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<QWidget *, Qt::FocusPolicy> i(m_childrenFocusPolicies);- while (i.hasNext()) {- i.next();- i.key()->setFocusPolicy(i.value());- }- }- }+ StyleShortcutSelectivePanel::onPreferenceChanged(prefName);}//-----------------------------------------------------------------------------diff --git a/toonz/sources/toonz/viewerpane.h b/toonz/sources/toonz/viewerpane.hindex 168089183..e75eaca67 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 "styleshortcutselectivepanel.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 StyleShortcutSelectivePanel,+ public FlipConsoleOwner {Q_OBJECTfriend class SceneViewer;@@ -38,8 +39,6 @@ class SceneViewerPanel final : public TPanel, public FlipConsoleOwner {TPanelTitleBarButton *m_subcameraPreviewButton;bool m_onionSkinActive = false;- QHash<QWidget *, Qt::FocusPolicy> m_childrenFocusPolicies;-public:#if QT_VERSION >= 0x050500SceneViewerPanel(QWidget *parent = 0, Qt::WindowFlags flags = 0);@@ -77,7 +76,7 @@ protected slots:void onPlayingStatusChanged(bool playing);void enableFullPreview(bool enabled);void enableSubCameraPreview(bool enabled);- void onPreferenceChanged(const QString &prefName);+ void onPreferenceChanged(const QString &prefName) override;};#endifdiff --git a/toonz/sources/toonzqt/paletteviewergui.cpp b/toonz/sources/toonzqt/paletteviewergui.cppindex a692b7123..4cabe0d65 100644--- a/toonz/sources/toonzqt/paletteviewergui.cpp+++ b/toonz/sources/toonzqt/paletteviewergui.cpp@@ -593,6 +593,7 @@ void PageViewer::paintEvent(QPaintEvent *e) {// if numpad shortcut is activated, draw shortcut scopeif (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),@@ -639,6 +640,7 @@ void PageViewer::paintEvent(QPaintEvent *e) {// if numpad shortcut is activated, draw shortcut scopeif (Preferences::instance()->isUseNumpadForSwitchingStylesEnabled() &&+ m_viewType == LEVEL_PALETTE &&palette->getStyleShortcut(styleIndex) >= 0) {QRect itemRect = getItemRect(i);// paint dark@@ -832,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 setp.setFont(preFont);// revert brush