]>
Commit | Line | Data |
---|---|---|
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 |
34 | class QFormLayout; |
35 | ||
931f20b0 JH |
36 | namespace pv { |
37 | ||
38 | class SigSession; | |
39 | ||
40 | namespace view { | |
41 | ||
01fd3263 JH |
42 | class View; |
43 | ||
931f20b0 JH |
44 | class Trace : public SelectableItem |
45 | { | |
46 | Q_OBJECT | |
47 | ||
48 | private: | |
fe08b6e8 | 49 | static const QPen AxisPen; |
931f20b0 JH |
50 | static const int LabelHitPadding; |
51 | ||
52 | protected: | |
53 | Trace(SigSession &session, QString name); | |
54 | ||
55 | public: | |
56 | /** | |
57 | * Gets the name of this signal. | |
58 | */ | |
59 | QString get_name() const; | |
60 | ||
61 | /** | |
62 | * Sets the name of the signal. | |
63 | */ | |
64 | virtual void set_name(QString name); | |
65 | ||
66 | /** | |
67 | * Get the colour of the signal. | |
68 | */ | |
69 | QColor get_colour() const; | |
70 | ||
71 | /** | |
72 | * Set the colour of the signal. | |
73 | */ | |
74 | void set_colour(QColor colour); | |
75 | ||
76 | /** | |
77 | * Gets the vertical layout offset of this signal. | |
78 | */ | |
79 | int get_v_offset() const; | |
80 | ||
81 | /** | |
82 | * Sets the vertical layout offset of this signal. | |
83 | */ | |
84 | void set_v_offset(int v_offset); | |
85 | ||
86 | /** | |
87 | * Returns true if the trace is visible and enabled. | |
88 | */ | |
89 | virtual bool enabled() const = 0; | |
90 | ||
e0fc5810 | 91 | virtual void set_view(pv::view::View *view); |
01fd3263 | 92 | |
931f20b0 | 93 | /** |
fe08b6e8 | 94 | * Paints the background layer of the trace with a QPainter |
931f20b0 | 95 | * @param p the QPainter to paint into. |
931f20b0 JH |
96 | * @param left the x-coordinate of the left edge of the signal |
97 | * @param right the x-coordinate of the right edge of the signal | |
931f20b0 | 98 | **/ |
fe08b6e8 JH |
99 | virtual void paint_back(QPainter &p, int left, int right); |
100 | ||
101 | /** | |
102 | * Paints the mid-layer of the trace with a QPainter | |
103 | * @param p the QPainter to paint into. | |
104 | * @param left the x-coordinate of the left edge of the signal | |
105 | * @param right the x-coordinate of the right edge of the signal | |
106 | **/ | |
107 | virtual void paint_mid(QPainter &p, int left, int right); | |
108 | ||
109 | /** | |
110 | * Paints the foreground layer of the trace with a QPainter | |
111 | * @param p the QPainter to paint into. | |
112 | * @param left the x-coordinate of the left edge of the signal | |
113 | * @param right the x-coordinate of the right edge of the signal | |
114 | **/ | |
115 | virtual void paint_fore(QPainter &p, int left, int right); | |
931f20b0 JH |
116 | |
117 | /** | |
118 | * Paints the signal label into a QGLWidget. | |
119 | * @param p the QPainter to paint into. | |
931f20b0 JH |
120 | * @param right the x-coordinate of the right edge of the header |
121 | * area. | |
122 | * @param hover true if the label is being hovered over by the mouse. | |
123 | */ | |
01fd3263 | 124 | virtual void paint_label(QPainter &p, int right, bool hover); |
931f20b0 JH |
125 | |
126 | /** | |
127 | * Determines if a point is in the header label rect. | |
931f20b0 JH |
128 | * @param left the x-coordinate of the left edge of the header |
129 | * area. | |
130 | * @param right the x-coordinate of the right edge of the header | |
131 | * area. | |
132 | * @param point the point to test. | |
133 | */ | |
01fd3263 | 134 | bool pt_in_label_rect(int left, int right, const QPoint &point); |
931f20b0 | 135 | |
9b6378f1 JH |
136 | virtual QMenu* create_context_menu(QWidget *parent); |
137 | ||
569d1e41 JH |
138 | pv::widgets::Popup* create_popup(QWidget *parent); |
139 | ||
fe08b6e8 JH |
140 | /** |
141 | * Gets the y-offset of the axis. | |
142 | */ | |
143 | int get_y() const; | |
144 | ||
d7c0ca4a JH |
145 | /** |
146 | * Computes the outline rectangle of a label. | |
147 | * @param p the QPainter to lay out text with. | |
148 | * @param right the x-coordinate of the right edge of the header | |
149 | * area. | |
150 | * @return Returns the rectangle of the signal label. | |
151 | */ | |
152 | QRectF get_label_rect(int right); | |
153 | ||
569d1e41 | 154 | protected: |
d7c0ca4a | 155 | |
410f9c81 JH |
156 | /** |
157 | * Gets the text colour. | |
158 | * @remarks This colour is computed by comparing the lightness | |
159 | * of the trace colour against a threshold to determine whether | |
160 | * white or black would be more visible. | |
161 | */ | |
162 | QColor get_text_colour() const; | |
163 | ||
fe08b6e8 JH |
164 | /** |
165 | * Paints a zero axis across the viewport. | |
166 | * @param p the QPainter to paint into. | |
167 | * @param y the y-offset of the axis. | |
168 | * @param left the x-coordinate of the left edge of the view. | |
169 | * @param right the x-coordinate of the right edge of the view. | |
170 | */ | |
171 | void paint_axis(QPainter &p, int y, int left, int right); | |
172 | ||
91e8bf08 JH |
173 | void add_colour_option(QWidget *parent, QFormLayout *form); |
174 | ||
37fd11b1 JH |
175 | void create_popup_form(); |
176 | ||
569d1e41 JH |
177 | virtual void populate_popup_form(QWidget *parent, QFormLayout *form); |
178 | ||
9b6378f1 | 179 | private slots: |
68456dab JH |
180 | void on_text_changed(const QString &text); |
181 | ||
91e8bf08 JH |
182 | void on_colour_changed(const QColor &colour); |
183 | ||
20eaae39 JH |
184 | void on_popup_closed(); |
185 | ||
931f20b0 | 186 | signals: |
aca00b1e | 187 | void visibility_changed(); |
931f20b0 | 188 | void text_changed(); |
91e8bf08 | 189 | void colour_changed(); |
931f20b0 JH |
190 | |
191 | protected: | |
192 | pv::SigSession &_session; | |
01fd3263 | 193 | pv::view::View *_view; |
931f20b0 JH |
194 | |
195 | QString _name; | |
196 | QColor _colour; | |
197 | int _v_offset; | |
198 | ||
37fd11b1 | 199 | private: |
20eaae39 JH |
200 | pv::widgets::Popup *_popup; |
201 | QFormLayout *_popup_form; | |
931f20b0 JH |
202 | }; |
203 | ||
204 | } // namespace view | |
205 | } // namespace pv | |
206 | ||
6739e8a5 | 207 | #endif // PULSEVIEW_PV_VIEW_TRACE_H |