From cede7cbd4792a55e542ca2fe3f31dfb4efb2691f Mon Sep 17 00:00:00 2001 From: shun_iwasawa Date: Oct 31 2016 10:45:48 +0000 Subject: enable shortcut in paletteviewer --- diff --git a/toonz/sources/toonz/CMakeLists.txt b/toonz/sources/toonz/CMakeLists.txt index 62ee338..a14ea2c 100644 --- a/toonz/sources/toonz/CMakeLists.txt +++ b/toonz/sources/toonz/CMakeLists.txt @@ -142,6 +142,7 @@ set(MOC_HEADERS cleanupsettingspane.h penciltestpopup.h locatorpopup.h + styleshortcutselectivepanel.h # Tracker file dummyprocessor.h metnum.h @@ -302,6 +303,7 @@ set(SOURCES cleanupsettingspane.cpp penciltestpopup.cpp locatorpopup.cpp + styleshortcutselectivepanel.cpp # Tracker file dummyprocessor.cpp metnum.cpp diff --git a/toonz/sources/toonz/comboviewerpane.cpp b/toonz/sources/toonz/comboviewerpane.cpp index 8a05db1..325f01a 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) { + : 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 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/comboviewerpane.h b/toonz/sources/toonz/comboviewerpane.h index c686438..e836830 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_OBJECT SceneViewer *m_sceneViewer; @@ -55,8 +56,6 @@ class ComboViewerPanel final : public TPanel, public FlipConsoleOwner { TPanelTitleBarButton *m_previewButton; TPanelTitleBarButton *m_subcameraPreviewButton; - QHash m_childrenFocusPolicies; - public: #if QT_VERSION >= 0x050500 ComboViewerPanel(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; }; #endif diff --git a/toonz/sources/toonz/sceneviewer.h b/toonz/sources/toonz/sceneviewer.h index 0941505..1362f66 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 functions diff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cpp index 201a553..c7270fd 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( - 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.cpp new file mode 100644 index 0000000..57b1fab --- /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 + +//----------------------------------------------------------------------------- + +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( + 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 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/styleshortcutselectivepanel.h b/toonz/sources/toonz/styleshortcutselectivepanel.h new file mode 100644 index 0000000..cacf5ce --- /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 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 file diff --git a/toonz/sources/toonz/tpanels.cpp b/toonz/sources/toonz/tpanels.cpp index 74fee6a..70dc4b1 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.h index ed6cbf8..c0ff58b 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_OBJECT TPaletteHandle *m_paletteHandle; diff --git a/toonz/sources/toonz/viewerpane.cpp b/toonz/sources/toonz/viewerpane.cpp index f10ad1a..ca8db6c 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) { + : 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 updates if (prefName == "BlankCount" || prefName == "BlankColor" || prefName.isEmpty()) m_flipConsole->onPreferenceChanged(); - if (prefName == "NumpadForSwitchingStyles" || prefName.isEmpty()) { - QList widgets = findChildren(); - 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 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.h index 1680891..e75eaca 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_OBJECT friend class SceneViewer; @@ -38,8 +39,6 @@ class SceneViewerPanel final : public TPanel, public FlipConsoleOwner { TPanelTitleBarButton *m_subcameraPreviewButton; bool m_onionSkinActive = false; - QHash m_childrenFocusPolicies; - public: #if QT_VERSION >= 0x050500 SceneViewerPanel(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; }; #endif diff --git a/toonz/sources/toonzqt/paletteviewergui.cpp b/toonz/sources/toonzqt/paletteviewergui.cpp index a692b71..4cabe0d 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 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), @@ -639,6 +640,7 @@ void PageViewer::paintEvent(QPaintEvent *e) { // 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 @@ -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 set p.setFont(preFont); // revert brush