Implemented individual colors for grid lines, axes and rulers (background configuration page)

This commit is contained in:
Matthias Koefferlein 2019-08-23 22:31:01 +02:00
parent 4ccb7386eb
commit 850e288a28
4 changed files with 342 additions and 185 deletions

View File

@ -1,136 +1,180 @@
<ui version="4.0" > <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GridNetConfigPage</class> <class>GridNetConfigPage</class>
<widget class="QFrame" name="GridNetConfigPage" > <widget class="QFrame" name="GridNetConfigPage">
<property name="geometry" > <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>483</width> <width>483</width>
<height>204</height> <height>341</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string>Settings</string> <string>Settings</string>
</property> </property>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout">
<property name="margin" > <property name="spacing">
<number>9</number>
</property>
<property name="spacing" >
<number>6</number> <number>6</number>
</property> </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> <item>
<widget class="QGroupBox" name="grid_group" > <widget class="QGroupBox" name="grid_group">
<property name="sizePolicy" > <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<hsizetype>5</hsizetype>
<vsizetype>5</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="title" > <property name="title">
<string>Show background decoration</string> <string>Show background decoration</string>
</property> </property>
<property name="checkable" > <property name="checkable">
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QGridLayout" > <layout class="QGridLayout">
<property name="margin" > <property name="leftMargin">
<number>9</number> <number>9</number>
</property> </property>
<property name="spacing" > <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> <number>6</number>
</property> </property>
<item row="1" column="0" > <item row="2" column="2" colspan="2">
<widget class="QLabel" name="label_5" > <widget class="QComboBox" name="style1_cbx">
<property name="text" >
<string>Grid </string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2" >
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Color</string>
</property>
<property name="alignment" >
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QLabel" name="Close style" >
<property name="text" >
<string>Close style</string>
</property>
<property name="alignment" >
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="2" colspan="2" >
<widget class="QComboBox" name="style1_cbx" >
<item> <item>
<property name="text" > <property name="text">
<string>Invisible</string> <string>Invisible</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Dots</string> <string>Dots</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Dotted lines</string> <string>Dotted lines</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Light dotted lines</string> <string>Light dotted lines</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Dotted lines, ten dots per division </string> <string>Dotted lines, ten dots per division </string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Crosses</string> <string>Crosses</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Lines</string> <string>Lines</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Lines with ticks, ten ticks per division</string> <string>Lines with ticks, ten ticks per division</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Checkerboard</string> <string>Checkerboard</string>
</property> </property>
</item> </item>
</widget> </widget>
</item> </item>
<item row="4" column="2" colspan="2" > <item row="10" column="1">
<widget class="QCheckBox" name="show_ruler" > <widget class="QLabel" name="label_7">
<property name="text" > <property name="text">
<string>Show Ruler</string> <string>Color</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="4" > <item row="5" column="0" colspan="5">
<spacer> <widget class="Line" name="line_2">
<property name="orientation" > <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > </widget>
</item>
<item row="6" column="2" colspan="2">
<widget class="QComboBox" name="style0_cbx">
<item>
<property name="text">
<string>Invisible</string>
</property>
</item>
<item>
<property name="text">
<string>Dots</string>
</property>
</item>
<item>
<property name="text">
<string>Dotted lines</string>
</property>
</item>
<item>
<property name="text">
<string>Light dotted lines</string>
</property>
</item>
<item>
<property name="text">
<string>Dotted lines, ten dots per division </string>
</property>
</item>
<item>
<property name="text">
<string>Crosses</string>
</property>
</item>
<item>
<property name="text">
<string>Lines</string>
</property>
</item>
<item>
<property name="text">
<string>Lines with ticks, ten ticks per division</string>
</property>
</item>
</widget>
</item>
<item row="0" column="3">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -138,145 +182,202 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="3" > <item row="10" column="2">
<spacer> <widget class="QPushButton" name="grid_ruler_color_pb">
<property name="orientation" > <property name="text">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2" >
<widget class="QPushButton" name="grid_net_color_pb" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string/> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1" > <item row="1" column="0" colspan="5">
<widget class="QLabel" name="label_2" > <widget class="Line" name="line">
<property name="text" > <property name="orientation">
<string>Far style</string> <enum>Qt::Horizontal</enum>
</property>
<property name="alignment" >
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="2" colspan="2" > <item row="3" column="2" colspan="2">
<widget class="QComboBox" name="style2_cbx" > <widget class="QComboBox" name="style2_cbx">
<item> <item>
<property name="text" > <property name="text">
<string>Invisible</string> <string>Invisible</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Dots</string> <string>Dots</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Dotted lines</string> <string>Dotted lines</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Light dotted lines</string> <string>Light dotted lines</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Dotted lines, ten dots per division </string> <string>Dotted lines, ten dots per division </string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Crosses</string> <string>Crosses</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Lines</string> <string>Lines</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Lines with ticks, ten ticks per division</string> <string>Lines with ticks, ten ticks per division</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Checkerboard</string> <string>Checkerboard</string>
</property> </property>
</item> </item>
</widget> </widget>
</item> </item>
<item row="3" column="1" > <item row="3" column="1">
<widget class="QLabel" name="label_4" > <widget class="QLabel" name="label_2">
<property name="text" > <property name="text">
<string>Axis style</string> <string>Far style</string>
</property> </property>
<property name="alignment" > <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="2" colspan="2" > <item row="2" column="1">
<widget class="QComboBox" name="style0_cbx" > <widget class="QLabel" name="Close style">
<item> <property name="text">
<property name="text" > <string>Close style</string>
<string>Invisible</string> </property>
</property> <property name="alignment">
</item> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<item> </property>
<property name="text" > </widget>
<string>Dots</string> </item>
</property> <item row="0" column="0" colspan="2">
</item> <widget class="QLabel" name="label_3">
<item> <property name="text">
<property name="text" > <string>Color (all)</string>
<string>Dotted lines</string> </property>
</property> <property name="alignment">
</item> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
<item> </property>
<property name="text" > </widget>
<string>Light dotted lines</string> </item>
</property> <item row="4" column="2">
</item> <widget class="QPushButton" name="grid_grid_color_pb">
<item> <property name="text">
<property name="text" > <string/>
<string>Dotted lines, ten dots per division </string> </property>
</property> </widget>
</item> </item>
<item> <item row="2" column="0">
<property name="text" > <widget class="QLabel" name="label_5">
<string>Crosses</string> <property name="text">
</property> <string>Grid </string>
</item> </property>
<item> </widget>
<property name="text" > </item>
<string>Lines</string> <item row="9" column="2" colspan="2">
</property> <widget class="QCheckBox" name="show_ruler">
</item> <property name="text">
<item> <string>Show Ruler</string>
<property name="text" > </property>
<string>Lines with ticks, ten ticks per division</string> </widget>
</property> </item>
</item> <item row="7" column="2">
<widget class="QPushButton" name="grid_axis_color_pb">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="4">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="6" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Style</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Color</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="grid_net_color_pb">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Axis</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Color</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Ruler</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="5">
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -284,7 +385,7 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<layoutdefault spacing="6" margin="11" /> <layoutdefault spacing="6" margin="11"/>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -86,6 +86,9 @@ void
GridNetPluginDeclaration::get_options (std::vector < std::pair<std::string, std::string> > &options) const GridNetPluginDeclaration::get_options (std::vector < std::pair<std::string, std::string> > &options) const
{ {
options.push_back (std::pair<std::string, std::string> (cfg_grid_color, "auto")); options.push_back (std::pair<std::string, std::string> (cfg_grid_color, "auto"));
options.push_back (std::pair<std::string, std::string> (cfg_grid_ruler_color, "auto"));
options.push_back (std::pair<std::string, std::string> (cfg_grid_axis_color, "auto"));
options.push_back (std::pair<std::string, std::string> (cfg_grid_grid_color, "auto"));
options.push_back (std::pair<std::string, std::string> (cfg_grid_style0, GridNetStyleConverter ().to_string (lay::GridNet::Invisible))); options.push_back (std::pair<std::string, std::string> (cfg_grid_style0, GridNetStyleConverter ().to_string (lay::GridNet::Invisible)));
options.push_back (std::pair<std::string, std::string> (cfg_grid_style1, GridNetStyleConverter ().to_string (lay::GridNet::Dots))); options.push_back (std::pair<std::string, std::string> (cfg_grid_style1, GridNetStyleConverter ().to_string (lay::GridNet::Dots)));
options.push_back (std::pair<std::string, std::string> (cfg_grid_style2, GridNetStyleConverter ().to_string (lay::GridNet::TenthDottedLines))); options.push_back (std::pair<std::string, std::string> (cfg_grid_style2, GridNetStyleConverter ().to_string (lay::GridNet::TenthDottedLines)));
@ -119,6 +122,9 @@ GridNetConfigPage::GridNetConfigPage (QWidget *parent)
mp_ui->setupUi (this); mp_ui->setupUi (this);
mp_grid_color_cbtn = new lay::ColorButton (mp_ui->grid_net_color_pb); mp_grid_color_cbtn = new lay::ColorButton (mp_ui->grid_net_color_pb);
mp_grid_grid_color_cbtn = new lay::ColorButton (mp_ui->grid_grid_color_pb);
mp_grid_axis_color_cbtn = new lay::ColorButton (mp_ui->grid_axis_color_pb);
mp_grid_ruler_color_cbtn = new lay::ColorButton (mp_ui->grid_ruler_color_pb);
} }
GridNetConfigPage::~GridNetConfigPage () GridNetConfigPage::~GridNetConfigPage ()
@ -145,6 +151,15 @@ GridNetConfigPage::setup (lay::PluginRoot *root)
root->config_get (cfg_grid_color, color, ColorConverter ()); root->config_get (cfg_grid_color, color, ColorConverter ());
mp_grid_color_cbtn->set_color (color); mp_grid_color_cbtn->set_color (color);
root->config_get (cfg_grid_grid_color, color, ColorConverter ());
mp_grid_grid_color_cbtn->set_color (color);
root->config_get (cfg_grid_axis_color, color, ColorConverter ());
mp_grid_axis_color_cbtn->set_color (color);
root->config_get (cfg_grid_ruler_color, color, ColorConverter ());
mp_grid_ruler_color_cbtn->set_color (color);
lay::GridNet::GridStyle style; lay::GridNet::GridStyle style;
style = lay::GridNet::Invisible; style = lay::GridNet::Invisible;
@ -166,6 +181,9 @@ GridNetConfigPage::commit (lay::PluginRoot *root)
root->config_set (cfg_grid_visible, mp_ui->grid_group->isChecked ()); root->config_set (cfg_grid_visible, mp_ui->grid_group->isChecked ());
root->config_set (cfg_grid_show_ruler, mp_ui->show_ruler->isChecked ()); root->config_set (cfg_grid_show_ruler, mp_ui->show_ruler->isChecked ());
root->config_set (cfg_grid_color, mp_grid_color_cbtn->get_color (), lay::ColorConverter ()); root->config_set (cfg_grid_color, mp_grid_color_cbtn->get_color (), lay::ColorConverter ());
root->config_set (cfg_grid_grid_color, mp_grid_grid_color_cbtn->get_color (), lay::ColorConverter ());
root->config_set (cfg_grid_axis_color, mp_grid_axis_color_cbtn->get_color (), lay::ColorConverter ());
root->config_set (cfg_grid_ruler_color, mp_grid_ruler_color_cbtn->get_color (), lay::ColorConverter ());
root->config_set (cfg_grid_style0, lay::GridNet::GridStyle (mp_ui->style0_cbx->currentIndex ()), GridNetStyleConverter ()); root->config_set (cfg_grid_style0, lay::GridNet::GridStyle (mp_ui->style0_cbx->currentIndex ()), GridNetStyleConverter ());
root->config_set (cfg_grid_style1, lay::GridNet::GridStyle (mp_ui->style1_cbx->currentIndex ()), GridNetStyleConverter ()); root->config_set (cfg_grid_style1, lay::GridNet::GridStyle (mp_ui->style1_cbx->currentIndex ()), GridNetStyleConverter ());
root->config_set (cfg_grid_style2, lay::GridNet::GridStyle (mp_ui->style2_cbx->currentIndex ()), GridNetStyleConverter ()); root->config_set (cfg_grid_style2, lay::GridNet::GridStyle (mp_ui->style2_cbx->currentIndex ()), GridNetStyleConverter ());
@ -196,6 +214,24 @@ GridNet::configure (const std::string &name, const std::string &value)
ColorConverter ().from_string (value, color); ColorConverter ().from_string (value, color);
need_update = test_and_set (m_color, color); need_update = test_and_set (m_color, color);
} else if (name == cfg_grid_grid_color) {
QColor color;
ColorConverter ().from_string (value, color);
need_update = test_and_set (m_grid_color, color);
} else if (name == cfg_grid_axis_color) {
QColor color;
ColorConverter ().from_string (value, color);
need_update = test_and_set (m_axis_color, color);
} else if (name == cfg_grid_ruler_color) {
QColor color;
ColorConverter ().from_string (value, color);
need_update = test_and_set (m_ruler_color, color);
} else if (name == cfg_grid_style0) { } else if (name == cfg_grid_style0) {
lay::GridNet::GridStyle style; lay::GridNet::GridStyle style;
@ -404,6 +440,17 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
color = QColor (128, 128, 128); // TODO: this is not a "real" automatic color .. color = QColor (128, 128, 128); // TODO: this is not a "real" automatic color ..
} }
QColor grid_color = color, axis_color = color, ruler_color = color;
if (m_grid_color.isValid ()) {
grid_color = m_grid_color;
}
if (m_axis_color.isValid ()) {
axis_color = m_axis_color;
}
if (m_ruler_color.isValid ()) {
ruler_color = m_ruler_color;
}
// TODO: currently, the grid net can only be rendered to a bitmap canvas .. // TODO: currently, the grid net can only be rendered to a bitmap canvas ..
BitmapViewObjectCanvas *bmp_canvas = dynamic_cast<BitmapViewObjectCanvas *> (&canvas); BitmapViewObjectCanvas *bmp_canvas = dynamic_cast<BitmapViewObjectCanvas *> (&canvas);
if (! bmp_canvas) { if (! bmp_canvas) {
@ -457,15 +504,15 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
painter.fill_rect (QPoint (xoffset, vp.height () - yoffset - rh / 2), painter.fill_rect (QPoint (xoffset, vp.height () - yoffset - rh / 2),
QPoint (xoffset + int (floor (0.5 + dgrid)), vp.height () - yoffset + rh / 2), QPoint (xoffset + int (floor (0.5 + dgrid)), vp.height () - yoffset + rh / 2),
color); ruler_color);
painter.draw_rect (QPoint (xoffset + int (floor (0.5 + dgrid)), vp.height () - yoffset - rh / 2), painter.draw_rect (QPoint (xoffset + int (floor (0.5 + dgrid)), vp.height () - yoffset - rh / 2),
QPoint (xoffset + int (floor (0.5 + 2 * dgrid)), vp.height () - yoffset + rh / 2), QPoint (xoffset + int (floor (0.5 + 2 * dgrid)), vp.height () - yoffset + rh / 2),
color); ruler_color);
painter.draw_text (tl::sprintf ("%g \265m", grid * 2).c_str (), painter.draw_text (tl::sprintf ("%g \265m", grid * 2).c_str (),
QPoint (xoffset + int (floor (0.5 + trans.ctrans (2 * grid))), vp.height () - yoffset - rh / 2 - 2), QPoint (xoffset + int (floor (0.5 + trans.ctrans (2 * grid))), vp.height () - yoffset - rh / 2 - 2),
color, -1, 1); ruler_color, -1, 1);
if (mp_view->global_trans ().fp_trans () != db::DFTrans ()) { if (mp_view->global_trans ().fp_trans () != db::DFTrans ()) {
@ -492,7 +539,7 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
QPoint p0 (xoffset + 2 * rh, vp.height () - yoffset - rh * 5); QPoint p0 (xoffset + 2 * rh, vp.height () - yoffset - rh * 5);
QPoint p1 = p0 + QPoint (int (floor (0.5 + (*e).p1 ().x () * 0.1 * rh * 4)), -int (floor (0.5 + (*e).p1 ().y () * 0.1 * rh * 4))); QPoint p1 = p0 + QPoint (int (floor (0.5 + (*e).p1 ().x () * 0.1 * rh * 4)), -int (floor (0.5 + (*e).p1 ().y () * 0.1 * rh * 4)));
QPoint p2 = p0 + QPoint (int (floor (0.5 + (*e).p2 ().x () * 0.1 * rh * 4)), -int (floor (0.5 + (*e).p2 ().y () * 0.1 * rh * 4))); QPoint p2 = p0 + QPoint (int (floor (0.5 + (*e).p2 ().x () * 0.1 * rh * 4)), -int (floor (0.5 + (*e).p2 ().y () * 0.1 * rh * 4)));
painter.draw_line (p1, p2, color); painter.draw_line (p1, p2, ruler_color);
} }
} }
@ -518,7 +565,7 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
n = nx; n = nx;
for (db::DCoord x = x1; n > 0; x += grid, --n) { for (db::DCoord x = x1; n > 0; x += grid, --n) {
for (db::DCoord y = y1; y < y2 + g * eps; y += g) { for (db::DCoord y = y1; y < y2 + g * eps; y += g) {
painter.set (draw_round (trans * db::DPoint (x, y), vp.height ()), color); painter.set (draw_round (trans * db::DPoint (x, y), vp.height ()), grid_color);
} }
} }
@ -526,7 +573,7 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
n = ny; n = ny;
for (db::DCoord y = y1; n > 0; y += grid, --n) { for (db::DCoord y = y1; n > 0; y += grid, --n) {
for (db::DCoord x = x1; x < x2 + g * eps; x += g) { for (db::DCoord x = x1; x < x2 + g * eps; x += g) {
painter.set (draw_round (trans * db::DPoint (x, y), vp.height ()), color); painter.set (draw_round (trans * db::DPoint (x, y), vp.height ()), grid_color);
} }
} }
} }
@ -536,8 +583,8 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
for (db::DCoord x = x1; x < x2 + grid * eps; x += grid) { for (db::DCoord x = x1; x < x2 + grid * eps; x += grid) {
for (db::DCoord y = y1; y < y2 + grid * eps; y += grid) { for (db::DCoord y = y1; y < y2 + grid * eps; y += grid) {
QPoint p (draw_round (trans * db::DPoint (x, y), vp.height ())); QPoint p (draw_round (trans * db::DPoint (x, y), vp.height ()));
painter.draw_line (p - QPoint (2, 0), p + QPoint (2, 0), color); painter.draw_line (p - QPoint (2, 0), p + QPoint (2, 0), grid_color);
painter.draw_line (p - QPoint (0, 2), p + QPoint (0, 2), color); painter.draw_line (p - QPoint (0, 2), p + QPoint (0, 2), grid_color);
} }
} }
@ -550,14 +597,14 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
for (db::DCoord x = x1; n > 0; x += grid, --n) { for (db::DCoord x = x1; n > 0; x += grid, --n) {
QPoint p1 (draw_round (trans * db::DPoint (x, y1), vp.height ())); QPoint p1 (draw_round (trans * db::DPoint (x, y1), vp.height ()));
QPoint p2 (draw_round (trans * db::DPoint (x, y2), vp.height ())); QPoint p2 (draw_round (trans * db::DPoint (x, y2), vp.height ()));
painter.draw_line (p1, p2, color); painter.draw_line (p1, p2, grid_color);
} }
n = ny; n = ny;
for (db::DCoord y = y1; n > 0; y += grid, --n) { for (db::DCoord y = y1; n > 0; y += grid, --n) {
QPoint p1 (draw_round (trans * db::DPoint (x1, y), vp.height ())); QPoint p1 (draw_round (trans * db::DPoint (x1, y), vp.height ()));
QPoint p2 (draw_round (trans * db::DPoint (x2, y), vp.height ())); QPoint p2 (draw_round (trans * db::DPoint (x2, y), vp.height ()));
painter.draw_line (p1, p2, color); painter.draw_line (p1, p2, grid_color);
} }
} else if (style == TenthMarkedLines) { } else if (style == TenthMarkedLines) {
@ -578,10 +625,10 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
for (db::DCoord x = x1; n > 0; x += grid, --n) { for (db::DCoord x = x1; n > 0; x += grid, --n) {
QPoint p1 (draw_round (trans * db::DPoint (x, y1), vp.height ())); QPoint p1 (draw_round (trans * db::DPoint (x, y1), vp.height ()));
QPoint p2 (draw_round (trans * db::DPoint (x, y2), vp.height ())); QPoint p2 (draw_round (trans * db::DPoint (x, y2), vp.height ()));
painter.draw_line (p1, p2, color); painter.draw_line (p1, p2, grid_color);
for (db::DCoord y = y1; y < y2 + g * eps; y += g) { for (db::DCoord y = y1; y < y2 + g * eps; y += g) {
QPoint p (draw_round (trans * db::DPoint (x, y), vp.height ())); QPoint p (draw_round (trans * db::DPoint (x, y), vp.height ()));
painter.draw_line (p - QPoint (2, 0), p + QPoint (2, 0), color); painter.draw_line (p - QPoint (2, 0), p + QPoint (2, 0), grid_color);
} }
} }
@ -589,10 +636,10 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
for (db::DCoord y = y1; n > 0; y += grid, --n) { for (db::DCoord y = y1; n > 0; y += grid, --n) {
QPoint p1 (draw_round (trans * db::DPoint (x1, y), vp.height ())); QPoint p1 (draw_round (trans * db::DPoint (x1, y), vp.height ()));
QPoint p2 (draw_round (trans * db::DPoint (x2, y), vp.height ())); QPoint p2 (draw_round (trans * db::DPoint (x2, y), vp.height ()));
painter.draw_line (p1, p2, color); painter.draw_line (p1, p2, grid_color);
for (db::DCoord x = x1; x < x2 + g * eps; x += g) { for (db::DCoord x = x1; x < x2 + g * eps; x += g) {
QPoint p (draw_round (trans * db::DPoint (x, y), vp.height ())); QPoint p (draw_round (trans * db::DPoint (x, y), vp.height ()));
painter.draw_line (p - QPoint (0, 2), p + QPoint (0, 2), color); painter.draw_line (p - QPoint (0, 2), p + QPoint (0, 2), grid_color);
} }
} }
@ -604,7 +651,7 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
if (idx - 2.0 * floor (idx * 0.5) < 0.5) { if (idx - 2.0 * floor (idx * 0.5) < 0.5) {
QPoint p1 (draw_round (trans * db::DPoint (x, y), vp.height ())); QPoint p1 (draw_round (trans * db::DPoint (x, y), vp.height ()));
QPoint p2 (draw_round (trans * db::DPoint (x + grid, y + grid), vp.height ())); QPoint p2 (draw_round (trans * db::DPoint (x + grid, y + grid), vp.height ()));
painter.fill_rect (p1, p2 + QPoint (-1, 1), color); painter.fill_rect (p1, p2 + QPoint (-1, 1), grid_color);
} }
} }
} }
@ -638,19 +685,19 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
// the way we iterate here is safe against integer overflow .. // the way we iterate here is safe against integer overflow ..
n = nx; n = nx;
for (db::DCoord x = x1; n > 0 && draw_xaxis; x += grid, --n) { for (db::DCoord x = x1; n > 0 && draw_xaxis; x += grid, --n) {
painter.set (draw_round (trans * db::DPoint (x, 0.0), vp.height ()), color); painter.set (draw_round (trans * db::DPoint (x, 0.0), vp.height ()), axis_color);
} }
for (db::DCoord y = y1; y < y2 + g * eps && draw_yaxis; y += g) { for (db::DCoord y = y1; y < y2 + g * eps && draw_yaxis; y += g) {
painter.set (draw_round (trans * db::DPoint (0.0, y), vp.height ()), color); painter.set (draw_round (trans * db::DPoint (0.0, y), vp.height ()), axis_color);
} }
if (m_style0 != Dots) { if (m_style0 != Dots) {
n = ny; n = ny;
for (db::DCoord y = y1; n > 0 && draw_yaxis; y += grid, --n) { for (db::DCoord y = y1; n > 0 && draw_yaxis; y += grid, --n) {
painter.set (draw_round (trans * db::DPoint (0.0, y), vp.height ()), color); painter.set (draw_round (trans * db::DPoint (0.0, y), vp.height ()), axis_color);
} }
for (db::DCoord x = x1; x < x2 + g * eps && draw_xaxis; x += g) { for (db::DCoord x = x1; x < x2 + g * eps && draw_xaxis; x += g) {
painter.set (draw_round (trans * db::DPoint (x, 0.0), vp.height ()), color); painter.set (draw_round (trans * db::DPoint (x, 0.0), vp.height ()), axis_color);
} }
} }
@ -658,13 +705,13 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
for (db::DCoord y = y1; y < y2 + grid * eps && draw_yaxis; y += grid) { for (db::DCoord y = y1; y < y2 + grid * eps && draw_yaxis; y += grid) {
QPoint p (draw_round (trans * db::DPoint (0.0, y), vp.height ())); QPoint p (draw_round (trans * db::DPoint (0.0, y), vp.height ()));
painter.draw_line (p - QPoint (2, 0), p + QPoint (2, 0), color); painter.draw_line (p - QPoint (2, 0), p + QPoint (2, 0), axis_color);
painter.draw_line (p - QPoint (0, 2), p + QPoint (0, 2), color); painter.draw_line (p - QPoint (0, 2), p + QPoint (0, 2), axis_color);
} }
for (db::DCoord x = x1; x < x2 + grid * eps && draw_xaxis; x += grid) { for (db::DCoord x = x1; x < x2 + grid * eps && draw_xaxis; x += grid) {
QPoint p (draw_round (trans * db::DPoint (x, 0.0), vp.height ())); QPoint p (draw_round (trans * db::DPoint (x, 0.0), vp.height ()));
painter.draw_line (p - QPoint (2, 0), p + QPoint (2, 0), color); painter.draw_line (p - QPoint (2, 0), p + QPoint (2, 0), axis_color);
painter.draw_line (p - QPoint (0, 2), p + QPoint (0, 2), color); painter.draw_line (p - QPoint (0, 2), p + QPoint (0, 2), axis_color);
} }
} else if (m_style0 == Lines) { } else if (m_style0 == Lines) {
@ -673,13 +720,13 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
if (draw_yaxis) { if (draw_yaxis) {
QPoint p1 (draw_round (trans * db::DPoint (0.0, y1), vp.height ())); QPoint p1 (draw_round (trans * db::DPoint (0.0, y1), vp.height ()));
QPoint p2 (draw_round (trans * db::DPoint (0.0, y2), vp.height ())); QPoint p2 (draw_round (trans * db::DPoint (0.0, y2), vp.height ()));
painter.draw_line (p1, p2, color); painter.draw_line (p1, p2, axis_color);
} }
if (draw_xaxis) { if (draw_xaxis) {
QPoint p1 (draw_round (trans * db::DPoint (x1, 0.0), vp.height ())); QPoint p1 (draw_round (trans * db::DPoint (x1, 0.0), vp.height ()));
QPoint p2 (draw_round (trans * db::DPoint (x2, 0.0), vp.height ())); QPoint p2 (draw_round (trans * db::DPoint (x2, 0.0), vp.height ()));
painter.draw_line (p1, p2, color); painter.draw_line (p1, p2, axis_color);
} }
} else if (m_style0 == TenthMarkedLines) { } else if (m_style0 == TenthMarkedLines) {
@ -698,20 +745,20 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas)
if (draw_yaxis) { if (draw_yaxis) {
QPoint p1 (draw_round (trans * db::DPoint (0.0, y1), vp.height ())); QPoint p1 (draw_round (trans * db::DPoint (0.0, y1), vp.height ()));
QPoint p2 (draw_round (trans * db::DPoint (0.0, y2), vp.height ())); QPoint p2 (draw_round (trans * db::DPoint (0.0, y2), vp.height ()));
painter.draw_line (p1, p2, color); painter.draw_line (p1, p2, axis_color);
for (db::DCoord y = y1; y < y2 + g * eps; y += g) { for (db::DCoord y = y1; y < y2 + g * eps; y += g) {
QPoint p (draw_round (trans * db::DPoint (0.0, y), vp.height ())); QPoint p (draw_round (trans * db::DPoint (0.0, y), vp.height ()));
painter.draw_line (p - QPoint (2, 0), p + QPoint (2, 0), color); painter.draw_line (p - QPoint (2, 0), p + QPoint (2, 0), axis_color);
} }
} }
if (draw_xaxis) { if (draw_xaxis) {
QPoint p1 (draw_round (trans * db::DPoint (x1, 0.0), vp.height ())); QPoint p1 (draw_round (trans * db::DPoint (x1, 0.0), vp.height ()));
QPoint p2 (draw_round (trans * db::DPoint (x2, 0.0), vp.height ())); QPoint p2 (draw_round (trans * db::DPoint (x2, 0.0), vp.height ()));
painter.draw_line (p1, p2, color); painter.draw_line (p1, p2, axis_color);
for (db::DCoord x = x1; x < x2 + g * eps; x += g) { for (db::DCoord x = x1; x < x2 + g * eps; x += g) {
QPoint p (draw_round (trans * db::DPoint (x, 0.0), vp.height ())); QPoint p (draw_round (trans * db::DPoint (x, 0.0), vp.height ()));
painter.draw_line (p - QPoint (0, 2), p + QPoint (0, 2), color); painter.draw_line (p - QPoint (0, 2), p + QPoint (0, 2), axis_color);
} }
} }

