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