]> sigrok.org Git - pulseview.git/blob - pv/view/triggermarker.cpp
9be3285510d89c866b8717ae82e36115129266f2
[pulseview.git] / pv / view / triggermarker.cpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2014 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 #include "triggermarker.hpp"
22 #include "view.hpp"
23
24 namespace pv {
25 namespace views {
26 namespace TraceView {
27
28 const QColor TriggerMarker::Colour(0x00, 0x00, 0xB0);
29
30 TriggerMarker::TriggerMarker(View &view, const pv::util::Timestamp& time) :
31         TimeItem(view),
32         time_(time)
33 {
34 }
35
36 TriggerMarker::TriggerMarker(const TriggerMarker &marker) :
37         TimeItem(marker.view_),
38         time_(marker.time_)
39 {
40 }
41
42 bool TriggerMarker::enabled() const
43 {
44         return true;
45 }
46
47 bool TriggerMarker::is_draggable() const
48 {
49         return false;
50 }
51
52 void TriggerMarker::set_time(const pv::util::Timestamp& time)
53 {
54         time_ = time;
55
56         view_.time_item_appearance_changed(true, true);
57 }
58
59 float TriggerMarker::get_x() const
60 {
61         return ((time_ - view_.offset()) / view_.scale()).convert_to<float>();
62 }
63
64 QPoint TriggerMarker::point(const QRect &rect) const
65 {
66         return QPoint(get_x(), rect.bottom());
67 }
68
69 void TriggerMarker::paint_fore(QPainter &p, const ViewItemPaintParams &pp)
70 {
71         if (!enabled())
72                 return;
73
74         QPen pen(Colour);
75         pen.setStyle(Qt::DashLine);
76
77         const float x = get_x();
78         p.setPen(pen);
79         p.drawLine(QPointF(x, pp.top()), QPointF(x, pp.bottom()));
80 }
81
82 } // namespace TraceView
83 } // namespace views
84 } // namespace pv