]> sigrok.org Git - pulseview.git/blame - pv/view/decodesignal.cpp
Update the viewport as new data is decoded
[pulseview.git] / pv / view / decodesignal.cpp
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
21extern "C" {
22#include <libsigrokdecode/libsigrokdecode.h>
23}
24
06bb4e6a
JH
25#include <extdef.h>
26
55d3603d
JH
27#include "decodesignal.h"
28
06bb4e6a 29#include <pv/sigsession.h>
119aff65 30#include <pv/data/decoder.h>
e0fc5810 31#include <pv/view/view.h>
9472f447 32#include <pv/view/decode/annotation.h>
119aff65 33
55d3603d
JH
34using namespace boost;
35using namespace std;
36
37namespace pv {
38namespace view {
39
06bb4e6a
JH
40const QColor DecodeSignal::DecodeColours[4] = {
41 QColor(0xEF, 0x29, 0x29), // Red
42 QColor(0xFC, 0xE9, 0x4F), // Yellow
43 QColor(0x8A, 0xE2, 0x34), // Green
44 QColor(0x72, 0x9F, 0xCF) // Blue
45};
46
119aff65 47DecodeSignal::DecodeSignal(pv::SigSession &session,
06bb4e6a 48 boost::shared_ptr<pv::data::Decoder> decoder, int index) :
119aff65
JH
49 Trace(session, QString(decoder->get_decoder()->name)),
50 _decoder(decoder)
55d3603d 51{
e0fc5810
JH
52 assert(_decoder);
53
06bb4e6a 54 _colour = DecodeColours[index % countof(DecodeColours)];
9cef9567
JH
55
56 connect(_decoder.get(), SIGNAL(new_decode_data()),
57 this, SLOT(on_new_decode_data()));
55d3603d
JH
58}
59
82c7f640
JH
60void DecodeSignal::init_context_bar_actions(QWidget *parent)
61{
62 (void)parent;
63}
64
55d3603d
JH
65bool DecodeSignal::enabled() const
66{
67 return true;
68}
69
e0fc5810
JH
70void DecodeSignal::set_view(pv::view::View *view)
71{
72 assert(view);
73 Trace::set_view(view);
74}
75
fe08b6e8
JH
76void DecodeSignal::paint_back(QPainter &p, int left, int right)
77{
78 paint_axis(p, get_y(), left, right);
79}
80
81void DecodeSignal::paint_mid(QPainter &p, int left, int right)
55d3603d 82{
9472f447
JH
83 using namespace pv::view::decode;
84
85 assert(_view);
fe08b6e8 86 const int y = get_y();
9472f447
JH
87
88 const double scale = _view->scale();
89 assert(scale > 0);
90
91 double samplerate = _decoder->get_samplerate();
92
93 // Show sample rate as 1Hz when it is unknown
94 if (samplerate == 0.0)
95 samplerate = 1.0;
96
97 const double pixels_offset = (_view->offset() -
98 _decoder->get_start_time()) / scale;
99 const double samples_per_pixel = samplerate * scale;
100
101 assert(_decoder);
102 vector< shared_ptr<Annotation> > annotations(_decoder->annotations());
103 BOOST_FOREACH(shared_ptr<Annotation> a, annotations) {
104 assert(a);
1ae79b11
JH
105 a->paint(p, _colour, _colour.darker(), get_text_colour(),
106 _text_size.height(), left, right, samples_per_pixel,
107 pixels_offset, y);
9472f447 108 }
55d3603d
JH
109}
110
111const list<QAction*> DecodeSignal::get_context_bar_actions()
112{
113 list<QAction*> actions;
114 return actions;
115}
116
9cef9567
JH
117void DecodeSignal::on_new_decode_data()
118{
119 if (_view)
120 _view->update_viewport();
121}
122
55d3603d
JH
123} // namespace view
124} // namespace pv