]> sigrok.org Git - pulseview.git/blob - pv/view/cursor.cpp
b854f2c4995be4a3f93a205f0b2c43c67bcbc534
[pulseview.git] / pv / view / cursor.cpp
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
23 #include "view.h"
24
25 #include <QBrush>
26 #include <QPainter>
27 #include <QRect>
28 #include <QRectF>
29
30 namespace pv {
31 namespace view {
32
33 const QColor Cursor::LineColour(32, 74, 135);
34 const QColor Cursor::FillColour(52, 101, 164);
35 const QColor Cursor::HighlightColour(83, 130, 186);
36 const QColor Cursor::TextColour(Qt::white);
37
38 const int Cursor::Size = 12;
39 const int Cursor::Offset = 1;
40
41 Cursor::Cursor(const View &view, double time) :
42         TimeMarker(view, LineColour, time)
43 {
44 }
45
46 QRectF Cursor::get_label_rect(const QRect &rect) const
47 {
48         const float x = (_time - _view.offset()) / _view.scale();
49         return QRectF(x - Size/2, rect.height() - Size - Offset,
50                 Size, Size);
51 }
52
53 void Cursor::paint_label(QPainter &p, const QRect &rect)
54 {
55         const QRectF r(get_label_rect(rect));
56
57         p.setPen(LineColour);
58         p.setBrush(QBrush(FillColour));
59         p.drawEllipse(r);
60
61         p.setPen(HighlightColour);
62         p.setBrush(QBrush());
63         p.drawEllipse(r.adjusted(1, 1, -1, -1));
64 }
65
66 } // namespace view
67 } // namespace pv