]> sigrok.org Git - pulseview.git/blame - pv/view/decodetrace.h
Improved decode annotation colouring
[pulseview.git] / pv / view / decodetrace.h
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
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
b9329558
JH
21#ifndef PULSEVIEW_PV_VIEW_DECODETRACE_H
22#define PULSEVIEW_PV_VIEW_DECODETRACE_H
55d3603d
JH
23
24#include "trace.h"
25
7491a29f 26#include <list>
4e5a4405
JH
27#include <map>
28
613d097c
JH
29#include <QSignalMapper>
30
55d3603d
JH
31#include <boost/shared_ptr.hpp>
32
4e5a4405
JH
33#include <pv/prop/binding/decoderoptions.h>
34
35struct srd_probe;
e563a7c0 36struct srd_decoder;
4e5a4405
JH
37
38class QComboBox;
39
55d3603d 40namespace pv {
119aff65
JH
41
42namespace data {
6e89374a 43class DecoderStack;
7491a29f
JH
44
45namespace decode {
06e810f2 46class Annotation;
7491a29f 47class Decoder;
287d607f 48class Row;
7491a29f 49}
119aff65
JH
50}
51
dd048a7e
JH
52namespace widgets {
53class DecoderGroupBox;
54}
55
55d3603d
JH
56namespace view {
57
b9329558 58class DecodeTrace : public Trace
55d3603d 59{
e0fc5810
JH
60 Q_OBJECT
61
7491a29f
JH
62private:
63 struct ProbeSelector
64 {
65 const QComboBox *_combo;
66 const boost::shared_ptr<pv::data::decode::Decoder> _decoder;
67 const srd_probe *_probe;
68 };
69
06bb4e6a
JH
70private:
71 static const QColor DecodeColours[4];
ad50ac1a 72 static const QColor ErrorBgColour;
5dfeb70f 73 static const QColor NoDecodeColour;
06bb4e6a 74
06e810f2
JH
75 static const double EndCapWidth;
76 static const int DrawPadding;
77
287d607f
JH
78 static const QColor Colours[16];
79 static const QColor OutlineColours[16];
06e810f2 80
55d3603d 81public:
b9329558 82 DecodeTrace(pv::SigSession &session,
6e89374a
JH
83 boost::shared_ptr<pv::data::DecoderStack> decoder_stack,
84 int index);
55d3603d
JH
85
86 bool enabled() const;
87
6e89374a 88 const boost::shared_ptr<pv::data::DecoderStack>& decoder() const;
b6b267bb 89
e0fc5810
JH
90 void set_view(pv::view::View *view);
91
55d3603d 92 /**
fe08b6e8
JH
93 * Paints the background layer of the trace with a QPainter
94 * @param p the QPainter to paint into.
95 * @param left the x-coordinate of the left edge of the signal.
96 * @param right the x-coordinate of the right edge of the signal.
97 **/
98 void paint_back(QPainter &p, int left, int right);
99
100 /**
101 * Paints the mid-layer of the trace with a QPainter
55d3603d 102 * @param p the QPainter to paint into.
55d3603d
JH
103 * @param left the x-coordinate of the left edge of the signal
104 * @param right the x-coordinate of the right edge of the signal
55d3603d 105 **/
fe08b6e8 106 void paint_mid(QPainter &p, int left, int right);
55d3603d 107
4e5a4405
JH
108 void populate_popup_form(QWidget *parent, QFormLayout *form);
109
c51482b3
JH
110 QMenu* create_context_menu(QWidget *parent);
111
5ed1adf5
JH
112 void delete_pressed();
113
ad50ac1a 114private:
06e810f2
JH
115 void draw_annotation(const pv::data::decode::Annotation &a, QPainter &p,
116 QColor text_colour, int text_height, int left, int right,
bf51365c 117 double samples_per_pixel, double pixels_offset, int y,
287d607f 118 size_t base_colour) const;
06e810f2
JH
119
120 void draw_instant(const pv::data::decode::Annotation &a, QPainter &p,
121 QColor fill, QColor outline, QColor text_color, int h, double x,
122 int y) const;
123
124 void draw_range(const pv::data::decode::Annotation &a, QPainter &p,
125 QColor fill, QColor outline, QColor text_color, int h, double start,
126 double end, int y) const;
127
ad50ac1a
JH
128 void draw_error(QPainter &p, const QString &message,
129 int left, int right);
130
5dfeb70f
JH
131 void draw_unresolved_period(QPainter &p, int h, int left,
132 int right, double samples_per_pixel, double pixels_offset);
133
613d097c 134 void create_decoder_form(int index,
7491a29f
JH
135 boost::shared_ptr<pv::data::decode::Decoder> &dec,
136 QWidget *parent, QFormLayout *form);
137
138 QComboBox* create_probe_selector(QWidget *parent,
139 const boost::shared_ptr<pv::data::decode::Decoder> &dec,
140 const srd_probe *const probe);
141
142 void commit_decoder_probes(
143 boost::shared_ptr<data::decode::Decoder> &dec);
4e5a4405
JH
144
145 void commit_probes();
146
9cef9567
JH
147private slots:
148 void on_new_decode_data();
149
c51482b3
JH
150 void on_delete();
151
4e5a4405
JH
152 void on_probe_selected(int);
153
7491a29f
JH
154 void on_stack_decoder(srd_decoder *decoder);
155
613d097c
JH
156 void on_delete_decoder(int index);
157
dd048a7e
JH
158 void on_show_hide_decoder(int index);
159
55d3603d 160private:
6e89374a 161 boost::shared_ptr<pv::data::DecoderStack> _decoder_stack;
e0fc5810
JH
162
163 uint64_t _decode_start, _decode_end;
4e5a4405 164
7491a29f
JH
165 std::list< boost::shared_ptr<pv::prop::binding::DecoderOptions> >
166 _bindings;
4e5a4405 167
7491a29f 168 std::list<ProbeSelector> _probe_selectors;
dd048a7e 169 std::vector<pv::widgets::DecoderGroupBox*> _decoder_forms;
613d097c 170
dd048a7e 171 QSignalMapper _delete_mapper, _show_hide_mapper;
55d3603d
JH
172};
173
174} // namespace view
175} // namespace pv
176
b9329558 177#endif // PULSEVIEW_PV_VIEW_DECODETRACE_H