From: Joel Holdsworth Date: Sun, 28 Oct 2012 16:47:09 +0000 (+0000) Subject: Added Cursor class X-Git-Tag: pulseview-0.1.0~233 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cabce9821fd09aeeac7f0986193a1656d8b01fe5;p=pulseview.git Added Cursor class --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f8665f7..ee79db21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,7 @@ set(pulseview_SOURCES pv/signaldata.cpp pv/sigsession.cpp pv/signal.cpp + pv/view/cursor.cpp pv/view/header.cpp pv/view/ruler.cpp pv/view/timemarker.cpp diff --git a/pv/view/cursor.cpp b/pv/view/cursor.cpp new file mode 100644 index 00000000..3ae5f58a --- /dev/null +++ b/pv/view/cursor.cpp @@ -0,0 +1,62 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "cursor.h" + +#include "view.h" + +#include +#include +#include +#include + +namespace pv { +namespace view { + +const QColor Cursor::LineColour(32, 74, 135); +const QColor Cursor::FillColour(52, 101, 164); +const QColor Cursor::HighlightColour(83, 130, 186); +const QColor Cursor::TextColour(Qt::white); + +const int Cursor::Size = 12; +const int Cursor::Offset = 1; + +Cursor::Cursor(const View &view, double time) : + TimeMarker(view, LineColour, time) +{ +} + +void Cursor::paint_label(QPainter &p, const QRect &rect) +{ + const float x = (_time - _view.offset()) / _view.scale(); + const QRectF r(x - Size/2, rect.height() - Size - Offset, + Size, Size); + + p.setPen(LineColour); + p.setBrush(QBrush(FillColour)); + p.drawEllipse(r); + + p.setPen(HighlightColour); + p.setBrush(QBrush()); + p.drawEllipse(r.adjusted(1, 1, -1, -1)); +} + +} // namespace view +} // namespace pv diff --git a/pv/view/cursor.h b/pv/view/cursor.h new file mode 100644 index 00000000..a982c05e --- /dev/null +++ b/pv/view/cursor.h @@ -0,0 +1,59 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PULSEVIEW_PV_VIEW_CURSOR_H +#define PULSEVIEW_PV_VIEW_CURSOR_H + +#include "timemarker.h" + +namespace pv { +namespace view { + +class Cursor : public TimeMarker +{ +private: + static const QColor LineColour; + static const QColor FillColour; + static const QColor HighlightColour; + + static const int Size; + static const int Offset; + +public: + /** + * Constructor. + * @param colour A reference to the colour of this cursor. + * @param time The time to set the flag to. + */ + Cursor(const View &view, double time); + +public: + /** + * Paints the cursor's label to the ruler. + * @param p The painter to draw with. + * @param rect The rectangle of the ruler client area. + */ + void paint_label(QPainter &p, const QRect &rect); +}; + +} // namespace view +} // namespace pv + +#endif // PULSEVIEW_PV_VIEW_CURSOR_H \ No newline at end of file