]> sigrok.org Git - pulseview.git/blob - pv/view/signal.h
Added _session reference to Signal objects
[pulseview.git] / pv / view / signal.h
1 /*
2  * This file is part of the PulseView project.
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
21 #ifndef PULSEVIEW_PV_SIGNAL_H
22 #define PULSEVIEW_PV_SIGNAL_H
23
24 #include <boost/shared_ptr.hpp>
25
26 #include <QColor>
27 #include <QComboBox>
28 #include <QPainter>
29 #include <QPen>
30 #include <QRect>
31 #include <QString>
32 #include <QWidgetAction>
33
34 #include <stdint.h>
35
36 #include <libsigrok/libsigrok.h>
37
38 #include "selectableitem.h"
39
40 namespace pv {
41
42 class SigSession;
43
44 namespace data {
45 class SignalData;
46 }
47
48 namespace view {
49
50 class Signal : public SelectableItem
51 {
52         Q_OBJECT
53
54 private:
55         static const int LabelHitPadding;
56
57         static const QPen SignalAxisPen;
58
59 protected:
60         Signal(pv::SigSession &session, const sr_probe *const probe);
61
62 public:
63         /**
64          * Gets the name of this signal.
65          */
66         QString get_name() const;
67
68         /**
69          * Sets the name of the signal.
70          */
71         void set_name(QString name);
72
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
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
93         /**
94          * Paints the signal with a QPainter
95          * @param p the QPainter to paint into.
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
99          * @param scale the scale in seconds per pixel.
100          * @param offset the time to show at the left hand edge of
101          *   the view in seconds.
102          **/
103         virtual void paint(QPainter &p, int y, int left, int right,
104                 double scale, double offset) = 0;
105
106         /**
107          * Paints the signal label into a QGLWidget.
108          * @param p the QPainter to paint into.
109          * @param y the y-coordinate of the signal.
110          * @param right the x-coordinate of the right edge of the header
111          *      area.
112          * @param hover true if the label is being hovered over by the mouse.
113          */
114         virtual void paint_label(QPainter &p, int y, int right,
115                 bool hover);
116
117         /**
118          * Determines if a point is in the header label rect.
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.
124          * @param point the point to test.
125          */
126         bool pt_in_label_rect(int y, int left, int right,
127                 const QPoint &point);
128
129 protected:
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
140 private:
141
142         /**
143          * Computes an caches the size of the label text.
144          */
145         void compute_text_size(QPainter &p);
146
147         /**
148          * Computes the outline rectangle of a label.
149          * @param p the QPainter to lay out text with.
150          * @param y the y-coordinate of the signal.
151          * @param right the x-coordinate of the right edge of the header
152          *      area.
153          * @return Returns the rectangle of the signal label.
154          */
155         QRectF get_label_rect(int y, int right);
156
157 private slots:
158         void on_text_changed(const QString &text);
159
160 signals:
161         void text_changed();    
162
163 protected:
164         pv::SigSession &_session;
165         const sr_probe *const _probe;
166
167         QString _name;
168         QColor _colour;
169         int _v_offset;
170
171         QSizeF _text_size;
172
173         QWidgetAction _name_action;
174         QComboBox _name_widget;
175         bool _updating_name_widget;
176 };
177
178 } // namespace view
179 } // namespace pv
180
181 #endif // PULSEVIEW_PV_SIGNAL_H