From 387a098664025596c9ca064c888440c658b75431 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 22 Dec 2021 20:18:11 +0100 Subject: [PATCH 1/7] Can copy from previous drawing --- app/src/mainwindow2.cpp | 2 ++ app/src/shortcutspage.cpp | 1 + app/ui/mainwindow2.ui | 13 +++++++++++-- core_lib/data/resources/kb.ini | 1 + core_lib/src/interface/editor.cpp | 18 ++++++++++++++++++ core_lib/src/interface/editor.h | 1 + core_lib/src/util/pencildef.h | 1 + 7 files changed, 35 insertions(+), 2 deletions(-) diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index 8013771718..bdda3124d6 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -272,6 +272,7 @@ void MainWindow2::createMenus() connect(ui->actionRedo, &QAction::triggered, mEditor, &Editor::redo); connect(ui->actionCut, &QAction::triggered, mEditor, &Editor::copyAndCut); connect(ui->actionCopy, &QAction::triggered, mEditor, &Editor::copy); + connect(ui->actionCopy_Previous, &QAction::triggered, mEditor, &Editor::copyFromPreviousFrame); connect(ui->actionPaste, &QAction::triggered, mEditor, &Editor::paste); connect(ui->actionClearFrame, &QAction::triggered, mEditor, &Editor::clearCurrentFrame); connect(mEditor->select(), &SelectionManager::selectionChanged, this, &MainWindow2::selectionChanged); @@ -1157,6 +1158,7 @@ void MainWindow2::setupKeyboardShortcuts() ui->actionRedo->setShortcut(cmdKeySeq(CMD_REDO)); ui->actionCut->setShortcut(cmdKeySeq(CMD_CUT)); ui->actionCopy->setShortcut(cmdKeySeq(CMD_COPY)); + ui->actionCopy_Previous->setShortcut(cmdKeySeq(CMD_COPY_PREVIOUS)); ui->actionPaste->setShortcut(cmdKeySeq(CMD_PASTE)); ui->actionClearFrame->setShortcut(cmdKeySeq(CMD_CLEAR_FRAME)); ui->actionSelect_All->setShortcut(cmdKeySeq(CMD_SELECT_ALL)); diff --git a/app/src/shortcutspage.cpp b/app/src/shortcutspage.cpp index 6ac8169727..34a7317ad5 100644 --- a/app/src/shortcutspage.cpp +++ b/app/src/shortcutspage.cpp @@ -302,6 +302,7 @@ static QString getHumanReadableShortcutName(const QString& cmdName) {CMD_ADD_FRAME, ShortcutsPage::tr("Add Frame", "Shortcut")}, {CMD_CLEAR_FRAME, ShortcutsPage::tr("Clear Frame", "Shortcut")}, {CMD_COPY, ShortcutsPage::tr("Copy", "Shortcut")}, + {CMD_COPY_PREVIOUS, ShortcutsPage::tr("Copy Previous", "Shortcut")}, {CMD_CUT, ShortcutsPage::tr("Cut", "Shortcut")}, {CMD_DELETE_CUR_LAYER, ShortcutsPage::tr("Delete Current Layer", "Shortcut")}, {CMD_DESELECT_ALL, ShortcutsPage::tr("Deselect All", "Shortcut")}, diff --git a/app/ui/mainwindow2.ui b/app/ui/mainwindow2.ui index d05a490dc6..c33d2e439e 100644 --- a/app/ui/mainwindow2.ui +++ b/app/ui/mainwindow2.ui @@ -49,7 +49,7 @@ 0 0 831 - 22 + 26 @@ -112,6 +112,7 @@ + @@ -1160,7 +1161,7 @@ Remove Frames - + @@ -1173,6 +1174,14 @@ Status Bar + + + Copy Previous + + + Copy from Previous frame + + diff --git a/core_lib/data/resources/kb.ini b/core_lib/data/resources/kb.ini index d29ea3aadf..e30163d761 100644 --- a/core_lib/data/resources/kb.ini +++ b/core_lib/data/resources/kb.ini @@ -16,6 +16,7 @@ CmdUndo=Ctrl+Z CmdRedo=Ctrl+Shift+Z CmdCut=Ctrl+X CmdCopy=Ctrl+C +CmdCopyPrevious=Ctrl+Left CmdPaste=Ctrl+V CmdSelectAll=Ctrl+A CmdDeselectAll=Ctrl+D diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index a69310431c..ae08612e99 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -550,6 +550,24 @@ void Editor::copyAndCut() } } +void Editor::copyFromPreviousFrame() +{ + Layer* currentLayer = layers()->currentLayer(); + if (currentLayer->type() == Layer::BITMAP || currentLayer->type() == Layer::VECTOR) { + if (currentLayer->keyExists(mFrame) + && select()->somethingSelected() + && currentLayer->keyExists(currentLayer->getPreviousKeyFramePosition(mFrame))) + { + scrubBackward(); + copy(); + scrubForward(); + paste(); + mScribbleArea->applySelectionChanges(); + deselectAll(); + } + } +} + void Editor::pasteToCanvas(BitmapImage* bitmapImage, int frameNumber) { Layer* currentLayer = layers()->currentLayer(); diff --git a/core_lib/src/interface/editor.h b/core_lib/src/interface/editor.h index 5d79114359..235dd855fe 100644 --- a/core_lib/src/interface/editor.h +++ b/core_lib/src/interface/editor.h @@ -197,6 +197,7 @@ class Editor : public QObject void copy(); void copyAndCut(); + void copyFromPreviousFrame(); void paste(); bool canCopy() const; diff --git a/core_lib/src/util/pencildef.h b/core_lib/src/util/pencildef.h index 987c99aa00..df2f3443d2 100644 --- a/core_lib/src/util/pencildef.h +++ b/core_lib/src/util/pencildef.h @@ -128,6 +128,7 @@ const static int MaxFramesBound = 9999; #define CMD_CUT "CmdCut" #define CMD_COPY "CmdCopy" #define CMD_PASTE "CmdPaste" +#define CMD_COPY_PREVIOUS "CmdCopyPrevious" #define CMD_SELECT_ALL "CmdSelectAll" #define CMD_DESELECT_ALL "CmdDeselectAll" #define CMD_CLEAR_FRAME "CmdClearFrame" From 6ebb88c697112d39ab0eb97333d3141582be5608 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Thu, 23 Dec 2021 10:28:30 +0100 Subject: [PATCH 2/7] Changed menu text --- app/ui/mainwindow2.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/ui/mainwindow2.ui b/app/ui/mainwindow2.ui index c33d2e439e..09effce1f2 100644 --- a/app/ui/mainwindow2.ui +++ b/app/ui/mainwindow2.ui @@ -1176,7 +1176,7 @@ - Copy Previous + Copy from Previous Copy from Previous frame From 09c0bf9978eac6153c5ee41f888aef54eea2c5c6 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 8 Jun 2022 09:14:38 +0200 Subject: [PATCH 3/7] Refactored code. Renamed functions and menu labels. --- app/src/mainwindow2.cpp | 4 ++-- app/ui/mainwindow2.ui | 10 +++++----- core_lib/src/interface/editor.cpp | 27 +++++++++++++++------------ core_lib/src/interface/editor.h | 2 +- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index bdda3124d6..08619be40a 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -272,7 +272,7 @@ void MainWindow2::createMenus() connect(ui->actionRedo, &QAction::triggered, mEditor, &Editor::redo); connect(ui->actionCut, &QAction::triggered, mEditor, &Editor::copyAndCut); connect(ui->actionCopy, &QAction::triggered, mEditor, &Editor::copy); - connect(ui->actionCopy_Previous, &QAction::triggered, mEditor, &Editor::copyFromPreviousFrame); + connect(ui->actionPaste_Previous, &QAction::triggered, mEditor, &Editor::pasteFromPreviousFrame); connect(ui->actionPaste, &QAction::triggered, mEditor, &Editor::paste); connect(ui->actionClearFrame, &QAction::triggered, mEditor, &Editor::clearCurrentFrame); connect(mEditor->select(), &SelectionManager::selectionChanged, this, &MainWindow2::selectionChanged); @@ -1158,7 +1158,7 @@ void MainWindow2::setupKeyboardShortcuts() ui->actionRedo->setShortcut(cmdKeySeq(CMD_REDO)); ui->actionCut->setShortcut(cmdKeySeq(CMD_CUT)); ui->actionCopy->setShortcut(cmdKeySeq(CMD_COPY)); - ui->actionCopy_Previous->setShortcut(cmdKeySeq(CMD_COPY_PREVIOUS)); + ui->actionPaste_Previous->setShortcut(cmdKeySeq(CMD_COPY_PREVIOUS)); ui->actionPaste->setShortcut(cmdKeySeq(CMD_PASTE)); ui->actionClearFrame->setShortcut(cmdKeySeq(CMD_CLEAR_FRAME)); ui->actionSelect_All->setShortcut(cmdKeySeq(CMD_SELECT_ALL)); diff --git a/app/ui/mainwindow2.ui b/app/ui/mainwindow2.ui index c7b42b120d..0bb3c2cc62 100644 --- a/app/ui/mainwindow2.ui +++ b/app/ui/mainwindow2.ui @@ -49,7 +49,7 @@ 0 0 831 - 24 + 26 @@ -112,8 +112,8 @@ - + @@ -1171,12 +1171,12 @@ Status Bar - + - Copy from Previous + Paste from previous keyframe - Copy from Previous frame + Paste from previous keyframe diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index bec0025f57..2c92a72dce 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -50,7 +50,6 @@ GNU General Public License for more details. #include "timeline.h" #include "util.h" - Editor::Editor(QObject* parent) : QObject(parent) { mBackupIndex = -1; @@ -550,24 +549,28 @@ void Editor::copyAndCut() } } -void Editor::copyFromPreviousFrame() +void Editor::pasteFromPreviousFrame() { Layer* currentLayer = layers()->currentLayer(); - if (currentLayer->type() == Layer::BITMAP || currentLayer->type() == Layer::VECTOR) { - if (currentLayer->keyExists(mFrame) - && select()->somethingSelected() - && currentLayer->keyExists(currentLayer->getPreviousKeyFramePosition(mFrame))) - { - scrubBackward(); - copy(); - scrubForward(); + int prevFrame = currentLayer->getPreviousKeyFramePosition(mFrame); + if (currentLayer->keyExists(mFrame) && prevFrame != mFrame) + { + if (currentLayer->type() == Layer::BITMAP) { + BitmapImage* bitmapImage = static_cast(currentLayer->getKeyFrameAt(prevFrame)); + if (select()->somethingSelected()) + clipboards()->copyBitmapImage(bitmapImage, select()->mySelectionRect()); + else + clipboards()->copyBitmapImage(bitmapImage, mScribbleArea->getCameraRect()); + paste(); + } else if (currentLayer->type() == Layer::VECTOR) { + VectorImage* vectorImage = static_cast(currentLayer->getKeyFrameAt(prevFrame)); + clipboards()->copyVectorImage(vectorImage); paste(); - mScribbleArea->applySelectionChanges(); - deselectAll(); } } } + void Editor::pasteToCanvas(BitmapImage* bitmapImage, int frameNumber) { Layer* currentLayer = layers()->currentLayer(); diff --git a/core_lib/src/interface/editor.h b/core_lib/src/interface/editor.h index 235dd855fe..5b50b996e9 100644 --- a/core_lib/src/interface/editor.h +++ b/core_lib/src/interface/editor.h @@ -197,7 +197,7 @@ class Editor : public QObject void copy(); void copyAndCut(); - void copyFromPreviousFrame(); + void pasteFromPreviousFrame(); void paste(); bool canCopy() const; From 06392afca024c11b7d1964d9e3e59443997ae6e4 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 8 Jun 2022 16:02:59 +0200 Subject: [PATCH 4/7] Copy entire keyframe if nothing selected. Clean up code. --- core_lib/src/interface/editor.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 2c92a72dce..0aea1a99f5 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -555,22 +555,25 @@ void Editor::pasteFromPreviousFrame() int prevFrame = currentLayer->getPreviousKeyFramePosition(mFrame); if (currentLayer->keyExists(mFrame) && prevFrame != mFrame) { - if (currentLayer->type() == Layer::BITMAP) { + if (currentLayer->type() == Layer::BITMAP) + { BitmapImage* bitmapImage = static_cast(currentLayer->getKeyFrameAt(prevFrame)); if (select()->somethingSelected()) + { clipboards()->copyBitmapImage(bitmapImage, select()->mySelectionRect()); + paste(); + } else - clipboards()->copyBitmapImage(bitmapImage, mScribbleArea->getCameraRect()); - paste(); - } else if (currentLayer->type() == Layer::VECTOR) { + pasteToCanvas(bitmapImage, mFrame); + } + else if (currentLayer->type() == Layer::VECTOR) + { VectorImage* vectorImage = static_cast(currentLayer->getKeyFrameAt(prevFrame)); - clipboards()->copyVectorImage(vectorImage); - paste(); + pasteToCanvas(vectorImage, mFrame); } } } - void Editor::pasteToCanvas(BitmapImage* bitmapImage, int frameNumber) { Layer* currentLayer = layers()->currentLayer(); From 6607fbf858e3fa62ec478e7e2210bdd48eefed6a Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Thu, 9 Jun 2022 17:29:26 +0200 Subject: [PATCH 5/7] Backup of pasting. Not using clipboard. --- core_lib/src/interface/editor.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 0aea1a99f5..d4b61b3dd9 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -557,10 +557,11 @@ void Editor::pasteFromPreviousFrame() { if (currentLayer->type() == Layer::BITMAP) { + backup(tr("Paste from previous")); BitmapImage* bitmapImage = static_cast(currentLayer->getKeyFrameAt(prevFrame)); if (select()->somethingSelected()) { - clipboards()->copyBitmapImage(bitmapImage, select()->mySelectionRect()); + bitmapImage->copy(select()->mySelectionRect().toRect()); paste(); } else @@ -568,6 +569,7 @@ void Editor::pasteFromPreviousFrame() } else if (currentLayer->type() == Layer::VECTOR) { + backup(tr("Paste from previous")); VectorImage* vectorImage = static_cast(currentLayer->getKeyFrameAt(prevFrame)); pasteToCanvas(vectorImage, mFrame); } From ef6a5139790168f0dc66ab4bcb0ce7b0db2c5ad1 Mon Sep 17 00:00:00 2001 From: MrStevns Date: Fri, 10 Jun 2022 07:39:01 +0200 Subject: [PATCH 6/7] Fix paste stopped working with selections --- core_lib/src/interface/editor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index d4b61b3dd9..afd24225ce 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -561,8 +561,8 @@ void Editor::pasteFromPreviousFrame() BitmapImage* bitmapImage = static_cast(currentLayer->getKeyFrameAt(prevFrame)); if (select()->somethingSelected()) { - bitmapImage->copy(select()->mySelectionRect().toRect()); - paste(); + BitmapImage copy = bitmapImage->copy(select()->mySelectionRect().toRect()); + pasteToCanvas(©, mFrame); } else pasteToCanvas(bitmapImage, mFrame); From 79873e96f5d7932183400af10b74e29f6fe1e9f7 Mon Sep 17 00:00:00 2001 From: Jakob Gahde Date: Fri, 17 Jun 2022 08:36:08 +0200 Subject: [PATCH 7/7] Ensure consistent naming/spelling for paste from previous keyframe --- app/src/mainwindow2.cpp | 2 +- app/src/shortcutspage.cpp | 2 +- app/ui/mainwindow2.ui | 4 ++-- core_lib/data/resources/kb.ini | 2 +- core_lib/src/interface/editor.cpp | 34 +++++++++++++++++-------------- core_lib/src/util/pencildef.h | 2 +- 6 files changed, 25 insertions(+), 21 deletions(-) diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index 7793575452..81b36880e0 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -1195,7 +1195,7 @@ void MainWindow2::setupKeyboardShortcuts() ui->actionRedo->setShortcut(cmdKeySeq(CMD_REDO)); ui->actionCut->setShortcut(cmdKeySeq(CMD_CUT)); ui->actionCopy->setShortcut(cmdKeySeq(CMD_COPY)); - ui->actionPaste_Previous->setShortcut(cmdKeySeq(CMD_COPY_PREVIOUS)); + ui->actionPaste_Previous->setShortcut(cmdKeySeq(CMD_PASTE_FROM_PREVIOUS)); ui->actionPaste->setShortcut(cmdKeySeq(CMD_PASTE)); ui->actionClearFrame->setShortcut(cmdKeySeq(CMD_CLEAR_FRAME)); ui->actionSelect_All->setShortcut(cmdKeySeq(CMD_SELECT_ALL)); diff --git a/app/src/shortcutspage.cpp b/app/src/shortcutspage.cpp index 34a7317ad5..acabdea55e 100644 --- a/app/src/shortcutspage.cpp +++ b/app/src/shortcutspage.cpp @@ -302,7 +302,7 @@ static QString getHumanReadableShortcutName(const QString& cmdName) {CMD_ADD_FRAME, ShortcutsPage::tr("Add Frame", "Shortcut")}, {CMD_CLEAR_FRAME, ShortcutsPage::tr("Clear Frame", "Shortcut")}, {CMD_COPY, ShortcutsPage::tr("Copy", "Shortcut")}, - {CMD_COPY_PREVIOUS, ShortcutsPage::tr("Copy Previous", "Shortcut")}, + {CMD_PASTE_FROM_PREVIOUS, ShortcutsPage::tr("Paste from Previous Keyframe", "Shortcut")}, {CMD_CUT, ShortcutsPage::tr("Cut", "Shortcut")}, {CMD_DELETE_CUR_LAYER, ShortcutsPage::tr("Delete Current Layer", "Shortcut")}, {CMD_DESELECT_ALL, ShortcutsPage::tr("Deselect All", "Shortcut")}, diff --git a/app/ui/mainwindow2.ui b/app/ui/mainwindow2.ui index fd3fe54f4e..57905d5d22 100644 --- a/app/ui/mainwindow2.ui +++ b/app/ui/mainwindow2.ui @@ -1192,10 +1192,10 @@ - Paste from previous keyframe + Paste from Previous Keyframe - Paste from previous keyframe + Paste from Previous Keyframe diff --git a/core_lib/data/resources/kb.ini b/core_lib/data/resources/kb.ini index e30163d761..5e417811fa 100644 --- a/core_lib/data/resources/kb.ini +++ b/core_lib/data/resources/kb.ini @@ -16,7 +16,7 @@ CmdUndo=Ctrl+Z CmdRedo=Ctrl+Shift+Z CmdCut=Ctrl+X CmdCopy=Ctrl+C -CmdCopyPrevious=Ctrl+Left +CmdPasteFromPrevious=Ctrl+Left CmdPaste=Ctrl+V CmdSelectAll=Ctrl+A CmdDeselectAll=Ctrl+D diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 1a4e56da9d..b8ab068f59 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -560,27 +560,31 @@ void Editor::pasteFromPreviousFrame() { Layer* currentLayer = layers()->currentLayer(); int prevFrame = currentLayer->getPreviousKeyFramePosition(mFrame); - if (currentLayer->keyExists(mFrame) && prevFrame != mFrame) + if (!currentLayer->keyExists(mFrame) || prevFrame == mFrame) { - if (currentLayer->type() == Layer::BITMAP) + return; + } + + if (currentLayer->type() == Layer::BITMAP) + { + backup(tr("Paste from Previous Keyframe")); + BitmapImage* bitmapImage = static_cast(currentLayer->getKeyFrameAt(prevFrame)); + if (select()->somethingSelected()) { - backup(tr("Paste from previous")); - BitmapImage* bitmapImage = static_cast(currentLayer->getKeyFrameAt(prevFrame)); - if (select()->somethingSelected()) - { - BitmapImage copy = bitmapImage->copy(select()->mySelectionRect().toRect()); - pasteToCanvas(©, mFrame); - } - else - pasteToCanvas(bitmapImage, mFrame); + BitmapImage copy = bitmapImage->copy(select()->mySelectionRect().toRect()); + pasteToCanvas(©, mFrame); } - else if (currentLayer->type() == Layer::VECTOR) + else { - backup(tr("Paste from previous")); - VectorImage* vectorImage = static_cast(currentLayer->getKeyFrameAt(prevFrame)); - pasteToCanvas(vectorImage, mFrame); + pasteToCanvas(bitmapImage, mFrame); } } + else if (currentLayer->type() == Layer::VECTOR) + { + backup(tr("Paste from Previous Keyframe")); + VectorImage* vectorImage = static_cast(currentLayer->getKeyFrameAt(prevFrame)); + pasteToCanvas(vectorImage, mFrame); + } } void Editor::pasteToCanvas(BitmapImage* bitmapImage, int frameNumber) diff --git a/core_lib/src/util/pencildef.h b/core_lib/src/util/pencildef.h index 3efb60fafc..a463c301d1 100644 --- a/core_lib/src/util/pencildef.h +++ b/core_lib/src/util/pencildef.h @@ -129,7 +129,7 @@ const static int MaxFramesBound = 9999; #define CMD_CUT "CmdCut" #define CMD_COPY "CmdCopy" #define CMD_PASTE "CmdPaste" -#define CMD_COPY_PREVIOUS "CmdCopyPrevious" +#define CMD_PASTE_FROM_PREVIOUS "CmdPasteFromPrevious" #define CMD_SELECT_ALL "CmdSelectAll" #define CMD_DESELECT_ALL "CmdDeselectAll" #define CMD_CLEAR_FRAME "CmdClearFrame"