From 1fff13ac8d4340945657cf9622a5e2cf1ccf0bdd Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 30 Nov 2014 16:16:10 +0000 Subject: [PATCH] WIP: Flag: Added time marker flags --- CMakeLists.txt | 2 ++ pv/view/cursorheader.cpp | 10 +++++++ pv/view/cursorheader.hpp | 2 ++ pv/view/flag.cpp | 51 +++++++++++++++++++++++++++++++++++ pv/view/flag.hpp | 58 ++++++++++++++++++++++++++++++++++++++++ pv/view/view.cpp | 11 ++++++++ pv/view/view.hpp | 13 +++++++++ 7 files changed, 147 insertions(+) create mode 100644 pv/view/flag.cpp create mode 100644 pv/view/flag.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 835d09bb..8997f4f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,6 +168,7 @@ set(pulseview_SOURCES pv/view/cursor.cpp pv/view/cursorheader.cpp pv/view/cursorpair.cpp + pv/view/flag.cpp pv/view/header.cpp pv/view/marginwidget.cpp pv/view/logicsignal.cpp @@ -212,6 +213,7 @@ set(pulseview_HEADERS pv/toolbars/samplingbar.hpp pv/view/cursor.hpp pv/view/cursorheader.hpp + pv/view/flag.hpp pv/view/header.hpp pv/view/logicsignal.hpp pv/view/marginwidget.hpp diff --git a/pv/view/cursorheader.cpp b/pv/view/cursorheader.cpp index 6a0894c1..06dc251b 100644 --- a/pv/view/cursorheader.cpp +++ b/pv/view/cursorheader.cpp @@ -78,6 +78,11 @@ void CursorHeader::paintEvent(QPaintEvent*) // Draw the trigger marker view_.trigger_marker().paint_label(p, r); + // Draw the flags + std::vector flags(view_.flags()); + for (Flag &f : flags) + f.paint_label(p, r); + // Draw the cursors if (view_.cursors_shown()) view_.cursors().draw_markers(p, r); @@ -141,5 +146,10 @@ void CursorHeader::mouseReleaseEvent(QMouseEvent *) grabbed_marker_.reset(); } +void CursorHeader::mouseDoubleClickEvent(QMouseEvent *e) +{ + view_.add_flag(view_.offset() + ((double)e->x() + 0.5) * view_.scale()); +} + } // namespace view } // namespace pv diff --git a/pv/view/cursorheader.hpp b/pv/view/cursorheader.hpp index 90a000f1..ac1aa3eb 100644 --- a/pv/view/cursorheader.hpp +++ b/pv/view/cursorheader.hpp @@ -59,6 +59,8 @@ class CursorHeader : public MarginWidget void mousePressEvent(QMouseEvent *e); void mouseReleaseEvent(QMouseEvent *); + void mouseDoubleClickEvent(QMouseEvent *e); + int calculateTextHeight(); std::weak_ptr grabbed_marker_; diff --git a/pv/view/flag.cpp b/pv/view/flag.cpp new file mode 100644 index 00000000..4359950f --- /dev/null +++ b/pv/view/flag.cpp @@ -0,0 +1,51 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2014 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 "triggermarker.hpp" +#include "view.hpp" + +#include + +#include + +using std::shared_ptr; + +namespace pv { +namespace view { + +const QColor Flag::FillColour(0x73, 0xD2, 0x16); + +Flag::Flag(View &view, double time) : + TimeMarker(view, FillColour, time) +{ +} + +Flag::Flag(const Flag &flag) : + TimeMarker(flag.view_, FillColour, flag.time_) +{ +} + +QString Flag::get_text() const +{ + return ""; +} + +} // namespace view +} // namespace pv diff --git a/pv/view/flag.hpp b/pv/view/flag.hpp new file mode 100644 index 00000000..180870a5 --- /dev/null +++ b/pv/view/flag.hpp @@ -0,0 +1,58 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2014 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_FLAG_H +#define PULSEVIEW_PV_VIEW_FLAG_H + +#include "timemarker.hpp" + +namespace pv { +namespace view { + +class Flag : public TimeMarker +{ + Q_OBJECT + +public: + static const QColor FillColour; + +public: + /** + * Constructor. + * @param view A reference to the view that owns this cursor pair. + * @param time The time to set the flag to. + */ + Flag(View &view, double time); + + /** + * Copy constructor. + */ + Flag(const Flag &flag); + + /** + * Gets the text to show in the marker. + */ + QString get_text() const; +}; + +} // namespace view +} // namespace pv + +#endif // PULSEVIEW_PV_VIEW_FLAG_H diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 4de08d5d..2e119860 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -371,6 +371,17 @@ const CursorPair& View::cursors() const return cursors_; } +void View::add_flag(double time) +{ + flags_.push_back(Flag(*this, time)); + appearance_changed(false, true); +} + +const std::vector& View::flags() const +{ + return flags_; +} + const QPoint& View::hover_point() const { return hover_point_; diff --git a/pv/view/view.hpp b/pv/view/view.hpp index e9f734d7..f04b27f3 100644 --- a/pv/view/view.hpp +++ b/pv/view/view.hpp @@ -35,6 +35,7 @@ #include #include "cursorpair.hpp" +#include "flag.hpp" #include "rowitemowner.hpp" #include "triggermarker.hpp" @@ -167,6 +168,16 @@ class View : public QAbstractScrollArea, public RowItemOwner { */ const CursorPair& cursors() const; + /** + * Adds a new flag at a specified time. + */ + void add_flag(double time); + + /** + * Gets the list of flags. + */ + const std::vector& flags() const; + const QPoint& hover_point() const; void update_viewport(); @@ -284,6 +295,8 @@ private Q_SLOTS: bool show_cursors_; CursorPair cursors_; + std::vector flags_; + QPoint hover_point_; unsigned int sticky_events_;