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