This will be used for non-signal traces such as the decode trace.
pv/view/selectableitem.cpp
pv/view/signal.cpp
pv/view/timemarker.cpp
+ pv/view/trace.cpp
pv/view/view.cpp
pv/view/viewport.cpp
)
pv/view/selectableitem.h
pv/view/signal.h
pv/view/timemarker.h
+ pv/view/trace.h
pv/view/view.h
pv/view/viewport.h
)
namespace pv {
namespace view {
-const int Signal::LabelHitPadding = 2;
-
const QPen Signal::SignalAxisPen(QColor(128, 128, 128, 64));
const char *const ProbeNames[] = {
};
Signal::Signal(pv::SigSession &session, const sr_probe *const probe) :
- _session(session),
+ Trace(session, probe->name),
_probe(probe),
- _name(probe->name),
- _v_offset(0),
_name_action(NULL),
_name_widget(),
_updating_name_widget(false)
this, SLOT(on_text_changed(const QString&)));
}
-QString Signal::get_name() const
-{
- return _name;
-}
-
void Signal::set_name(QString name)
{
- _name = name;
+ Trace::set_name(name);
_updating_name_widget = true;
_name_widget.setEditText(name);
_updating_name_widget = false;
}
-QColor Signal::get_colour() const
-{
- return _colour;
-}
-
-void Signal::set_colour(QColor colour)
-{
- _colour = colour;
-}
-
-int Signal::get_v_offset() const
-{
- return _v_offset;
-}
-
-void Signal::set_v_offset(int v_offset)
+bool Signal::enabled() const
{
- _v_offset = v_offset;
-}
-
-void Signal::paint_label(QPainter &p, int y, int right, bool hover)
-{
- p.setBrush(_colour);
-
- if (!_probe->enabled)
- return;
-
- const QColor colour = get_colour();
-
- compute_text_size(p);
- const QRectF label_rect = get_label_rect(y, right);
-
- // Paint the label
- const QPointF points[] = {
- label_rect.topLeft(),
- label_rect.topRight(),
- QPointF(right, y),
- label_rect.bottomRight(),
- label_rect.bottomLeft()
- };
-
- const QPointF highlight_points[] = {
- QPointF(label_rect.left() + 1, label_rect.top() + 1),
- QPointF(label_rect.right(), label_rect.top() + 1),
- QPointF(right - 1, y),
- QPointF(label_rect.right(), label_rect.bottom() - 1),
- QPointF(label_rect.left() + 1, label_rect.bottom() - 1)
- };
-
- if (selected()) {
- p.setPen(highlight_pen());
- p.setBrush(Qt::transparent);
- p.drawPolygon(points, countof(points));
- }
-
- p.setPen(Qt::transparent);
- p.setBrush(hover ? colour.lighter() : colour);
- p.drawPolygon(points, countof(points));
-
- p.setPen(colour.lighter());
- p.setBrush(Qt::transparent);
- p.drawPolygon(highlight_points, countof(highlight_points));
-
- p.setPen(colour.darker());
- p.setBrush(Qt::transparent);
- p.drawPolygon(points, countof(points));
-
- // Paint the text
- p.setPen((colour.lightness() > 64) ? Qt::black : Qt::white);
- p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name);
-}
-
-bool Signal::pt_in_label_rect(int y, int left, int right,
- const QPoint &point)
-{
- (void)left;
-
- const QRectF label = get_label_rect(y, right);
- return QRectF(
- QPointF(label.left() - LabelHitPadding,
- label.top() - LabelHitPadding),
- QPointF(right, label.bottom() + LabelHitPadding)
- ).contains(point);
+ return _probe->enabled;
}
void Signal::paint_axis(QPainter &p, int y, int left, int right)
p.drawLine(QPointF(left, y + 0.5f), QPointF(right, y + 0.5f));
}
-void Signal::compute_text_size(QPainter &p)
-{
- _text_size = QSize(
- p.boundingRect(QRectF(), 0, _name).width(),
- p.boundingRect(QRectF(), 0, "Tg").height());
-}
-
-QRectF Signal::get_label_rect(int y, int right)
-{
- using pv::view::View;
-
- const QSizeF label_size(
- _text_size.width() + View::LabelPadding.width() * 2,
- ceilf((_text_size.height() + View::LabelPadding.height() * 2) / 2) * 2);
- const float label_arrow_length = label_size.height() / 2;
- return QRectF(
- right - label_arrow_length - label_size.width() - 0.5,
- y + 0.5f - label_size.height() / 2,
- label_size.width(), label_size.height());
-}
-
void Signal::on_text_changed(const QString &text)
{
- _name = text;
+ Trace::set_name(text);
text_changed();
}
#ifndef PULSEVIEW_PV_SIGNAL_H
#define PULSEVIEW_PV_SIGNAL_H
-#include <boost/shared_ptr.hpp>
-
-#include <QColor>
#include <QComboBox>
-#include <QPainter>
#include <QPen>
-#include <QRect>
-#include <QString>
#include <QWidgetAction>
#include <stdint.h>
#include <libsigrok/libsigrok.h>
-#include "selectableitem.h"
+#include "trace.h"
namespace pv {
-class SigSession;
-
namespace data {
class SignalData;
}
namespace view {
-class Signal : public SelectableItem
+class Signal : public Trace
{
Q_OBJECT
private:
- static const int LabelHitPadding;
-
static const QPen SignalAxisPen;
protected:
Signal(pv::SigSession &session, const sr_probe *const probe);
public:
- /**
- * Gets the name of this signal.
- */
- QString get_name() const;
-
/**
* Sets the name of the signal.
*/
void set_name(QString name);
/**
- * Get the colour of the signal.
- */
- QColor get_colour() const;
-
- /**
- * Set the colour of the signal.
- */
- void set_colour(QColor colour);
-
- /**
- * Gets the vertical layout offset of this signal.
- */
- int get_v_offset() const;
-
- /**
- * Sets the vertical layout offset of this signal.
- */
- void set_v_offset(int v_offset);
-
- /**
- * 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.
- **/
- virtual void paint(QPainter &p, int y, int left, int right,
- double scale, double offset) = 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.
+ * Returns true if the trace is visible and enabled.
*/
- virtual void paint_label(QPainter &p, int y, 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 enabled() const;
protected:
*/
void paint_axis(QPainter &p, int y, int left, int right);
-private:
-
- /**
- * Computes an caches the size of the label text.
- */
- void compute_text_size(QPainter &p);
-
- /**
- * 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);
-
private slots:
void on_text_changed(const QString &text);
-signals:
- void text_changed();
-
protected:
- pv::SigSession &_session;
const sr_probe *const _probe;
- QString _name;
- QColor _colour;
- int _v_offset;
-
- QSizeF _text_size;
-
QWidgetAction _name_action;
QComboBox _name_widget;
bool _updating_name_widget;
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2013 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 <extdef.h>
+
+#include <assert.h>
+#include <math.h>
+
+#include "trace.h"
+#include "view.h"
+
+namespace pv {
+namespace view {
+
+const int Trace::LabelHitPadding = 2;
+
+Trace::Trace(pv::SigSession &session, QString name) :
+ _session(session),
+ _name(name),
+ _v_offset(0)
+{
+}
+
+QString Trace::get_name() const
+{
+ return _name;
+}
+
+void Trace::set_name(QString name)
+{
+ _name = name;
+}
+
+QColor Trace::get_colour() const
+{
+ return _colour;
+}
+
+void Trace::set_colour(QColor colour)
+{
+ _colour = colour;
+}
+
+int Trace::get_v_offset() const
+{
+ return _v_offset;
+}
+
+void Trace::set_v_offset(int v_offset)
+{
+ _v_offset = v_offset;
+}
+
+void Trace::paint_label(QPainter &p, int y, int right, bool hover)
+{
+ p.setBrush(_colour);
+
+ if (!enabled())
+ return;
+
+ const QColor colour = get_colour();
+
+ compute_text_size(p);
+ const QRectF label_rect = get_label_rect(y, right);
+
+ // Paint the label
+ const QPointF points[] = {
+ label_rect.topLeft(),
+ label_rect.topRight(),
+ QPointF(right, y),
+ label_rect.bottomRight(),
+ label_rect.bottomLeft()
+ };
+
+ const QPointF highlight_points[] = {
+ QPointF(label_rect.left() + 1, label_rect.top() + 1),
+ QPointF(label_rect.right(), label_rect.top() + 1),
+ QPointF(right - 1, y),
+ QPointF(label_rect.right(), label_rect.bottom() - 1),
+ QPointF(label_rect.left() + 1, label_rect.bottom() - 1)
+ };
+
+ if (selected()) {
+ p.setPen(highlight_pen());
+ p.setBrush(Qt::transparent);
+ p.drawPolygon(points, countof(points));
+ }
+
+ p.setPen(Qt::transparent);
+ p.setBrush(hover ? colour.lighter() : colour);
+ p.drawPolygon(points, countof(points));
+
+ p.setPen(colour.lighter());
+ p.setBrush(Qt::transparent);
+ p.drawPolygon(highlight_points, countof(highlight_points));
+
+ p.setPen(colour.darker());
+ p.setBrush(Qt::transparent);
+ p.drawPolygon(points, countof(points));
+
+ // Paint the text
+ p.setPen((colour.lightness() > 64) ? Qt::black : Qt::white);
+ p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name);
+}
+
+bool Trace::pt_in_label_rect(int y, int left, int right,
+ const QPoint &point)
+{
+ (void)left;
+
+ const QRectF label = get_label_rect(y, right);
+ return QRectF(
+ QPointF(label.left() - LabelHitPadding,
+ label.top() - LabelHitPadding),
+ QPointF(right, label.bottom() + LabelHitPadding)
+ ).contains(point);
+}
+
+void Trace::compute_text_size(QPainter &p)
+{
+ _text_size = QSize(
+ p.boundingRect(QRectF(), 0, _name).width(),
+ p.boundingRect(QRectF(), 0, "Tg").height());
+}
+
+QRectF Trace::get_label_rect(int y, int right)
+{
+ using pv::view::View;
+
+ const QSizeF label_size(
+ _text_size.width() + View::LabelPadding.width() * 2,
+ ceilf((_text_size.height() + View::LabelPadding.height() * 2) / 2) * 2);
+ const float label_arrow_length = label_size.height() / 2;
+ return QRectF(
+ right - label_arrow_length - label_size.width() - 0.5,
+ y + 0.5f - label_size.height() / 2,
+ label_size.width(), label_size.height());
+}
+
+} // namespace view
+} // namespace pv
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2013 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_TRACE_H
+#define PULSEVIEW_PV_TRACE_H
+
+#include <QColor>
+#include <QPainter>
+#include <QRect>
+#include <QString>
+
+#include <stdint.h>
+
+#include "selectableitem.h"
+
+namespace pv {
+
+class SigSession;
+
+namespace view {
+
+class Trace : public SelectableItem
+{
+ Q_OBJECT
+
+private:
+ static const int LabelHitPadding;
+
+protected:
+ Trace(SigSession &session, QString name);
+
+public:
+ /**
+ * Gets the name of this signal.
+ */
+ QString get_name() const;
+
+ /**
+ * Sets the name of the signal.
+ */
+ virtual void set_name(QString name);
+
+ /**
+ * Get the colour of the signal.
+ */
+ QColor get_colour() const;
+
+ /**
+ * Set the colour of the signal.
+ */
+ void set_colour(QColor colour);
+
+ /**
+ * Gets the vertical layout offset of this signal.
+ */
+ int get_v_offset() const;
+
+ /**
+ * Sets the vertical layout offset of this signal.
+ */
+ void set_v_offset(int v_offset);
+
+ /**
+ * Returns true if the trace is visible and enabled.
+ */
+ virtual bool enabled() const = 0;
+
+ /**
+ * 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;
+
+ /**
+ * 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);
+
+ /**
+ * 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);
+
+private:
+
+ /**
+ * Computes an caches the size of the label text.
+ */
+ void compute_text_size(QPainter &p);
+
+ /**
+ * 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);
+
+signals:
+ void text_changed();
+
+protected:
+ pv::SigSession &_session;
+
+ QString _name;
+ QColor _colour;
+ int _v_offset;
+
+ QSizeF _text_size;
+};
+
+} // namespace view
+} // namespace pv
+
+#endif // PULSEVIEW_PV_TRACEL_H