]> sigrok.org Git - pulseview.git/blame - pv/view/trace.h
DecodeTrace: Removed set_view
[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
a77dac4e 88 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 /**
7db87de3 115 * Paints the signal label.
931f20b0 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 122
9b6378f1
JH
123 virtual QMenu* create_context_menu(QWidget *parent);
124
569d1e41
JH
125 pv::widgets::Popup* create_popup(QWidget *parent);
126
fe08b6e8
JH
127 /**
128 * Gets the y-offset of the axis.
129 */
130 int get_y() const;
131
d7c0ca4a
JH
132 /**
133 * Computes the outline rectangle of a label.
d7c0ca4a
JH
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 */
1053d05c 138 QRectF label_rect(int right);
d7c0ca4a 139
33c62f44
JH
140public:
141 virtual void hover_point_changed();
142
569d1e41 143protected:
d7c0ca4a 144
410f9c81
JH
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
fe08b6e8
JH
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
91e8bf08
JH
162 void add_colour_option(QWidget *parent, QFormLayout *form);
163
37fd11b1
JH
164 void create_popup_form();
165
569d1e41
JH
166 virtual void populate_popup_form(QWidget *parent, QFormLayout *form);
167
e9213170 168private Q_SLOTS:
68456dab
JH
169 void on_text_changed(const QString &text);
170
91e8bf08
JH
171 void on_colour_changed(const QColor &colour);
172
20eaae39
JH
173 void on_popup_closed();
174
e9213170 175Q_SIGNALS:
aca00b1e 176 void visibility_changed();
931f20b0 177 void text_changed();
91e8bf08 178 void colour_changed();
931f20b0
JH
179
180protected:
01fd3263 181 pv::view::View *_view;
931f20b0
JH
182
183 QString _name;
184 QColor _colour;
185 int _v_offset;
186
37fd11b1 187private:
20eaae39
JH
188 pv::widgets::Popup *_popup;
189 QFormLayout *_popup_form;
931f20b0
JH
190};
191
192} // namespace view
193} // namespace pv
194
6739e8a5 195#endif // PULSEVIEW_PV_VIEW_TRACE_H