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_TRACE_H
22 #define PULSEVIEW_PV_TRACE_H
32 #include "selectableitem.h"
46 class Trace : public SelectableItem
51 static const QPen AxisPen;
52 static const int LabelHitPadding;
55 Trace(SigSession &session, QString name);
59 * Gets the name of this signal.
61 QString get_name() const;
64 * Sets the name of the signal.
66 virtual void set_name(QString name);
69 * Get the colour of the signal.
71 QColor get_colour() const;
74 * Set the colour of the signal.
76 void set_colour(QColor colour);
79 * Gets the vertical layout offset of this signal.
81 int get_v_offset() const;
84 * Sets the vertical layout offset of this signal.
86 void set_v_offset(int v_offset);
89 * Returns true if the trace is visible and enabled.
91 virtual bool enabled() const = 0;
93 virtual void set_view(pv::view::View *view);
96 * Paints the background layer of the trace with a QPainter
97 * @param p the QPainter to paint into.
98 * @param left the x-coordinate of the left edge of the signal
99 * @param right the x-coordinate of the right edge of the signal
101 virtual void paint_back(QPainter &p, int left, int right);
104 * Paints the mid-layer of the trace with a QPainter
105 * @param p the QPainter to paint into.
106 * @param left the x-coordinate of the left edge of the signal
107 * @param right the x-coordinate of the right edge of the signal
109 virtual void paint_mid(QPainter &p, int left, int right);
112 * Paints the foreground layer of the trace with a QPainter
113 * @param p the QPainter to paint into.
114 * @param left the x-coordinate of the left edge of the signal
115 * @param right the x-coordinate of the right edge of the signal
117 virtual void paint_fore(QPainter &p, int left, int right);
120 * Paints the signal label into a QGLWidget.
121 * @param p the QPainter to paint into.
122 * @param right the x-coordinate of the right edge of the header
124 * @param hover true if the label is being hovered over by the mouse.
126 virtual void paint_label(QPainter &p, int right, bool hover);
129 * Determines if a point is in the header label rect.
130 * @param left the x-coordinate of the left edge of the header
132 * @param right the x-coordinate of the right edge of the header
134 * @param point the point to test.
136 bool pt_in_label_rect(int left, int right, const QPoint &point);
138 virtual QMenu* create_context_menu(QWidget *parent);
140 pv::widgets::Popup* create_popup(QWidget *parent);
143 * Gets the y-offset of the axis.
149 * Gets the text colour.
150 * @remarks This colour is computed by comparing the lightness
151 * of the trace colour against a threshold to determine whether
152 * white or black would be more visible.
154 QColor get_text_colour() const;
157 * Paints a zero axis across the viewport.
158 * @param p the QPainter to paint into.
159 * @param y the y-offset of the axis.
160 * @param left the x-coordinate of the left edge of the view.
161 * @param right the x-coordinate of the right edge of the view.
163 void paint_axis(QPainter &p, int y, int left, int right);
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_action_set_name_triggered();
186 void on_action_set_colour_triggered();
192 pv::SigSession &_session;
193 pv::view::View *_view;
205 #endif // PULSEVIEW_PV_TRACEL_H