2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP
21 #define PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP
30 #include <QSignalMapper>
32 #include <pv/binding/decoder.hpp>
33 #include <pv/data/decode/row.hpp>
34 #include <pv/data/signalbase.hpp>
39 using std::shared_ptr;
63 class DecoderGroupBox;
69 class DecodeTrace : public Trace
74 struct ChannelSelector
76 const QComboBox *combo_;
77 const QComboBox *combo_initial_pin_;
78 const shared_ptr<pv::data::decode::Decoder> decoder_;
79 const srd_channel *pdch_;
83 static const QColor DecodeColours[4];
84 static const QColor ErrorBgColour;
85 static const QColor NoDecodeColour;
87 static const int ArrowSize;
88 static const double EndCapWidth;
89 static const int RowTitleMargin;
90 static const int DrawPadding;
92 static const QColor Colours[16];
93 static const QColor OutlineColours[16];
96 DecodeTrace(pv::Session &session, shared_ptr<data::SignalBase> signalbase,
101 const shared_ptr<pv::data::DecoderStack>& decoder() const;
103 shared_ptr<data::SignalBase> base() const;
106 * Computes the vertical extents of the contents of this row item.
107 * @return A pair containing the minimum and maximum y-values.
109 pair<int, int> v_extents() const;
112 * Paints the background layer of the trace with a QPainter
113 * @param p the QPainter to paint into.
114 * @param pp the painting parameters object to paint with..
116 void paint_back(QPainter &p, ViewItemPaintParams &pp);
119 * Paints the mid-layer of the trace with a QPainter
120 * @param p the QPainter to paint into.
121 * @param pp the painting parameters object to paint with.
123 void paint_mid(QPainter &p, ViewItemPaintParams &pp);
126 * Paints the foreground layer of the trace with a QPainter
127 * @param p the QPainter to paint into.
128 * @param pp the painting parameters object to paint with.
130 void paint_fore(QPainter &p, ViewItemPaintParams &pp);
132 void populate_popup_form(QWidget *parent, QFormLayout *form);
134 QMenu* create_context_menu(QWidget *parent);
136 void delete_pressed();
139 void draw_annotations(vector<pv::data::decode::Annotation> annotations,
140 QPainter &p, int h, const ViewItemPaintParams &pp, int y,
141 size_t base_colour, int row_title_width);
143 void draw_annotation(const pv::data::decode::Annotation &a, QPainter &p,
144 int h, const ViewItemPaintParams &pp, int y,
145 size_t base_colour, int row_title_width) const;
147 void draw_annotation_block(vector<pv::data::decode::Annotation> annotations,
148 QPainter &p, int h, int y, size_t base_colour) const;
150 void draw_instant(const pv::data::decode::Annotation &a, QPainter &p,
151 int h, double x, int y) const;
153 void draw_range(const pv::data::decode::Annotation &a, QPainter &p,
154 int h, double start, double end, int y, const ViewItemPaintParams &pp,
155 int row_title_width) const;
157 void draw_error(QPainter &p, const QString &message,
158 const ViewItemPaintParams &pp);
160 void draw_unresolved_period(QPainter &p, int h, int left,
163 pair<double, double> get_pixels_offset_samples_per_pixel() const;
166 * Determines the start and end sample for a given pixel range.
167 * @param x_start the X coordinate of the start sample in the view
168 * @param x_end the X coordinate of the end sample in the view
169 * @return Returns a pair containing the start sample and the end
170 * sample that correspond to the start and end coordinates.
172 pair<uint64_t, uint64_t> get_sample_range(int x_start, int x_end) const;
174 int get_row_at_point(const QPoint &point);
176 const QString get_annotation_at_point(const QPoint &point);
178 void create_decoder_form(int index,
179 shared_ptr<pv::data::decode::Decoder> &dec,
180 QWidget *parent, QFormLayout *form);
182 QComboBox* create_channel_selector(QWidget *parent,
183 const shared_ptr<pv::data::decode::Decoder> &dec,
184 const srd_channel *const pdch);
186 QComboBox* create_channel_selector_initial_pin(QWidget *parent,
187 const shared_ptr<pv::data::decode::Decoder> &dec,
188 const srd_channel *const pdch);
190 void commit_decoder_channels(shared_ptr<data::decode::Decoder> &dec);
192 void commit_channels();
195 void hover_point_changed();
198 void on_new_decode_data();
202 void on_channel_selected(int);
204 void on_initial_pin_selected(int);
206 void on_stack_decoder(srd_decoder *decoder);
208 void on_delete_decoder(int index);
210 void on_show_hide_decoder(int index);
213 pv::Session &session_;
215 vector<data::decode::Row> visible_rows_;
216 uint64_t decode_start_, decode_end_;
218 list< shared_ptr<pv::binding::Decoder> > bindings_;
220 list<ChannelSelector> channel_selectors_;
221 vector<pv::widgets::DecoderGroupBox*> decoder_forms_;
223 map<data::decode::Row, int> row_title_widths_;
224 int row_height_, max_visible_rows_;
226 int min_useful_label_width_;
228 QSignalMapper delete_mapper_, show_hide_mapper_;
231 } // namespace TraceView
235 #endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP