diff --git a/src/laybasic/layHierarchyControlPanel.cc b/src/laybasic/layHierarchyControlPanel.cc index 4958f1d91..ab8798605 100644 --- a/src/laybasic/layHierarchyControlPanel.cc +++ b/src/laybasic/layHierarchyControlPanel.cc @@ -35,6 +35,9 @@ #include #include #include +#include +#include +#include #include "dbClipboard.h" #include "dbClipboardData.h" @@ -321,6 +324,8 @@ 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 (); } @@ -660,13 +665,6 @@ void HierarchyControlPanel::set_background_color (QColor c) { m_background_color = c; - QColor hl; - if (c.green () > 128) { - hl = QColor (192, 192, 255); - } else { - hl = QColor (0, 0, 80); - } - for (std::vector ::const_iterator f = mp_cell_lists.begin (); f != mp_cell_lists.end (); ++f) { QPalette pl ((*f)->palette ()); pl.setColor (QPalette::Base, c); @@ -889,6 +887,7 @@ HierarchyControlPanel::do_update_content (int cv_index) HCPCellTreeWidget *cell_list = new HCPCellTreeWidget (cl_frame, "tree"); 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/layHierarchyControlPanel.h b/src/laybasic/layHierarchyControlPanel.h index 6669b2bc1..0a0618770 100644 --- a/src/laybasic/layHierarchyControlPanel.h +++ b/src/laybasic/layHierarchyControlPanel.h @@ -300,6 +300,7 @@ private: QColor m_text_color; tl::DeferredMethod m_do_update_content_dm; tl::DeferredMethod m_do_full_update_content_dm; + std::auto_ptr mp_tree_style; // locate the CellTreeItem in the tree corresponding to a partial path starting from p. CellTreeItem *find_child_item (cell_path_type::const_iterator start, cell_path_type::const_iterator end, CellTreeItem *p); diff --git a/src/laybasic/layLayerControlPanel.cc b/src/laybasic/layLayerControlPanel.cc index c04ff7e62..c7d3df82d 100644 --- a/src/laybasic/layLayerControlPanel.cc +++ b/src/laybasic/layLayerControlPanel.cc @@ -308,6 +308,8 @@ 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/layLayerControlPanel.h b/src/laybasic/layLayerControlPanel.h index 201cb76c9..a99af4932 100644 --- a/src/laybasic/layLayerControlPanel.h +++ b/src/laybasic/layLayerControlPanel.h @@ -326,6 +326,7 @@ public slots: private: QTabBar *mp_tab_bar; LCPTreeWidget *mp_layer_list; + std::auto_ptr mp_ll_style; LayerTreeModel *mp_model; lay::LayoutView *mp_view; bool m_needs_update; diff --git a/src/laybasic/layWidgets.cc b/src/laybasic/layWidgets.cc index 2b891a757..deadd4923 100644 --- a/src/laybasic/layWidgets.cc +++ b/src/laybasic/layWidgets.cc @@ -934,8 +934,9 @@ const int le_decoration_space = 2; // additional distance between decoration ic DecoratedLineEdit::DecoratedLineEdit (QWidget *parent) : QLineEdit (parent), - m_clear_button_enabled (false), m_options_button_enabled (false), mp_options_menu (0), - m_escape_signal_enabled (false), m_tab_signal_enabled (false) + m_clear_button_enabled (false), m_options_button_enabled (false), + m_escape_signal_enabled (false), m_tab_signal_enabled (false), + mp_options_menu (0) { mp_options_label = new QLabel (this); mp_options_label->hide (); @@ -1105,5 +1106,84 @@ 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 738fbaebb..9c599ef13 100644 --- a/src/laybasic/layWidgets.h +++ b/src/laybasic/layWidgets.h @@ -30,6 +30,7 @@ #include #include #include +#include namespace db { @@ -443,6 +444,21 @@ 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