WIP: config options for mouse tracking options.

This commit is contained in:
Matthias Koefferlein 2020-09-07 23:19:44 +02:00
parent 307c10f184
commit df1583b5db
10 changed files with 354 additions and 36 deletions

View File

@ -62,7 +62,6 @@ ac_from_buttons (unsigned int buttons)
Service::Service (db::Manager *manager, lay::LayoutView *view, db::ShapeIterator::flags_type flags)
: lay::EditorServiceBase (view),
lay::Plugin (view),
db::Object (manager),
mp_view (view),
mp_transient_marker (0),
@ -83,7 +82,6 @@ Service::Service (db::Manager *manager, lay::LayoutView *view, db::ShapeIterator
Service::Service (db::Manager *manager, lay::LayoutView *view)
: lay::EditorServiceBase (view),
lay::Plugin (view),
db::Object (manager),
mp_view (view),
mp_transient_marker (0),
@ -261,6 +259,8 @@ Service::configure (const std::string &name, const std::string &value)
tl::from_string (value, m_hier_copy_mode);
service_configuration_changed ();
} else {
lay::EditorServiceBase::configure (name, value);
}
return false; // not taken
@ -813,7 +813,7 @@ Service::activated ()
void
Service::deactivated ()
{
clear_mouse_cursors ();
lay::EditorServiceBase::deactivated ();
edit_cancel ();

View File

@ -72,7 +72,6 @@ std::map<std::string, tl::Variant> pcell_parameters_from_string (const std::stri
class EDT_PUBLIC Service
: public lay::EditorServiceBase,
public lay::Plugin,
public db::Object
{
public:
@ -216,22 +215,6 @@ public:
return m_color;
}
/**
* @brief Obtain the lay::ViewService interface
*/
lay::ViewService *view_service_interface ()
{
return this;
}
/**
* @brief Obtain the lay::Editable interface
*/
lay::Editable *editable_interface ()
{
return this;
}
/**
* @brief Get the selection container
*/

View File

@ -4236,6 +4236,7 @@ public:
menu_entries.push_back (lay::menu_item ("cm_reset_window_state", "reset_window_state", at, tl::to_string (QObject::tr ("Restore Window")))),
menu_entries.push_back (lay::separator ("selection_group", at));
menu_entries.push_back (lay::config_menu_item ("transient_selection", at, tl::to_string (QObject::tr ("Highlight Object Under Mouse")), cfg_sel_transient_mode, "?"));
menu_entries.push_back (lay::config_menu_item ("mouse_tracking", at, tl::to_string (QObject::tr ("Mouse tracking")), cfg_tracking_cursor_enabled, "?"));
at = "help_menu.end";
menu_entries.push_back (lay::menu_item ("cm_show_all_tips", "show_all_tips", at, tl::to_string (QObject::tr ("Show All Tips"))));

View File

@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LayoutViewConfigPage2d</class>
<widget class="QFrame" name="LayoutViewConfigPage2d">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>608</width>
<height>318</height>
</rect>
</property>
<property name="windowTitle">
<string>Settings</string>
</property>
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<widget class="QGroupBox" name="tracking_cb">
<property name="title">
<string>Mouse tracking</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="1" column="1">
<widget class="lay::ColorButton" name="color_pb">
<property name="toolTip">
<string>The color in which the rulers are drawn</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="2">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>71</width>
<height>31</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="textLabel3_2">
<property name="text">
<string>Cursor color</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="label">
<property name="text">
<string>With mouse tracking enabled, a cursor will appear which indicates the snapped mouse position and whether the mouse snaps to objects.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>lay::ColorButton</class>
<extends>QPushButton</extends>
<header>layWidgets.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>color_pb</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@ -23,6 +23,8 @@
#include "layEditorServiceBase.h"
#include "layViewport.h"
#include "layLayoutView.h"
#include "laybasicConfig.h"
#include "layConverters.h"
namespace lay
{
@ -47,15 +49,50 @@ make_circle (double r, const db::DPoint &center, db::DPolygon &poly, bool as_hol
}
}
class MouseCursorViewObject
class TrackingCursorBase
: public lay::ViewObject
{
public:
MouseCursorViewObject (lay::ViewObjectWidget *widget, const db::DPoint &pt, bool solid)
: lay::ViewObject (widget, false), m_pt (pt), m_solid (solid)
TrackingCursorBase (lay::EditorServiceBase *service, lay::ViewObjectWidget *widget)
: lay::ViewObject (widget, false), mp_service (service)
{ }
uint32_t cursor_color (lay::ViewObjectCanvas &canvas) const
{
QColor color;
if (mp_service) {
color = mp_service->tracking_cursor_color ();
}
if (! color.isValid ()) {
color = canvas.foreground_color ();
}
return color.rgb ();
}
virtual void render (const lay::Viewport &vp, lay::ViewObjectCanvas &canvas)
{
if (mp_service && mp_service->tracking_cursor_enabled ()) {
do_render (vp, canvas);
}
}
protected:
virtual void do_render (const lay::Viewport &vp, lay::ViewObjectCanvas &canvas) = 0;
private:
lay::EditorServiceBase *mp_service;
};
class MouseCursorViewObject
: public TrackingCursorBase
{
public:
MouseCursorViewObject (lay::EditorServiceBase *service, lay::ViewObjectWidget *widget, const db::DPoint &pt, bool solid)
: TrackingCursorBase (service, widget), m_pt (pt), m_solid (solid)
{ }
protected:
virtual void do_render (const lay::Viewport &vp, lay::ViewObjectCanvas &canvas)
{
int dither_pattern = 0; // solid
int cross_dither_pattern = 6; // dotted
@ -64,10 +101,10 @@ public:
std::vector <lay::ViewOp> ops;
ops.resize (1);
ops[0] = lay::ViewOp (canvas.foreground_color ().rgb (), lay::ViewOp::Copy, 0, (unsigned int) dither_pattern, 0, lay::ViewOp::Rect, lw, 0);
ops[0] = lay::ViewOp (cursor_color (canvas), lay::ViewOp::Copy, 0, (unsigned int) dither_pattern, 0, lay::ViewOp::Rect, lw, 0);
lay::CanvasPlane *plane = canvas.plane (ops);
ops[0] = lay::ViewOp (canvas.foreground_color ().rgb (), lay::ViewOp::Copy, 0, (unsigned int) cross_dither_pattern, 0, lay::ViewOp::Rect, lw, 0);
ops[0] = lay::ViewOp (cursor_color (canvas), lay::ViewOp::Copy, 0, (unsigned int) cross_dither_pattern, 0, lay::ViewOp::Rect, lw, 0);
lay::CanvasPlane *cross_plane = canvas.plane (ops);
lay::Renderer &r = canvas.renderer ();
@ -95,14 +132,15 @@ private:
};
class EdgeMarkerViewObject
: public lay::ViewObject
: public TrackingCursorBase
{
public:
EdgeMarkerViewObject (lay::ViewObjectWidget *widget, const db::DEdge &edge, bool solid)
: lay::ViewObject (widget, false), m_edge (edge), m_solid (solid)
EdgeMarkerViewObject (lay::EditorServiceBase *service, lay::ViewObjectWidget *widget, const db::DEdge &edge, bool solid)
: TrackingCursorBase (service, widget), m_edge (edge), m_solid (solid)
{ }
virtual void render (const lay::Viewport &vp, lay::ViewObjectCanvas &canvas)
protected:
virtual void do_render (const lay::Viewport &vp, lay::ViewObjectCanvas &canvas)
{
if (m_edge.is_degenerate ()) {
return;
@ -115,10 +153,10 @@ public:
std::vector <lay::ViewOp> ops;
ops.resize (1);
ops[0] = lay::ViewOp (canvas.foreground_color ().rgb (), lay::ViewOp::Copy, solid_style, 0, 0, lay::ViewOp::Rect, lw, 0);
ops[0] = lay::ViewOp (cursor_color (canvas), lay::ViewOp::Copy, solid_style, 0, 0, lay::ViewOp::Rect, lw, 0);
lay::CanvasPlane *arrow_plane = canvas.plane (ops);
ops[0] = lay::ViewOp (canvas.foreground_color ().rgb (), lay::ViewOp::Copy, m_solid ? solid_style : dashed_style, 1, 0, lay::ViewOp::Rect, lw, 0);
ops[0] = lay::ViewOp (cursor_color (canvas), lay::ViewOp::Copy, m_solid ? solid_style : dashed_style, 1, 0, lay::ViewOp::Rect, lw, 0);
lay::CanvasPlane *edge_plane = canvas.plane (ops);
lay::Renderer &r = canvas.renderer ();
@ -166,7 +204,9 @@ private:
EditorServiceBase::EditorServiceBase (lay::LayoutView *view)
: lay::ViewService (view->view_object_widget ()),
lay::Editable (view)
lay::Editable (view),
lay::Plugin (view),
m_cursor_enabled (true)
{
// .. nothing yet ..
}
@ -179,13 +219,13 @@ EditorServiceBase::~EditorServiceBase ()
void
EditorServiceBase::add_mouse_cursor (const db::DPoint &pt, bool emphasize)
{
m_mouse_cursor_markers.push_back (new MouseCursorViewObject (widget (), pt, emphasize));
m_mouse_cursor_markers.push_back (new MouseCursorViewObject (this, widget (), pt, emphasize));
}
void
EditorServiceBase::add_edge_marker (const db::DEdge &e, bool emphasize)
{
m_mouse_cursor_markers.push_back (new EdgeMarkerViewObject (widget (), e, emphasize));
m_mouse_cursor_markers.push_back (new EdgeMarkerViewObject (this, widget (), e, emphasize));
}
void
@ -197,4 +237,46 @@ EditorServiceBase::clear_mouse_cursors ()
m_mouse_cursor_markers.clear ();
}
bool
EditorServiceBase::configure (const std::string &name, const std::string &value)
{
bool needs_update = false;
if (name == cfg_tracking_cursor_color) {
QColor color;
lay::ColorConverter ().from_string (value, color);
if (color != m_cursor_color) {
m_cursor_color = color;
needs_update = true;
}
} else if (name == cfg_tracking_cursor_enabled) {
bool f = m_cursor_enabled;
tl::from_string (value, f);
if (f != m_cursor_enabled) {
m_cursor_enabled = f;
needs_update = true;
}
}
if (needs_update) {
for (std::vector<lay::ViewObject *>::iterator r = m_mouse_cursor_markers.begin (); r != m_mouse_cursor_markers.end (); ++r) {
(*r)->redraw ();
}
}
// NOTE: we don't take the value as other services may be interested too.
return false;
}
void
EditorServiceBase::deactivated ()
{
clear_mouse_cursors ();
}
}

View File

@ -27,6 +27,7 @@
#include "laybasicCommon.h"
#include "layEditable.h"
#include "layViewObject.h"
#include "layPlugin.h"
namespace lay
{
@ -38,7 +39,8 @@ namespace lay
*/
class LAYBASIC_PUBLIC EditorServiceBase
: public lay::ViewService,
public lay::Editable
public lay::Editable,
public lay::Plugin
{
public:
/**
@ -51,6 +53,22 @@ public:
*/
~EditorServiceBase ();
/**
* @brief Obtain the lay::ViewService interface
*/
lay::ViewService *view_service_interface ()
{
return this;
}
/**
* @brief Obtain the lay::Editable interface
*/
lay::Editable *editable_interface ()
{
return this;
}
/**
* @brief Adds a mouse cursor to the given point
*/
@ -66,9 +84,31 @@ public:
*/
void clear_mouse_cursors ();
/**
* @brief Gets the tracking cursor color
*/
QColor tracking_cursor_color () const
{
return m_cursor_color;
}
/**
* @brief Gets a value indicating whether the tracking cursor is enabled
*/
bool tracking_cursor_enabled () const
{
return m_cursor_enabled;
}
protected:
virtual bool configure (const std::string &name, const std::string &value);
virtual void deactivated ();
private:
// The marker representing the mouse cursor
std::vector<lay::ViewObject *> m_mouse_cursor_markers;
QColor m_cursor_color;
bool m_cursor_enabled;
};
}

View File

@ -31,6 +31,7 @@
#include "ui_LayoutViewConfigPage2a.h"
#include "ui_LayoutViewConfigPage2b.h"
#include "ui_LayoutViewConfigPage2c.h"
#include "ui_LayoutViewConfigPage2d.h"
#include "ui_LayoutViewConfigPage3a.h"
#include "ui_LayoutViewConfigPage3b.h"
#include "ui_LayoutViewConfigPage3c.h"
@ -389,6 +390,42 @@ LayoutViewConfigPage2c::commit (lay::Dispatcher *root)
root->config_set (cfg_search_range, (unsigned int) mp_ui->search_range_spinbx->value ());
}
// ------------------------------------------------------------
// LayoutConfigPage2d implementation
LayoutViewConfigPage2d::LayoutViewConfigPage2d (QWidget *parent)
: lay::ConfigPage (parent)
{
mp_ui = new Ui::LayoutViewConfigPage2d ();
mp_ui->setupUi (this);
}
LayoutViewConfigPage2d::~LayoutViewConfigPage2d ()
{
delete mp_ui;
mp_ui = 0;
}
void
LayoutViewConfigPage2d::setup (lay::Dispatcher *root)
{
QColor color;
root->config_get (cfg_tracking_cursor_color, color, lay::ColorConverter ());
mp_ui->color_pb->set_color (color);
bool enabled = 0;
root->config_get (cfg_tracking_cursor_enabled, enabled);
mp_ui->tracking_cb->setChecked (enabled);
}
void
LayoutViewConfigPage2d::commit (lay::Dispatcher *root)
{
lay::ColorConverter cc;
root->config_set (cfg_tracking_cursor_color, mp_ui->color_pb->get_color (), cc);
root->config_set (cfg_tracking_cursor_enabled, mp_ui->tracking_cb->isChecked ());
}
// ------------------------------------------------------------
// LayoutConfigPage3a implementation
@ -1516,6 +1553,8 @@ public:
options.push_back (std::pair<std::string, std::string> (cfg_sel_halo, "true"));
options.push_back (std::pair<std::string, std::string> (cfg_sel_transient_mode, "true"));
options.push_back (std::pair<std::string, std::string> (cfg_sel_inside_pcells_mode, "false"));
options.push_back (std::pair<std::string, std::string> (cfg_tracking_cursor_enabled, "true"));
options.push_back (std::pair<std::string, std::string> (cfg_tracking_cursor_color, cc.to_string (QColor ())));
options.push_back (std::pair<std::string, std::string> (cfg_background_color, cc.to_string (QColor ())));
options.push_back (std::pair<std::string, std::string> (cfg_ctx_color, cc.to_string (QColor ())));
options.push_back (std::pair<std::string, std::string> (cfg_ctx_dimming, "50"));
@ -1571,6 +1610,7 @@ public:
pages.push_back (std::make_pair (tl::to_string (QObject::tr ("Display|Optimization")), new LayoutViewConfigPage3f (parent)));
pages.push_back (std::make_pair (tl::to_string (QObject::tr ("Application|Selection")), new LayoutViewConfigPage2c (parent)));
pages.push_back (std::make_pair (tl::to_string (QObject::tr ("Application|Tracking")), new LayoutViewConfigPage2d (parent)));
pages.push_back (std::make_pair (tl::to_string (QObject::tr ("Application|Layer Properties")), new LayoutViewConfigPage5 (parent)));
pages.push_back (std::make_pair (tl::to_string (QObject::tr ("Application|Units")), new LayoutViewConfigPage3c (parent)));

View File

@ -38,6 +38,7 @@ namespace Ui {
class LayoutViewConfigPage2a;
class LayoutViewConfigPage2b;
class LayoutViewConfigPage2c;
class LayoutViewConfigPage2d;
class LayoutViewConfigPage3a;
class LayoutViewConfigPage3b;
class LayoutViewConfigPage3c;
@ -138,7 +139,23 @@ private:
Ui::LayoutViewConfigPage2c *mp_ui;
};
class LayoutViewConfigPage3a
class LayoutViewConfigPage2d
: public lay::ConfigPage
{
Q_OBJECT
public:
LayoutViewConfigPage2d (QWidget *parent);
~LayoutViewConfigPage2d ();
virtual void setup (lay::Dispatcher *root);
virtual void commit (lay::Dispatcher *root);
private:
Ui::LayoutViewConfigPage2d *mp_ui;
};
class LayoutViewConfigPage3a
: public lay::ConfigPage
{
Q_OBJECT

View File

@ -31,6 +31,7 @@ FORMS = \
LayoutViewConfigPage2a.ui \
LayoutViewConfigPage2b.ui \
LayoutViewConfigPage2c.ui \
LayoutViewConfigPage2d.ui \
LayoutViewConfigPage3a.ui \
LayoutViewConfigPage3b.ui \
LayoutViewConfigPage3c.ui \

View File

@ -75,6 +75,9 @@ static const std::string cfg_sel_line_style ("sel-line-style");
static const std::string cfg_sel_transient_mode ("sel-transient-mode");
static const std::string cfg_sel_inside_pcells_mode ("sel-inside-pcells-mode");
static const std::string cfg_tracking_cursor_color ("tracking-cursor-color");
static const std::string cfg_tracking_cursor_enabled ("tracking-cursor-enabled");
static const std::string cfg_markers_visible ("markers-visible");
static const std::string cfg_min_inst_label_size ("min-inst-label-size");