]> sigrok.org Git - pulseview.git/blame - pv/view/trace.h
Renamed pv::data::Decoder to DecoderStack
[pulseview.git] / pv / view / trace.h
CommitLineData
931f20b0
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
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.
10 *
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.
15 *
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
19 */
20
6739e8a5
JH
21#ifndef PULSEVIEW_PV_VIEW_TRACE_H
22#define PULSEVIEW_PV_VIEW_TRACE_H
931f20b0
JH
23
24#include <QColor>
25#include <QPainter>
fe08b6e8 26#include <QPen>
931f20b0
JH
27#include <QRect>
28#include <QString>
29
30#include <stdint.h>
31
32#include "selectableitem.h"
33
b213ef09
JH
34class QFormLayout;
35
931f20b0
JH
36namespace pv {
37
38class SigSession;
39
40namespace view {
41
01fd3263
JH
42class View;
43
931f20b0
JH
44class Trace : public SelectableItem
45{
46 Q_OBJECT
47
48private:
fe08b6e8 49 static const QPen AxisPen;
931f20b0
JH
50 static const int LabelHitPadding;
51
52protected:
53 Trace(SigSession &session, QString name);
54
55public:
56 /**
57 * Gets the name of this signal.
58 */
59 QString get_name() const;
60
61 /**
62 * Sets the name of the signal.
63 */
64 virtual void set_name(QString name);
65
66 /**
67 * Get the colour of the signal.
68 */
69 QColor get_colour() const;
70
71 /**
72 * Set the colour of the signal.
73 */
74 void set_colour(QColor colour);
75
76 /**
77 * Gets the vertical layout offset of this signal.
78 */
79 int get_v_offset() const;
80
81 /**
82 * Sets the vertical layout offset of this signal.
83 */
84 void set_v_offset(int v_offset);
85
86 /**
87 * Returns true if the trace is visible and enabled.
88 */
89 virtual bool enabled() const = 0;
90
e0fc5810 91 virtual void set_view(pv::view::View *view);
01fd3263 92
931f20b0 93 /**
fe08b6e8 94 * Paints the background layer of the trace with a QPainter
931f20b0 95 * @param p the QPainter to paint into.
931f20b0
JH
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
931f20b0 98 **/
fe08b6e8
JH
99 virtual void paint_back(QPainter &p, int left, int right);
100
101 /**
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
106 **/
107 virtual void paint_mid(QPainter &p, int left, int right);
108
109 /**
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
114 **/
115 virtual void paint_fore(QPainter &p, int left, int right);
931f20b0
JH
116
117 /**
118 * Paints the signal label into a QGLWidget.
119 * @param p the QPainter to paint into.
931f20b0
JH
120 * @param right the x-coordinate of the right edge of the header
121 * area.
122 * @param hover true if the label is being hovered over by the mouse.
123 */
01fd3263 124 virtual void paint_label(QPainter &p, int right, bool hover);
931f20b0
JH
125
126 /**
127 * Determines if a point is in the header label rect.
931f20b0
JH
128 * @param left the x-coordinate of the left edge of the header
129 * area.
130 * @param right the x-coordinate of the right edge of the header
131 * area.
132 * @param point the point to test.
133 */
01fd3263 134 bool pt_in_label_rect(int left, int right, const QPoint &point);
931f20b0 135
9b6378f1
JH
136 virtual QMenu* create_context_menu(QWidget *parent);
137
569d1e41
JH
138 pv::widgets::Popup* create_popup(QWidget *parent);
139
fe08b6e8
JH
140 /**
141 * Gets the y-offset of the axis.
142 */
143 int get_y() const;
144
569d1e41 145protected:
410f9c81
JH
146 /**
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.
151 */
152 QColor get_text_colour() const;
153
fe08b6e8
JH
154 /**
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.
160 */
161 void paint_axis(QPainter &p, int y, int left, int right);
162
91e8bf08
JH
163 void add_colour_option(QWidget *parent, QFormLayout *form);
164
569d1e41
JH
165 virtual void populate_popup_form(QWidget *parent, QFormLayout *form);
166
931f20b0
JH
167private:
168
169 /**
170 * Computes an caches the size of the label text.
171 */
172 void compute_text_size(QPainter &p);
173
174 /**
175 * Computes the outline rectangle of a label.
176 * @param p the QPainter to lay out text with.
931f20b0
JH
177 * @param right the x-coordinate of the right edge of the header
178 * area.
179 * @return Returns the rectangle of the signal label.
180 */
01fd3263 181 QRectF get_label_rect(int right);
931f20b0 182
9b6378f1 183private slots:
68456dab
JH
184 void on_text_changed(const QString &text);
185
91e8bf08
JH
186 void on_colour_changed(const QColor &colour);
187
931f20b0 188signals:
aca00b1e 189 void visibility_changed();
931f20b0 190 void text_changed();
91e8bf08 191 void colour_changed();
931f20b0
JH
192
193protected:
194 pv::SigSession &_session;
01fd3263 195 pv::view::View *_view;
931f20b0
JH
196
197 QString _name;
198 QColor _colour;
199 int _v_offset;
200
201 QSizeF _text_size;
202};
203
204} // namespace view
205} // namespace pv
206
6739e8a5 207#endif // PULSEVIEW_PV_VIEW_TRACE_H