Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undoable Polyline segments #1861

Merged
merged 6 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/src/mainwindow2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,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, mEditor, &Editor::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);
Expand Down Expand Up @@ -1185,6 +1186,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));
Expand Down
1 change: 1 addition & 0 deletions app/src/shortcutspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ static QString getHumanReadableShortcutName(const QString& cmdName)
{CMD_TOOL_SELECT, ShortcutsPage::tr("Select Tool", "Shortcut")},
{CMD_TOOL_SMUDGE, ShortcutsPage::tr("Smudge Tool", "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")},
Expand Down
8 changes: 8 additions & 0 deletions app/ui/mainwindow2.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,14 @@
<string>30°</string>
</property>
</action>
<action name="actionRemoveLastPolylineSegment">
<property name="text">
<string>Remove Last Polyline Segment</string>
</property>
<property name="toolTip">
<string>Removes the lastest Polyline segment</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down
1 change: 1 addition & 0 deletions core_lib/data/resources/kb.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CmdExportMovie=
CmdExportPalette=
CmdExportSound=Ctrl+I
CmdUndo=Ctrl+Z
CmdRemoveLastPolylineSegment=Backspace
CmdRedo=Ctrl+Shift+Z
CmdCut=Ctrl+X
CmdCopy=Ctrl+C
Expand Down
5 changes: 5 additions & 0 deletions core_lib/src/interface/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ void Editor::undo()
}
}

void Editor::removeLastPolylineSegment()
{
emit shouldRemoveLastPolylineSegment();
}
J5lx marked this conversation as resolved.
Show resolved Hide resolved

void Editor::redo()
{
if (!mBackupList.empty() && mBackupIndex < mBackupList.size() - 2)
Expand Down
3 changes: 3 additions & 0 deletions core_lib/src/interface/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class Editor : public QObject
void updateLayerCount();
void updateBackup();

void shouldRemoveLastPolylineSegment();

void objectLoaded();

void fpsChanged(int fps);
Expand Down Expand Up @@ -211,6 +213,7 @@ class Editor : public QObject

void onCurrentLayerWillChange(int index);
void undo();
void removeLastPolylineSegment();
void redo();

void copy();
Expand Down
17 changes: 17 additions & 0 deletions core_lib/src/tool/polylinetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ void PolylineTool::loadSettings()
{
StrokeTool::loadSettings();

connect(mEditor, &Editor::shouldRemoveLastPolylineSegment, this, &PolylineTool::removeLastSegment);

mPropertyEnabled[WIDTH] = true;
mPropertyEnabled[BEZIER] = true;
mPropertyEnabled[ANTI_ALIASING] = true;
Expand Down Expand Up @@ -198,6 +200,21 @@ void PolylineTool::pointerDoubleClickEvent(PointerEvent* event)
endPolyline(mPoints);
}

void PolylineTool::removeLastSegment()
{
if (!isActive()) return;

if (mPoints.size() > 1)
{
mPoints.removeLast();
drawPolyline(mPoints, getCurrentPoint());
}
else if (mPoints.size() == 1)
{
cancelPolyline();
clearToolData();
}
}

bool PolylineTool::keyPressEvent(QKeyEvent* event)
{
Expand Down
1 change: 1 addition & 0 deletions core_lib/src/tool/polylinetool.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class PolylineTool : public StrokeTool
private:
QList<QPointF> mPoints;

void removeLastSegment();
void drawPolyline(QList<QPointF> points, QPointF endPoint);
void cancelPolyline();
void endPolyline(QList<QPointF> points);
Expand Down
1 change: 1 addition & 0 deletions core_lib/src/util/pencildef.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ const static int MaxFramesBound = 9999;
#define CMD_EXPORT_PALETTE "CmdExportPalette"
#define CMD_EXPORT_SOUND "CmdExportSound"
#define CMD_UNDO "CmdUndo"
#define CMD_REMOVE_LAST_POLYLINE_SEGMENT "CmdRemoveLastPolylineSegment"
#define CMD_REDO "CmdRedo"
#define CMD_CUT "CmdCut"
#define CMD_COPY "CmdCopy"
Expand Down
Loading