]> sigrok.org Git - pulseview.git/blob - pv/view/trace.h
Make decoder popups close when pressing enter
[pulseview.git] / pv / view / trace.h
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
34 class QFormLayout;
35
36 namespace pv {
37 namespace view {
38
39 class View;
40
41 class Trace : public SelectableItem
42 {
43         Q_OBJECT
44
45 private:
46         static const QPen AxisPen;
47         static const int LabelHitPadding;
48
49 protected:
50         Trace(QString name);
51
52 public:
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         virtual 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 into a QGLWidget.
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         /**
124          * Determines if a point is in the header label rect.
125          * @param left the x-coordinate of the left edge of the header
126          *      area.
127          * @param right the x-coordinate of the right edge of the header
128          *      area.
129          * @param point the point to test.
130          */
131         bool pt_in_label_rect(int left, int right, const QPoint &point);
132
133         virtual QMenu* create_context_menu(QWidget *parent);
134
135         pv::widgets::Popup* create_popup(QWidget *parent);
136
137         /**
138          * Gets the y-offset of the axis.
139          */
140         int get_y() const;
141
142         /**
143          * Computes the outline rectangle of a label.
144          * @param p the QPainter to lay out text with.
145          * @param right the x-coordinate of the right edge of the header
146          *      area.
147          * @return Returns the rectangle of the signal label.
148          */
149         QRectF get_label_rect(int right);
150
151         bool eventFilter(QObject *obj, QEvent *evt);
152
153 protected:
154
155         /**
156          * Gets the text colour.
157          * @remarks This colour is computed by comparing the lightness
158          * of the trace colour against a threshold to determine whether
159          * white or black would be more visible.
160          */
161         QColor get_text_colour() const;
162
163         /**
164          * Paints a zero axis across the viewport.
165          * @param p the QPainter to paint into.
166          * @param y the y-offset of the axis.
167          * @param left the x-coordinate of the left edge of the view.
168          * @param right the x-coordinate of the right edge of the view.
169          */
170         void paint_axis(QPainter &p, int y, int left, int right);
171
172         void add_colour_option(QWidget *parent, QFormLayout *form);
173
174         void create_popup_form();
175
176         virtual void populate_popup_form(QWidget *parent, QFormLayout *form);
177
178         void close_popup();
179
180 private Q_SLOTS:
181         void on_text_changed(const QString &text);
182
183         void on_colour_changed(const QColor &colour);
184
185         void on_popup_closed();
186
187 Q_SIGNALS:
188         void visibility_changed();
189         void text_changed();    
190         void colour_changed();
191
192 protected:
193         pv::view::View *_view;
194
195         QString _name;
196         QColor _colour;
197         int _v_offset;
198
199 private:
200         pv::widgets::Popup *_popup;
201         QFormLayout *_popup_form;
202 };
203
204 } // namespace view
205 } // namespace pv
206
207 #endif // PULSEVIEW_PV_VIEW_TRACE_H