]>
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 | ||
21 | #include "cursor.h" | |
22 | ||
3a6fe081 | 23 | #include "ruler.h" |
cabce982 JH |
24 | #include "view.h" |
25 | ||
26 | #include <QBrush> | |
27 | #include <QPainter> | |
34c1ef02 | 28 | #include <QPointF> |
cabce982 JH |
29 | #include <QRect> |
30 | #include <QRectF> | |
31 | ||
34c1ef02 JH |
32 | #include <stdio.h> |
33 | ||
34 | #include <extdef.h> | |
35 | ||
cabce982 JH |
36 | namespace pv { |
37 | namespace view { | |
38 | ||
39 | const QColor Cursor::LineColour(32, 74, 135); | |
40 | const QColor Cursor::FillColour(52, 101, 164); | |
41 | const QColor Cursor::HighlightColour(83, 130, 186); | |
42 | const QColor Cursor::TextColour(Qt::white); | |
43 | ||
cabce982 JH |
44 | const int Cursor::Offset = 1; |
45 | ||
34c1ef02 JH |
46 | const int Cursor::ArrowSize = 4; |
47 | ||
96d3ad83 JH |
48 | Cursor::Cursor(const View &view, double time, Cursor &other) : |
49 | TimeMarker(view, LineColour, time), | |
50 | _other(other) | |
cabce982 JH |
51 | { |
52 | } | |
53 | ||
ca4ec3ea | 54 | QRectF Cursor::get_label_rect(const QRect &rect) const |
cabce982 JH |
55 | { |
56 | const float x = (_time - _view.offset()) / _view.scale(); | |
34c1ef02 JH |
57 | |
58 | const QSizeF label_size( | |
59 | _text_size.width() + View::LabelPadding.width() * 2, | |
60 | _text_size.height() + View::LabelPadding.height() * 2); | |
61 | return QRectF(x - label_size.width() / 2 - 0.5f, | |
62 | rect.height() - label_size.height() - Offset - ArrowSize - 0.5f, | |
63 | label_size.width() + 1, label_size.height() + 1); | |
ca4ec3ea JH |
64 | } |
65 | ||
3a6fe081 JH |
66 | void Cursor::paint_label(QPainter &p, const QRect &rect, |
67 | unsigned int prefix) | |
ca4ec3ea | 68 | { |
3a6fe081 | 69 | compute_text_size(p, prefix); |
ca4ec3ea | 70 | const QRectF r(get_label_rect(rect)); |
cabce982 | 71 | |
96d3ad83 JH |
72 | if (_time > _other.time()) |
73 | { | |
74 | const QPointF points[] = { | |
75 | r.topLeft(), | |
76 | r.topRight(), | |
77 | r.bottomRight(), | |
78 | QPointF(r.left() + ArrowSize, r.bottom()), | |
79 | QPointF(r.left(), rect.bottom()), | |
80 | }; | |
81 | ||
82 | const QPointF highlight_points[] = { | |
83 | QPointF(r.left() + 1, r.top() + 1), | |
84 | QPointF(r.right() - 1, r.top() + 1), | |
85 | QPointF(r.right() - 1, r.bottom() - 1), | |
86 | QPointF(r.left() + ArrowSize - 1, r.bottom() - 1), | |
87 | QPointF(r.left() + 1, rect.bottom() - 1), | |
88 | }; | |
89 | ||
90 | p.setPen(Qt::transparent); | |
91 | p.setBrush(FillColour); | |
92 | p.drawPolygon(points, countof(points)); | |
93 | ||
94 | p.setPen(HighlightColour); | |
95 | p.setBrush(Qt::transparent); | |
96 | p.drawPolygon(highlight_points, countof(highlight_points)); | |
97 | ||
98 | p.setPen(LineColour); | |
99 | p.setBrush(Qt::transparent); | |
100 | p.drawPolygon(points, countof(points)); | |
101 | } | |
102 | else | |
103 | { | |
104 | const QPointF points[] = { | |
105 | r.topRight(), | |
106 | r.topLeft(), | |
107 | r.bottomLeft(), | |
108 | QPointF(r.right() - ArrowSize, r.bottom()), | |
109 | QPointF(r.right(), rect.bottom()), | |
110 | }; | |
111 | ||
112 | const QPointF highlight_points[] = { | |
113 | QPointF(r.right() - 1, r.top() + 1), | |
114 | QPointF(r.left() + 1, r.top() + 1), | |
115 | QPointF(r.left() + 1, r.bottom() - 1), | |
116 | QPointF(r.right() - ArrowSize + 1, r.bottom() - 1), | |
117 | QPointF(r.right() - 1, rect.bottom() - 1), | |
118 | }; | |
119 | ||
120 | p.setPen(Qt::transparent); | |
121 | p.setBrush(FillColour); | |
122 | p.drawPolygon(points, countof(points)); | |
123 | ||
124 | p.setPen(HighlightColour); | |
125 | p.setBrush(Qt::transparent); | |
126 | p.drawPolygon(highlight_points, countof(highlight_points)); | |
127 | ||
128 | p.setPen(LineColour); | |
129 | p.setBrush(Qt::transparent); | |
130 | p.drawPolygon(points, countof(points)); | |
131 | } | |
34c1ef02 JH |
132 | |
133 | p.setPen(TextColour); | |
3a6fe081 JH |
134 | p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter, |
135 | Ruler::format_time(_time, prefix, 2)); | |
34c1ef02 JH |
136 | } |
137 | ||
3a6fe081 | 138 | void Cursor::compute_text_size(QPainter &p, unsigned int prefix) |
34c1ef02 | 139 | { |
3a6fe081 JH |
140 | _text_size = p.boundingRect(QRectF(), 0, |
141 | Ruler::format_time(_time, prefix, 2)).size(); | |
cabce982 JH |
142 | } |
143 | ||
144 | } // namespace view | |
145 | } // namespace pv |