]> sigrok.org Git - pulseview.git/blame - pv/views/trace/decodetrace.hpp
DecodeTrace: Add widget container
[pulseview.git] / pv / views / trace / decodetrace.hpp
CommitLineData
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
9ba13f5e 30#include <QColor>
9f97b357 31#include <QComboBox>
74bf6666 32#include <QPolygon>
cf0a3c9c 33#include <QPushButton>
613d097c 34#include <QSignalMapper>
5b6ae103 35#include <QTimer>
613d097c 36
3cc9ad7b 37#include <pv/binding/decoder.hpp>
a82325d1 38#include <pv/data/decode/decoder.hpp>
20d90d22 39#include <pv/data/decode/annotation.hpp>
2acdb232 40#include <pv/data/decode/row.hpp>
aca9aa83 41#include <pv/data/signalbase.hpp>
4e5a4405 42
84002113 43using std::deque;
6f925ba9
UH
44using std::list;
45using std::map;
84002113 46using std::mutex;
6f925ba9
UH
47using std::pair;
48using std::shared_ptr;
49using std::vector;
50
8bd26d8b 51struct srd_channel;
e563a7c0 52struct srd_decoder;
4e5a4405 53
55d3603d 54namespace pv {
119aff65 55
2b81ae46 56class Session;
83c23cc9 57
119aff65 58namespace data {
9f97b357 59struct DecodeChannel;
ad908057 60class DecodeSignal;
7491a29f
JH
61
62namespace decode {
63class Decoder;
64}
20f59e95 65} // namespace data
119aff65 66
dd048a7e
JH
67namespace widgets {
68class DecoderGroupBox;
69}
70
f4e57597 71namespace views {
1573bf16 72namespace trace {
55d3603d 73
84002113
SA
74struct RowData {
75 // When adding a field, make sure it's initialized properly in
76 // DecodeTrace::update_rows()
77
78 data::decode::Row decode_row;
74bf6666
SA
79 unsigned int height, expanded_height, title_width, animation_step;
80 bool exists, currently_visible;
81 bool expand_marker_highlighted, expanding, expanded, collapsing;
82 QPolygon expand_marker_shape;
83 float anim_height, anim_shape;
dca3cbee
SA
84
85 QWidget* container;
84002113
SA
86};
87
b9329558 88class DecodeTrace : public Trace
55d3603d 89{
e0fc5810
JH
90 Q_OBJECT
91
06bb4e6a 92private:
641574bc
SA
93 static const QColor ErrorBgColor;
94 static const QColor NoDecodeColor;
06bb4e6a 95
88908838 96 static const int ArrowSize;
06e810f2 97 static const double EndCapWidth;
aee9dcf3 98 static const int RowTitleMargin;
06e810f2
JH
99 static const int DrawPadding;
100
5b6ae103 101 static const int MaxTraceUpdateRate;
74bf6666 102 static const unsigned int AnimationDurationInTicks;
5b6ae103 103
55d3603d 104public:
6f925ba9 105 DecodeTrace(pv::Session &session, shared_ptr<data::SignalBase> signalbase,
6e89374a 106 int index);
55d3603d 107
ab185f78
SA
108 ~DecodeTrace();
109
55d3603d
JH
110 bool enabled() const;
111
6f925ba9 112 shared_ptr<data::SignalBase> base() const;
bb7dd726 113
a5d93c27
JH
114 /**
115 * Computes the vertical extents of the contents of this row item.
116 * @return A pair containing the minimum and maximum y-values.
117 */
6f925ba9 118 pair<int, int> v_extents() const;
a5d93c27 119
55d3603d 120 /**
fe08b6e8
JH
121 * Paints the background layer of the trace with a QPainter
122 * @param p the QPainter to paint into.
3eb29afd 123 * @param pp the painting parameters object to paint with..
223d0c37 124 */
60938e04 125 void paint_back(QPainter &p, ViewItemPaintParams &pp);
fe08b6e8
JH
126
127 /**
128 * Paints the mid-layer of the trace with a QPainter
55d3603d 129 * @param p the QPainter to paint into.
3eb29afd 130 * @param pp the painting parameters object to paint with.
223d0c37 131 */
60938e04 132 void paint_mid(QPainter &p, ViewItemPaintParams &pp);
55d3603d 133
88908838
JH
134 /**
135 * Paints the foreground layer of the trace with a QPainter
136 * @param p the QPainter to paint into.
3eb29afd 137 * @param pp the painting parameters object to paint with.
223d0c37 138 */
60938e04 139 void paint_fore(QPainter &p, ViewItemPaintParams &pp);
88908838 140
4e5a4405
JH
141 void populate_popup_form(QWidget *parent, QFormLayout *form);
142
9e773fec 143 QMenu* create_header_context_menu(QWidget *parent);
c51482b3 144
be843692
SA
145 virtual QMenu* create_view_context_menu(QWidget *parent, QPoint &click_pos);
146
74bf6666
SA
147 virtual void delete_pressed();
148
149 virtual void hover_point_changed(const QPoint &hp);
150
151 virtual void mouse_left_press_event(const QMouseEvent* event);
5ed1adf5 152
ad50ac1a 153private:
6f925ba9 154 void draw_annotations(vector<pv::data::decode::Annotation> annotations,
50631798 155 QPainter &p, int h, const ViewItemPaintParams &pp, int y,
9ba13f5e 156 QColor row_color, int row_title_width);
50631798 157
06e810f2 158 void draw_annotation(const pv::data::decode::Annotation &a, QPainter &p,
520362f8 159 int h, const ViewItemPaintParams &pp, int y,
9ba13f5e 160 QColor row_color, int row_title_width) const;
06e810f2 161
5c48ce32 162 void draw_annotation_block(qreal start, qreal end,
20d90d22 163 pv::data::decode::Annotation::Class ann_class, bool use_ann_format,
9ba13f5e 164 QPainter &p, int h, int y, QColor row_color) const;
50631798 165
06e810f2 166 void draw_instant(const pv::data::decode::Annotation &a, QPainter &p,
5c48ce32 167 int h, qreal x, int y) const;
06e810f2
JH
168
169 void draw_range(const pv::data::decode::Annotation &a, QPainter &p,
5c48ce32 170 int h, qreal start, qreal end, int y, const ViewItemPaintParams &pp,
aee9dcf3 171 int row_title_width) const;
06e810f2 172
ad50ac1a 173 void draw_error(QPainter &p, const QString &message,
5b5fa4da 174 const ViewItemPaintParams &pp);
ad50ac1a 175
5dfeb70f 176 void draw_unresolved_period(QPainter &p, int h, int left,
7f8517f6
SA
177 int right) const;
178
6f925ba9 179 pair<double, double> get_pixels_offset_samples_per_pixel() const;
7f8517f6
SA
180
181 /**
182 * Determines the start and end sample for a given pixel range.
183 * @param x_start the X coordinate of the start sample in the view
184 * @param x_end the X coordinate of the end sample in the view
185 * @return Returns a pair containing the start sample and the end
186 * sample that correspond to the start and end coordinates.
187 */
67fb15bf 188 pair<uint64_t, uint64_t> get_view_sample_range(int x_start, int x_end) const;
5dfeb70f 189
9ba13f5e
SA
190 QColor get_row_color(int row_index) const;
191 QColor get_annotation_color(QColor row_color, int annotation_index) const;
192
84002113
SA
193 unsigned int get_row_y(const RowData* row) const;
194
195 RowData* get_row_at_point(const QPoint &point);
e2f90c50 196
117cdea3 197 const QString get_annotation_at_point(const QPoint &point);
e2f90c50 198
cf0a3c9c
SA
199 void update_stack_button();
200
613d097c 201 void create_decoder_form(int index,
6f925ba9 202 shared_ptr<pv::data::decode::Decoder> &dec,
7491a29f
JH
203 QWidget *parent, QFormLayout *form);
204
6ac6242b 205 QComboBox* create_channel_selector(QWidget *parent,
a82325d1 206 const data::decode::DecodeChannel *ch);
9f97b357 207 QComboBox* create_channel_selector_init_state(QWidget *parent,
a82325d1 208 const data::decode::DecodeChannel *ch);
4e5a4405 209
5a914348
SA
210 void export_annotations(vector<data::decode::Annotation> *annotations) const;
211
84002113
SA
212 void update_rows();
213
e9213170 214private Q_SLOTS:
ab185f78
SA
215 void on_setting_changed(const QString &key, const QVariant &value);
216
ad908057 217 void on_new_annotations();
5b6ae103 218 void on_delayed_trace_update();
eee3eab9 219 void on_decode_reset();
1b56c646 220 void on_decode_finished();
556259d2 221 void on_pause_decode();
9cef9567 222
c51482b3
JH
223 void on_delete();
224
6ac6242b 225 void on_channel_selected(int);
4e5a4405 226
9f97b357
SA
227 void on_channels_updated();
228
229 void on_init_state_changed(int);
407c9ebe 230
7491a29f
JH
231 void on_stack_decoder(srd_decoder *decoder);
232
613d097c
JH
233 void on_delete_decoder(int index);
234
dd048a7e
JH
235 void on_show_hide_decoder(int index);
236
c764c995
SA
237 void on_copy_annotation_to_clipboard();
238
be843692 239 void on_export_row();
5a914348 240 void on_export_all_rows();
99ba5f28
SA
241 void on_export_row_with_cursor();
242 void on_export_all_rows_with_cursor();
be843692 243 void on_export_row_from_here();
5a914348 244 void on_export_all_rows_from_here();
be843692 245
74bf6666
SA
246 void on_animation_timer();
247
55d3603d 248private:
2b81ae46 249 pv::Session &session_;
ad908057 250 shared_ptr<data::DecodeSignal> decode_signal_;
e0fc5810 251
84002113
SA
252 deque<RowData> rows_;
253 mutable mutex row_modification_mutex_;
4e5a4405 254
9f97b357
SA
255 map<QComboBox*, uint16_t> channel_id_map_; // channel selector -> decode channel ID
256 map<QComboBox*, uint16_t> init_state_map_; // init state selector -> decode channel ID
6f925ba9 257 list< shared_ptr<pv::binding::Decoder> > bindings_;
4e5a4405 258
84002113 259 const data::decode::Row* selected_row_;
99ba5f28 260 pair<uint64_t, uint64_t> selected_sample_range_;
be843692 261
6f925ba9 262 vector<pv::widgets::DecoderGroupBox*> decoder_forms_;
cf0a3c9c 263 QPushButton* stack_button_;
613d097c 264
9741d6e0
SA
265 unsigned int default_row_height_, annotation_height_;
266 unsigned int visible_rows_, max_visible_rows_;
88908838 267
752281db 268 int min_useful_label_width_;
84002113 269 bool always_show_all_rows_;
752281db 270
8dbbc7f0 271 QSignalMapper delete_mapper_, show_hide_mapper_;
5b6ae103 272
74bf6666
SA
273 QTimer delayed_trace_updater_, animation_timer_;
274
275 QPolygon default_marker_shape_;
55d3603d
JH
276};
277
1573bf16 278} // namespace trace
f4e57597 279} // namespace views
55d3603d
JH
280} // namespace pv
281
f4e57597 282#endif // PULSEVIEW_PV_VIEWS_TRACEVIEW_DECODETRACE_HPP