pv/view/logicsignal.cpp
pv/view/rowitem.cpp
pv/view/rowitemowner.cpp
+ pv/view/rowitempaintparams.cpp
pv/view/ruler.cpp
pv/view/selectableitem.cpp
pv/view/signal.cpp
return make_pair(-NominalHeight / 2, NominalHeight / 2);
}
-void AnalogSignal::paint_back(QPainter &p, int left, int right)
+void AnalogSignal::paint_back(QPainter &p, const RowItemPaintParams &pp)
{
if (channel_->enabled())
- paint_axis(p, get_visual_y(), left, right);
+ paint_axis(p, get_visual_y(), pp.left(), pp.right());
}
-void AnalogSignal::paint_mid(QPainter &p, int left, int right)
+void AnalogSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp)
{
assert(data_);
- assert(right >= left);
assert(owner_);
const int y = get_visual_y();
const int64_t last_sample = snapshot->get_sample_count() - 1;
const double samples_per_pixel = samplerate * scale;
const double start = samplerate * (offset - start_time);
- const double end = start + samples_per_pixel * (right - left);
+ const double end = start + samples_per_pixel * pp.width();
const int64_t start_sample = min(max((int64_t)floor(start),
(int64_t)0), last_sample);
(int64_t)0), last_sample);
if (samples_per_pixel < EnvelopeThreshold)
- paint_trace(p, snapshot, y, left,
+ paint_trace(p, snapshot, y, pp.left(),
start_sample, end_sample,
pixels_offset, samples_per_pixel);
else
- paint_envelope(p, snapshot, y, left,
+ paint_envelope(p, snapshot, y, pp.left(),
start_sample, end_sample,
pixels_offset, samples_per_pixel);
}
/**
* Paints the background layer of the signal with a QPainter
* @param p the QPainter to paint into.
- * @param left the x-coordinate of the left edge of the signal.
- * @param right the x-coordinate of the right edge of the signal.
+ * @param pp the painting parameters object to paint with..
**/
- void paint_back(QPainter &p, int left, int right);
+ void paint_back(QPainter &p, const RowItemPaintParams &pp);
/**
* Paints the mid-layer of the signal with a QPainter
* @param p the QPainter to paint into.
- * @param left the x-coordinate of the left edge of the signal.
- * @param right the x-coordinate of the right edge of the signal.
+ * @param pp the painting parameters object to paint with..
**/
- void paint_mid(QPainter &p, int left, int right);
+ void paint_mid(QPainter &p, const RowItemPaintParams &pp);
private:
void paint_trace(QPainter &p,
return make_pair(-row_height / 2, row_height * 7 / 2);
}
-void DecodeTrace::paint_back(QPainter &p, int left, int right)
+void DecodeTrace::paint_back(QPainter &p, const RowItemPaintParams &pp)
{
- Trace::paint_back(p, left, right);
- paint_axis(p, get_visual_y(), left, right);
+ Trace::paint_back(p, pp);
+ paint_axis(p, get_visual_y(), pp.left(), pp.right());
}
-void DecodeTrace::paint_mid(QPainter &p, int left, int right)
+void DecodeTrace::paint_mid(QPainter &p, const RowItemPaintParams &pp)
{
using namespace pv::data::decode;
const QString err = decoder_stack_->error_message();
if (!err.isEmpty())
{
- draw_unresolved_period(p, annotation_height, left, right);
- draw_error(p, err, left, right);
+ draw_unresolved_period(
+ p, annotation_height, pp.left(), pp.right());
+ draw_error(p, err, pp);
return;
}
// Iterate through the rows
int y = get_visual_y();
- pair<uint64_t, uint64_t> sample_range = get_sample_range(left, right);
+ pair<uint64_t, uint64_t> sample_range = get_sample_range(
+ pp.left(), pp.right());
assert(decoder_stack_);
const vector<Row> rows(decoder_stack_->get_visible_rows());
if (!annotations.empty()) {
for (const Annotation &a : annotations)
draw_annotation(a, p, get_text_colour(),
- annotation_height, left, right, y,
- base_colour);
+ annotation_height, pp, y, base_colour);
y += row_height_;
visible_rows_.push_back(rows[i]);
}
// Draw the hatching
- draw_unresolved_period(p, annotation_height, left, right);
+ draw_unresolved_period(p, annotation_height, pp.left(), pp.right());
}
-void DecodeTrace::paint_fore(QPainter &p, int left, int right)
+void DecodeTrace::paint_fore(QPainter &p, const RowItemPaintParams &pp)
{
using namespace pv::data::decode;
- (void)right;
-
assert(row_height_);
for (size_t i = 0; i < visible_rows_.size(); i++)
if (i != 0)
{
const QPointF points[] = {
- QPointF(left, y - ArrowSize),
- QPointF(left + ArrowSize, y),
- QPointF(left, y + ArrowSize)
+ QPointF(pp.left(), y - ArrowSize),
+ QPointF(pp.left() + ArrowSize, y),
+ QPointF(pp.left(), y + ArrowSize)
};
p.drawPolygon(points, countof(points));
}
- const QRect r(left + ArrowSize * 2, y - row_height_ / 2,
- right - left, row_height_);
+ const QRect r(pp.left() + ArrowSize * 2, y - row_height_ / 2,
+ pp.right() - pp.left(), row_height_);
const QString h(visible_rows_[i].title());
const int f = Qt::AlignLeft | Qt::AlignVCenter |
Qt::TextDontClip;
}
void DecodeTrace::draw_annotation(const pv::data::decode::Annotation &a,
- QPainter &p, QColor text_color, int h, int left, int right, int y,
+ QPainter &p, QColor text_color, int h, const RowItemPaintParams &pp, int y,
size_t base_colour) const
{
double samples_per_pixel, pixels_offset;
const QColor &fill = Colours[colour];
const QColor &outline = OutlineColours[colour];
- if (start > right + DrawPadding || end < left - DrawPadding)
+ if (start > pp.right() + DrawPadding || end < pp.left() - DrawPadding)
return;
if (a.start_sample() == a.end_sample())
}
void DecodeTrace::draw_error(QPainter &p, const QString &message,
- int left, int right)
+ const RowItemPaintParams &pp)
{
const int y = get_visual_y();
p.setBrush(ErrorBgColour);
const QRectF bounding_rect =
- QRectF(left, INT_MIN / 2 + y, right - left, INT_MAX);
+ QRectF(pp.width(), INT_MIN / 2 + y, pp.width(), INT_MAX);
const QRectF text_rect = p.boundingRect(bounding_rect,
Qt::AlignCenter, message);
const float r = text_rect.height() / 4;
/**
* Paints the background layer of the trace with a QPainter
* @param p the QPainter to paint into.
- * @param left the x-coordinate of the left edge of the signal.
- * @param right the x-coordinate of the right edge of the signal.
+ * @param pp the painting parameters object to paint with..
**/
- void paint_back(QPainter &p, int left, int right);
+ void paint_back(QPainter &p, const RowItemPaintParams &pp);
/**
* Paints the mid-layer of the trace with a QPainter
* @param p the QPainter to paint into.
- * @param left the x-coordinate of the left edge of the signal
- * @param right the x-coordinate of the right edge of the signal
+ * @param pp the painting parameters object to paint with.
**/
- void paint_mid(QPainter &p, int left, int right);
+ void paint_mid(QPainter &p, const RowItemPaintParams &pp);
/**
* Paints the foreground layer of the trace with a QPainter
* @param p the QPainter to paint into.
- * @param left the x-coordinate of the left edge of the signal
- * @param right the x-coordinate of the right edge of the signal
+ * @param pp the painting parameters object to paint with.
**/
- void paint_fore(QPainter &p, int left, int right);
+ void paint_fore(QPainter &p, const RowItemPaintParams &pp);
void populate_popup_form(QWidget *parent, QFormLayout *form);
private:
void draw_annotation(const pv::data::decode::Annotation &a, QPainter &p,
- QColor text_colour, int text_height, int left, int right, int y,
+ QColor text_colour, int text_height, const RowItemPaintParams &pp, int y,
size_t base_colour) const;
void draw_instant(const pv::data::decode::Annotation &a, QPainter &p,
double end, int y) const;
void draw_error(QPainter &p, const QString &message,
- int left, int right);
+ const RowItemPaintParams &pp);
void draw_unresolved_period(QPainter &p, int h, int left,
int right) const;
return make_pair(-SignalHeight - SignalMargin, SignalMargin);
}
-void LogicSignal::paint_back(QPainter &p, int left, int right)
+void LogicSignal::paint_back(QPainter &p, const RowItemPaintParams &pp)
{
if (channel_->enabled())
- paint_axis(p, get_visual_y(), left, right);
+ paint_axis(p, get_visual_y(), pp.left(), pp.right());
}
-void LogicSignal::paint_mid(QPainter &p, int left, int right)
+void LogicSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp)
{
using pv::view::View;
assert(channel_);
assert(data_);
- assert(right >= left);
assert(owner_);
const int y = get_visual_y();
const int64_t last_sample = snapshot->get_sample_count() - 1;
const double samples_per_pixel = samplerate * scale;
const double start = samplerate * (offset - start_time);
- const double end = start + samples_per_pixel * (right - left);
+ const double end = start + samples_per_pixel * pp.width();
snapshot->get_subsampled_edges(edges,
min(max((int64_t)floor(start), (int64_t)0), last_sample),
for (auto i = edges.cbegin() + 1; i != edges.cend() - 1; i++) {
const float x = ((*i).first / samples_per_pixel -
- pixels_offset) + left;
+ pixels_offset) + pp.left();
*line++ = QLineF(x, high_offset, x, low_offset);
}
p.setPen(HighColour);
paint_caps(p, cap_lines, edges, true, samples_per_pixel,
- pixels_offset, left, high_offset);
+ pixels_offset, pp.left(), high_offset);
p.setPen(LowColour);
paint_caps(p, cap_lines, edges, false, samples_per_pixel,
- pixels_offset, left, low_offset);
+ pixels_offset, pp.left(), low_offset);
delete[] cap_lines;
}
-void LogicSignal::paint_fore(QPainter &p, int left, int right)
+void LogicSignal::paint_fore(QPainter &p, const RowItemPaintParams &pp)
{
- (void)left;
-
// Draw the trigger marker
if (!trigger_match_)
return;
const int pad = TriggerMarkerPadding;
const QSize size = pixmap->size();
const QPoint point(
- right - size.width() - pad * 2,
+ pp.right() - size.width() - pad * 2,
y - (SignalHeight + size.height()) / 2);
p.setPen(QPen(Qt::NoPen));
/**
* Paints the background layer of the signal with a QPainter
* @param p the QPainter to paint into.
- * @param left the x-coordinate of the left edge of the signal.
- * @param right the x-coordinate of the right edge of the signal.
+ * @param pp the painting parameters object to paint with..
**/
- void paint_back(QPainter &p, int left, int right);
+ void paint_back(QPainter &p, const RowItemPaintParams &pp);
/**
* Paints the mid-layer of the signal with a QPainter
* @param p the QPainter to paint into.
- * @param left the x-coordinate of the left edge of the signal.
- * @param right the x-coordinate of the right edge of the signal.
+ * @param pp the painting parameters object to paint with..
**/
- void paint_mid(QPainter &p, int left, int right);
+ void paint_mid(QPainter &p, const RowItemPaintParams &pp);
/**
* Paints the foreground layer of the signal with a QPainter
* @param p the QPainter to paint into.
- * @param left the x-coordinate of the left edge of the signal
- * @param right the x-coordinate of the right edge of the signal
+ * @param pp the painting parameters object to paint with.
**/
- virtual void paint_fore(QPainter &p, int left, int right);
+ virtual void paint_fore(QPainter &p, const RowItemPaintParams &pp);
private:
void paint_caps(QPainter &p, QLineF *const lines,
return QPoint(0, visual_v_offset());
}
-void RowItem::paint_back(QPainter &p, int left, int right)
+void RowItem::paint_back(QPainter &p, const RowItemPaintParams &pp)
{
(void)p;
- (void)left;
- (void)right;
+ (void)pp;
}
-void RowItem::paint_mid(QPainter &p, int left, int right)
+void RowItem::paint_mid(QPainter &p, const RowItemPaintParams &pp)
{
(void)p;
- (void)left;
- (void)right;
+ (void)pp;
}
-void RowItem::paint_fore(QPainter &p, int left, int right)
+void RowItem::paint_fore(QPainter &p, const RowItemPaintParams &pp)
{
(void)p;
- (void)left;
- (void)right;
+ (void)pp;
}
void RowItem::hover_point_changed()
#include <QPropertyAnimation>
+#include "rowitempaintparams.hpp"
#include "selectableitem.hpp"
namespace pv {
/**
* Paints the background layer of the trace with a QPainter
* @param p the QPainter to paint into.
- * @param left the x-coordinate of the left edge of the signal
- * @param right the x-coordinate of the right edge of the signal
+ * @param pp the painting parameters object to paint with.
**/
- virtual void paint_back(QPainter &p, int left, int right);
+ virtual void paint_back(QPainter &p, const RowItemPaintParams &pp);
/**
* Paints the mid-layer of the trace with a QPainter
* @param p the QPainter to paint into.
- * @param left the x-coordinate of the left edge of the signal
- * @param right the x-coordinate of the right edge of the signal
+ * @param pp the painting parameters object to paint with.
**/
- virtual void paint_mid(QPainter &p, int left, int right);
+ virtual void paint_mid(QPainter &p, const RowItemPaintParams &pp);
/**
* Paints the foreground layer of the trace with a QPainter
* @param p the QPainter to paint into.
- * @param left the x-coordinate of the left edge of the signal
- * @param right the x-coordinate of the right edge of the signal
+ * @param pp the painting parameters object to paint with.
**/
- virtual void paint_fore(QPainter &p, int left, int right);
+ virtual void paint_fore(QPainter &p, const RowItemPaintParams &pp);
/**
* Paints the signal label.
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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 <cassert>
+
+#include "rowitempaintparams.hpp"
+
+namespace pv {
+namespace view {
+
+RowItemPaintParams::RowItemPaintParams(int left, int right) :
+ left_(left),
+ right_(right) {
+ assert(left <= right);
+}
+
+} // namespace view
+} // namespace pv
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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 PULSEVIEW_PV_VIEW_ROWITEMPAINTPARAMS_H
+#define PULSEVIEW_PV_VIEW_ROWITEMPAINTPARAMS_H
+
+namespace pv {
+namespace view {
+
+class RowItemPaintParams
+{
+public:
+ RowItemPaintParams(int left, int right);
+
+ int left() const {
+ return left_;
+ }
+
+ int right() const {
+ return right_;
+ }
+
+ int width() const {
+ return right_ - left_;
+ }
+
+private:
+ int left_;
+ int right_;
+};
+
+} // namespace view
+} // namespace pv
+
+#endif // PULSEVIEW_PV_VIEW_ROWITEMPAINTPARAMS_H
#include <cmath>
#include <algorithm>
+#include "rowitempaintparams.hpp"
#include "signal.hpp"
#include "view.hpp"
#include "viewport.hpp"
if (view_.cursors_shown())
view_.cursors().draw_viewport_background(p, rect());
+ const RowItemPaintParams pp(0, width());
+
// Plot the signal
for (const shared_ptr<RowItem> r : row_items)
{
assert(r);
- r->paint_back(p, 0, width());
+ r->paint_back(p, pp);
}
for (const shared_ptr<RowItem> r : row_items)
- r->paint_mid(p, 0, width());
+ r->paint_mid(p, pp);
for (const shared_ptr<RowItem> r : row_items)
- r->paint_fore(p, 0, width());
+ r->paint_fore(p, pp);
if (view_.cursors_shown())
view_.cursors().draw_viewport_foreground(p, rect());
${PROJECT_SOURCE_DIR}/pv/view/logicsignal.cpp
${PROJECT_SOURCE_DIR}/pv/view/rowitem.cpp
${PROJECT_SOURCE_DIR}/pv/view/rowitemowner.cpp
+ ${PROJECT_SOURCE_DIR}/pv/view/rowitempaintparams.cpp
${PROJECT_SOURCE_DIR}/pv/view/ruler.cpp
${PROJECT_SOURCE_DIR}/pv/view/selectableitem.cpp
${PROJECT_SOURCE_DIR}/pv/view/signal.cpp