From 980cd73c5a3c7739b3b11f5ee2438c7c5fe7c79b Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Tue, 28 Dec 2021 22:39:04 +0100 Subject: [PATCH] Implemented request: show snapped cursor position in lower left position display. --- src/edt/edt/edtPartialService.cc | 3 +- src/laybasic/laybasic/gsiDeclLayPlugin.cc | 36 ++++++++++++++++++- src/laybasic/laybasic/layEditorServiceBase.cc | 6 +++- src/laybasic/laybasic/layEditorServiceBase.h | 19 ++++++++++ src/laybasic/laybasic/layMouseTracker.cc | 14 +++++++- src/laybasic/laybasic/layViewObject.h | 10 ++++++ 6 files changed, 84 insertions(+), 4 deletions(-) diff --git a/src/edt/edt/edtPartialService.cc b/src/edt/edt/edtPartialService.cc index 75fdfa989..e577f2213 100644 --- a/src/edt/edt/edtPartialService.cc +++ b/src/edt/edt/edtPartialService.cc @@ -1545,11 +1545,12 @@ PartialService::mouse_move_event (const db::DPoint &p, unsigned int buttons, boo // thus, we can bring the point on grid or to an object's edge or vertex snap_details = snap2 (p); m_current = snap_details.snapped_point; + mouse_cursor_from_snap_details (snap_details); } else { m_current = m_start + snap (p - m_start); + clear_mouse_cursors (); } - mouse_cursor_from_snap_details (snap_details); selection_to_view (); m_alt_ac = lay::AC_Global; diff --git a/src/laybasic/laybasic/gsiDeclLayPlugin.cc b/src/laybasic/laybasic/gsiDeclLayPlugin.cc index 5a7345f5b..5751fbb2b 100644 --- a/src/laybasic/laybasic/gsiDeclLayPlugin.cc +++ b/src/laybasic/laybasic/gsiDeclLayPlugin.cc @@ -268,6 +268,24 @@ public: } } + virtual bool has_tracking_position () const + { + if (f_has_tracking_position.can_issue ()) { + return f_has_tracking_position.issue (&lay::ViewService::has_tracking_position); + } else { + return lay::ViewService::has_tracking_position (); + } + } + + virtual db::DPoint tracking_position () const + { + if (f_tracking_position.can_issue ()) { + return f_tracking_position.issue (&lay::ViewService::tracking_position); + } else { + return lay::ViewService::tracking_position (); + } + } + gsi::Callback f_menu_activated; gsi::Callback f_configure; gsi::Callback f_config_finalize; @@ -284,6 +302,8 @@ public: gsi::Callback f_deactivated; gsi::Callback f_drag_cancel; gsi::Callback f_update; + gsi::Callback f_has_tracking_position; + gsi::Callback f_tracking_position; }; class PluginFactoryBase @@ -793,7 +813,7 @@ Class decl_Plugin ("lay", "Plugin", "If the plugin implements some press-and-drag or a click-and-drag operation, this callback should " "cancel this operation and return in some state waiting for a new mouse event." ) + - callback ("update", &gsi::PluginBase::update, &gsi::PluginBase::f_update, + callback ("update", &gsi::PluginBase::update, &gsi::PluginBase::f_update, "@brief Gets called when the view has changed\n" "This method is called in particular if the view has changed the visible rectangle, i.e. after zooming in or out or panning. " "This callback can be used to update any internal states that depend on the view's state." @@ -810,6 +830,20 @@ Class decl_Plugin ("lay", "Plugin", "in the mouse move handler unless a button is pressed or the cursor is explicitly set again in the mouse_move_event.\n" "\n" "The cursor type is one of the cursor constants in the \\Cursor class, i.e. 'CursorArrow' for the normal cursor." + ) + + callback ("has_tracking_position", &gsi::PluginBase::has_tracking_position, &gsi::PluginBase::f_has_tracking_position, + "@brief Gets a value indicating whether the plugin provides a tracking position\n" + "The tracking position is shown in the lower-left corner of the layout window to indicate the current position.\n" + "If this method returns true for the active service, the application will fetch the position by calling \\tracking_position " + "rather than displaying the original mouse position.\n" + "\n" + "This method has been added in version 0.27.6." + ) + + callback ("tracking_position", &gsi::PluginBase::tracking_position, &gsi::PluginBase::f_tracking_position, + "@brief Gets the tracking position\n" + "See \\has_tracking_position for details.\n" + "\n" + "This method has been added in version 0.27.6." ), "@brief The plugin object\n" "\n" diff --git a/src/laybasic/laybasic/layEditorServiceBase.cc b/src/laybasic/laybasic/layEditorServiceBase.cc index f89883c20..a099bae44 100644 --- a/src/laybasic/laybasic/layEditorServiceBase.cc +++ b/src/laybasic/laybasic/layEditorServiceBase.cc @@ -206,7 +206,8 @@ EditorServiceBase::EditorServiceBase (lay::LayoutView *view) : lay::ViewService (view->view_object_widget ()), lay::Editable (view), lay::Plugin (view), - m_cursor_enabled (true) + m_cursor_enabled (true), + m_has_tracking_position (false) { // .. nothing yet .. } @@ -219,6 +220,8 @@ EditorServiceBase::~EditorServiceBase () void EditorServiceBase::add_mouse_cursor (const db::DPoint &pt, bool emphasize) { + m_has_tracking_position = true; + m_tracking_position = pt; m_mouse_cursor_markers.push_back (new MouseCursorViewObject (this, widget (), pt, emphasize)); } @@ -231,6 +234,7 @@ EditorServiceBase::add_edge_marker (const db::DEdge &e, bool emphasize) void EditorServiceBase::clear_mouse_cursors () { + m_has_tracking_position = false; for (std::vector::iterator r = m_mouse_cursor_markers.begin (); r != m_mouse_cursor_markers.end (); ++r) { delete *r; } diff --git a/src/laybasic/laybasic/layEditorServiceBase.h b/src/laybasic/laybasic/layEditorServiceBase.h index 9f1a35c5b..22ee9e7ef 100644 --- a/src/laybasic/laybasic/layEditorServiceBase.h +++ b/src/laybasic/laybasic/layEditorServiceBase.h @@ -105,6 +105,22 @@ public: return m_cursor_enabled; } + /** + * @brief Gets a value indicating whether a cursor position it set + */ + virtual bool has_tracking_position () const + { + return m_has_tracking_position; + } + + /** + * @brief Gets the cursor position if one is set + */ + virtual db::DPoint tracking_position () const + { + return m_tracking_position; + } + protected: virtual bool configure (const std::string &name, const std::string &value); virtual void deactivated (); @@ -114,6 +130,9 @@ 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; }; } diff --git a/src/laybasic/laybasic/layMouseTracker.cc b/src/laybasic/laybasic/layMouseTracker.cc index 85e652ad9..43e42568a 100644 --- a/src/laybasic/laybasic/layMouseTracker.cc +++ b/src/laybasic/laybasic/layMouseTracker.cc @@ -38,8 +38,20 @@ bool MouseTracker::mouse_move_event (const db::DPoint &p, unsigned int /*buttons*/, bool prio) { if (prio) { - mp_view->current_pos (p.x (), p.y ()); + + // NOTE: because the tracker grabs first and grabbers are registered first gets served last, the + // tracker will receive the event after all other mouse grabbers have been served and had their + // chance to set the tracking position. + lay::ViewService *vs = mp_view->view_object_widget ()->active_service (); + db::DPoint tp = p; + if (vs && vs->enabled () && vs->has_tracking_position ()) { + tp = vs->tracking_position (); + } + + mp_view->current_pos (tp.x (), tp.y ()); + } + return false; } diff --git a/src/laybasic/laybasic/layViewObject.h b/src/laybasic/laybasic/layViewObject.h index 6be3330a6..bbe45a8eb 100644 --- a/src/laybasic/laybasic/layViewObject.h +++ b/src/laybasic/laybasic/layViewObject.h @@ -380,6 +380,16 @@ public: */ virtual void drag_cancel () { } + /** + * @brief Gets a value indicating whether a cursor position it set + */ + virtual bool has_tracking_position () const { return false; } + + /** + * @brief Gets the cursor position if one is set + */ + virtual db::DPoint tracking_position () const { return db::DPoint (); } + /** * @brief Enable or disable a service *