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