Implemented request: show snapped cursor position in lower left position display.

This commit is contained in:
Matthias Koefferlein 2021-12-28 22:39:04 +01:00
parent 5f73d11fb1
commit 980cd73c5a
6 changed files with 84 additions and 4 deletions

View File

@ -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 // thus, we can bring the point on grid or to an object's edge or vertex
snap_details = snap2 (p); snap_details = snap2 (p);
m_current = snap_details.snapped_point; m_current = snap_details.snapped_point;
mouse_cursor_from_snap_details (snap_details);
} else { } else {
m_current = m_start + snap (p - m_start); m_current = m_start + snap (p - m_start);
clear_mouse_cursors ();
} }
mouse_cursor_from_snap_details (snap_details);
selection_to_view (); selection_to_view ();
m_alt_ac = lay::AC_Global; m_alt_ac = lay::AC_Global;

View File

@ -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, bool> (&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, db::DPoint> (&lay::ViewService::tracking_position);
} else {
return lay::ViewService::tracking_position ();
}
}
gsi::Callback f_menu_activated; gsi::Callback f_menu_activated;
gsi::Callback f_configure; gsi::Callback f_configure;
gsi::Callback f_config_finalize; gsi::Callback f_config_finalize;
@ -284,6 +302,8 @@ public:
gsi::Callback f_deactivated; gsi::Callback f_deactivated;
gsi::Callback f_drag_cancel; gsi::Callback f_drag_cancel;
gsi::Callback f_update; gsi::Callback f_update;
gsi::Callback f_has_tracking_position;
gsi::Callback f_tracking_position;
}; };
class PluginFactoryBase class PluginFactoryBase
@ -810,6 +830,20 @@ Class<gsi::PluginBase> 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" "in the mouse move handler unless a button is pressed or the cursor is explicitly set again in the mouse_move_event.\n"
"\n" "\n"
"The cursor type is one of the cursor constants in the \\Cursor class, i.e. 'CursorArrow' for the normal cursor." "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" "@brief The plugin object\n"
"\n" "\n"

View File

@ -206,7 +206,8 @@ EditorServiceBase::EditorServiceBase (lay::LayoutView *view)
: lay::ViewService (view->view_object_widget ()), : lay::ViewService (view->view_object_widget ()),
lay::Editable (view), lay::Editable (view),
lay::Plugin (view), lay::Plugin (view),
m_cursor_enabled (true) m_cursor_enabled (true),
m_has_tracking_position (false)
{ {
// .. nothing yet .. // .. nothing yet ..
} }
@ -219,6 +220,8 @@ EditorServiceBase::~EditorServiceBase ()
void void
EditorServiceBase::add_mouse_cursor (const db::DPoint &pt, bool emphasize) 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)); 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 void
EditorServiceBase::clear_mouse_cursors () EditorServiceBase::clear_mouse_cursors ()
{ {
m_has_tracking_position = false;
for (std::vector<lay::ViewObject *>::iterator r = m_mouse_cursor_markers.begin (); r != m_mouse_cursor_markers.end (); ++r) { for (std::vector<lay::ViewObject *>::iterator r = m_mouse_cursor_markers.begin (); r != m_mouse_cursor_markers.end (); ++r) {
delete *r; delete *r;
} }

View File

@ -105,6 +105,22 @@ public:
return m_cursor_enabled; 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: protected:
virtual bool configure (const std::string &name, const std::string &value); virtual bool configure (const std::string &name, const std::string &value);
virtual void deactivated (); virtual void deactivated ();
@ -114,6 +130,9 @@ private:
std::vector<lay::ViewObject *> m_mouse_cursor_markers; std::vector<lay::ViewObject *> m_mouse_cursor_markers;
QColor m_cursor_color; QColor m_cursor_color;
bool m_cursor_enabled; bool m_cursor_enabled;
lay::LayoutView *mp_view;
bool m_has_tracking_position;
db::DPoint m_tracking_position;
}; };
} }

View File

@ -38,8 +38,20 @@ bool
MouseTracker::mouse_move_event (const db::DPoint &p, unsigned int /*buttons*/, bool prio) MouseTracker::mouse_move_event (const db::DPoint &p, unsigned int /*buttons*/, bool prio)
{ {
if (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; return false;
} }

View File

@ -380,6 +380,16 @@ public:
*/ */
virtual void drag_cancel () { } 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 * @brief Enable or disable a service
* *