}
}
-void CursorPair::draw_viewport_background(QPainter &p,
- const QRect &rect)
-{
+void CursorPair::paint_back(QPainter &p, const ViewItemPaintParams &pp) {
+ if (!enabled())
+ return;
+
p.setPen(Qt::NoPen);
p.setBrush(QBrush(View::CursorAreaColour));
const int l = (int)max(min(
offsets.first, offsets.second), 0.0f);
const int r = (int)min(max(
- offsets.first, offsets.second), (float)rect.width());
-
- p.drawRect(l, 0, r - l, rect.height());
-}
-
-void CursorPair::draw_viewport_foreground(QPainter &p,
- const QRect &rect)
-{
- assert(first_);
- assert(second_);
+ offsets.first, offsets.second), (float)pp.width());
- first_->paint(p, rect);
- second_->paint(p, rect);
+ p.drawRect(l, pp.top(), r - l, pp.height());
}
void CursorPair::compute_text_size(QPainter &p, unsigned int prefix)
void paint_label(QPainter &p, const QRect &rect);
- void draw_viewport_background(QPainter &p, const QRect &rect);
-
- void draw_viewport_foreground(QPainter &p, const QRect &rect);
+ /**
+ * Paints the background layer of the item with a QPainter
+ * @param p the QPainter to paint into.
+ * @param pp the painting parameters object to paint with.
+ **/
+ void paint_back(QPainter &p, const ViewItemPaintParams &pp);
void compute_text_size(QPainter &p, unsigned int prefix);
time_changed();
}
-void TimeMarker::paint(QPainter &p, const QRect &rect)
-{
- const float x = get_x();
- p.setPen(colour_.darker());
- p.drawLine(QPointF(x, rect.top()), QPointF(x, rect.bottom()));
-}
-
QRectF TimeMarker::label_rect(const QRectF &rect) const
{
const float x = (time_ - view_.offset()) / view_.scale();
p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter, get_text());
}
+void TimeMarker::paint_fore(QPainter &p, const ViewItemPaintParams &pp)
+{
+ if (!enabled())
+ return;
+
+ const float x = get_x();
+ p.setPen(colour_.darker());
+ p.drawLine(QPointF(x, pp.top()), QPointF(x, pp.bottom()));
+}
+
pv::widgets::Popup* TimeMarker::create_popup(QWidget *parent)
{
using pv::widgets::Popup;
*/
QPoint point() const;
- /**
- * Paints the marker to the viewport.
- * @param p The painter to draw with.
- * @param rect The rectangle of the viewport client area.
- */
- virtual void paint(QPainter &p, const QRect &rect);
-
/**
* Computes the outline rectangle of a label.
* @param rect the rectangle of the header area.
*/
void paint_label(QPainter &p, const QRect &rect);
+ /**
+ * Paints the foreground layer of the item with a QPainter
+ * @param p the QPainter to paint into.
+ * @param pp the painting parameters object to paint with.
+ **/
+ void paint_fore(QPainter &p, const ViewItemPaintParams &pp);
+
pv::widgets::Popup* create_popup(QWidget *parent);
private Q_SLOTS:
using std::abs;
using std::max;
using std::min;
+using std::none_of;
using std::shared_ptr;
using std::stable_sort;
using std::vector;
void Viewport::paintEvent(QPaintEvent*)
{
vector< shared_ptr<RowItem> > row_items(view_.begin(), view_.end());
+ assert(none_of(row_items.begin(), row_items.end(),
+ [](const shared_ptr<RowItem> &r) { return !r; }));
+
stable_sort(row_items.begin(), row_items.end(),
[](const shared_ptr<RowItem> &a, const shared_ptr<RowItem> &b) {
return a->visual_v_offset() < b->visual_v_offset(); });
+ const vector< shared_ptr<TimeItem> > time_items(view_.time_items());
+ assert(none_of(time_items.begin(), time_items.end(),
+ [](const shared_ptr<TimeItem> &t) { return !t; }));
+
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
- if (view_.cursors_shown())
- view_.cursors()->draw_viewport_background(p, rect());
-
const ViewItemPaintParams pp(rect(), view_.scale(), view_.offset());
- // Plot the signal
+ for (const shared_ptr<TimeItem> t : time_items)
+ t->paint_back(p, pp);
for (const shared_ptr<RowItem> r : row_items)
- {
- assert(r);
r->paint_back(p, pp);
- }
+ for (const shared_ptr<TimeItem> t : time_items)
+ t->paint_mid(p, pp);
for (const shared_ptr<RowItem> r : row_items)
r->paint_mid(p, pp);
for (const shared_ptr<RowItem> r : row_items)
r->paint_fore(p, pp);
-
- if (view_.cursors_shown())
- view_.cursors()->draw_viewport_foreground(p, rect());
+ for (const shared_ptr<TimeItem> t : time_items)
+ t->paint_fore(p, pp);
p.end();
}