]>
Commit | Line | Data |
---|---|---|
55d3603d JH |
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 | |
efdec55a | 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
55d3603d JH |
18 | */ |
19 | ||
f4e57597 SA |
20 | #ifndef PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP |
21 | #define PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP | |
55d3603d | 22 | |
2acdb232 | 23 | #include "trace.hpp" |
55d3603d | 24 | |
7491a29f | 25 | #include <list> |
4e5a4405 | 26 | #include <map> |
f9abf97e | 27 | #include <memory> |
50631798 | 28 | #include <vector> |
4e5a4405 | 29 | |
613d097c JH |
30 | #include <QSignalMapper> |
31 | ||
3cc9ad7b | 32 | #include <pv/binding/decoder.hpp> |
2acdb232 | 33 | #include <pv/data/decode/row.hpp> |
aca9aa83 | 34 | #include <pv/data/signalbase.hpp> |
4e5a4405 | 35 | |
6f925ba9 UH |
36 | using std::list; |
37 | using std::map; | |
38 | using std::pair; | |
39 | using std::shared_ptr; | |
40 | using std::vector; | |
41 | ||
8bd26d8b | 42 | struct srd_channel; |
e563a7c0 | 43 | struct srd_decoder; |
4e5a4405 JH |
44 | |
45 | class QComboBox; | |
46 | ||
55d3603d | 47 | namespace pv { |
119aff65 | 48 | |
2b81ae46 | 49 | class Session; |
83c23cc9 | 50 | |
119aff65 | 51 | namespace data { |
6e89374a | 52 | class DecoderStack; |
bb7dd726 | 53 | class SignalBase; |
7491a29f JH |
54 | |
55 | namespace decode { | |
06e810f2 | 56 | class Annotation; |
7491a29f | 57 | class Decoder; |
287d607f | 58 | class Row; |
7491a29f | 59 | } |
119aff65 JH |
60 | } |
61 | ||
dd048a7e JH |
62 | namespace widgets { |
63 | class DecoderGroupBox; | |
64 | } | |
65 | ||
f4e57597 SA |
66 | namespace views { |
67 | namespace TraceView { | |
55d3603d | 68 | |
b9329558 | 69 | class DecodeTrace : public Trace |
55d3603d | 70 | { |
e0fc5810 JH |
71 | Q_OBJECT |
72 | ||
7491a29f | 73 | private: |
6ac6242b | 74 | struct ChannelSelector |
7491a29f | 75 | { |
8dbbc7f0 | 76 | const QComboBox *combo_; |
6f925ba9 | 77 | const shared_ptr<pv::data::decode::Decoder> decoder_; |
8dbbc7f0 | 78 | const srd_channel *pdch_; |
7491a29f JH |
79 | }; |
80 | ||
06bb4e6a JH |
81 | private: |
82 | static const QColor DecodeColours[4]; | |
ad50ac1a | 83 | static const QColor ErrorBgColour; |
5dfeb70f | 84 | static const QColor NoDecodeColour; |
06bb4e6a | 85 | |
88908838 | 86 | static const int ArrowSize; |
06e810f2 | 87 | static const double EndCapWidth; |
aee9dcf3 | 88 | static const int RowTitleMargin; |
06e810f2 JH |
89 | static const int DrawPadding; |
90 | ||
287d607f JH |
91 | static const QColor Colours[16]; |
92 | static const QColor OutlineColours[16]; | |
06e810f2 | 93 | |
55d3603d | 94 | public: |
6f925ba9 | 95 | DecodeTrace(pv::Session &session, shared_ptr<data::SignalBase> signalbase, |
6e89374a | 96 | int index); |
55d3603d JH |
97 | |
98 | bool enabled() const; | |
99 | ||
6f925ba9 | 100 | const shared_ptr<pv::data::DecoderStack>& decoder() const; |
b6b267bb | 101 | |
6f925ba9 | 102 | shared_ptr<data::SignalBase> base() const; |
bb7dd726 | 103 | |
a5d93c27 JH |
104 | /** |
105 | * Computes the vertical extents of the contents of this row item. | |
106 | * @return A pair containing the minimum and maximum y-values. | |
107 | */ | |
6f925ba9 | 108 | pair<int, int> v_extents() const; |
a5d93c27 | 109 | |
55d3603d | 110 | /** |
fe08b6e8 JH |
111 | * Paints the background layer of the trace with a QPainter |
112 | * @param p the QPainter to paint into. | |
3eb29afd | 113 | * @param pp the painting parameters object to paint with.. |
223d0c37 | 114 | */ |
60938e04 | 115 | void paint_back(QPainter &p, ViewItemPaintParams &pp); |
fe08b6e8 JH |
116 | |
117 | /** | |
118 | * Paints the mid-layer of the trace with a QPainter | |
55d3603d | 119 | * @param p the QPainter to paint into. |
3eb29afd | 120 | * @param pp the painting parameters object to paint with. |
223d0c37 | 121 | */ |
60938e04 | 122 | void paint_mid(QPainter &p, ViewItemPaintParams &pp); |
55d3603d | 123 | |
88908838 JH |
124 | /** |
125 | * Paints the foreground layer of the trace with a QPainter | |
126 | * @param p the QPainter to paint into. | |
3eb29afd | 127 | * @param pp the painting parameters object to paint with. |
223d0c37 | 128 | */ |
60938e04 | 129 | void paint_fore(QPainter &p, ViewItemPaintParams &pp); |
88908838 | 130 | |
4e5a4405 JH |
131 | void populate_popup_form(QWidget *parent, QFormLayout *form); |
132 | ||
c51482b3 JH |
133 | QMenu* create_context_menu(QWidget *parent); |
134 | ||
5ed1adf5 JH |
135 | void delete_pressed(); |
136 | ||
ad50ac1a | 137 | private: |
6f925ba9 | 138 | void draw_annotations(vector<pv::data::decode::Annotation> annotations, |
50631798 | 139 | QPainter &p, int h, const ViewItemPaintParams &pp, int y, |
aee9dcf3 | 140 | size_t base_colour, int row_title_width); |
50631798 | 141 | |
06e810f2 | 142 | void draw_annotation(const pv::data::decode::Annotation &a, QPainter &p, |
520362f8 | 143 | int h, const ViewItemPaintParams &pp, int y, |
aee9dcf3 | 144 | size_t base_colour, int row_title_width) const; |
06e810f2 | 145 | |
6f925ba9 | 146 | void draw_annotation_block(vector<pv::data::decode::Annotation> annotations, |
33707990 | 147 | QPainter &p, int h, int y, size_t base_colour) const; |
50631798 | 148 | |
06e810f2 | 149 | void draw_instant(const pv::data::decode::Annotation &a, QPainter &p, |
f765c3db | 150 | int h, double x, int y) const; |
06e810f2 JH |
151 | |
152 | void draw_range(const pv::data::decode::Annotation &a, QPainter &p, | |
f765c3db | 153 | int h, double start, double end, int y, const ViewItemPaintParams &pp, |
aee9dcf3 | 154 | int row_title_width) const; |
06e810f2 | 155 | |
ad50ac1a | 156 | void draw_error(QPainter &p, const QString &message, |
5b5fa4da | 157 | const ViewItemPaintParams &pp); |
ad50ac1a | 158 | |
5dfeb70f | 159 | void draw_unresolved_period(QPainter &p, int h, int left, |
7f8517f6 SA |
160 | int right) const; |
161 | ||
6f925ba9 | 162 | pair<double, double> get_pixels_offset_samples_per_pixel() const; |
7f8517f6 SA |
163 | |
164 | /** | |
165 | * Determines the start and end sample for a given pixel range. | |
166 | * @param x_start the X coordinate of the start sample in the view | |
167 | * @param x_end the X coordinate of the end sample in the view | |
168 | * @return Returns a pair containing the start sample and the end | |
169 | * sample that correspond to the start and end coordinates. | |
170 | */ | |
6f925ba9 | 171 | pair<uint64_t, uint64_t> get_sample_range(int x_start, int x_end) const; |
5dfeb70f | 172 | |
117cdea3 | 173 | int get_row_at_point(const QPoint &point); |
e2f90c50 | 174 | |
117cdea3 | 175 | const QString get_annotation_at_point(const QPoint &point); |
e2f90c50 | 176 | |
613d097c | 177 | void create_decoder_form(int index, |
6f925ba9 | 178 | shared_ptr<pv::data::decode::Decoder> &dec, |
7491a29f JH |
179 | QWidget *parent, QFormLayout *form); |
180 | ||
6ac6242b | 181 | QComboBox* create_channel_selector(QWidget *parent, |
6f925ba9 | 182 | const shared_ptr<pv::data::decode::Decoder> &dec, |
8bd26d8b | 183 | const srd_channel *const pdch); |
7491a29f | 184 | |
c063290a | 185 | void commit_decoder_channels(shared_ptr<data::decode::Decoder> &dec); |
4e5a4405 | 186 | |
6ac6242b | 187 | void commit_channels(); |
4e5a4405 | 188 | |
33c62f44 JH |
189 | public: |
190 | void hover_point_changed(); | |
191 | ||
e9213170 | 192 | private Q_SLOTS: |
9cef9567 JH |
193 | void on_new_decode_data(); |
194 | ||
c51482b3 JH |
195 | void on_delete(); |
196 | ||
6ac6242b | 197 | void on_channel_selected(int); |
4e5a4405 | 198 | |
7491a29f JH |
199 | void on_stack_decoder(srd_decoder *decoder); |
200 | ||
613d097c JH |
201 | void on_delete_decoder(int index); |
202 | ||
dd048a7e JH |
203 | void on_show_hide_decoder(int index); |
204 | ||
55d3603d | 205 | private: |
2b81ae46 | 206 | pv::Session &session_; |
e0fc5810 | 207 | |
6f925ba9 | 208 | vector<data::decode::Row> visible_rows_; |
8dbbc7f0 | 209 | uint64_t decode_start_, decode_end_; |
4e5a4405 | 210 | |
6f925ba9 | 211 | list< shared_ptr<pv::binding::Decoder> > bindings_; |
4e5a4405 | 212 | |
6f925ba9 UH |
213 | list<ChannelSelector> channel_selectors_; |
214 | vector<pv::widgets::DecoderGroupBox*> decoder_forms_; | |
613d097c | 215 | |
6f925ba9 | 216 | map<data::decode::Row, int> row_title_widths_; |
eee89ff8 | 217 | int row_height_, max_visible_rows_; |
88908838 | 218 | |
752281db SA |
219 | int min_useful_label_width_; |
220 | ||
8dbbc7f0 | 221 | QSignalMapper delete_mapper_, show_hide_mapper_; |
55d3603d JH |
222 | }; |
223 | ||
f4e57597 SA |
224 | } // namespace TraceView |
225 | } // namespace views | |
55d3603d JH |
226 | } // namespace pv |
227 | ||
f4e57597 | 228 | #endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP |