diff --git a/src/edt/edt/edtMainService.cc b/src/edt/edt/edtMainService.cc index 30e5ff26c..8f1500a3f 100644 --- a/src/edt/edt/edtMainService.cc +++ b/src/edt/edt/edtMainService.cc @@ -2113,7 +2113,8 @@ MainService::cm_tap () int icon_size = menu->style ()->pixelMetric (QStyle::PM_ButtonIconSize); - QPoint mp = view ()->view_object_widget ()->mapToGlobal (view ()->view_object_widget ()->mouse_position ()); + db::Point mp_local = view ()->view_object_widget ()->mouse_position (); + QPoint mp = view ()->view_object_widget ()->mapToGlobal (QPoint (mp_local.x (), mp_local.y ())); for (std::vector::const_iterator l = tapped_layers.begin (); l != tapped_layers.end (); ++l) { QAction *a = menu->addAction (lay::LayerTreeModel::icon_for_layer (*l, view (), icon_size, icon_size, 0, true), tl::to_qstring ((*l)->display_string (view (), true, true /*with source*/))); diff --git a/src/laybasic/laybasic/layGridNet.cc b/src/laybasic/laybasic/layGridNet.cc index 47fc79b81..d23d7c858 100644 --- a/src/laybasic/laybasic/layGridNet.cc +++ b/src/laybasic/laybasic/layGridNet.cc @@ -23,16 +23,14 @@ #include "laybasicConfig.h" #include "layGridNet.h" -#if defined(HAVE_QT) // @@@ -# include "layWidgets.h" -#endif -#include "layLayoutView.h" #include "layConverters.h" +#include "layLayoutView.h" #include "layFixedFont.h" #include "laySnap.h" #include "dbTrans.h" -#if defined(HAVE_QT) // @@@ -# include "ui_GridNetConfigPage.h" + +#if defined(HAVE_QT) +# include "layGridNetConfigPage.h" #endif namespace lay @@ -56,32 +54,28 @@ static struct { { lay::GridNet::CheckerBoard, "checkerboard" } }; -class GridNetStyleConverter +void +GridNetStyleConverter::from_string (const std::string &value, lay::GridNet::GridStyle &style) { -public: - void - from_string (const std::string &value, lay::GridNet::GridStyle &style) - { - for (unsigned int i = 0; i < sizeof (grid_styles) / sizeof (grid_styles [0]); ++i) { - if (value == grid_styles [i].string) { - style = grid_styles [i].style; - return; - } + for (unsigned int i = 0; i < sizeof (grid_styles) / sizeof (grid_styles [0]); ++i) { + if (value == grid_styles [i].string) { + style = grid_styles [i].style; + return; } - throw tl::Exception (tl::to_string (tr ("Invalid grid net style: ")) + value); } + throw tl::Exception (tl::to_string (tr ("Invalid grid net style: ")) + value); +} - std::string - to_string (lay::GridNet::GridStyle style) - { - for (unsigned int i = 0; i < sizeof (grid_styles) / sizeof (grid_styles [0]); ++i) { - if (style == grid_styles [i].style) { - return grid_styles [i].string; - } +std::string +GridNetStyleConverter::to_string (lay::GridNet::GridStyle style) +{ + for (unsigned int i = 0; i < sizeof (grid_styles) / sizeof (grid_styles [0]); ++i) { + if (style == grid_styles [i].style) { + return grid_styles [i].string; } - return ""; } -}; + return ""; +} // ------------------------------------------------------------ // Implementation of the GridNetPluginDeclaration @@ -118,85 +112,6 @@ GridNetPluginDeclaration::create_plugin (db::Manager *, Dispatcher *, lay::Layou static tl::RegisteredClass config_decl (new GridNetPluginDeclaration (), 2010, "GridNetPlugin"); -// ------------------------------------------------------------ -// Implementation of the configuration page - -#if defined(HAVE_QT) -GridNetConfigPage::GridNetConfigPage (QWidget *parent) - : lay::ConfigPage (parent) -{ - mp_ui = new Ui::GridNetConfigPage (); - mp_ui->setupUi (this); - - 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 () -{ - delete mp_ui; - mp_ui = 0; -} - -void -GridNetConfigPage::setup (lay::Dispatcher *root) -{ - std::string value; - - // Grid visibility - bool visible = false; - root->config_get (cfg_grid_visible, visible); - mp_ui->grid_group->setChecked (visible); - - bool show_ruler = false; - root->config_get (cfg_grid_show_ruler, show_ruler); - mp_ui->show_ruler->setChecked (show_ruler); - - QColor color; - root->config_get (cfg_grid_color, color, ColorConverter ()); - 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; - - style = lay::GridNet::Invisible; - root->config_get (cfg_grid_style0, style, GridNetStyleConverter ()); - mp_ui->style0_cbx->setCurrentIndex (int (style)); - - style = lay::GridNet::Invisible; - root->config_get (cfg_grid_style1, style, GridNetStyleConverter ()); - mp_ui->style1_cbx->setCurrentIndex (int (style)); - - style = lay::GridNet::Invisible; - root->config_get (cfg_grid_style2, style, GridNetStyleConverter ()); - mp_ui->style2_cbx->setCurrentIndex (int (style)); -} - -void -GridNetConfigPage::commit (lay::Dispatcher *root) -{ - 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_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_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 ()); -} -#endif - // ------------------------------------------------------------ // Implementation of the GridNet object @@ -302,14 +217,14 @@ public: // .. nothing yet .. } - void set (const QPoint &p, QColor c) + void set (const db::Point &p, lay::Color c) { if (p.x () >= 0 && p.x () < m_width && p.y () >= 0 && p.y () < m_height) { ((unsigned int *) mp_img->scanLine (p.y ())) [p.x ()] = c.rgb (); } } - void draw_line (const QPoint &p1, const QPoint &p2, QColor c) + void draw_line (const db::Point &p1, const db::Point &p2, lay::Color c) { if (p1.x () == p2.x ()) { @@ -343,28 +258,28 @@ public: } } - void fill_rect (const QPoint &p1, const QPoint &p2, QColor c) + void fill_rect (const db::Point &p1, const db::Point &p2, lay::Color c) { int y1 = std::min (p1.y (), p2.y ()); int y2 = std::max (p1.y (), p2.y ()); for (int y = y1; y <= y2; ++y) { - draw_line (QPoint (p1.x (), y), QPoint (p2.x (), y), c); + draw_line (db::Point (p1.x (), y), db::Point (p2.x (), y), c); } } - void draw_rect (const QPoint &p1, const QPoint &p2, QColor c) + void draw_rect (const db::Point &p1, const db::Point &p2, lay::Color c) { int y1 = std::min (p1.y (), p2.y ()); int y2 = std::max (p1.y (), p2.y ()); int x1 = std::min (p1.x (), p2.x ()); int x2 = std::max (p1.x (), p2.x ()); - draw_line (QPoint (x1, y1), QPoint (x2, y1), c); - draw_line (QPoint (x1, y2), QPoint (x2, y2), c); - draw_line (QPoint (x1, y1), QPoint (x1, y2), c); - draw_line (QPoint (x2, y1), QPoint (x2, y2), c); + draw_line (db::Point (x1, y1), db::Point (x2, y1), c); + draw_line (db::Point (x1, y2), db::Point (x2, y2), c); + draw_line (db::Point (x1, y1), db::Point (x1, y2), c); + draw_line (db::Point (x2, y1), db::Point (x2, y2), c); } - void draw_text (const char *t, const QPoint &p, QColor c, int halign, int valign) + void draw_text (const char *t, const db::Point &p, lay::Color c, int halign, int valign) { const lay::FixedFont &ff = lay::FixedFont::get_font (m_resolution); int x = p.x (), y = p.y (); @@ -516,16 +431,16 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas) int xoffset = int (floor (0.5 + fw * 2.5)); int yoffset = int (floor (0.5 + fw * 2.5)); - painter.fill_rect (QPoint (xoffset, vp.height () - yoffset - rh / 2), - QPoint (xoffset + int (floor (0.5 + dgrid)), vp.height () - yoffset + rh / 2), + painter.fill_rect (db::Point (xoffset, vp.height () - yoffset - rh / 2), + db::Point (xoffset + int (floor (0.5 + dgrid)), vp.height () - yoffset + rh / 2), ruler_color); - 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), + painter.draw_rect (db::Point (xoffset + int (floor (0.5 + dgrid)), vp.height () - yoffset - rh / 2), + db::Point (xoffset + int (floor (0.5 + 2 * dgrid)), vp.height () - yoffset + rh / 2), ruler_color); 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), + db::Point (xoffset + int (floor (0.5 + trans.ctrans (2 * grid))), vp.height () - yoffset - rh / 2 - 2), ruler_color, -1, 1); if (mp_view->global_trans ().fp_trans () != db::DFTrans ()) { @@ -550,9 +465,9 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas) poly.transform (db::FTrans (mp_view->global_trans ().fp_trans ())); for (db::Polygon::polygon_edge_iterator e = poly.begin_edge (); !e.at_end (); ++e) { - 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 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))); + db::Point p0 (xoffset + 2 * rh, vp.height () - yoffset - rh * 5); + db::Point p1 = p0 + db::Vector (int (floor (0.5 + (*e).p1 ().x () * 0.1 * rh * 4)), -int (floor (0.5 + (*e).p1 ().y () * 0.1 * rh * 4))); + db::Point p2 = p0 + db::Vector (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, ruler_color); } @@ -596,9 +511,9 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas) for (db::DCoord x = x1; x < x2 + grid * eps; x += grid) { for (db::DCoord y = y1; y < y2 + grid * eps; y += grid) { - QPoint p (draw_round (trans * db::DPoint (x, y), vp.height ())); - painter.draw_line (p - QPoint (2, 0), p + QPoint (2, 0), grid_color); - painter.draw_line (p - QPoint (0, 2), p + QPoint (0, 2), grid_color); + db::Point p (draw_round (trans * db::DPoint (x, y), vp.height ())); + painter.draw_line (p - db::Vector (2, 0), p + db::Vector (2, 0), grid_color); + painter.draw_line (p - db::Vector (0, 2), p + db::Vector (0, 2), grid_color); } } @@ -609,15 +524,15 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas) // the way we iterate here is safe against integer overflow .. n = nx; for (db::DCoord x = x1; n > 0; x += grid, --n) { - QPoint p1 (draw_round (trans * db::DPoint (x, y1), vp.height ())); - QPoint p2 (draw_round (trans * db::DPoint (x, y2), vp.height ())); + db::Point p1 (draw_round (trans * db::DPoint (x, y1), vp.height ())); + db::Point p2 (draw_round (trans * db::DPoint (x, y2), vp.height ())); painter.draw_line (p1, p2, grid_color); } n = ny; for (db::DCoord y = y1; n > 0; y += grid, --n) { - QPoint p1 (draw_round (trans * db::DPoint (x1, y), vp.height ())); - QPoint p2 (draw_round (trans * db::DPoint (x2, y), vp.height ())); + db::Point p1 (draw_round (trans * db::DPoint (x1, y), vp.height ())); + db::Point p2 (draw_round (trans * db::DPoint (x2, y), vp.height ())); painter.draw_line (p1, p2, grid_color); } @@ -637,23 +552,23 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas) // the way we iterate here is safe against integer overflow .. n = nx; for (db::DCoord x = x1; n > 0; x += grid, --n) { - QPoint p1 (draw_round (trans * db::DPoint (x, y1), vp.height ())); - QPoint p2 (draw_round (trans * db::DPoint (x, y2), vp.height ())); + db::Point p1 (draw_round (trans * db::DPoint (x, y1), vp.height ())); + db::Point p2 (draw_round (trans * db::DPoint (x, y2), vp.height ())); painter.draw_line (p1, p2, grid_color); for (db::DCoord y = y1; y < y2 + g * eps; y += g) { - QPoint p (draw_round (trans * db::DPoint (x, y), vp.height ())); - painter.draw_line (p - QPoint (2, 0), p + QPoint (2, 0), grid_color); + db::Point p (draw_round (trans * db::DPoint (x, y), vp.height ())); + painter.draw_line (p - db::Vector (2, 0), p + db::Vector (2, 0), grid_color); } } n = ny; for (db::DCoord y = y1; n > 0; y += grid, --n) { - QPoint p1 (draw_round (trans * db::DPoint (x1, y), vp.height ())); - QPoint p2 (draw_round (trans * db::DPoint (x2, y), vp.height ())); + db::Point p1 (draw_round (trans * db::DPoint (x1, y), vp.height ())); + db::Point p2 (draw_round (trans * db::DPoint (x2, y), vp.height ())); painter.draw_line (p1, p2, grid_color); for (db::DCoord x = x1; x < x2 + g * eps; x += g) { - QPoint p (draw_round (trans * db::DPoint (x, y), vp.height ())); - painter.draw_line (p - QPoint (0, 2), p + QPoint (0, 2), grid_color); + db::Point p (draw_round (trans * db::DPoint (x, y), vp.height ())); + painter.draw_line (p - db::Vector (0, 2), p + db::Vector (0, 2), grid_color); } } @@ -663,9 +578,9 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas) for (db::DCoord y = y1; y < y2 + grid * eps; y += grid) { double idx = (x + y) / grid + eps; if (idx - 2.0 * floor (idx * 0.5) < 0.5) { - QPoint p1 (draw_round (trans * db::DPoint (x, y), vp.height ())); - QPoint p2 (draw_round (trans * db::DPoint (x + grid, y + grid), vp.height ())); - painter.fill_rect (p1, p2 + QPoint (-1, 1), grid_color); + db::Point p1 (draw_round (trans * db::DPoint (x, y), vp.height ())); + db::Point p2 (draw_round (trans * db::DPoint (x + grid, y + grid), vp.height ())); + painter.fill_rect (p1, p2 + db::Vector (-1, 1), grid_color); } } } @@ -718,28 +633,28 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas) } else if (m_style0 == Crosses) { 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 ())); - painter.draw_line (p - QPoint (2, 0), p + QPoint (2, 0), axis_color); - painter.draw_line (p - QPoint (0, 2), p + QPoint (0, 2), axis_color); + db::Point p (draw_round (trans * db::DPoint (0.0, y), vp.height ())); + painter.draw_line (p - db::Vector (2, 0), p + db::Vector (2, 0), axis_color); + painter.draw_line (p - db::Vector (0, 2), p + db::Vector (0, 2), axis_color); } 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 ())); - painter.draw_line (p - QPoint (2, 0), p + QPoint (2, 0), axis_color); - painter.draw_line (p - QPoint (0, 2), p + QPoint (0, 2), axis_color); + db::Point p (draw_round (trans * db::DPoint (x, 0.0), vp.height ())); + painter.draw_line (p - db::Vector (2, 0), p + db::Vector (2, 0), axis_color); + painter.draw_line (p - db::Vector (0, 2), p + db::Vector (0, 2), axis_color); } } else if (m_style0 == Lines) { // the way we iterate here is safe against integer overflow .. if (draw_yaxis) { - QPoint p1 (draw_round (trans * db::DPoint (0.0, y1), vp.height ())); - QPoint p2 (draw_round (trans * db::DPoint (0.0, y2), vp.height ())); + db::Point p1 (draw_round (trans * db::DPoint (0.0, y1), vp.height ())); + db::Point p2 (draw_round (trans * db::DPoint (0.0, y2), vp.height ())); painter.draw_line (p1, p2, axis_color); } if (draw_xaxis) { - QPoint p1 (draw_round (trans * db::DPoint (x1, 0.0), vp.height ())); - QPoint p2 (draw_round (trans * db::DPoint (x2, 0.0), vp.height ())); + db::Point p1 (draw_round (trans * db::DPoint (x1, 0.0), vp.height ())); + db::Point p2 (draw_round (trans * db::DPoint (x2, 0.0), vp.height ())); painter.draw_line (p1, p2, axis_color); } @@ -757,22 +672,22 @@ GridNet::render_bg (const lay::Viewport &vp, ViewObjectCanvas &canvas) // the way we iterate here is safe against integer overflow .. if (draw_yaxis) { - QPoint p1 (draw_round (trans * db::DPoint (0.0, y1), vp.height ())); - QPoint p2 (draw_round (trans * db::DPoint (0.0, y2), vp.height ())); + db::Point p1 (draw_round (trans * db::DPoint (0.0, y1), vp.height ())); + db::Point p2 (draw_round (trans * db::DPoint (0.0, y2), vp.height ())); painter.draw_line (p1, p2, axis_color); for (db::DCoord y = y1; y < y2 + g * eps; y += g) { - QPoint p (draw_round (trans * db::DPoint (0.0, y), vp.height ())); - painter.draw_line (p - QPoint (2, 0), p + QPoint (2, 0), axis_color); + db::Point p (draw_round (trans * db::DPoint (0.0, y), vp.height ())); + painter.draw_line (p - db::Vector (2, 0), p + db::Vector (2, 0), axis_color); } } if (draw_xaxis) { - QPoint p1 (draw_round (trans * db::DPoint (x1, 0.0), vp.height ())); - QPoint p2 (draw_round (trans * db::DPoint (x2, 0.0), vp.height ())); + db::Point p1 (draw_round (trans * db::DPoint (x1, 0.0), vp.height ())); + db::Point p2 (draw_round (trans * db::DPoint (x2, 0.0), vp.height ())); painter.draw_line (p1, p2, axis_color); for (db::DCoord x = x1; x < x2 + g * eps; x += g) { - QPoint p (draw_round (trans * db::DPoint (x, 0.0), vp.height ())); - painter.draw_line (p - QPoint (0, 2), p + QPoint (0, 2), axis_color); + db::Point p (draw_round (trans * db::DPoint (x, 0.0), vp.height ())); + painter.draw_line (p - db::Vector (0, 2), p + db::Vector (0, 2), axis_color); } } diff --git a/src/laybasic/laybasic/layGridNet.h b/src/laybasic/laybasic/layGridNet.h index 011091d6e..469d3d232 100644 --- a/src/laybasic/laybasic/layGridNet.h +++ b/src/laybasic/laybasic/layGridNet.h @@ -53,28 +53,6 @@ public: virtual lay::Plugin *create_plugin (db::Manager *, lay::Dispatcher *, lay::LayoutViewBase *view) const; }; -#if defined(HAVE_QT) // @@@ -class GridNetConfigPage - : public lay::ConfigPage -{ -Q_OBJECT - -public: - GridNetConfigPage (QWidget *parent); - ~GridNetConfigPage (); - - virtual void setup (lay::Dispatcher *root); - virtual void commit (lay::Dispatcher *root); - -private: - Ui::GridNetConfigPage *mp_ui; - 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; -}; -#endif - class GridNet : public lay::BackgroundViewObject, public lay::Plugin @@ -111,6 +89,13 @@ private: GridStyle m_style2; }; +class GridNetStyleConverter +{ +public: + void from_string (const std::string &value, lay::GridNet::GridStyle &style); + std::string to_string (lay::GridNet::GridStyle style); +}; + } #endif diff --git a/src/laybasic/laybasic/layGridNetConfigPage.cc b/src/laybasic/laybasic/layGridNetConfigPage.cc new file mode 100644 index 000000000..07866fd48 --- /dev/null +++ b/src/laybasic/laybasic/layGridNetConfigPage.cc @@ -0,0 +1,113 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2022 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + + +#include "laybasicConfig.h" +#include "layGridNetConfigPage.h" +#include "layConverters.h" +#include "layDispatcher.h" +#include "layGridNet.h" +#include "layWidgets.h" +#include "ui_GridNetConfigPage.h" + +namespace lay +{ + +// ------------------------------------------------------------ +// Implementation of the configuration page + +GridNetConfigPage::GridNetConfigPage (QWidget *parent) + : lay::ConfigPage (parent) +{ + mp_ui = new Ui::GridNetConfigPage (); + mp_ui->setupUi (this); + + 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 () +{ + delete mp_ui; + mp_ui = 0; +} + +void +GridNetConfigPage::setup (lay::Dispatcher *root) +{ + std::string value; + + // Grid visibility + bool visible = false; + root->config_get (cfg_grid_visible, visible); + mp_ui->grid_group->setChecked (visible); + + bool show_ruler = false; + root->config_get (cfg_grid_show_ruler, show_ruler); + mp_ui->show_ruler->setChecked (show_ruler); + + QColor color; + root->config_get (cfg_grid_color, color, ColorConverter ()); + 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; + + style = lay::GridNet::Invisible; + root->config_get (cfg_grid_style0, style, GridNetStyleConverter ()); + mp_ui->style0_cbx->setCurrentIndex (int (style)); + + style = lay::GridNet::Invisible; + root->config_get (cfg_grid_style1, style, GridNetStyleConverter ()); + mp_ui->style1_cbx->setCurrentIndex (int (style)); + + style = lay::GridNet::Invisible; + root->config_get (cfg_grid_style2, style, GridNetStyleConverter ()); + mp_ui->style2_cbx->setCurrentIndex (int (style)); +} + +void +GridNetConfigPage::commit (lay::Dispatcher *root) +{ + 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_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_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 ()); +} + +} // namespace lay + diff --git a/src/laybasic/laybasic/layGridNetConfigPage.h b/src/laybasic/laybasic/layGridNetConfigPage.h new file mode 100644 index 000000000..1e6599131 --- /dev/null +++ b/src/laybasic/laybasic/layGridNetConfigPage.h @@ -0,0 +1,60 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2022 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + + +#ifndef HDR_layGridNetConfigPage +#define HDR_layGridNetConfigPage + +#include "layPluginConfigPage.h" + +namespace Ui { + class GridNetConfigPage; +} + +namespace lay { + +class ColorButton; + +class GridNetConfigPage + : public lay::ConfigPage +{ +Q_OBJECT + +public: + GridNetConfigPage (QWidget *parent); + ~GridNetConfigPage (); + + virtual void setup (lay::Dispatcher *root); + virtual void commit (lay::Dispatcher *root); + +private: + Ui::GridNetConfigPage *mp_ui; + 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; +}; + +} + +#endif + diff --git a/src/laybasic/laybasic/layNetlistBrowserModel.cc b/src/laybasic/laybasic/layNetlistBrowserModel.cc index 8ed6a964b..67e15af1a 100644 --- a/src/laybasic/laybasic/layNetlistBrowserModel.cc +++ b/src/laybasic/laybasic/layNetlistBrowserModel.cc @@ -2380,7 +2380,7 @@ NetlistBrowserModel::NetlistBrowserModel (QWidget *parent, db::LayoutToNetlist * { mp_root.reset (new RootItemData ()); mp_indexer.reset (new SingleIndexedNetlistModel (l2ndb->netlist ())); - connect (mp_colorizer, SIGNAL (colors_changed ()), this, SLOT (colors_changed ())); + mp_colorizer->colors_changed.add (this, &NetlistBrowserModel::colors_changed); m_object_column = 0; m_status_column = -1; @@ -2393,7 +2393,7 @@ NetlistBrowserModel::NetlistBrowserModel (QWidget *parent, db::LayoutVsSchematic { mp_root.reset (new RootItemData ()); mp_indexer.reset (new NetlistCrossReferenceModel (lvsdb->cross_ref ())); - connect (mp_colorizer, SIGNAL (colors_changed ()), this, SLOT (colors_changed ())); + mp_colorizer->colors_changed.add (this, &NetlistBrowserModel::colors_changed); m_object_column = 0; m_status_column = 1; diff --git a/src/laybasic/laybasic/layNetlistBrowserModel.h b/src/laybasic/laybasic/layNetlistBrowserModel.h index 3028792bc..6a43c954c 100644 --- a/src/laybasic/laybasic/layNetlistBrowserModel.h +++ b/src/laybasic/laybasic/layNetlistBrowserModel.h @@ -221,7 +221,7 @@ struct LAYBASIC_PUBLIC NetlistObjectsPath * - terminals and nets */ class LAYBASIC_PUBLIC NetlistBrowserModel - : public QAbstractItemModel + : public QAbstractItemModel, public tl::Object { Q_OBJECT diff --git a/src/laybasic/laybasic/laySnap.cc b/src/laybasic/laybasic/laySnap.cc index 1243a7218..c123da738 100644 --- a/src/laybasic/laybasic/laySnap.cc +++ b/src/laybasic/laybasic/laySnap.cc @@ -129,19 +129,17 @@ int draw_round (double x) } } -#if defined(HAVE_QT) -QPoint draw_round (db::DPoint p, int h) +db::Point draw_round (db::DPoint p, int h) { - return QPoint (draw_round (p.x ()), h - 1 - draw_round (p.y ())); + return db::Point (draw_round (p.x ()), h - 1 - draw_round (p.y ())); } -std::pair +std::pair draw_round (const db::DPoint &p1, const db::DPoint &p2, int h) { std::pair dp = draw_round_dbl (p1, p2, h); return std::make_pair (draw_round (dp.first, h), draw_round (dp.second, h)); } -#endif std::pair draw_round_dbl (const db::DPoint &p1, const db::DPoint &p2, int /*h*/) diff --git a/src/laybasic/laybasic/laySnap.h b/src/laybasic/laybasic/laySnap.h index 776cb1acd..750ac55a8 100644 --- a/src/laybasic/laybasic/laySnap.h +++ b/src/laybasic/laybasic/laySnap.h @@ -246,17 +246,15 @@ namespace lay */ LAYBASIC_PUBLIC int draw_round (double x); -#if defined(HAVE_QT) /** * @brief rounding (and height-transformation) of a double point */ - LAYBASIC_PUBLIC QPoint draw_round (db::DPoint p, int h); + LAYBASIC_PUBLIC db::Point draw_round (db::DPoint p, int h); /** * @brief rounding (and height-transformation) of a two-point vector */ - LAYBASIC_PUBLIC std::pair draw_round (const db::DPoint &p1, const db::DPoint &p2, int h); -#endif + LAYBASIC_PUBLIC std::pair draw_round (const db::DPoint &p1, const db::DPoint &p2, int h); /** * @brief rounding (and height-transformation) of a two-point vector diff --git a/src/laybasic/laybasic/layViewObject.cc b/src/laybasic/laybasic/layViewObject.cc index 9f8ac62d8..564353267 100644 --- a/src/laybasic/laybasic/layViewObject.cc +++ b/src/laybasic/laybasic/layViewObject.cc @@ -493,7 +493,7 @@ BEGIN_PROTECTED const DragDropDataBase *dd = get_drag_drop_data (event->mimeData ()); if (dd) { - db::DPoint p = pixel_to_um (event->pos ()); + db::DPoint p = pixel_to_um (db::Point (event->pos ().x (), event->pos ().y ())); bool done = drag_enter_event (p, dd); service_iterator svc = begin_services (); @@ -538,7 +538,7 @@ BEGIN_PROTECTED const DragDropDataBase *dd = get_drag_drop_data (event->mimeData ()); if (dd) { - db::DPoint p = pixel_to_um (event->pos ()); + db::DPoint p = pixel_to_um (db::Point (event->pos ().x (), event->pos ().y ())); bool done = drag_move_event (p, dd); service_iterator svc = begin_services (); @@ -562,7 +562,7 @@ BEGIN_PROTECTED const DragDropDataBase *dd = get_drag_drop_data (event->mimeData ()); if (dd) { - db::DPoint p = pixel_to_um (event->pos ()); + db::DPoint p = pixel_to_um (db::Point (event->pos ().x (), event->pos ().y ())); bool done = drop_event (p, dd); service_iterator svc = begin_services (); @@ -583,7 +583,7 @@ ViewObjectWidget::mouseMoveEvent (QMouseEvent *e) { BEGIN_PROTECTED ensure_entered (); - m_mouse_pos = e->pos (); + m_mouse_pos = db::Point (e->pos ().x (), e->pos ().y ()); m_mouse_buttons = qt_to_buttons (e->buttons (), e->modifiers ()); do_mouse_move (); END_PROTECTED @@ -683,13 +683,13 @@ BEGIN_PROTECTED bool done = false; - m_mouse_pos = e->pos (); - m_mouse_pressed = e->pos (); + m_mouse_pos = db::Point (e->pos ().x (), e->pos ().y ()); + m_mouse_pressed = m_mouse_pos; m_mouse_pressed_state = false; unsigned int buttons = qt_to_buttons (e->buttons (), e->modifiers ()); - db::DPoint p = pixel_to_um (e->pos ()); + db::DPoint p = pixel_to_um (m_mouse_pos); for (std::list::iterator g = m_grabbed.begin (); !done && g != m_grabbed.end (); ) { std::list::iterator gg = g; @@ -805,7 +805,7 @@ BEGIN_PROTECTED #if QT_VERSION < 0x60000 int delta = e->delta (); - db::DPoint p = pixel_to_um (e->pos ()); + db::DPoint p = pixel_to_um (db::Point (e->pos ().x (), e->pos ().y ())); bool horizontal = (e->orientation () == Qt::Horizontal); #else int delta = e->angleDelta ().y (); @@ -852,8 +852,8 @@ ViewObjectWidget::mousePressEvent (QMouseEvent *e) ensure_entered (); setFocus (); - m_mouse_pos = e->pos (); - m_mouse_pressed = e->pos (); + m_mouse_pos = db::Point (e->pos ().x (), e->pos ().y ()); + m_mouse_pressed = m_mouse_pos; m_mouse_buttons = qt_to_buttons (e->buttons (), e->modifiers ()); @@ -869,8 +869,8 @@ BEGIN_PROTECTED bool done = false; - m_mouse_pos = e->pos (); - db::DPoint p = pixel_to_um (e->pos ()); + m_mouse_pos = db::Point (e->pos ().x (), e->pos ().y ()); + db::DPoint p = pixel_to_um (m_mouse_pos); for (std::list::iterator g = m_grabbed.begin (); !done && g != m_grabbed.end (); ) { std::list::iterator gg = g; diff --git a/src/laybasic/laybasic/laybasic.pro b/src/laybasic/laybasic/laybasic.pro index f2f707d15..59c6456ac 100644 --- a/src/laybasic/laybasic/laybasic.pro +++ b/src/laybasic/laybasic/laybasic.pro @@ -120,6 +120,7 @@ DEFINES += MAKE_LAYBASIC_LIBRARY layEditorServiceBase.cc \ layFileDialog.cc \ layGenericSyntaxHighlighter.cc \ + layGridNetConfigPage.cc \ layHierarchyControlPanel.cc \ layIndexedNetlistModel.cc \ layItemDelegates.cc \ @@ -193,6 +194,7 @@ DEFINES += MAKE_LAYBASIC_LIBRARY layEditorServiceBase.h \ layFileDialog.h \ layGenericSyntaxHighlighter.h \ + layGridNetConfigPage.h \ layHierarchyControlPanel.h \ layIndexedNetlistModel.h \ layItemDelegates.h \ diff --git a/src/laybasic/unit_tests/layBitmapsToImage.cc b/src/laybasic/unit_tests/layBitmapsToImage.cc index 120c3eafc..299d2c81d 100644 --- a/src/laybasic/unit_tests/layBitmapsToImage.cc +++ b/src/laybasic/unit_tests/layBitmapsToImage.cc @@ -95,7 +95,7 @@ TEST(1) lay::DitherPattern dp; lay::LineStyles ls; - QMutex m; + tl::Mutex m; lay::bitmaps_to_image (view_ops, pbitmaps, dp, ls, &img, 32, 32, 0, &m); EXPECT_EQ (to_string (img, 0x800000),