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