From: Soeren Apel Date: Mon, 28 Dec 2015 20:20:23 +0000 (+0100) Subject: Use alternating trace background colors when not using their own X-Git-Tag: pulseview-0.3.0~24 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ac0708fb7e6b4010d90a569386810d3d2edc7eb9;p=pulseview.git Use alternating trace background colors when not using their own --- diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index 3727afa2..f7bba9ff 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -41,6 +41,9 @@ namespace view { const QPen Trace::AxisPen(QColor(128, 128, 128, 64)); const int Trace::LabelHitPadding = 2; +const QColor Trace::DarkBGColour(235, 235, 235); // Quite light grey +const QColor Trace::BrightBGColour(245, 245, 245); // Very light grey + Trace::Trace(QString name) : name_(name), coloured_bg_(true), // Default setting is set in MainWindow::setup_ui() @@ -181,19 +184,21 @@ QRectF Trace::hit_box_rect(const ViewItemPaintParams &pp) const void Trace::paint_back(QPainter &p, const ViewItemPaintParams &pp) { - if (coloured_bg_) { - p.setPen(QPen(Qt::NoPen)); + if (coloured_bg_) p.setBrush(bgcolour_); + else + p.setBrush(bgcolour_state_ ? BrightBGColour : DarkBGColour); - const std::pair extents = v_extents(); + p.setPen(QPen(Qt::NoPen)); - const int x = 0; - const int y = get_visual_y() + extents.first; - const int w = pp.right() - pp.left(); - const int h = extents.second - extents.first; + const std::pair extents = v_extents(); - p.drawRect(x, y, w, h); - } + const int x = 0; + const int y = get_visual_y() + extents.first; + const int w = pp.right() - pp.left(); + const int h = extents.second - extents.first; + + p.drawRect(x, y, w, h); } void Trace::paint_axis(QPainter &p, const ViewItemPaintParams &pp, int y) diff --git a/pv/view/trace.hpp b/pv/view/trace.hpp index 74daf4a5..95efb607 100644 --- a/pv/view/trace.hpp +++ b/pv/view/trace.hpp @@ -49,6 +49,9 @@ private: static const QPen AxisPen; static const int LabelHitPadding; + static const QColor BrightBGColour; + static const QColor DarkBGColour; + protected: Trace(QString name); @@ -136,7 +139,7 @@ private Q_SLOTS: protected: QString name_; QColor colour_, bgcolour_; - bool coloured_bg_; + bool coloured_bg_, coloured_bg_state_; private: pv::widgets::Popup *popup_; diff --git a/pv/view/tracetreeitem.cpp b/pv/view/tracetreeitem.cpp index 21fecb7e..44c5d4b9 100644 --- a/pv/view/tracetreeitem.cpp +++ b/pv/view/tracetreeitem.cpp @@ -138,5 +138,10 @@ QPoint TraceTreeItem::point(const QRect &rect) const return QPoint(rect.right(), get_visual_y()); } +void TraceTreeItem::set_bgcolour_state(bool state) +{ + bgcolour_state_ = state; +} + } // namespace view } // namespace pv diff --git a/pv/view/tracetreeitem.hpp b/pv/view/tracetreeitem.hpp index c41b67d7..3632ded2 100644 --- a/pv/view/tracetreeitem.hpp +++ b/pv/view/tracetreeitem.hpp @@ -110,6 +110,14 @@ public: */ QPoint point(const QRect &rect) const; + /** + * Sets the new background colour state: false means dark, true means bright. + * This is to allow for alternating backgrounds but has no effect + * when coloured background colours are used. + * @param state New bg color state to use. + */ + void set_bgcolour_state(bool state); + /** * Computes the vertical extents of the contents of this row item. * @return A pair containing the minimum and maximum y-values. @@ -122,6 +130,8 @@ protected: int layout_v_offset_; int visual_v_offset_; + bool bgcolour_state_; + private: QPropertyAnimation v_offset_animation_; }; diff --git a/pv/view/tracetreeitemowner.cpp b/pv/view/tracetreeitemowner.cpp index 56433752..24174794 100644 --- a/pv/view/tracetreeitemowner.cpp +++ b/pv/view/tracetreeitemowner.cpp @@ -105,6 +105,23 @@ pair TraceTreeItemOwner::v_extents() const return extents; } +bool TraceTreeItemOwner::reassign_bgcolour_states(bool next_bgcolour_state) +{ + vector< shared_ptr > items = trace_tree_child_items(); + + // Sort items according to vertical position + sort(items.begin(), items.end(), + [](const shared_ptr a, const shared_ptr b) { + return a->layout_v_offset() > b->layout_v_offset(); }); + + for (const shared_ptr item : items) { + item->set_bgcolour_state(next_bgcolour_state); + next_bgcolour_state = !next_bgcolour_state; + } + + return next_bgcolour_state; +} + void TraceTreeItemOwner::restack_items() { } diff --git a/pv/view/tracetreeitemowner.hpp b/pv/view/tracetreeitemowner.hpp index cbb74427..3e7927a8 100644 --- a/pv/view/tracetreeitemowner.hpp +++ b/pv/view/tracetreeitemowner.hpp @@ -97,6 +97,14 @@ public: */ std::pair v_extents() const; + /* + * Reassigns background color states to all its children, thereby + * providing them with alternating backgrounds. + * @param next_brightness_state First brightness state to use. + * @return The next brightness state to use. + */ + bool reassign_bgcolour_states(bool next_bgcolour_state); + public: virtual void row_item_appearance_changed(bool label, bool content) = 0; diff --git a/pv/view/view.cpp b/pv/view/view.cpp index eeb8afd2..c9b08bf8 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -546,6 +546,12 @@ void View::restack_all_trace_tree_items() for (auto &o : sorted_owners) o->restack_items(); + // Re-assign background colors + bool next_bgcolour_state = 0; + + for (auto &o : sorted_owners) + next_bgcolour_state = o->reassign_bgcolour_states(next_bgcolour_state); + // Animate the items to their destination for (const auto &i : items) i->animate_to_layout_v_offset();