From 49d9d15c8517527eeccf2e035f91ca64bdaeea52 Mon Sep 17 00:00:00 2001 From: Rodney Date: Apr 14 2020 11:24:37 +0000 Subject: Merge pull request #3233 from turtletooth/hide_console Allow to Hide Console in Viewer --- diff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cpp index 20cf63c..70b8ef5 100644 --- a/toonz/sources/toonz/sceneviewerevents.cpp +++ b/toonz/sources/toonz/sceneviewerevents.cpp @@ -75,7 +75,7 @@ namespace { void initToonzEvent(TMouseEvent &toonzEvent, QMouseEvent *event, int widgetHeight, double pressure, int devPixRatio) { - toonzEvent.m_pos = TPointD(event->pos().x() * devPixRatio, + toonzEvent.m_pos = TPointD(event->pos().x() * devPixRatio, widgetHeight - 1 - event->pos().y() * devPixRatio); toonzEvent.m_mousePos = event->pos(); toonzEvent.m_pressure = 1.0; @@ -310,7 +310,7 @@ void SceneViewer::tabletEvent(QTabletEvent *e) { #ifdef LINUX // for Linux, create context menu on right click here. // could possibly merge with OSX code above - if(e->button() == Qt::RightButton) { + if (e->button() == Qt::RightButton) { m_mouseButton = Qt::NoButton; onContextMenu(e->pos(), e->globalPos()); } @@ -931,12 +931,12 @@ void SceneViewer::wheelEvent(QWheelEvent *event) { default: // Qt::MouseEventSynthesizedByQt, // Qt::MouseEventSynthesizedByApplication - { - std::cout << "not supported event: Qt::MouseEventSynthesizedByQt, " - "Qt::MouseEventSynthesizedByApplication" - << std::endl; - break; - } + { + std::cout << "not supported event: Qt::MouseEventSynthesizedByQt, " + "Qt::MouseEventSynthesizedByApplication" + << std::endl; + break; + } } // end switch @@ -1032,8 +1032,8 @@ void SceneViewer::gestureEvent(QGestureEvent *e) { qreal rotationDelta = gesture->rotationAngle() - gesture->lastRotationAngle(); if (m_isFlippedX != m_isFlippedY) rotationDelta = -rotationDelta; - TAffine aff = getViewMatrix().inv(); - TPointD center = aff * TPointD(0, 0); + TAffine aff = getViewMatrix().inv(); + TPointD center = aff * TPointD(0, 0); if (!m_rotating && !m_zooming) { m_rotationDelta += rotationDelta; double absDelta = abs(m_rotationDelta); @@ -1174,9 +1174,10 @@ bool SceneViewer::event(QEvent *e) { break; } */ - if (e->type() == QEvent::Gesture && CommandManager::instance() - ->getAction(MI_TouchGestureControl) - ->isChecked()) { + if (e->type() == QEvent::Gesture && + CommandManager::instance() + ->getAction(MI_TouchGestureControl) + ->isChecked()) { gestureEvent(static_cast(e)); return true; } @@ -1216,7 +1217,7 @@ bool SceneViewer::event(QEvent *e) { // Disable keyboard shortcuts while the tool is busy with a mouse drag // operation. - if ( tool->isDragging() ) { + if (tool->isDragging()) { e->accept(); } @@ -1597,6 +1598,13 @@ void SceneViewer::onContextMenu(const QPoint &pos, const QPoint &globalPos) { cvp->addShowHideContextMenu(menu); } + SceneViewerPanel *svp = qobject_cast( + parentWidget()->parentWidget()->parentWidget()); + if (svp) { + menu->addSeparator(); + svp->addShowHideContextMenu(menu); + } + menu->exec(globalPos); delete menu; menuVisible = false; @@ -1644,13 +1652,13 @@ void SceneViewer::dropEvent(QDropEvent *e) { IoCmd::loadResources(args); - if (acceptResourceOrFolderDrop(mimeData->urls())) { - // Force Copy Action - e->setDropAction(Qt::CopyAction); - // For files, don't accept original proposed action in case it's a move - e->accept(); - return; - } + if (acceptResourceOrFolderDrop(mimeData->urls())) { + // Force Copy Action + e->setDropAction(Qt::CopyAction); + // For files, don't accept original proposed action in case it's a move + e->accept(); + return; + } } e->acceptProposedAction(); } @@ -1664,8 +1672,8 @@ void SceneViewer::onToolSwitched() { TTool *tool = TApp::instance()->getCurrentTool()->getTool(); if (tool) { - tool->updateMatrix(); - if (tool->getViewer()) tool->getViewer()->setGuidedStrokePickerMode(0); + tool->updateMatrix(); + if (tool->getViewer()) tool->getViewer()->setGuidedStrokePickerMode(0); } onLevelChanged(); diff --git a/toonz/sources/toonz/tpanels.cpp b/toonz/sources/toonz/tpanels.cpp index 2121489..e300e4e 100644 --- a/toonz/sources/toonz/tpanels.cpp +++ b/toonz/sources/toonz/tpanels.cpp @@ -861,33 +861,6 @@ OpenFloatingPanel openStyleEditorCommand(MI_OpenStyleControl, "StyleEditor", QObject::tr("Style Editor")); //----------------------------------------------------------------------------- -//============================================================================= -// SceneViewer -//----------------------------------------------------------------------------- - -class SceneViewerFactory final : public TPanelFactory { -public: - SceneViewerFactory() : TPanelFactory("SceneViewer") {} - - TPanel *createPanel(QWidget *parent) override { - SceneViewerPanel *panel = new SceneViewerPanel(parent); - panel->setObjectName(getPanelType()); - panel->setWindowTitle(QObject::tr("Viewer")); - panel->setMinimumSize(220, 280); - return panel; - } - - void initialize(TPanel *panel) override { assert(0); } - -} sceneViewerFactory; - -//============================================================================= -OpenFloatingPanel openSceneViewerCommand(MI_OpenLevelView, "SceneViewer", - QObject::tr("Viewer")); -//----------------------------------------------------------------------------- - -//----------------------------------------------------------------------------- - class ToolbarFactory final : public TPanelFactory { public: ToolbarFactory() : TPanelFactory("ToolBar") {} @@ -1333,6 +1306,53 @@ OpenFloatingPanel openComboViewerCommand(MI_OpenComboViewer, "ComboViewer", //----------------------------------------------------------------------------- //============================================================================= +// SceneViewer +//----------------------------------------------------------------------------- + +SceneViewerPanelContainer::SceneViewerPanelContainer(QWidget* parent) + : StyleShortcutSwitchablePanel(parent) { + m_sceneViewer = new SceneViewerPanel(parent); + setFocusProxy(m_sceneViewer); + setWidget(m_sceneViewer); + + m_sceneViewer->initializeTitleBar(getTitleBar()); +} +// reimplementation of TPanel::widgetInThisPanelIsFocused +bool SceneViewerPanelContainer::widgetInThisPanelIsFocused() { + return m_sceneViewer->hasFocus(); +} +// reimplementation of TPanel::widgetFocusOnEnter +void SceneViewerPanelContainer::widgetFocusOnEnter() { + m_sceneViewer->onEnterPanel(); +} +void SceneViewerPanelContainer::widgetClearFocusOnLeave() { + m_sceneViewer->onLeavePanel(); +} + + +//----------------------------------------------------------------------------- + +class SceneViewerFactory final : public TPanelFactory { +public: + SceneViewerFactory() : TPanelFactory("SceneViewer") {} + + TPanel* createPanel(QWidget* parent) override { + SceneViewerPanelContainer* panel = new SceneViewerPanelContainer(parent); + panel->setObjectName(getPanelType()); + panel->setWindowTitle(QObject::tr("Viewer")); + panel->setMinimumSize(220, 280); + //panel->resize(700, 600); + return panel; + } + void initialize(TPanel* panel) override { assert(0); } +} sceneViewerFactory; + +//============================================================================= +OpenFloatingPanel openSceneViewerCommand(MI_OpenLevelView, "SceneViewer", + QObject::tr("Viewer")); +//----------------------------------------------------------------------------- + +//============================================================================= // CleanupSettings DockWindow //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/tpanels.h b/toonz/sources/toonz/tpanels.h index 44af77f..092b5ba 100644 --- a/toonz/sources/toonz/tpanels.h +++ b/toonz/sources/toonz/tpanels.h @@ -26,6 +26,7 @@ class FunctionViewer; class FlipBook; class ToolOptions; class ComboViewerPanel; +class SceneViewerPanel; class FxSettings; class VectorGuidedDrawingPane; @@ -272,6 +273,25 @@ protected: }; //========================================================= +// SceneViewerPanel +//--------------------------------------------------------- + +class SceneViewerPanelContainer final : public StyleShortcutSwitchablePanel { + Q_OBJECT + SceneViewerPanel *m_sceneViewer; + +public: + SceneViewerPanelContainer(QWidget* parent); + // reimplementation of TPanel::widgetInThisPanelIsFocused + bool widgetInThisPanelIsFocused() override; + +protected: + // reimplementation of TPanel::widgetFocusOnEnter + void widgetFocusOnEnter() override; + void widgetClearFocusOnLeave() override; +}; + +//========================================================= // FxSettingsPanel //--------------------------------------------------------- diff --git a/toonz/sources/toonz/viewerpane.cpp b/toonz/sources/toonz/viewerpane.cpp index b77e071..327d845 100644 --- a/toonz/sources/toonz/viewerpane.cpp +++ b/toonz/sources/toonz/viewerpane.cpp @@ -61,9 +61,19 @@ #include #include #include +#include #include "viewerpane.h" +enum CV_Parts { + CVPARTS_None = 0, + CVPARTS_TOOLBAR = 0x1, + CVPARTS_TOOLOPTIONS = 0x2, + CVPARTS_FLIPCONSOLE = 0x4, + CVPARTS_End = 0x8, + CVPARTS_ALL = CVPARTS_TOOLBAR | CVPARTS_TOOLOPTIONS | CVPARTS_FLIPCONSOLE +}; + using namespace DVGui; //============================================================================= @@ -77,17 +87,16 @@ SceneViewerPanel::SceneViewerPanel(QWidget *parent, Qt::WindowFlags flags) #else SceneViewerPanel::SceneViewerPanel(QWidget *parent, Qt::WFlags flags) #endif - : StyleShortcutSwitchablePanel(parent) { - QFrame *hbox = new QFrame(this); - hbox->setFrameStyle(QFrame::StyledPanel); - hbox->setObjectName("ViewerPanel"); + : QFrame(parent) { + setFrameStyle(QFrame::StyledPanel); + setObjectName("ViewerPanel"); - QVBoxLayout *mainLayout = new QVBoxLayout(hbox); + QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setMargin(0); mainLayout->setSpacing(0); // Viewer - QWidget *viewer = new QWidget(hbox); + QWidget *viewer = new QWidget(this); QGridLayout *viewerL = new QGridLayout(viewer); ImageUtils::FullScreenWidget *fsWidget = @@ -173,15 +182,79 @@ SceneViewerPanel::SceneViewerPanel(QWidget *parent, Qt::WFlags flags) ->getFrameRate()); updateFrameRange(), updateFrameMarkers(); - hbox->setLayout(mainLayout); - setWidget(hbox); + setLayout(mainLayout); + + m_visiblePartsFlag = CVPARTS_ALL; + updateShowHide(); + + setFocusProxy(m_sceneViewer); +} + +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +/*! toggle show/hide of the widgets according to m_visibleFlag + */ + +void SceneViewerPanel::updateShowHide() { + // flip console + m_flipConsole->showHideAllParts(m_visiblePartsFlag & CVPARTS_FLIPCONSOLE); + update(); +} + +//----------------------------------------------------------------------------- +/*! showing the show/hide commands + */ + +void SceneViewerPanel::contextMenuEvent(QContextMenuEvent* event) { + QMenu* menu = new QMenu(this); + addShowHideContextMenu(menu); + menu->exec(event->globalPos()); +} + + +//----------------------------------------------------------------------------- - initializeTitleBar( - getTitleBar()); // note: initializeTitleBar() refers to m_sceneViewer +void SceneViewerPanel::addShowHideContextMenu(QMenu* menu) { + QMenu* showHideMenu = menu->addMenu(tr("GUI Show / Hide")); + // actions + + QAction* flipConsoleSHAct = showHideMenu->addAction(tr("Console")); + flipConsoleSHAct->setCheckable(true); + flipConsoleSHAct->setChecked(m_visiblePartsFlag & CVPARTS_FLIPCONSOLE); + flipConsoleSHAct->setData((UINT)CVPARTS_FLIPCONSOLE); + + QActionGroup* showHideActGroup = new QActionGroup(this); + showHideActGroup->setExclusive(false); + showHideActGroup->addAction(flipConsoleSHAct); + + connect(showHideActGroup, SIGNAL(triggered(QAction*)), this, + SLOT(onShowHideActionTriggered(QAction*))); + + showHideMenu->addSeparator(); + showHideMenu->addAction(CommandManager::instance()->getAction(MI_ViewCamera)); + showHideMenu->addAction(CommandManager::instance()->getAction(MI_ViewTable)); + showHideMenu->addAction(CommandManager::instance()->getAction(MI_FieldGuide)); + showHideMenu->addAction(CommandManager::instance()->getAction(MI_SafeArea)); + showHideMenu->addAction(CommandManager::instance()->getAction(MI_ViewBBox)); + showHideMenu->addAction( + CommandManager::instance()->getAction(MI_ViewColorcard)); + showHideMenu->addAction(CommandManager::instance()->getAction(MI_ViewRuler)); } //----------------------------------------------------------------------------- +/*! slot function for show/hide the parts + */ + +void SceneViewerPanel::onShowHideActionTriggered(QAction* act) { + CV_Parts part = (CV_Parts)act->data().toUInt(); + assert(part < CVPARTS_End); + + m_visiblePartsFlag ^= part; + + updateShowHide(); +} void SceneViewerPanel::onDrawFrame( int frame, const ImagePainter::VisualSettings &settings) { @@ -229,7 +302,6 @@ SceneViewerPanel::~SceneViewerPanel() {} //----------------------------------------------------------------------------- void SceneViewerPanel::showEvent(QShowEvent *event) { - StyleShortcutSwitchablePanel::showEvent(event); TApp *app = TApp::instance(); TFrameHandle *frameHandle = app->getCurrentFrame(); TSceneHandle *sceneHandle = app->getCurrentScene(); @@ -250,7 +322,9 @@ void SceneViewerPanel::showEvent(QShowEvent *event) { ret = ret && connect(sceneHandle, SIGNAL(nameSceneChanged()), this, SLOT(changeWindowTitle())); - + ret = + ret && connect(sceneHandle, SIGNAL(preferenceChanged(const QString&)), + m_flipConsole, SLOT(onPreferenceChanged(const QString&))); ret = ret && connect(levelHandle, SIGNAL(xshLevelSwitched(TXshLevel *)), this, SLOT(onXshLevelSwitched(TXshLevel *))); ret = ret && connect(levelHandle, SIGNAL(xshLevelChanged()), this, @@ -275,12 +349,12 @@ void SceneViewerPanel::showEvent(QShowEvent *event) { // Aggiorno FPS al valore definito nel viewer corrente. // frameHandle->setPreviewFrameRate(m_fpsSlider->value()); m_flipConsole->setActive(true); + m_flipConsole->onPreferenceChanged(""); } //----------------------------------------------------------------------------- void SceneViewerPanel::hideEvent(QHideEvent *event) { - StyleShortcutSwitchablePanel::hideEvent(event); TApp *app = TApp::instance(); TFrameHandle *frameHandle = app->getCurrentFrame(); TSceneHandle *sceneHandle = app->getCurrentScene(); @@ -313,6 +387,8 @@ void SceneViewerPanel::hideEvent(QHideEvent *event) { disconnect(app->getCurrentTool(), SIGNAL(toolSwitched()), m_sceneViewer, SLOT(onToolSwitched())); + disconnect(app->getCurrentScene(), SIGNAL(preferenceChanged(const QString&)), + m_flipConsole, SLOT(onPreferenceChanged(const QString&))); m_flipConsole->setActive(false); } @@ -522,6 +598,7 @@ void SceneViewerPanel::changeWindowTitle() { // zoom = sqrt(m_sceneViewer->getViewMatrix().det()); ToonzScene *scene = app->getCurrentScene()->getScene(); if (!scene) return; + if (!parentWidget()) return; int frame = app->getCurrentFrame()->getFrame(); QString name; if (app->getCurrentFrame()->isEditingScene()) { @@ -535,7 +612,7 @@ void SceneViewerPanel::changeWindowTitle() { name + tr(" :: Frame: ") + tr(std::to_string(frame + 1).c_str()); int col = app->getCurrentColumn()->getColumnIndex(); if (col < 0) { - setWindowTitle(name); + parentWidget()->setWindowTitle(name); return; } TXsheet *xsh = app->getCurrentXsheet()->getXsheet(); @@ -552,7 +629,7 @@ void SceneViewerPanel::changeWindowTitle() { name = name + tr(" (Flipped)"); } } - setWindowTitle(name); + parentWidget()->setWindowTitle(name); return; } assert(cell.m_level.getPointer()); @@ -581,7 +658,7 @@ void SceneViewerPanel::changeWindowTitle() { } } - setWindowTitle(name); + parentWidget()->setWindowTitle(name); } //----------------------------------------------------------------------------- @@ -692,13 +769,6 @@ void SceneViewerPanel::onFrameTypeChanged() { //----------------------------------------------------------------------------- -void SceneViewerPanel::onPreferenceChanged(const QString &prefName) { - m_flipConsole->onPreferenceChanged(prefName); - StyleShortcutSwitchablePanel::onPreferenceChanged(prefName); -} - -//----------------------------------------------------------------------------- - void SceneViewerPanel::playAudioFrame(int frame) { if (m_first) { m_first = false; @@ -756,3 +826,20 @@ void SceneViewerPanel::setFlipHButtonChecked(bool checked) { void SceneViewerPanel::setFlipVButtonChecked(bool checked) { m_flipConsole->setChecked(FlipConsole::eFlipVertical, checked); } + +//----------------------------------------------------------------------------- + +void SceneViewerPanel::setVisiblePartsFlag(UINT flag) { + m_visiblePartsFlag = flag; + updateShowHide(); +} + +// SaveLoadQSettings +void SceneViewerPanel::save(QSettings& settings) const { + settings.setValue("visibleParts", m_visiblePartsFlag); +} + +void SceneViewerPanel::load(QSettings& settings) { + m_visiblePartsFlag = settings.value("visibleParts", CVPARTS_ALL).toUInt(); + updateShowHide(); +} \ No newline at end of file diff --git a/toonz/sources/toonz/viewerpane.h b/toonz/sources/toonz/viewerpane.h index 9d0034e..6197d74 100644 --- a/toonz/sources/toonz/viewerpane.h +++ b/toonz/sources/toonz/viewerpane.h @@ -3,11 +3,13 @@ #ifndef VIEWER_PANE_INCLUDED #define VIEWER_PANE_INCLUDED -#include "styleshortcutswitchablepanel.h" #include "sceneviewer.h" #include "toonzqt/intfield.h" #include "toonzqt/keyframenavigator.h" #include "toonzqt/flipconsoleowner.h" +#include "saveloadqsettings.h" + +#include class SceneViewer; class QPoint; @@ -25,8 +27,9 @@ class Ruler; class FlipConsole; class TXshLevel; -class SceneViewerPanel final : public StyleShortcutSwitchablePanel, - public FlipConsoleOwner { +class SceneViewerPanel final : public QFrame, + public FlipConsoleOwner, + public SaveLoadQSettings { Q_OBJECT friend class SceneViewer; @@ -38,6 +41,7 @@ class SceneViewerPanel final : public StyleShortcutSwitchablePanel, TPanelTitleBarButton *m_previewButton; TPanelTitleBarButton *m_subcameraPreviewButton; bool m_onionSkinActive = false; + UINT m_visiblePartsFlag; bool m_playSound = true; bool m_hasSoundtrack = false; bool m_playing = false; @@ -55,30 +59,40 @@ public: #endif ~SceneViewerPanel(); + // toggle show/hide of the widgets according to m_visiblePartsFlag + void setVisiblePartsFlag(UINT flag); + void updateShowHide(); + void addShowHideContextMenu(QMenu*); + void onDrawFrame(int frame, const ImagePainter::VisualSettings &settings) override; - bool widgetInThisPanelIsFocused() override { - return m_sceneViewer->hasFocus(); + + void onEnterPanel() { + m_sceneViewer->setFocus(Qt::OtherFocusReason); + // activate shortcut key for this flipconsole + m_flipConsole->makeCurrent(); } + void onLeavePanel() { m_sceneViewer->clearFocus(); } + + // SaveLoadQSettings + virtual void save(QSettings& settings) const override; + virtual void load(QSettings& settings) override; + + void initializeTitleBar(TPanelTitleBar* titleBar); protected: void showEvent(QShowEvent *) override; void hideEvent(QHideEvent *) override; void resizeEvent(QResizeEvent *) override; - void initializeTitleBar(TPanelTitleBar *titleBar); void createFrameToolBar(); void createPlayToolBar(); void addColorMaskButton(QWidget *parent, const char *iconSVGName, int id); // reimplementation of TPanel::widgetFocusOnEnter - void widgetFocusOnEnter() override { - m_sceneViewer->setFocus(Qt::OtherFocusReason); - // activate shortcut key for this flipconsole - m_flipConsole->makeCurrent(); - }; - void widgetClearFocusOnLeave() override { m_sceneViewer->clearFocus(); }; + void enableFlipConsoleForCamerastand(bool on); void playAudioFrame(int frame); bool hasSoundtrack(); + void contextMenuEvent(QContextMenuEvent* event) override; public slots: @@ -97,9 +111,10 @@ protected slots: void onSceneSwitched(); void onFrameTypeChanged(); void onPlayingStatusChanged(bool playing); + // for showing/hiding the parts + void onShowHideActionTriggered(QAction*); void enableFullPreview(bool enabled); void enableSubCameraPreview(bool enabled); - void onPreferenceChanged(const QString &prefName) override; }; #endif