]> sigrok.org Git - pulseview.git/blame - pv/view/signal.h
Added _session reference to Signal objects
[pulseview.git] / pv / view / signal.h
CommitLineData
28a4c9c5 1/*
b3f22de0 2 * This file is part of the PulseView project.
28a4c9c5
JH
3 *
4 * Copyright (C) 2012 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
640d091b
UH
21#ifndef PULSEVIEW_PV_SIGNAL_H
22#define PULSEVIEW_PV_SIGNAL_H
23
28a4c9c5 24#include <boost/shared_ptr.hpp>
e3f65ace 25
b3b57abc 26#include <QColor>
9e40e83d 27#include <QComboBox>
3e46726a 28#include <QPainter>
3ef6182a 29#include <QPen>
e3f65ace 30#include <QRect>
28a4c9c5 31#include <QString>
9e40e83d 32#include <QWidgetAction>
e3f65ace 33
28a4c9c5
JH
34#include <stdint.h>
35
cec48d16
JH
36#include <libsigrok/libsigrok.h>
37
e0e90d80
JH
38#include "selectableitem.h"
39
51e77110
JH
40namespace pv {
41
c0f86852
JH
42class SigSession;
43
1b1ec774 44namespace data {
28a4c9c5 45class SignalData;
1b1ec774 46}
28a4c9c5 47
a2f71ef0
JH
48namespace view {
49
e0e90d80 50class Signal : public SelectableItem
28a4c9c5 51{
2a2512b2
JH
52 Q_OBJECT
53
3e46726a 54private:
a29bb7fb 55 static const int LabelHitPadding;
3e46726a 56
3ef6182a
JH
57 static const QPen SignalAxisPen;
58
28a4c9c5 59protected:
c0f86852 60 Signal(pv::SigSession &session, const sr_probe *const probe);
28a4c9c5
JH
61
62public:
49f8ff3f
JH
63 /**
64 * Gets the name of this signal.
65 */
28a4c9c5
JH
66 QString get_name() const;
67
49f8ff3f
JH
68 /**
69 * Sets the name of the signal.
70 */
71 void set_name(QString name);
72
b3b57abc
JH
73 /**
74 * Get the colour of the signal.
75 */
76 QColor get_colour() const;
77
78 /**
79 * Set the colour of the signal.
80 */
81 void set_colour(QColor colour);
82
2e575351
JH
83 /**
84 * Gets the vertical layout offset of this signal.
85 */
86 int get_v_offset() const;
87
88 /**
89 * Sets the vertical layout offset of this signal.
90 */
91 void set_v_offset(int v_offset);
92
3b18c57d 93 /**
64b60583
JH
94 * Paints the signal with a QPainter
95 * @param p the QPainter to paint into.
2658961b
JH
96 * @param y the y-coordinate to draw the signal at
97 * @param left the x-coordinate of the left edge of the signal
98 * @param right the x-coordinate of the right edge of the signal
fb0d32cb 99 * @param scale the scale in seconds per pixel.
3b18c57d 100 * @param offset the time to show at the left hand edge of
fb0d32cb 101 * the view in seconds.
3b18c57d 102 **/
2658961b
JH
103 virtual void paint(QPainter &p, int y, int left, int right,
104 double scale, double offset) = 0;
a29bb7fb
JH
105
106 /**
107 * Paints the signal label into a QGLWidget.
108 * @param p the QPainter to paint into.
2658961b
JH
109 * @param y the y-coordinate of the signal.
110 * @param right the x-coordinate of the right edge of the header
111 * area.
a29bb7fb
JH
112 * @param hover true if the label is being hovered over by the mouse.
113 */
2658961b 114 virtual void paint_label(QPainter &p, int y, int right,
a29bb7fb
JH
115 bool hover);
116
117 /**
118 * Determines if a point is in the header label rect.
2658961b
JH
119 * @param y the y-coordinate of the signal.
120 * @param left the x-coordinate of the left edge of the header
121 * area.
122 * @param right the x-coordinate of the right edge of the header
123 * area.
a29bb7fb
JH
124 * @param point the point to test.
125 */
2658961b
JH
126 bool pt_in_label_rect(int y, int left, int right,
127 const QPoint &point);
a29bb7fb 128
3ef6182a
JH
129protected:
130
131 /**
132 * Paints a zero axis across the viewport.
133 * @param p the QPainter to paint into.
134 * @param y the y-offset of the axis.
135 * @param left the x-coordinate of the left edge of the view.
136 * @param right the x-coordinate of the right edge of the view.
137 */
138 void paint_axis(QPainter &p, int y, int left, int right);
139
a29bb7fb 140private:
ed6f0f4f
JH
141
142 /**
143 * Computes an caches the size of the label text.
144 */
145 void compute_text_size(QPainter &p);
146
3b258424
JH
147 /**
148 * Computes the outline rectangle of a label.
149 * @param p the QPainter to lay out text with.
2658961b
JH
150 * @param y the y-coordinate of the signal.
151 * @param right the x-coordinate of the right edge of the header
152 * area.
3b258424
JH
153 * @return Returns the rectangle of the signal label.
154 */
2658961b 155 QRectF get_label_rect(int y, int right);
3e46726a 156
9e40e83d
JH
157private slots:
158 void on_text_changed(const QString &text);
159
160signals:
161 void text_changed();
162
28a4c9c5 163protected:
c0f86852 164 pv::SigSession &_session;
cec48d16
JH
165 const sr_probe *const _probe;
166
28a4c9c5 167 QString _name;
b3b57abc 168 QColor _colour;
2e575351 169 int _v_offset;
b3b57abc 170
ed6f0f4f 171 QSizeF _text_size;
9e40e83d
JH
172
173 QWidgetAction _name_action;
174 QComboBox _name_widget;
175 bool _updating_name_widget;
28a4c9c5 176};
51e77110 177
8d634081 178} // namespace view
51e77110 179} // namespace pv
640d091b
UH
180
181#endif // PULSEVIEW_PV_SIGNAL_H