2 * This file is part of the PulseView project.
4 * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef PULSEVIEW_PV_VIEW_TRACE_H
22 #define PULSEVIEW_PV_VIEW_TRACE_H
32 #include "selectableitem.h"
44 class Trace : public SelectableItem
49 static const QPen AxisPen;
50 static const int LabelHitPadding;
53 Trace(SigSession &session, QString name);
57 * Gets the name of this signal.
59 QString get_name() const;
62 * Sets the name of the signal.
64 virtual void set_name(QString name);
67 * Get the colour of the signal.
69 QColor get_colour() const;
72 * Set the colour of the signal.
74 void set_colour(QColor colour);
77 * Gets the vertical layout offset of this signal.
79 int get_v_offset() const;
82 * Sets the vertical layout offset of this signal.
84 void set_v_offset(int v_offset);
87 * Returns true if the trace is visible and enabled.
89 virtual bool enabled() const = 0;
91 virtual void set_view(pv::view::View *view);
94 * Paints the background layer of the trace with a QPainter
95 * @param p the QPainter to paint into.
96 * @param left the x-coordinate of the left edge of the signal
97 * @param right the x-coordinate of the right edge of the signal
99 virtual void paint_back(QPainter &p, int left, int right);
102 * Paints the mid-layer of the trace with a QPainter
103 * @param p the QPainter to paint into.
104 * @param left the x-coordinate of the left edge of the signal
105 * @param right the x-coordinate of the right edge of the signal
107 virtual void paint_mid(QPainter &p, int left, int right);
110 * Paints the foreground layer of the trace with a QPainter
111 * @param p the QPainter to paint into.
112 * @param left the x-coordinate of the left edge of the signal
113 * @param right the x-coordinate of the right edge of the signal
115 virtual void paint_fore(QPainter &p, int left, int right);
118 * Paints the signal label into a QGLWidget.
119 * @param p the QPainter to paint into.
120 * @param right the x-coordinate of the right edge of the header
122 * @param hover true if the label is being hovered over by the mouse.
124 virtual void paint_label(QPainter &p, int right, bool hover);
127 * Determines if a point is in the header label rect.
128 * @param left the x-coordinate of the left edge of the header
130 * @param right the x-coordinate of the right edge of the header
132 * @param point the point to test.
134 bool pt_in_label_rect(int left, int right, const QPoint &point);
136 virtual QMenu* create_context_menu(QWidget *parent);
138 pv::widgets::Popup* create_popup(QWidget *parent);
141 * Gets the y-offset of the axis.
147 * Gets the text colour.
148 * @remarks This colour is computed by comparing the lightness
149 * of the trace colour against a threshold to determine whether
150 * white or black would be more visible.
152 QColor get_text_colour() const;
155 * Paints a zero axis across the viewport.
156 * @param p the QPainter to paint into.
157 * @param y the y-offset of the axis.
158 * @param left the x-coordinate of the left edge of the view.
159 * @param right the x-coordinate of the right edge of the view.
161 void paint_axis(QPainter &p, int y, int left, int right);
163 void add_colour_option(QWidget *parent, QFormLayout *form);
165 virtual void populate_popup_form(QWidget *parent, QFormLayout *form);
170 * Computes an caches the size of the label text.
172 void compute_text_size(QPainter &p);
175 * Computes the outline rectangle of a label.
176 * @param p the QPainter to lay out text with.
177 * @param right the x-coordinate of the right edge of the header
179 * @return Returns the rectangle of the signal label.
181 QRectF get_label_rect(int right);
184 void on_text_changed(const QString &text);
186 void on_colour_changed(const QColor &colour);
189 void visibility_changed();
191 void colour_changed();
194 pv::SigSession &_session;
195 pv::view::View *_view;
207 #endif // PULSEVIEW_PV_VIEW_TRACE_H