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