]> sigrok.org Git - pulseview.git/blame - pv/views/trace/triggermarker.cpp
Session: Fix issue #67 by improving error handling
[pulseview.git] / pv / views / trace / triggermarker.cpp
CommitLineData
51ae69ae
TS
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
efdec55a 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
51ae69ae
TS
18 */
19
20#include "triggermarker.hpp"
21#include "view.hpp"
22
23namespace pv {
f4e57597 24namespace views {
1573bf16 25namespace trace {
51ae69ae 26
641574bc 27const QColor TriggerMarker::Color(0x00, 0x00, 0xB0);
51ae69ae
TS
28
29TriggerMarker::TriggerMarker(View &view, const pv::util::Timestamp& time) :
30 TimeItem(view),
31 time_(time)
32{
33}
34
35TriggerMarker::TriggerMarker(const TriggerMarker &marker) :
36 TimeItem(marker.view_),
37 time_(marker.time_)
38{
39}
40
41bool TriggerMarker::enabled() const
42{
43 return true;
44}
45
119c5c23 46bool TriggerMarker::is_draggable(QPoint pos) const
51ae69ae 47{
119c5c23 48 (void)pos;
51ae69ae
TS
49 return false;
50}
51
52void TriggerMarker::set_time(const pv::util::Timestamp& time)
53{
54 time_ = time;
9f094349 55
51ae69ae
TS
56 view_.time_item_appearance_changed(true, true);
57}
58
710c2a18 59const pv::util::Timestamp TriggerMarker::time() const
60{
61 return time_;
62}
63
51ae69ae
TS
64float TriggerMarker::get_x() const
65{
66 return ((time_ - view_.offset()) / view_.scale()).convert_to<float>();
67}
68
a3d5a7c7 69QPoint TriggerMarker::drag_point(const QRect &rect) const
51ae69ae 70{
963be497
SA
71 (void)rect;
72
73 // The trigger marker cannot be moved, so there is no drag point
74 return QPoint(INT_MIN, INT_MIN);
51ae69ae
TS
75}
76
60938e04 77void TriggerMarker::paint_fore(QPainter &p, ViewItemPaintParams &pp)
51ae69ae
TS
78{
79 if (!enabled())
80 return;
81
641574bc 82 QPen pen(Color);
51ae69ae
TS
83 pen.setStyle(Qt::DashLine);
84
85 const float x = get_x();
86 p.setPen(pen);
87 p.drawLine(QPointF(x, pp.top()), QPointF(x, pp.bottom()));
88}
89
1573bf16 90} // namespace trace
f4e57597 91} // namespace views
51ae69ae 92} // namespace pv