]> sigrok.org Git - pulseview.git/blame_incremental - pv/view/trace.h
DecodeTrace: Removed set_view
[pulseview.git] / pv / view / trace.h
... / ...
CommitLineData
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
21#ifndef PULSEVIEW_PV_VIEW_TRACE_H
22#define PULSEVIEW_PV_VIEW_TRACE_H
23
24#include <QColor>
25#include <QPainter>
26#include <QPen>
27#include <QRect>
28#include <QString>
29
30#include <stdint.h>
31
32#include "selectableitem.h"
33
34class QFormLayout;
35
36namespace pv {
37namespace view {
38
39class View;
40
41class Trace : public SelectableItem
42{
43 Q_OBJECT
44
45private:
46 static const QPen AxisPen;
47 static const int LabelHitPadding;
48
49protected:
50 Trace(QString name);
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
88 void set_view(pv::view::View *view);
89
90 /**
91 * Paints the background layer of the trace with a QPainter
92 * @param p the QPainter to paint into.
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
95 **/
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);
113
114 /**
115 * Paints the signal label.
116 * @param p the QPainter to paint into.
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 */
121 virtual void paint_label(QPainter &p, int right, bool hover);
122
123 virtual QMenu* create_context_menu(QWidget *parent);
124
125 pv::widgets::Popup* create_popup(QWidget *parent);
126
127 /**
128 * Gets the y-offset of the axis.
129 */
130 int get_y() const;
131
132 /**
133 * Computes the outline rectangle of a label.
134 * @param right the x-coordinate of the right edge of the header
135 * area.
136 * @return Returns the rectangle of the signal label.
137 */
138 QRectF label_rect(int right);
139
140public:
141 virtual void hover_point_changed();
142
143protected:
144
145 /**
146 * Gets the text colour.
147 * @remarks This colour is computed by comparing the lightness
148 * of the trace colour against a threshold to determine whether
149 * white or black would be more visible.
150 */
151 QColor get_text_colour() const;
152
153 /**
154 * Paints a zero axis across the viewport.
155 * @param p the QPainter to paint into.
156 * @param y the y-offset of the axis.
157 * @param left the x-coordinate of the left edge of the view.
158 * @param right the x-coordinate of the right edge of the view.
159 */
160 void paint_axis(QPainter &p, int y, int left, int right);
161
162 void add_colour_option(QWidget *parent, QFormLayout *form);
163
164 void create_popup_form();
165
166 virtual void populate_popup_form(QWidget *parent, QFormLayout *form);
167
168private Q_SLOTS:
169 void on_text_changed(const QString &text);
170
171 void on_colour_changed(const QColor &colour);
172
173 void on_popup_closed();
174
175Q_SIGNALS:
176 void visibility_changed();
177 void text_changed();
178 void colour_changed();
179
180protected:
181 pv::view::View *_view;
182
183 QString _name;
184 QColor _colour;
185 int _v_offset;
186
187private:
188 pv::widgets::Popup *_popup;
189 QFormLayout *_popup_form;
190};
191
192} // namespace view
193} // namespace pv
194
195#endif // PULSEVIEW_PV_VIEW_TRACE_H