From 3e69f9c60bf8b469f529b7c311e46c266e74a8ec Mon Sep 17 00:00:00 2001 From: Jeremy Bullock Date: Nov 29 2017 10:58:38 +0000 Subject: Allow down arrow to create new frame in level strip. (#1028) * New Level Strip Drawing with Down Arrow (optional in preferences > drawing) --- diff --git a/toonz/sources/include/toonz/preferences.h b/toonz/sources/include/toonz/preferences.h index c2317f2..801ca00 100644 --- a/toonz/sources/include/toonz/preferences.h +++ b/toonz/sources/include/toonz/preferences.h @@ -168,9 +168,6 @@ public: void setCameraUnits(std::string s); QString getCameraUnits() const { return m_cameraUnits; } - // void setRoomChoice(std::string s); - // QString getRoomChoice() const { return m_roomChoice; } - void setCurrentRoomChoice(int currentRoomChoice); void setCurrentRoomChoice(QString currentRoomChoice); QString getCurrentRoomChoice() const; @@ -351,7 +348,6 @@ public: void setVectorSnappingTarget(int target); int getVectorSnappingTarget() { return m_vectorSnappingTarget; } - void setKeepFillOnVectorSimplify(bool on); bool getKeepFillOnVectorSimplify() { return m_keepFillOnVectorSimplify; } @@ -360,6 +356,11 @@ public: return m_useHigherDpiOnVectorSimplify; } + void setDownArrowLevelStripNewFrame(bool on); + bool getDownArrowLevelStripNewFrame() { + return m_downArrowInLevelStripCreatesNewFrame; + } + // Tools Tab void setDropdownShortcutsCycleOptions(bool on); bool getDropdownShortcutsCycleOptions() { @@ -586,6 +587,7 @@ private: bool m_onionSkinDuringPlayback, m_ignoreImageDpi, m_syncLevelRenumberWithXsheet; bool m_keepFillOnVectorSimplify, m_useHigherDpiOnVectorSimplify; + bool m_downArrowInLevelStripCreatesNewFrame; TPixel32 m_viewerBGColor, m_previewBGColor, m_chessboardColor1, m_chessboardColor2; bool m_showRasterImagesDarkenBlendedInViewer, diff --git a/toonz/sources/include/toonz/tframehandle.h b/toonz/sources/include/toonz/tframehandle.h index 6d5a656..b3c37ef 100644 --- a/toonz/sources/include/toonz/tframehandle.h +++ b/toonz/sources/include/toonz/tframehandle.h @@ -105,7 +105,7 @@ public: public slots: - void nextFrame(); + void nextFrame(TFrameId = 0); void prevFrame(); void firstFrame(); void lastFrame(); diff --git a/toonz/sources/toonz/filmstrip.cpp b/toonz/sources/toonz/filmstrip.cpp index f5dacbe..75fcb89 100644 --- a/toonz/sources/toonz/filmstrip.cpp +++ b/toonz/sources/toonz/filmstrip.cpp @@ -927,11 +927,20 @@ void FilmstripFrames::keyPressEvent(QKeyEvent *event) { level->getFids(fids); if (fids.empty()) return; + // If on a level frame pass the frame id after the last frame to allow + // creating a new frame with the down arrow key + TFrameId newId = 0; + if (Preferences::instance()->getDownArrowLevelStripNewFrame() && + fh->getFrameType() == TFrameHandle::LevelFrame) { + int frameCount = (int)fids.size(); + newId = index2fid(frameCount); + } + fh->setFrameIds(fids); if (event->key() == Qt::Key_Up) fh->prevFrame(); else if (event->key() == Qt::Key_Down) - fh->nextFrame(); + fh->nextFrame(newId); else if (event->key() == Qt::Key_Home) fh->firstFrame(); else if (event->key() == Qt::Key_End) diff --git a/toonz/sources/toonz/preferencespopup.cpp b/toonz/sources/toonz/preferencespopup.cpp index 3858889..6c3314a 100644 --- a/toonz/sources/toonz/preferencespopup.cpp +++ b/toonz/sources/toonz/preferencespopup.cpp @@ -521,6 +521,12 @@ void PreferencesPopup::onUseHigherDpiOnVectorSimplifyChanged(int index) { //----------------------------------------------------------------------------- +void PreferencesPopup::onDownArrowInLevelStripCreatesNewFrame(int index) { + m_pref->setDownArrowLevelStripNewFrame(index == Qt::Checked); +} + +//----------------------------------------------------------------------------- + void PreferencesPopup::onSubsceneFolderChanged(int index) { m_pref->enableSubsceneFolder(index == Qt::Checked); } @@ -1335,6 +1341,8 @@ PreferencesPopup::PreferencesPopup() tr("Keep fill when using \"Replace Vectors\" command"), this); m_useHigherDpiOnVectorSimplifyCB = new CheckBox( tr("Use higher DPI for calculations - Slower but more accurate"), this); + m_downArrowInLevelStripCreatesNewFrame = new CheckBox( + tr("Down arrow at end of level strip creates a new frame"), this); //--- Tools ------------------------------- categoryList->addItem(tr("Tools")); @@ -1637,6 +1645,8 @@ PreferencesPopup::PreferencesPopup() m_pref->getKeepFillOnVectorSimplify()); m_useHigherDpiOnVectorSimplifyCB->setChecked( m_pref->getUseHigherDpiOnVectorSimplify()); + m_downArrowInLevelStripCreatesNewFrame->setChecked( + m_pref->getDownArrowLevelStripNewFrame()); m_newLevelToCameraSizeCB->setChecked( m_pref->isNewLevelSizeToCameraSizeEnabled()); QStringList scanLevelTypes; @@ -2169,6 +2179,8 @@ PreferencesPopup::PreferencesPopup() Qt::AlignLeft | Qt::AlignVCenter); drawingFrameLay->addWidget(m_useNumpadForSwitchingStyles, 0, Qt::AlignLeft | Qt::AlignVCenter); + drawingFrameLay->addWidget(m_downArrowInLevelStripCreatesNewFrame, 0, + Qt::AlignLeft | Qt::AlignVCenter); QGroupBox *replaceVectorGroupBox = new QGroupBox( tr("Replace Vectors with Simplified Vectors Command"), this); QVBoxLayout *replaceVectorsLay = new QVBoxLayout(); @@ -2623,6 +2635,9 @@ PreferencesPopup::PreferencesPopup() ret = ret && connect(m_useHigherDpiOnVectorSimplifyCB, SIGNAL(stateChanged(int)), SLOT(onUseHigherDpiOnVectorSimplifyChanged(int))); + ret = ret && connect(m_downArrowInLevelStripCreatesNewFrame, + SIGNAL(stateChanged(int)), + SLOT(onDownArrowInLevelStripCreatesNewFrame(int))); ret = ret && connect(m_newLevelToCameraSizeCB, SIGNAL(clicked(bool)), SLOT(onNewLevelToCameraSizeChanged(bool))); diff --git a/toonz/sources/toonz/preferencespopup.h b/toonz/sources/toonz/preferencespopup.h index 6cdcb19..231b107 100644 --- a/toonz/sources/toonz/preferencespopup.h +++ b/toonz/sources/toonz/preferencespopup.h @@ -77,7 +77,7 @@ private: *m_useNumpadForSwitchingStyles, *m_expandFunctionHeader, *m_useHigherDpiOnVectorSimplifyCB, *m_keepFillOnVectorSimplifyCB, *m_newLevelToCameraSizeCB, *m_ignoreImageDpiCB, - *m_syncLevelRenumberWithXsheet; + *m_syncLevelRenumberWithXsheet, *m_downArrowInLevelStripCreatesNewFrame; DVGui::FileField *m_customProjectRootFileField; @@ -144,6 +144,7 @@ private slots: void onGetFillOnlySavebox(int index); void onFitToFlipbook(int); void onDropdownShortcutsCycleOptionsChanged(int); + void onDownArrowInLevelStripCreatesNewFrame(int); void onAddLevelFormat(); void onRemoveLevelFormat(); void onEditLevelFormat(); diff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cpp index 7ba8164..b53947d 100644 --- a/toonz/sources/toonz/sceneviewerevents.cpp +++ b/toonz/sources/toonz/sceneviewerevents.cpp @@ -1256,9 +1256,25 @@ void SceneViewer::keyPressEvent(QKeyEvent *event) { if (key == TwConsts::TK_UpArrow || key == TwConsts::TK_LeftArrow) fh->prevFrame(); - else if (key == TwConsts::TK_DownArrow || key == TwConsts::TK_RightArrow) - fh->nextFrame(); - else if (key == TwConsts::TK_Home) + else if (key == TwConsts::TK_DownArrow || key == TwConsts::TK_RightArrow) { + // If on a level frame pass the frame id after the last frame to allow + // creating a new frame with the down arrow key + TFrameId newId = 0; + if (Preferences::instance()->getDownArrowLevelStripNewFrame() && + fh->getFrameType() == TFrameHandle::LevelFrame) { + TXshSimpleLevel *level = + TApp::instance()->getCurrentLevel()->getLevel()->getSimpleLevel(); + if (level) { + std::vector fids; + level->getFids(fids); + if (!fids.empty()) { + int frameCount = (int)fids.size(); + newId = level->index2fid(frameCount); + } + } + } + fh->nextFrame(newId); + } else if (key == TwConsts::TK_Home) fh->firstFrame(); else if (key == TwConsts::TK_End) fh->lastFrame(); diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cpp index dd95bd3..34d6874 100644 --- a/toonz/sources/toonzlib/preferences.cpp +++ b/toonz/sources/toonzlib/preferences.cpp @@ -291,6 +291,7 @@ Preferences::Preferences() , m_regionAntialias(false) , m_keepFillOnVectorSimplify(true) , m_useHigherDpiOnVectorSimplify(false) + , m_downArrowInLevelStripCreatesNewFrame(false) , m_viewerBGColor(128, 128, 128, 255) , m_previewBGColor(64, 64, 64, 255) , m_chessboardColor1(180, 180, 180) @@ -575,6 +576,8 @@ Preferences::Preferences() getValue(*m_settings, "useHigherDpiOnVectorSimplify", m_useHigherDpiOnVectorSimplify); getValue(*m_settings, "keepFillOnVectorSimplify", m_keepFillOnVectorSimplify); + getValue(*m_settings, "downArrowInLevelStripCreatesNewFrame", + m_downArrowInLevelStripCreatesNewFrame); getValue(*m_settings, "DragCellsBehaviour", m_dragCellsBehaviour); getValue(*m_settings, "LineTestFpsCapture", m_lineTestFpsCapture); @@ -1342,6 +1345,13 @@ void Preferences::setUseHigherDpiOnVectorSimplify(bool on) { //----------------------------------------------------------------- +void Preferences::setDownArrowLevelStripNewFrame(bool on) { + m_downArrowInLevelStripCreatesNewFrame = on; + m_settings->setValue("downArrowInLevelStripCreatesNewFrame", on ? "1" : "0"); +} + +//----------------------------------------------------------------- + void Preferences::enableLevelsBackup(bool enabled) { m_levelsBackupEnabled = enabled; m_settings->setValue("levelsBackupEnabled", enabled ? "1" : "0"); diff --git a/toonz/sources/toonzlib/tframehandle.cpp b/toonz/sources/toonzlib/tframehandle.cpp index 6b6738c..12f7cce 100644 --- a/toonz/sources/toonzlib/tframehandle.cpp +++ b/toonz/sources/toonzlib/tframehandle.cpp @@ -122,7 +122,7 @@ void TFrameHandle::setFid(const TFrameId &fid) { //----------------------------------------------------------------------------- -void TFrameHandle::nextFrame() { +void TFrameHandle::nextFrame(TFrameId id) { if (m_frameType == LevelFrame) { // std::vector fids; // if(!getCurrentLevelFids(fids)) return; @@ -134,8 +134,12 @@ void TFrameHandle::nextFrame() { // frame dopo l'ultimo. // TXshSimpleLevel *sl = // TApp::instance()->getCurrentLevel()->getSimpleLevel(); - TFrameId fid = m_fids.back(); // sl->index2fid(sl->getFrameCount()); - setFid(fid); + if (id != 0) { + setFid(id); + } else { + TFrameId fid = m_fids.back(); // sl->index2fid(sl->getFrameCount()); + setFid(fid); + } } else setFid(*it); } else {