From cb527cc50b2b5f7eb1786f69eb0a9d3c11ee566d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=B6fferlein?= Date: Sun, 10 Apr 2022 18:41:58 +0200 Subject: [PATCH] Issue-1058: implemented backspace button for path and polygon (#1061) --- src/edt/edt/edtService.cc | 11 ++++++++++ src/edt/edt/edtService.h | 12 +++++++++++ src/edt/edt/edtServiceImpl.cc | 22 +++++++++++++++++++- src/edt/edt/edtServiceImpl.h | 2 ++ src/laybasic/laybasic/layEditorServiceBase.h | 1 - 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/edt/edt/edtService.cc b/src/edt/edt/edtService.cc index d7e481492..40dbefc39 100644 --- a/src/edt/edt/edtService.cc +++ b/src/edt/edt/edtService.cc @@ -796,6 +796,17 @@ Service::mouse_click_event (const db::DPoint &p, unsigned int buttons, bool prio } } +bool +Service::key_event (unsigned int key, unsigned int buttons) +{ + if (view ()->is_editable () && m_editing && buttons == 0 && key == Qt::Key_Backspace) { + do_delete (); + return true; + } else { + return false; + } +} + void Service::activated () { diff --git a/src/edt/edt/edtService.h b/src/edt/edt/edtService.h index 41236648e..f084f7a01 100644 --- a/src/edt/edt/edtService.h +++ b/src/edt/edt/edtService.h @@ -322,6 +322,11 @@ public: */ virtual bool mouse_double_click_event (const db::DPoint &p, unsigned int buttons, bool prio); + /** + * @brief Implements the key handler + */ + virtual bool key_event (unsigned int /*key*/, unsigned int /*buttons*/); + /** * @brief Implement the mouse mode: deactivate mouse mode */ @@ -430,6 +435,13 @@ protected: */ virtual bool do_mouse_click (const db::DPoint & /*p*/) { return false; } + /** + * @brief Reimplemented by the specific implementation of the shape editors + * + * This method is called when the backspace button is pressed + */ + virtual void do_delete () { } + /** * @brief Reimplemented by the specific implementation of the shape editors * diff --git a/src/edt/edt/edtServiceImpl.cc b/src/edt/edt/edtServiceImpl.cc index 8a499991d..b22360339 100644 --- a/src/edt/edt/edtServiceImpl.cc +++ b/src/edt/edt/edtServiceImpl.cc @@ -420,6 +420,16 @@ PolygonService::do_mouse_move_inactive (const db::DPoint &p) mouse_cursor_from_snap_details (snap_details); } +void +PolygonService::do_delete () +{ + if (m_points.size () > 2) { + m_points.erase (m_points.end () - 2); + m_last = m_points.end()[-2]; + update_marker (); + } +} + void PolygonService::do_mouse_move (const db::DPoint &p) { @@ -1058,7 +1068,17 @@ PathService::do_mouse_click (const db::DPoint &p) return false; } -void +void +PathService::do_delete () +{ + if (m_points.size () > 2) { + m_points.erase (m_points.end () - 2); + m_last = m_points.end()[-2]; + update_marker (); + } +} + +void PathService::do_finish_edit () { // one point is reserved for the "current one" diff --git a/src/edt/edt/edtServiceImpl.h b/src/edt/edt/edtServiceImpl.h index 301122c0c..c3caf4383 100644 --- a/src/edt/edt/edtServiceImpl.h +++ b/src/edt/edt/edtServiceImpl.h @@ -89,6 +89,7 @@ public: PolygonService (db::Manager *manager, lay::LayoutView *view); virtual lay::PropertiesPage *properties_page (db::Manager *manager, QWidget *parent); + virtual void do_delete (); virtual void do_begin_edit (const db::DPoint &p); virtual void do_mouse_move (const db::DPoint &p); virtual void do_mouse_move_inactive (const db::DPoint &p); @@ -181,6 +182,7 @@ public: virtual void do_mouse_move (const db::DPoint &p); virtual bool do_mouse_click (const db::DPoint &p); virtual void do_mouse_move_inactive (const db::DPoint &p); + virtual void do_delete (); virtual void do_finish_edit (); virtual void do_cancel_edit (); virtual bool do_activated (); diff --git a/src/laybasic/laybasic/layEditorServiceBase.h b/src/laybasic/laybasic/layEditorServiceBase.h index dfeb5332b..d088c22fe 100644 --- a/src/laybasic/laybasic/layEditorServiceBase.h +++ b/src/laybasic/laybasic/layEditorServiceBase.h @@ -130,7 +130,6 @@ private: std::vector m_mouse_cursor_markers; QColor m_cursor_color; bool m_cursor_enabled; - lay::LayoutView *mp_view; bool m_has_tracking_position; db::DPoint m_tracking_position; };