]> sigrok.org Git - pulseview.git/blame - pv/view/decodesignal.cpp
Improved annotation painting
[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
25#include "decodesignal.h"
26
119aff65 27#include <pv/data/decoder.h>
e0fc5810 28#include <pv/view/view.h>
9472f447 29#include <pv/view/decode/annotation.h>
119aff65 30
55d3603d
JH
31using namespace boost;
32using namespace std;
33
34namespace pv {
35namespace view {
36
119aff65
JH
37DecodeSignal::DecodeSignal(pv::SigSession &session,
38 boost::shared_ptr<pv::data::Decoder> decoder) :
39 Trace(session, QString(decoder->get_decoder()->name)),
40 _decoder(decoder)
55d3603d 41{
e0fc5810
JH
42 assert(_decoder);
43
55d3603d
JH
44 _colour = Qt::red;
45}
46
82c7f640
JH
47void DecodeSignal::init_context_bar_actions(QWidget *parent)
48{
49 (void)parent;
50}
51
55d3603d
JH
52bool DecodeSignal::enabled() const
53{
54 return true;
55}
56
e0fc5810
JH
57void DecodeSignal::set_view(pv::view::View *view)
58{
59 assert(view);
60 Trace::set_view(view);
61}
62
fe08b6e8
JH
63void DecodeSignal::paint_back(QPainter &p, int left, int right)
64{
65 paint_axis(p, get_y(), left, right);
66}
67
68void DecodeSignal::paint_mid(QPainter &p, int left, int right)
55d3603d 69{
9472f447
JH
70 using namespace pv::view::decode;
71
72 assert(_view);
fe08b6e8 73 const int y = get_y();
9472f447
JH
74
75 const double scale = _view->scale();
76 assert(scale > 0);
77
78 double samplerate = _decoder->get_samplerate();
79
80 // Show sample rate as 1Hz when it is unknown
81 if (samplerate == 0.0)
82 samplerate = 1.0;
83
84 const double pixels_offset = (_view->offset() -
85 _decoder->get_start_time()) / scale;
86 const double samples_per_pixel = samplerate * scale;
87
88 assert(_decoder);
89 vector< shared_ptr<Annotation> > annotations(_decoder->annotations());
90 BOOST_FOREACH(shared_ptr<Annotation> a, annotations) {
91 assert(a);
1ae79b11
JH
92 a->paint(p, _colour, _colour.darker(), get_text_colour(),
93 _text_size.height(), left, right, samples_per_pixel,
94 pixels_offset, y);
9472f447 95 }
55d3603d
JH
96}
97
98const list<QAction*> DecodeSignal::get_context_bar_actions()
99{
100 list<QAction*> actions;
101 return actions;
102}
103
104} // namespace view
105} // namespace pv