diff --git a/src/lay/layApplication.cc b/src/lay/layApplication.cc index 945933dee..09da07490 100644 --- a/src/lay/layApplication.cc +++ b/src/lay/layApplication.cc @@ -27,12 +27,12 @@ #include "layMainWindow.h" #include "layMacroEditorDialog.h" #include "layVersion.h" -#include "tlExceptions.h" #include "layMacro.h" #include "layCrashMessage.h" #include "layRuntimeErrorForm.h" #include "layProgress.h" #include "layTextProgress.h" +#include "layBackgroundAwareTreeStyle.h" #include "gtf.h" #include "gsiDecl.h" #include "gsiInterpreter.h" @@ -42,6 +42,7 @@ #include "dbStatic.h" #include "dbLibrary.h" #include "dbLibraryManager.h" +#include "tlExceptions.h" #include "tlException.h" #include "tlAssert.h" #include "tlLog.h" @@ -498,6 +499,11 @@ Application::Application (int &argc, char **argv, bool non_ui_mode) mp_qapp = this; mp_qapp_gui = (non_ui_mode ? 0 : this); + + // install a special style proxy to overcome the issue of black-on-black tree expanders + if (mp_qapp_gui) { + mp_qapp_gui->setStyle (new lay::BackgroundAwareTreeStyle (0)); + } // initialize the system codecs (Hint: this must be done after the QApplication is initialized because // it will call setlocale) diff --git a/src/laybasic/SimpleCellSelectionForm.ui b/src/laybasic/SimpleCellSelectionForm.ui deleted file mode 100644 index 0ac66895d..000000000 --- a/src/laybasic/SimpleCellSelectionForm.ui +++ /dev/null @@ -1,470 +0,0 @@ - - - SimpleCellSelectionForm - - - - 0 - 0 - 629 - 525 - - - - Select Cell - - - - 6 - - - 9 - - - 9 - - - 9 - - - 9 - - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - 6 - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 451 - 16 - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - 6 - - - - - - 1 - 1 - - - - - - - - (* and ? can be used to match any text) - - - - - - - Selected cell - - - - - - - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Find next</p></body></html> - - - ... - - - - :/find.png:/find.png - - - true - - - - - - - - - - Cell list - - - - - - - - 1 - 1 - - - - QAbstractItemView::ExtendedSelection - - - true - - - - - - - - 1 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 1 - 1 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - 6 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 1 - 1 - - - - true - - - - - - - Parents - - - - - - - - 0 - 0 - - - - Select - - - - - - - - - - :/right.png - - - - - - - - - - - 1 - 1 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - 6 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Children - - - - - - - - 1 - 1 - - - - true - - - - - - - - 0 - 0 - - - - Select - - - - - - - - - - :/right.png - - - - - - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 611 - 16 - - - - - - - - Qt::Horizontal - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 91 - 31 - - - - - - - - Ok - - - true - - - - - - - Cancel - - - - - - - - - - - - - - diff --git a/src/laybasic/layBackgroundAwareTreeStyle.cc b/src/laybasic/layBackgroundAwareTreeStyle.cc new file mode 100644 index 000000000..07dd747e0 --- /dev/null +++ b/src/laybasic/layBackgroundAwareTreeStyle.cc @@ -0,0 +1,110 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2017 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 "layBackgroundAwareTreeStyle.h" + +#include +#include + +namespace lay +{ + +// ------------------------------------------------------------- +// BackgroundAwareTreeStyle implementation + +BackgroundAwareTreeStyle::BackgroundAwareTreeStyle (QStyle *org_style) + : QProxyStyle (org_style) +{ + // .. nothing yet .. +} + +void +BackgroundAwareTreeStyle::drawPrimitive (QStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const +{ + if (pe == PE_IndicatorBranch) { + + static const int sz = 9; + + int mid_h = opt->rect.x () + opt->rect.width () / 2; + int mid_v = opt->rect.y () + opt->rect.height () / 2; + + if (opt->state & State_Children) { + + QColor c; + + QPalette::ColorGroup cg = QPalette::Disabled; + if ((w && w->isEnabled ()) || (!w && (opt->state & State_Enabled))) { + if ((w && w->hasFocus ()) || (!w && (opt->state & State_HasFocus))) { + cg = QPalette::Normal; + } else { + cg = QPalette::Inactive; + } + } + if (opt->state & State_Selected) { + c = opt->palette.color (cg, QPalette::HighlightedText); + } else { + c = opt->palette.color (cg, QPalette::Text); + } + if (! (opt->state & State_MouseOver)) { + if (c.green () < 128) { + c = QColor ((c.red () * 3 + 255) / 4, (c.green () * 3 + 255) / 4, (c.blue () * 3 + 255) / 4); + } else { + c = QColor ((c.red () * 8) / 9, (c.green () * 8) / 9, (c.blue () * 8) / 9); + } + } + + QPen old_pen = p->pen (); + p->setPen (Qt::NoPen); + QBrush old_brush = p->brush (); + p->setBrush (c); + QPainter::RenderHints old_rh = p->renderHints (); + p->setRenderHints (QPainter::Antialiasing); + + if (opt->state & State_Open) { + QPoint points[] = { + QPoint (mid_h - sz / 2, mid_v - sz / 3), + QPoint (mid_h + sz / 2, mid_v - sz / 3), + QPoint (mid_h, mid_v + sz / 3) + }; + p->drawPolygon (points, sizeof (points) / sizeof (points[0])); + } else { + QPoint points[] = { + QPoint (mid_h - sz / 3, mid_v - sz / 2), + QPoint (mid_h + sz / 3, mid_v), + QPoint (mid_h - sz / 3, mid_v + sz / 2) + }; + p->drawPolygon (points, sizeof (points) / sizeof (points[0])); + } + + p->setPen (old_pen); + p->setBrush (old_brush); + p->setRenderHints (old_rh); + return; + + } + + } + + QProxyStyle::drawPrimitive (pe, opt, p, w); +} + +} diff --git a/src/laybasic/layBackgroundAwareTreeStyle.h b/src/laybasic/layBackgroundAwareTreeStyle.h new file mode 100644 index 000000000..6324a65f9 --- /dev/null +++ b/src/laybasic/layBackgroundAwareTreeStyle.h @@ -0,0 +1,52 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2017 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_layBackgroundAwareTreeStyle +#define HDR_layBackgroundAwareTreeStyle + +#include "laybasicCommon.h" + +#include + +namespace lay +{ + +/** + * @brief A style tailoring the drawing of the branch indicator + * This proxy style is making the branch indicator a triangle and aware of the + * palette of the tree. + * The default Gtk style is not, hence making the background dark means the + * triangles become invisible. + */ +class LAYBASIC_PUBLIC BackgroundAwareTreeStyle + : public QProxyStyle +{ +public: + BackgroundAwareTreeStyle (QStyle *org_style); + void drawPrimitive (PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const; +}; + +} // namespace lay + +#endif + diff --git a/src/laybasic/layHierarchyControlPanel.cc b/src/laybasic/layHierarchyControlPanel.cc index 3b11e1b2b..c7ba03ad3 100644 --- a/src/laybasic/layHierarchyControlPanel.cc +++ b/src/laybasic/layHierarchyControlPanel.cc @@ -332,7 +332,9 @@ HierarchyControlPanel::HierarchyControlPanel (lay::LayoutView *view, QWidget *pa mp_view->cellviews_changed_event.add (this, &HierarchyControlPanel::update_required); mp_view->hier_changed_event.add (this, &HierarchyControlPanel::update_required); + /* @@@ mp_tree_style.reset (new BackgroundAwareTreeStyle (style ())); + @@@ */ do_update_content (); } @@ -895,7 +897,6 @@ HierarchyControlPanel::do_update_content (int cv_index) HCPCellTreeWidget *cell_list = new HCPCellTreeWidget (cl_frame, "tree", mp_view->view_object_widget ()); cl_ly->addWidget (cell_list); - cell_list->setStyle (mp_tree_style.get ()); cell_list->setModel (new CellTreeModel (cell_list, mp_view, cv_index, m_flat ? CellTreeModel::Flat : 0, 0, m_sorting)); cell_list->setUniformRowHeights (true); diff --git a/src/laybasic/layLayerControlPanel.cc b/src/laybasic/layLayerControlPanel.cc index 0a8520e56..ba09a7da2 100644 --- a/src/laybasic/layLayerControlPanel.cc +++ b/src/laybasic/layLayerControlPanel.cc @@ -400,8 +400,6 @@ LayerControlPanel::LayerControlPanel (lay::LayoutView *view, db::Manager *manage mp_model = new lay::LayerTreeModel (this, view); mp_layer_list = new LCPTreeWidget (this, mp_model, "layer_tree"); - mp_ll_style.reset (new BackgroundAwareTreeStyle (mp_layer_list->style ())); - mp_layer_list->setStyle (mp_ll_style.get ()); mp_model->set_font (mp_layer_list->font ()); /* * At least with Qt 4.2.x setting uniform row heights has a strange side effect: diff --git a/src/laybasic/layWidgets.cc b/src/laybasic/layWidgets.cc index 7182692cc..4b255e8a1 100644 --- a/src/laybasic/layWidgets.cc +++ b/src/laybasic/layWidgets.cc @@ -1108,84 +1108,5 @@ void DecoratedLineEdit::resizeEvent (QResizeEvent * /*event*/) } } -// ------------------------------------------------------------- -// BackgroundAwareTreeStyle implementation - -BackgroundAwareTreeStyle::BackgroundAwareTreeStyle (QStyle *org_style) - : QProxyStyle (org_style) -{ - // .. nothing yet .. -} - -void -BackgroundAwareTreeStyle::drawPrimitive (QStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const -{ - if (pe == PE_IndicatorBranch) { - - static const int sz = 9; - - int mid_h = opt->rect.x () + opt->rect.width () / 2; - int mid_v = opt->rect.y () + opt->rect.height () / 2; - - if (opt->state & State_Children) { - - QColor c; - - QPalette::ColorGroup cg = QPalette::Disabled; - if ((w && w->isEnabled ()) || (!w && (opt->state & State_Enabled))) { - if ((w && w->hasFocus ()) || (!w && (opt->state & State_HasFocus))) { - cg = QPalette::Normal; - } else { - cg = QPalette::Inactive; - } - } - if (opt->state & State_Selected) { - c = opt->palette.color (cg, QPalette::HighlightedText); - } else { - c = opt->palette.color (cg, QPalette::Text); - } - if (! (opt->state & State_MouseOver)) { - if (c.green () < 128) { - c = QColor ((c.red () * 3 + 255) / 4, (c.green () * 3 + 255) / 4, (c.blue () * 3 + 255) / 4); - } else { - c = QColor ((c.red () * 8) / 9, (c.green () * 8) / 9, (c.blue () * 8) / 9); - } - } - - QPen old_pen = p->pen (); - p->setPen (Qt::NoPen); - QBrush old_brush = p->brush (); - p->setBrush (c); - QPainter::RenderHints old_rh = p->renderHints (); - p->setRenderHints (QPainter::Antialiasing); - - if (opt->state & State_Open) { - QPoint points[] = { - QPoint (mid_h - sz / 2, mid_v - sz / 3), - QPoint (mid_h + sz / 2, mid_v - sz / 3), - QPoint (mid_h, mid_v + sz / 3) - }; - p->drawPolygon (points, sizeof (points) / sizeof (points[0])); - } else { - QPoint points[] = { - QPoint (mid_h - sz / 3, mid_v - sz / 2), - QPoint (mid_h + sz / 3, mid_v), - QPoint (mid_h - sz / 3, mid_v + sz / 2) - }; - p->drawPolygon (points, sizeof (points) / sizeof (points[0])); - } - - p->setPen (old_pen); - p->setBrush (old_brush); - p->setRenderHints (old_rh); - return; - - } - - } - - QProxyStyle::drawPrimitive (pe, opt, p, w); -} - } diff --git a/src/laybasic/layWidgets.h b/src/laybasic/layWidgets.h index 9c599ef13..001a70a57 100644 --- a/src/laybasic/layWidgets.h +++ b/src/laybasic/layWidgets.h @@ -444,21 +444,6 @@ private: int m_default_left_margin, m_default_right_margin; }; -/** - * @brief A style tailoring the drawing of the branch indicator - * This proxy style is making the branch indicator a triangle and aware of the - * palette of the tree. - * The default Gtk style is not, hence making the background dark means the - * triangles become invisible. - */ -class BackgroundAwareTreeStyle - : public QProxyStyle -{ -public: - BackgroundAwareTreeStyle (QStyle *org_style); - void drawPrimitive (PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const; -}; - } // namespace lay #endif diff --git a/src/laybasic/laybasic.pro b/src/laybasic/laybasic.pro index 17cd2506f..0f07c6e0e 100644 --- a/src/laybasic/laybasic.pro +++ b/src/laybasic/laybasic.pro @@ -67,7 +67,6 @@ FORMS = \ SaveLayoutOptionsDialog.ui \ SaveLayoutAsOptionsDialog.ui \ SelectStippleForm.ui \ - SimpleCellSelectionForm.ui \ TipDialog.ui \ UserPropertiesForm.ui \ UserPropertiesEditForm.ui \ @@ -176,7 +175,8 @@ SOURCES = \ laySelectLineStyleForm.cc \ layLineStylePalette.cc \ layEditLineStylesForm.cc \ - layEditLineStyleWidget.cc + layEditLineStyleWidget.cc \ + layBackgroundAwareTreeStyle.cc HEADERS = \ gtf.h \ @@ -270,7 +270,8 @@ HEADERS = \ layEditLineStylesForm.h \ layEditLineStyleWidget.h \ laybasicCommon.h \ - laybasicConfig.h + laybasicConfig.h \ + layBackgroundAwareTreeStyle.h INCLUDEPATH += ../tl ../gsi ../db ../rdb DEPENDPATH += ../tl ../gsi ../db ../rdb