2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
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
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);
44 const int Cursor::Size = 12;
45 const int Cursor::Offset = 1;
47 const int Cursor::ArrowSize = 4;
49 Cursor::Cursor(const View &view, double time) :
50 TimeMarker(view, LineColour, time)
54 QRectF Cursor::get_label_rect(const QRect &rect) const
56 const float x = (_time - _view.offset()) / _view.scale();
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);
66 void Cursor::paint_label(QPainter &p, const QRect &rect,
69 compute_text_size(p, prefix);
70 const QRectF r(get_label_rect(rect));
72 const float h_centre = (r.left() + r.right()) / 2;
73 const QPointF points[] = {
75 QPointF(r.right(), r.bottom()),
76 QPointF(h_centre + ArrowSize, r.bottom()),
77 QPointF(h_centre, rect.bottom()),
78 QPointF(h_centre - ArrowSize, r.bottom()),
79 QPointF(r.left(), r.bottom()),
83 const QPointF highlight_points[] = {
84 QPointF(r.right() - 1, r.top() + 1),
85 QPointF(r.right() - 1, r.bottom() - 1),
86 QPointF(h_centre + ArrowSize - 1, r.bottom() - 1),
87 QPointF(h_centre, rect.bottom() - 1),
88 QPointF(h_centre - ArrowSize + 1, r.bottom() - 1),
89 QPointF(r.left() + 1, r.bottom() - 1),
90 QPointF(r.left() + 1, r.top() + 1),
93 p.setPen(Qt::transparent);
94 p.setBrush(FillColour);
95 p.drawPolygon(points, countof(points));
97 p.setPen(HighlightColour);
98 p.setBrush(Qt::transparent);
99 p.drawPolygon(highlight_points, countof(highlight_points));
101 p.setPen(LineColour);
102 p.setBrush(Qt::transparent);
103 p.drawPolygon(points, countof(points));
105 p.setPen(TextColour);
106 p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter,
107 Ruler::format_time(_time, prefix, 2));
110 void Cursor::compute_text_size(QPainter &p, unsigned int prefix)
112 _text_size = p.boundingRect(QRectF(), 0,
113 Ruler::format_time(_time, prefix, 2)).size();