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