]> sigrok.org Git - pulseview.git/blob - pv/view/decodesignal.cpp
Improved annotation painting
[pulseview.git] / pv / view / decodesignal.cpp
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
21 extern "C" {
22 #include <libsigrokdecode/libsigrokdecode.h>
23 }
24
25 #include "decodesignal.h"
26
27 #include <pv/data/decoder.h>
28 #include <pv/view/view.h>
29 #include <pv/view/decode/annotation.h>
30
31 using namespace boost;
32 using namespace std;
33
34 namespace pv {
35 namespace view {
36
37 DecodeSignal::DecodeSignal(pv::SigSession &session,
38         boost::shared_ptr<pv::data::Decoder> decoder) :
39         Trace(session, QString(decoder->get_decoder()->name)),
40         _decoder(decoder)
41 {
42         assert(_decoder);
43
44         _colour = Qt::red;
45 }
46
47 void DecodeSignal::init_context_bar_actions(QWidget *parent)
48 {
49         (void)parent;
50 }
51
52 bool DecodeSignal::enabled() const
53 {
54         return true;
55 }
56
57 void DecodeSignal::set_view(pv::view::View *view)
58 {
59         assert(view);
60         Trace::set_view(view);
61 }
62
63 void DecodeSignal::paint_back(QPainter &p, int left, int right)
64 {
65         paint_axis(p, get_y(), left, right);
66 }
67
68 void DecodeSignal::paint_mid(QPainter &p, int left, int right)
69 {
70         using namespace pv::view::decode;
71
72         assert(_view);
73         const int y = get_y();
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);
92                 a->paint(p, _colour, _colour.darker(), get_text_colour(),
93                         _text_size.height(), left, right, samples_per_pixel,
94                         pixels_offset, y);
95         }
96 }
97
98 const list<QAction*> DecodeSignal::get_context_bar_actions()
99 {
100         list<QAction*> actions;
101         return actions;
102 }
103
104 } // namespace view
105 } // namespace pv