]> sigrok.org Git - pulseview.git/blame - pv/view/trace.h
Don't allow disabled probes to be selected
[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 36namespace pv {
931f20b0
JH
37namespace view {
38
01fd3263
JH
39class View;
40
931f20b0
JH
41class Trace : public SelectableItem
42{
43 Q_OBJECT
44
45private:
fe08b6e8 46 static const QPen AxisPen;
931f20b0
JH
47 static const int LabelHitPadding;
48
49protected:
83c23cc9 50 Trace(QString name);
931f20b0
JH
51
52public:
53 /**
54 * Gets the name of this signal.
55 */
56 QString get_name() const;
57
58 /**
59 * Sets the name of the signal.
60 */
61 virtual void set_name(QString name);
62
63 /**
64 * Get the colour of the signal.
65 */
66 QColor get_colour() const;
67
68 /**
69 * Set the colour of the signal.
70 */
71 void set_colour(QColor colour);
72
73 /**
74 * Gets the vertical layout offset of this signal.
75 */
76 int get_v_offset() const;
77
78 /**
79 * Sets the vertical layout offset of this signal.
80 */
81 void set_v_offset(int v_offset);
82
83 /**
84 * Returns true if the trace is visible and enabled.
85 */
86 virtual bool enabled() const = 0;
87
e0fc5810 88 virtual void set_view(pv::view::View *view);
01fd3263 89
931f20b0 90 /**
fe08b6e8 91 * Paints the background layer of the trace with a QPainter
931f20b0 92 * @param p the QPainter to paint into.
931f20b0
JH
93 * @param left the x-coordinate of the left edge of the signal
94 * @param right the x-coordinate of the right edge of the signal
931f20b0 95 **/
fe08b6e8
JH
96 virtual void paint_back(QPainter &p, int left, int right);
97
98 /**
99 * Paints the mid-layer of the trace with a QPainter
100 * @param p the QPainter to paint into.
101 * @param left the x-coordinate of the left edge of the signal
102 * @param right the x-coordinate of the right edge of the signal
103 **/
104 virtual void paint_mid(QPainter &p, int left, int right);
105
106 /**
107 * Paints the foreground layer of the trace with a QPainter
108 * @param p the QPainter to paint into.
109 * @param left the x-coordinate of the left edge of the signal
110 * @param right the x-coordinate of the right edge of the signal
111 **/
112 virtual void paint_fore(QPainter &p, int left, int right);
931f20b0
JH
113
114 /**
115 * Paints the signal label into a QGLWidget.
116 * @param p the QPainter to paint into.
931f20b0
JH
117 * @param right the x-coordinate of the right edge of the header
118 * area.
119 * @param hover true if the label is being hovered over by the mouse.
120 */
01fd3263 121 virtual void paint_label(QPainter &p, int right, bool hover);
931f20b0
JH
122
123 /**
124 * Determines if a point is in the header label rect.
931f20b0
JH
125 * @param left the x-coordinate of the left edge of the header
126 * area.
127 * @param right the x-coordinate of the right edge of the header
128 * area.
129 * @param point the point to test.
130 */
01fd3263 131 bool pt_in_label_rect(int left, int right, const QPoint &point);
931f20b0 132
9b6378f1
JH
133 virtual QMenu* create_context_menu(QWidget *parent);
134
569d1e41
JH
135 pv::widgets::Popup* create_popup(QWidget *parent);
136
fe08b6e8
JH
137 /**
138 * Gets the y-offset of the axis.
139 */
140 int get_y() const;
141
d7c0ca4a
JH
142 /**
143 * Computes the outline rectangle of a label.
144 * @param p the QPainter to lay out text with.
145 * @param right the x-coordinate of the right edge of the header
146 * area.
147 * @return Returns the rectangle of the signal label.
148 */
149 QRectF get_label_rect(int right);
150
569d1e41 151protected:
d7c0ca4a 152
410f9c81
JH
153 /**
154 * Gets the text colour.
155 * @remarks This colour is computed by comparing the lightness
156 * of the trace colour against a threshold to determine whether
157 * white or black would be more visible.
158 */
159 QColor get_text_colour() const;
160
fe08b6e8
JH
161 /**
162 * Paints a zero axis across the viewport.
163 * @param p the QPainter to paint into.
164 * @param y the y-offset of the axis.
165 * @param left the x-coordinate of the left edge of the view.
166 * @param right the x-coordinate of the right edge of the view.
167 */
168 void paint_axis(QPainter &p, int y, int left, int right);
169
91e8bf08
JH
170 void add_colour_option(QWidget *parent, QFormLayout *form);
171
37fd11b1
JH
172 void create_popup_form();
173
569d1e41
JH
174 virtual void populate_popup_form(QWidget *parent, QFormLayout *form);
175
9b6378f1 176private slots:
68456dab
JH
177 void on_text_changed(const QString &text);
178
91e8bf08
JH
179 void on_colour_changed(const QColor &colour);
180
20eaae39
JH
181 void on_popup_closed();
182
931f20b0 183signals:
aca00b1e 184 void visibility_changed();
931f20b0 185 void text_changed();
91e8bf08 186 void colour_changed();
931f20b0
JH
187
188protected:
01fd3263 189 pv::view::View *_view;
931f20b0
JH
190
191 QString _name;
192 QColor _colour;
193 int _v_offset;
194
37fd11b1 195private:
20eaae39
JH
196 pv::widgets::Popup *_popup;
197 QFormLayout *_popup_form;
931f20b0
JH
198};
199
200} // namespace view
201} // namespace pv
202
6739e8a5 203#endif // PULSEVIEW_PV_VIEW_TRACE_H