]>
Commit | Line | Data |
---|---|---|
cabce982 JH |
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 | ||
2acdb232 | 21 | #include "cursor.hpp" |
cabce982 | 22 | |
3ccf0f7f | 23 | #include "ruler.hpp" |
2acdb232 JH |
24 | #include "view.hpp" |
25 | #include "pv/util.hpp" | |
cabce982 | 26 | |
4fabd61a | 27 | #include <QApplication> |
cabce982 JH |
28 | #include <QBrush> |
29 | #include <QPainter> | |
34c1ef02 | 30 | #include <QPointF> |
cabce982 JH |
31 | #include <QRect> |
32 | #include <QRectF> | |
33 | ||
f9abf97e JH |
34 | #include <cassert> |
35 | #include <cstdio> | |
e899d8bd | 36 | #include <limits> |
34c1ef02 | 37 | |
e899d8bd | 38 | using std::abs; |
f9abf97e | 39 | using std::shared_ptr; |
e899d8bd | 40 | using std::numeric_limits; |
58864c5c | 41 | |
cabce982 | 42 | namespace pv { |
f4e57597 SA |
43 | namespace views { |
44 | namespace TraceView { | |
cabce982 | 45 | |
cabce982 | 46 | const QColor Cursor::FillColour(52, 101, 164); |
34c1ef02 | 47 | |
8debe10d | 48 | Cursor::Cursor(View &view, double time) : |
4fabd61a | 49 | TimeMarker(view, FillColour, time) |
cabce982 JH |
50 | { |
51 | } | |
52 | ||
096fb584 JH |
53 | bool Cursor::enabled() const |
54 | { | |
55 | return view_.cursors_shown(); | |
56 | } | |
57 | ||
3b84fd6d JH |
58 | QString Cursor::get_text() const |
59 | { | |
3ccf0f7f JS |
60 | const shared_ptr<Cursor> other = get_other_cursor(); |
61 | const pv::util::Timestamp& diff = abs(time_ - other->time_); | |
62 | ||
63 | return Ruler::format_time_with_distance( | |
64 | diff, time_, view_.tick_prefix(), view_.time_unit(), view_.tick_precision()); | |
3b84fd6d JH |
65 | } |
66 | ||
689dea92 | 67 | QRectF Cursor::label_rect(const QRectF &rect) const |
cabce982 | 68 | { |
58864c5c JH |
69 | const shared_ptr<Cursor> other(get_other_cursor()); |
70 | assert(other); | |
71 | ||
60d9b99a | 72 | const float x = ((time_ - view_.offset())/ view_.scale()).convert_to<float>(); |
34c1ef02 | 73 | |
4fabd61a | 74 | QFontMetrics m(QApplication::font()); |
3b84fd6d | 75 | QSize text_size = m.boundingRect(get_text()).size(); |
4fabd61a | 76 | |
34c1ef02 | 77 | const QSizeF label_size( |
ec39632d JH |
78 | text_size.width() + LabelPadding.width() * 2, |
79 | text_size.height() + LabelPadding.height() * 2); | |
199441e4 | 80 | const float top = rect.height() - label_size.height() - |
6abffa97 | 81 | TimeMarker::ArrowSize - 0.5f; |
5139748b | 82 | const float height = label_size.height(); |
199441e4 | 83 | |
60d9b99a JS |
84 | const pv::util::Timestamp& other_time = other->time(); |
85 | ||
e899d8bd | 86 | if (time_ > other_time || |
60d9b99a | 87 | (abs(time_ - other_time).is_zero() && this > other.get())) |
199441e4 JH |
88 | return QRectF(x, top, label_size.width(), height); |
89 | else | |
60d9b99a | 90 | return QRectF(x - label_size.width(), top, label_size.width(), height); |
ca4ec3ea JH |
91 | } |
92 | ||
58864c5c JH |
93 | shared_ptr<Cursor> Cursor::get_other_cursor() const |
94 | { | |
5c5ce757 JH |
95 | const shared_ptr<CursorPair> cursors(view_.cursors()); |
96 | assert(cursors); | |
97 | return (cursors->first().get() == this) ? | |
98 | cursors->second() : cursors->first(); | |
58864c5c JH |
99 | } |
100 | ||
f4e57597 SA |
101 | } // namespace TraceView |
102 | } // namespace views | |
cabce982 | 103 | } // namespace pv |