#include "analogsignal.h"
#include "pv/data/analog.h"
#include "pv/data/analogsnapshot.h"
+#include "pv/view/view.h"
using namespace boost;
using namespace std;
_scale = scale;
}
-void AnalogSignal::paint(QPainter &p, int y, int left, int right, double scale,
- double offset)
+void AnalogSignal::paint(QPainter &p, int left, int right)
{
- assert(scale > 0);
assert(_data);
assert(right >= left);
+ assert(_view);
+ const int y = _v_offset - _view->v_offset();
+
+ const double scale = _view->scale();
+ assert(scale > 0);
+
+ const double offset = _view->offset();
+
if (!_probe->enabled)
return;
/**
* Paints the signal with a QPainter
* @param p the QPainter to paint into.
- * @param y the y-coordinate to draw the signal at.
* @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 scale the scale in seconds per pixel.
- * @param offset the time to show at the left hand edge of
- * the view in seconds.
**/
- void paint(QPainter &p, int y, int left, int right, double scale,
- double offset);
+ void paint(QPainter &p, int left, int right);
private:
void paint_trace(QPainter &p,
return true;
}
-void DecodeSignal::paint(QPainter &p, int y, int left, int right,
- double scale, double offset)
+void DecodeSignal::paint(QPainter &p, int left, int right)
{
(void)p;
- (void)y;
(void)left;
(void)right;
- (void)offset;
-
- assert(scale > 0);
}
const list<QAction*> DecodeSignal::get_context_bar_actions()
/**
* Paints the trace with a QPainter
* @param p the QPainter to paint into.
- * @param y the y-coordinate to draw the signal at
* @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 scale the scale in seconds per pixel.
- * @param offset the time to show at the left hand edge of
- * the view in seconds.
**/
- void paint(QPainter &p, int y, int left, int right,
- double scale, double offset);
+ void paint(QPainter &p, int left, int right);
const std::list<QAction*> get_context_bar_actions();
const int w = width();
const vector< shared_ptr<Trace> > traces(_view.get_traces());
- const int v_offset = _view.v_offset();
BOOST_FOREACH(const shared_ptr<Trace> t, traces)
{
assert(t);
-
- if (t->pt_in_label_rect(t->get_v_offset() - v_offset,
- 0, w, pt))
+ if (t->pt_in_label_rect(0, w, pt))
return t;
}
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
- const int v_offset = _view.v_offset();
const bool dragging = !_drag_traces.empty();
BOOST_FOREACH(const shared_ptr<Trace> t, traces)
{
assert(t);
- const int y = t->get_v_offset() - v_offset;
const bool highlight = !dragging && t->pt_in_label_rect(
- y, 0, w, _mouse_point);
- t->paint_label(painter, y, w, highlight);
+ 0, w, _mouse_point);
+ t->paint_label(painter, w, highlight);
}
painter.end();
#include "pv/sigsession.h"
#include "pv/data/logic.h"
#include "pv/data/logicsnapshot.h"
+#include "pv/view/view.h"
using namespace boost;
using namespace std;
return actions;
}
-void LogicSignal::paint(QPainter &p, int y, int left, int right,
- double scale, double offset)
+void LogicSignal::paint(QPainter &p, int left, int right)
{
using pv::view::View;
vector< pair<int64_t, bool> > edges;
assert(_probe);
- assert(scale > 0);
assert(_data);
assert(right >= left);
+ assert(_view);
+ const int y = _v_offset - _view->v_offset();
+
+ const double scale = _view->scale();
+ assert(scale > 0);
+
+ const double offset = _view->offset();
+
if (!_probe->enabled)
return;
/**
* Paints the signal with a QPainter
* @param p the QPainter to paint into.
- * @param y the y-coordinate to draw the signal at.
* @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 scale the scale in seconds per pixel.
- * @param offset the time to show at the left hand edge of
- * the view in seconds.
**/
- void paint(QPainter &p, int y, int left, int right, double scale,
- double offset);
+ void paint(QPainter &p, int left, int right);
private:
_v_offset = v_offset;
}
-void Trace::paint_label(QPainter &p, int y, int right, bool hover)
+void Trace::set_view(pv::view::View *view)
{
+ assert(view);
+ _view = view;
+}
+
+void Trace::paint_label(QPainter &p, int right, bool hover)
+{
+ assert(_view);
+ const int y = _v_offset - _view->v_offset();
+
p.setBrush(_colour);
if (!enabled())
const QColor colour = get_colour();
compute_text_size(p);
- const QRectF label_rect = get_label_rect(y, right);
+ const QRectF label_rect = get_label_rect(right);
// Paint the label
const QPointF points[] = {
p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name);
}
-bool Trace::pt_in_label_rect(int y, int left, int right,
- const QPoint &point)
+bool Trace::pt_in_label_rect(int left, int right, const QPoint &point)
{
(void)left;
- const QRectF label = get_label_rect(y, right);
+ const QRectF label = get_label_rect(right);
return QRectF(
QPointF(label.left() - LabelHitPadding,
label.top() - LabelHitPadding),
p.boundingRect(QRectF(), 0, "Tg").height());
}
-QRectF Trace::get_label_rect(int y, int right)
+QRectF Trace::get_label_rect(int right)
{
using pv::view::View;
+ assert(_view);
+ const int y = _v_offset - _view->v_offset();
+
const QSizeF label_size(
_text_size.width() + View::LabelPadding.width() * 2,
ceilf((_text_size.height() + View::LabelPadding.height() * 2) / 2) * 2);
namespace view {
+class View;
+
class Trace : public SelectableItem
{
Q_OBJECT
*/
virtual bool enabled() const = 0;
+ void set_view(pv::view::View *view);
+
/**
* Paints the trace with a QPainter
* @param p the QPainter to paint into.
- * @param y the y-coordinate to draw the signal at
* @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 scale the scale in seconds per pixel.
- * @param offset the time to show at the left hand edge of
- * the view in seconds.
**/
- virtual void paint(QPainter &p, int y, int left, int right,
- double scale, double offset) = 0;
+ virtual void paint(QPainter &p, int left, int right) = 0;
/**
* Paints the signal label into a QGLWidget.
* @param p the QPainter to paint into.
- * @param y the y-coordinate of the signal.
* @param right the x-coordinate of the right edge of the header
* area.
* @param hover true if the label is being hovered over by the mouse.
*/
- virtual void paint_label(QPainter &p, int y, int right,
- bool hover);
+ virtual void paint_label(QPainter &p, int right, bool hover);
/**
* Determines if a point is in the header label rect.
- * @param y the y-coordinate of the signal.
* @param left the x-coordinate of the left edge of the header
* area.
* @param right the x-coordinate of the right edge of the header
* area.
* @param point the point to test.
*/
- bool pt_in_label_rect(int y, int left, int right,
- const QPoint &point);
+ bool pt_in_label_rect(int left, int right, const QPoint &point);
private:
/**
* Computes the outline rectangle of a label.
* @param p the QPainter to lay out text with.
- * @param y the y-coordinate of the signal.
* @param right the x-coordinate of the right edge of the header
* area.
* @return Returns the rectangle of the signal label.
*/
- QRectF get_label_rect(int y, int right);
+ QRectF get_label_rect(int right);
signals:
void text_changed();
protected:
pv::SigSession &_session;
+ pv::view::View *_view;
QString _name;
QColor _colour;
void View::signals_changed()
{
int offset = SignalMargin + SignalHeight;
- const vector< shared_ptr<Signal> > sigs(_session.get_signals());
- BOOST_FOREACH(shared_ptr<Signal> s, sigs) {
- s->init_context_bar_actions(NULL);
- s->set_v_offset(offset);
+ const vector< shared_ptr<Trace> > traces(get_traces());
+ BOOST_FOREACH(shared_ptr<Trace> t, traces) {
+ t->set_view(this);
+ t->init_context_bar_actions(NULL);
+ t->set_v_offset(offset);
offset += SignalHeight + 2 * SignalMargin;
}
_view.cursors().draw_viewport_background(p, rect());
// Plot the signal
- const int v_offset = _view.v_offset();
BOOST_FOREACH(const shared_ptr<Trace> t, traces)
{
assert(t);
- t->paint(p, t->get_v_offset() - v_offset, 0, width(),
- _view.scale(), _view.offset());
+ t->paint(p, 0, width());
}
if (_view.cursors_shown())