]> sigrok.org Git - pulseview.git/blame - pv/view/trace.h
Added Signal::populate_popup_form
[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
21#ifndef PULSEVIEW_PV_TRACE_H
22#define PULSEVIEW_PV_TRACE_H
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
34namespace pv {
35
36class SigSession;
37
569d1e41
JH
38namespace widgets {
39class Popup;
40}
41
931f20b0
JH
42namespace view {
43
01fd3263
JH
44class View;
45
931f20b0
JH
46class Trace : public SelectableItem
47{
48 Q_OBJECT
49
50private:
fe08b6e8 51 static const QPen AxisPen;
931f20b0
JH
52 static const int LabelHitPadding;
53
54protected:
55 Trace(SigSession &session, QString name);
56
57public:
58 /**
59 * Gets the name of this signal.
60 */
61 QString get_name() const;
62
63 /**
64 * Sets the name of the signal.
65 */
66 virtual void set_name(QString name);
67
68 /**
69 * Get the colour of the signal.
70 */
71 QColor get_colour() const;
72
73 /**
74 * Set the colour of the signal.
75 */
76 void set_colour(QColor colour);
77
78 /**
79 * Gets the vertical layout offset of this signal.
80 */
81 int get_v_offset() const;
82
83 /**
84 * Sets the vertical layout offset of this signal.
85 */
86 void set_v_offset(int v_offset);
87
88 /**
89 * Returns true if the trace is visible and enabled.
90 */
91 virtual bool enabled() const = 0;
92
e0fc5810 93 virtual void set_view(pv::view::View *view);
01fd3263 94
931f20b0 95 /**
fe08b6e8 96 * Paints the background layer of the trace with a QPainter
931f20b0 97 * @param p the QPainter to paint into.
931f20b0
JH
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
931f20b0 100 **/
fe08b6e8
JH
101 virtual void paint_back(QPainter &p, int left, int right);
102
103 /**
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
108 **/
109 virtual void paint_mid(QPainter &p, int left, int right);
110
111 /**
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
116 **/
117 virtual void paint_fore(QPainter &p, int left, int right);
931f20b0
JH
118
119 /**
120 * Paints the signal label into a QGLWidget.
121 * @param p the QPainter to paint into.
931f20b0
JH
122 * @param right the x-coordinate of the right edge of the header
123 * area.
124 * @param hover true if the label is being hovered over by the mouse.
125 */
01fd3263 126 virtual void paint_label(QPainter &p, int right, bool hover);
931f20b0
JH
127
128 /**
129 * Determines if a point is in the header label rect.
931f20b0
JH
130 * @param left the x-coordinate of the left edge of the header
131 * area.
132 * @param right the x-coordinate of the right edge of the header
133 * area.
134 * @param point the point to test.
135 */
01fd3263 136 bool pt_in_label_rect(int left, int right, const QPoint &point);
931f20b0 137
9b6378f1
JH
138 virtual QMenu* create_context_menu(QWidget *parent);
139
569d1e41
JH
140 pv::widgets::Popup* create_popup(QWidget *parent);
141
fe08b6e8
JH
142 /**
143 * Gets the y-offset of the axis.
144 */
145 int get_y() const;
146
569d1e41 147protected:
410f9c81
JH
148 /**
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.
153 */
154 QColor get_text_colour() const;
155
fe08b6e8
JH
156 /**
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.
162 */
163 void paint_axis(QPainter &p, int y, int left, int right);
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
JH
183private slots:
184 void on_action_set_name_triggered();
185
186 void on_action_set_colour_triggered();
187
931f20b0
JH
188signals:
189 void text_changed();
190
191protected:
192 pv::SigSession &_session;
01fd3263 193 pv::view::View *_view;
931f20b0
JH
194
195 QString _name;
196 QColor _colour;
197 int _v_offset;
198
199 QSizeF _text_size;
200};
201
202} // namespace view
203} // namespace pv
204
205#endif // PULSEVIEW_PV_TRACEL_H