diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index 2932ef6ad..8c138faf5 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -40,6 +40,7 @@ GNU General Public License for more details. #include "pencilsettings.h" #include "object.h" #include "editor.h" +#include "polylinetool.h" #include "filemanager.h" #include "colormanager.h" @@ -264,6 +265,7 @@ void MainWindow2::createMenus() //--- Edit Menu --- connect(mEditor, &Editor::updateBackup, this, &MainWindow2::undoActSetText); connect(ui->actionUndo, &QAction::triggered, mEditor, &Editor::undo); + connect(ui->actionRemoveLastPolylineSegment, &QAction::triggered, static_cast(mEditor->tools()->getTool(POLYLINE)), &PolylineTool::removeLastPolylineSegment); connect(ui->actionRedo, &QAction::triggered, mEditor, &Editor::redo); connect(ui->actionCut, &QAction::triggered, mEditor, &Editor::copyAndCut); connect(ui->actionCopy, &QAction::triggered, mEditor, &Editor::copy); @@ -1190,6 +1192,7 @@ void MainWindow2::setupKeyboardShortcuts() // edit menu ui->actionUndo->setShortcut(cmdKeySeq(CMD_UNDO)); ui->actionRedo->setShortcut(cmdKeySeq(CMD_REDO)); + ui->actionRemoveLastPolylineSegment->setShortcut(cmdKeySeq(CMD_REMOVE_LAST_POLYLINE_SEGMENT)); ui->actionCut->setShortcut(cmdKeySeq(CMD_CUT)); ui->actionCopy->setShortcut(cmdKeySeq(CMD_COPY)); ui->actionPaste_Previous->setShortcut(cmdKeySeq(CMD_PASTE_FROM_PREVIOUS)); @@ -1305,6 +1308,9 @@ void MainWindow2::setupKeyboardShortcuts() ui->actionHelp->setShortcut(cmdKeySeq(CMD_HELP)); ui->actionExit->setShortcut(cmdKeySeq(CMD_EXIT)); + + // Actions not in a menu won't work unless added to a widget + addAction(ui->actionRemoveLastPolylineSegment); } void MainWindow2::clearKeyboardShortcuts() diff --git a/app/src/shortcutspage.cpp b/app/src/shortcutspage.cpp index 36e887b6a..66caf4dc6 100644 --- a/app/src/shortcutspage.cpp +++ b/app/src/shortcutspage.cpp @@ -400,6 +400,7 @@ static QString getHumanReadableShortcutName(const QString& cmdName) {CMD_CHANGE_LINE_COLOR_LAYER, ShortcutsPage::tr("Change Line Color (All keyframes on layer)", "Shortcut")}, {CMD_CHANGE_LAYER_OPACITY, ShortcutsPage::tr("Change Layer / Keyframe Opacity", "Shortcut")}, {CMD_UNDO, ShortcutsPage::tr("Undo", "Shortcut")}, + {CMD_REMOVE_LAST_POLYLINE_SEGMENT, ShortcutsPage::tr("Remove Last Polyline Segment", "Shortcut")}, {CMD_ZOOM_100, ShortcutsPage::tr("Set Zoom to 100%", "Shortcut")}, {CMD_ZOOM_200, ShortcutsPage::tr("Set Zoom to 200%", "Shortcut")}, {CMD_ZOOM_25, ShortcutsPage::tr("Set Zoom to 25%", "Shortcut")}, diff --git a/app/ui/mainwindow2.ui b/app/ui/mainwindow2.ui index 39773e41a..68a843fe2 100644 --- a/app/ui/mainwindow2.ui +++ b/app/ui/mainwindow2.ui @@ -1273,6 +1273,14 @@ 30° + + + Remove Last Polyline Segment + + + Removes the lastest Polyline segment + + diff --git a/core_lib/data/resources/kb.ini b/core_lib/data/resources/kb.ini index 310431e1b..afcd263ec 100644 --- a/core_lib/data/resources/kb.ini +++ b/core_lib/data/resources/kb.ini @@ -20,6 +20,7 @@ CmdExportMovie= CmdExportGIF=Ctrl+G CmdExportPalette= CmdUndo=Ctrl+Z +CmdRemoveLastPolylineSegment=Backspace CmdRedo=Ctrl+Shift+Z CmdCut=Ctrl+X CmdCopy=Ctrl+C diff --git a/core_lib/src/tool/polylinetool.cpp b/core_lib/src/tool/polylinetool.cpp index 144a94729..4b8e1bcf7 100644 --- a/core_lib/src/tool/polylinetool.cpp +++ b/core_lib/src/tool/polylinetool.cpp @@ -211,6 +211,21 @@ void PolylineTool::pointerDoubleClickEvent(PointerEvent* event) endPolyline(mPoints); } +void PolylineTool::removeLastPolylineSegment() +{ + if (!isActive()) return; + + if (mPoints.size() > 1) + { + mPoints.removeLast(); + drawPolyline(mPoints, getCurrentPoint()); + } + else if (mPoints.size() == 1) + { + cancelPolyline(); + clearToolData(); + } +} bool PolylineTool::keyPressEvent(QKeyEvent* event) { diff --git a/core_lib/src/tool/polylinetool.h b/core_lib/src/tool/polylinetool.h index 14bcd8b15..da4b87606 100644 --- a/core_lib/src/tool/polylinetool.h +++ b/core_lib/src/tool/polylinetool.h @@ -47,6 +47,8 @@ class PolylineTool : public StrokeTool void setAA(const int AA) override; void setClosedPath(const bool closed) override; + void removeLastPolylineSegment(); + bool leavingThisTool() override; bool isActive() const override; diff --git a/core_lib/src/util/pencildef.h b/core_lib/src/util/pencildef.h index d69ffe879..bcd046e16 100644 --- a/core_lib/src/util/pencildef.h +++ b/core_lib/src/util/pencildef.h @@ -139,6 +139,7 @@ const static int MaxFramesBound = 9999; #define CMD_EXPORT_GIF "CmdExportGIF" #define CMD_EXPORT_PALETTE "CmdExportPalette" #define CMD_UNDO "CmdUndo" +#define CMD_REMOVE_LAST_POLYLINE_SEGMENT "CmdRemoveLastPolylineSegment" #define CMD_REDO "CmdRedo" #define CMD_CUT "CmdCut" #define CMD_COPY "CmdCopy"