View File

@ -62,6 +62,9 @@ public:
private: private:
Ui::GridNetConfigPage *mp_ui; Ui::GridNetConfigPage *mp_ui;
lay::ColorButton *mp_grid_color_cbtn; lay::ColorButton *mp_grid_color_cbtn;
lay::ColorButton *mp_grid_grid_color_cbtn;
lay::ColorButton *mp_grid_axis_color_cbtn;
lay::ColorButton *mp_grid_ruler_color_cbtn;
}; };
class GridNet class GridNet
@ -92,6 +95,9 @@ private:
bool m_show_ruler; bool m_show_ruler;
double m_grid; double m_grid;
QColor m_color; QColor m_color;
QColor m_grid_color;
QColor m_axis_color;
QColor m_ruler_color;
GridStyle m_style0; GridStyle m_style0;
GridStyle m_style1; GridStyle m_style1;
GridStyle m_style2; GridStyle m_style2;

View File

@ -38,6 +38,9 @@ namespace lay
static const std::string cfg_grid ("grid-micron"); static const std::string cfg_grid ("grid-micron");
static const std::string cfg_grid_color ("grid-color"); static const std::string cfg_grid_color ("grid-color");
static const std::string cfg_grid_ruler_color ("grid-ruler-color");
static const std::string cfg_grid_axis_color ("grid-axis-color");
static const std::string cfg_grid_grid_color ("grid-grid-color");
static const std::string cfg_grid_style0 ("grid-style0"); static const std::string cfg_grid_style0 ("grid-style0");
static const std::string cfg_grid_style1 ("grid-style1"); static const std::string cfg_grid_style1 ("grid-style1");
static const std::string cfg_grid_style2 ("grid-style2"); static const std::string cfg_grid_style2 ("grid-style2");