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;
64 class DecoderGroupBox;
70 class DecodeTrace : public Trace
75 struct ChannelSelector
77 const QComboBox *combo_;
78 const QComboBox *combo_initial_pin_;
79 const shared_ptr<pv::data::decode::Decoder> decoder_;
80 const srd_channel *pdch_;
84 static const QColor DecodeColours[4];
85 static const QColor ErrorBgColour;
86 static const QColor NoDecodeColour;
88 static const int ArrowSize;
89 static const double EndCapWidth;
90 static const int RowTitleMargin;
91 static const int DrawPadding;
93 static const QColor Colours[16];
94 static const QColor OutlineColours[16];
97 DecodeTrace(pv::Session &session, shared_ptr<data::SignalBase> signalbase,
100 bool enabled() const;
102 const shared_ptr<pv::data::DecoderStack>& decoder() const;
104 shared_ptr<data::SignalBase> base() const;
107 * Computes the vertical extents of the contents of this row item.
108 * @return A pair containing the minimum and maximum y-values.
110 pair<int, int> v_extents() const;
113 * Paints the background layer of the trace with a QPainter
114 * @param p the QPainter to paint into.
115 * @param pp the painting parameters object to paint with..
117 void paint_back(QPainter &p, ViewItemPaintParams &pp);
120 * Paints the mid-layer of the trace with a QPainter
121 * @param p the QPainter to paint into.
122 * @param pp the painting parameters object to paint with.
124 void paint_mid(QPainter &p, ViewItemPaintParams &pp);
127 * Paints the foreground layer of the trace with a QPainter
128 * @param p the QPainter to paint into.
129 * @param pp the painting parameters object to paint with.
131 void paint_fore(QPainter &p, ViewItemPaintParams &pp);
133 void populate_popup_form(QWidget *parent, QFormLayout *form);
135 QMenu* create_context_menu(QWidget *parent);
137 void delete_pressed();
140 void draw_annotations(vector<pv::data::decode::Annotation> annotations,
141 QPainter &p, int h, const ViewItemPaintParams &pp, int y,
142 size_t base_colour, int row_title_width);
144 void draw_annotation(const pv::data::decode::Annotation &a, QPainter &p,
145 int h, const ViewItemPaintParams &pp, int y,
146 size_t base_colour, int row_title_width) const;
148 void draw_annotation_block(vector<pv::data::decode::Annotation> annotations,
149 QPainter &p, int h, int y, size_t base_colour) const;
151 void draw_instant(const pv::data::decode::Annotation &a, QPainter &p,
152 int h, double x, int y) const;
154 void draw_range(const pv::data::decode::Annotation &a, QPainter &p,
155 int h, double start, double end, int y, const ViewItemPaintParams &pp,
156 int row_title_width) const;
158 void draw_error(QPainter &p, const QString &message,
159 const ViewItemPaintParams &pp);
161 void draw_unresolved_period(QPainter &p, int h, int left,
164 pair<double, double> get_pixels_offset_samples_per_pixel() const;
167 * Determines the start and end sample for a given pixel range.
168 * @param x_start the X coordinate of the start sample in the view
169 * @param x_end the X coordinate of the end sample in the view
170 * @return Returns a pair containing the start sample and the end
171 * sample that correspond to the start and end coordinates.
173 pair<uint64_t, uint64_t> get_sample_range(int x_start, int x_end) const;
175 int get_row_at_point(const QPoint &point);
177 const QString get_annotation_at_point(const QPoint &point);
179 void create_decoder_form(int index,
180 shared_ptr<pv::data::decode::Decoder> &dec,
181 QWidget *parent, QFormLayout *form);
183 QComboBox* create_channel_selector(QWidget *parent,
184 const shared_ptr<pv::data::decode::Decoder> &dec,
185 const srd_channel *const pdch);
187 QComboBox* create_channel_selector_initial_pin(QWidget *parent,
188 const shared_ptr<pv::data::decode::Decoder> &dec,
189 const srd_channel *const pdch);
191 void commit_decoder_channels(shared_ptr<data::decode::Decoder> &dec);
193 void commit_channels();
196 void hover_point_changed();
199 void on_new_annotations();
203 void on_channel_selected(int);
205 void on_initial_pin_selected(int);
207 void on_stack_decoder(srd_decoder *decoder);
209 void on_delete_decoder(int index);
211 void on_show_hide_decoder(int index);
214 pv::Session &session_;
215 shared_ptr<data::DecodeSignal> decode_signal_;
217 vector<data::decode::Row> visible_rows_;
218 uint64_t decode_start_, decode_end_;
220 list< shared_ptr<pv::binding::Decoder> > bindings_;
222 list<ChannelSelector> channel_selectors_;
223 vector<pv::widgets::DecoderGroupBox*> decoder_forms_;
225 map<data::decode::Row, int> row_title_widths_;
226 int row_height_, max_visible_rows_;
228 int min_useful_label_width_;
230 QSignalMapper delete_mapper_, show_hide_mapper_;
237 #endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP