]> sigrok.org Git - pulseview.git/blob - pv/views/trace/triggermarker.cpp
Show relative time of flags on hover
[pulseview.git] / pv / views / trace / 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, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "triggermarker.hpp"
21 #include "view.hpp"
22
23 namespace pv {
24 namespace views {
25 namespace trace {
26
27 const QColor TriggerMarker::Color(0x00, 0x00, 0xB0);
28
29 TriggerMarker::TriggerMarker(View &view, const pv::util::Timestamp& time) :
30         TimeItem(view),
31         time_(time)
32 {
33 }
34
35 TriggerMarker::TriggerMarker(const TriggerMarker &marker) :
36         TimeItem(marker.view_),
37         time_(marker.time_)
38 {
39 }
40
41 bool TriggerMarker::enabled() const
42 {
43         return true;
44 }
45
46 bool TriggerMarker::is_draggable(QPoint pos) const
47 {
48         (void)pos;
49         return false;
50 }
51
52 void TriggerMarker::set_time(const pv::util::Timestamp& time)
53 {
54         time_ = time;
55         view_.time_item_appearance_changed(true, true);
56 }
57
58 const pv::util::Timestamp TriggerMarker::time() const
59 {
60         return time_;
61 }
62
63 float TriggerMarker::get_x() const
64 {
65         return ((time_ - view_.offset()) / view_.scale()).convert_to<float>();
66 }
67
68 const pv::util::Timestamp TriggerMarker::delta(const pv::util::Timestamp& other) const
69 {
70         return other - time_;
71 }
72
73 QPoint TriggerMarker::drag_point(const QRect &rect) const
74 {
75         (void)rect;
76
77         // The trigger marker cannot be moved, so there is no drag point
78         return QPoint(INT_MIN, INT_MIN);
79 }
80
81 void TriggerMarker::paint_fore(QPainter &p, ViewItemPaintParams &pp)
82 {
83         if (!enabled())
84                 return;
85
86         QPen pen(Color);
87         pen.setStyle(Qt::DashLine);
88
89         const float x = get_x();
90         p.setPen(pen);
91         p.drawLine(QPointF(x, pp.top()), QPointF(x, pp.bottom()));
92 }
93
94 } // namespace trace
95 } // namespace views
96 } // namespace pv