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()
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<int, int> 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<int, int> 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)
static const QPen AxisPen;
static const int LabelHitPadding;
+ static const QColor BrightBGColour;
+ static const QColor DarkBGColour;
+
protected:
Trace(QString name);
protected:
QString name_;
QColor colour_, bgcolour_;
- bool coloured_bg_;
+ bool coloured_bg_, coloured_bg_state_;
private:
pv::widgets::Popup *popup_;
return QPoint(rect.right(), get_visual_y());
}
+void TraceTreeItem::set_bgcolour_state(bool state)
+{
+ bgcolour_state_ = state;
+}
+
} // namespace view
} // namespace pv
*/
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.
int layout_v_offset_;
int visual_v_offset_;
+ bool bgcolour_state_;
+
private:
QPropertyAnimation v_offset_animation_;
};
return extents;
}
+bool TraceTreeItemOwner::reassign_bgcolour_states(bool next_bgcolour_state)
+{
+ vector< shared_ptr<TraceTreeItem> > items = trace_tree_child_items();
+
+ // Sort items according to vertical position
+ sort(items.begin(), items.end(),
+ [](const shared_ptr<TraceTreeItem> a, const shared_ptr<TraceTreeItem> b) {
+ return a->layout_v_offset() > b->layout_v_offset(); });
+
+ for (const shared_ptr<TraceTreeItem> item : items) {
+ item->set_bgcolour_state(next_bgcolour_state);
+ next_bgcolour_state = !next_bgcolour_state;
+ }
+
+ return next_bgcolour_state;
+}
+
void TraceTreeItemOwner::restack_items()
{
}
*/
std::pair<int, int> 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;
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();